Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Oct 12, 2023
1 parent 91637f1 commit 68e140a
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 54 deletions.
5 changes: 5 additions & 0 deletions base/empty-like/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ tape( 'the function throws an error if provided a value having an unrecognized d
function noop() {},
{
'data': true
},
{
'shape': [ 1, 2, 3 ],
'order': 'row-major',
'dtype': 'foo_bar_beep_boop'
}
];

Expand Down
25 changes: 25 additions & 0 deletions base/expand-dimensions/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ tape( 'main export is a function', function test( t ) {
t.end();
});

tape( 'the function throws an error if provided an invalid `axis` argument', function test( t ) {
var values;
var x;
var i;

x = array( [ [ 1, 2 ], [ 3, 4 ] ] );

values = [
10,
-10,
99,
-99
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
return function badValue() {
expandDimensions( x, value );
};
}
});

tape( 'the function prepends singleton dimensions', function test( t ) {
var x;
var y;
Expand Down
5 changes: 5 additions & 0 deletions base/zeros-like/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ tape( 'the function throws an error if provided a value having an unrecognized d
function noop() {},
{
'data': true
},
{
'shape': [ 1, 2, 3 ],
'order': 'row-major',
'dtype': 'foo_bar_beep_boop'
}
];

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions empty-like/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ function emptyLike( x ) {
ndims = sh.length;
if ( ndims > 0 ) {
len = numel( sh );
if ( len < 0 ) {
len = 0; // note: we should only get here if an inferred shape is invalid (i.e., contains negative dimension sizes)
}
st = shape2strides( sh, order );
} else {
// For 0-dimensional arrays, the buffer should contain a single element...
Expand Down
3 changes: 2 additions & 1 deletion iter/columns/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var isReadOnly = require( './../../../base/assert/is-read-only' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var getShape = require( './../../../shape' );
var numel = require( './../../../base/numel' );
var slice = require( './../../../base/slice' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
Expand Down Expand Up @@ -114,7 +115,7 @@ function nditerColumns( x ) {
}
}
// Retrieve input array meta data:
shape = x.shape;
shape = getShape( x );
ndims = shape.length;

// Ensure that the input array has sufficient dimensions...
Expand Down
10 changes: 3 additions & 7 deletions iter/entries/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
var getShape = require( './../../../shape' );
var numel = require( './../../../base/numel' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
var format = require( '@stdlib/string/format' );
Expand Down Expand Up @@ -74,7 +74,6 @@ function nditerEntries( x ) {
var FLG;
var idx;
var dim;
var sh;
var N;
var i;

Expand All @@ -97,14 +96,11 @@ function nditerEntries( x ) {
}
}
// Retrieve input array meta data:
shape = x.shape;
shape = getShape( x );
ndims = shape.length;

// Copy the input shape:
sh = copyIndexed( shape );

// Check whether the input array is empty...
N = numel( sh );
N = numel( shape );
if ( N === 0 ) {
FLG = true;
}
Expand Down
3 changes: 2 additions & 1 deletion iter/rows/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var isReadOnly = require( './../../../base/assert/is-read-only' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var getShape = require( './../../../shape' );
var numel = require( './../../../base/numel' );
var slice = require( './../../../base/slice' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
Expand Down Expand Up @@ -114,7 +115,7 @@ function nditerRows( x ) {
}
}
// Retrieve input array meta data:
shape = x.shape;
shape = getShape( x );
ndims = shape.length;

// Ensure that the input array has sufficient dimensions...
Expand Down
10 changes: 3 additions & 7 deletions iter/values/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
var getShape = require( './../../../shape' );
var numel = require( './../../../base/numel' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
var format = require( '@stdlib/string/format' );
Expand Down Expand Up @@ -74,7 +74,6 @@ function nditerValues( x ) {
var FLG;
var idx;
var dim;
var sh;
var N;
var i;

Expand All @@ -97,14 +96,11 @@ function nditerValues( x ) {
}
}
// Retrieve input array meta data:
shape = x.shape;
shape = getShape( x );
ndims = shape.length;

// Copy the input shape:
sh = copyIndexed( shape );

// Check whether the input array is empty...
N = numel( sh );
N = numel( shape );
if ( N === 0 ) {
FLG = true;
}
Expand Down
7 changes: 5 additions & 2 deletions slice-assign/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var isReadOnly = require( './../../base/assert/is-read-only' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var MultiSlice = require( '@stdlib/slice/multi' );
var base = require( './../../base/slice-assign' );
var getShape = require( './../../shape' );
var format = require( '@stdlib/string/format' );


Expand Down Expand Up @@ -105,6 +106,7 @@ function sliceAssign( x, y, s ) {
var nargs;
var opts;
var args;
var sh;
var S;
var i;

Expand All @@ -130,8 +132,9 @@ function sliceAssign( x, y, s ) {
}
opts.strict = options.strict;
}
if ( nargs === 2 && y.shape.length > 0 ) {
throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', y.shape.join( ',' ), 0 ) );
sh = getShape( y );
if ( nargs === 2 && sh.length > 0 ) {
throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', sh.join( ',' ), 0 ) );
}
}
if ( isMultiSlice( s ) ) {
Expand Down
7 changes: 5 additions & 2 deletions slice/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var MultiSlice = require( '@stdlib/slice/multi' );
var base = require( './../../base/slice' );
var getShape = require( './../../shape' );
var format = require( '@stdlib/string/format' );


Expand Down Expand Up @@ -87,6 +88,7 @@ function slice( x, s ) {
var nargs;
var opts;
var args;
var sh;
var S;
var i;

Expand All @@ -106,8 +108,9 @@ function slice( x, s ) {
}
opts.strict = options.strict;
}
if ( nargs === 1 && x.shape.length > 0 ) {
throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', x.shape.join( ',' ), 0 ) );
sh = getShape( x );
if ( nargs === 1 && sh.length > 0 ) {
throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', sh.join( ',' ), 0 ) );
}
}
if ( isMultiSlice( s ) ) {
Expand Down
15 changes: 4 additions & 11 deletions test/dist/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,20 +21,13 @@
// MODULES //

var tape = require( 'tape' );
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( './../../dist' );
var main = require( './../../dist' );


// TESTS //

tape( 'main export is an object', function test( t ) {
tape( 'main export is defined', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof ns, 'object', 'main export is an object' );
t.end();
});

tape( 'the exported object contains key-value pairs', function test( t ) {
var keys = objectKeys( ns );
t.equal( keys.length > 0, true, 'has keys' );
t.strictEqual( main !== void 0, true, 'main export is defined' );
t.end();
});
6 changes: 3 additions & 3 deletions to-array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ limitations under the License.
var ndarray2array = require( '@stdlib/ndarray/to-array' );
```

#### ndarray2array( arr )
#### ndarray2array( x )

Converts an [ndarray][@stdlib/ndarray/ctor] to a generic array (which may include nested arrays).

Expand All @@ -53,10 +53,10 @@ var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;

var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
var x = ndarray( 'generic', buffer, shape, strides, offset, order );
// returns <ndarray>

var out = ndarray2array( arr );
var out = ndarray2array( x );
// returns [ [ 1, 2 ], [ 3, 4 ] ]
```

Expand Down
4 changes: 2 additions & 2 deletions to-array/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{{alias}}( arr )
{{alias}}( x )
Converts an ndarray to a generic array.

Parameters
----------
arr: ndarray
x: ndarray
Input array.

Returns
Expand Down
4 changes: 2 additions & 2 deletions to-array/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ndarray } from '@stdlib/types/ndarray';
/**
* Converts an ndarray to a generic array (which may include nested arrays).
*
* @param arr - input ndarray
* @param x - input ndarray
* @returns array (which may include nested arrays)
*
* @example
Expand All @@ -35,7 +35,7 @@ import { ndarray } from '@stdlib/types/ndarray';
* var out = ndarray2array( arr );
* // returns [ [ 1, 2 ], [ 3, 4 ] ]
*/
declare function ndarray2array( array: ndarray ): Array<any>;
declare function ndarray2array( x: ndarray ): Array<any>;


// EXPORTS //
Expand Down
17 changes: 11 additions & 6 deletions to-array/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
// MODULES //

var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var format = require( '@stdlib/string/format' );
var toArray = require( './../../base/to-array' );
var getStrides = require( './../../strides' );
var getOffset = require( './../../offset' );
var getShape = require( './../../shape' );
var getOrder = require( './../../order' );
var getData = require( './../../data-buffer' );
var format = require( '@stdlib/string/format' );


// MAIN //

/**
* Converts an ndarray to a generic array (which may include nested arrays).
*
* @param {ndarrayLike} arr - input ndarray
* @param {ndarrayLike} x - input ndarray
* @throws {TypeError} must provide an ndarray
* @returns {(EmptyArray|Array|Array<Array>)} array (which may include nested arrays)
*
Expand All @@ -48,11 +53,11 @@ var toArray = require( './../../base/to-array' );
* var out = ndarray2array( arr );
* // returns [ [ 1, 2 ], [ 3, 4 ] ]
*/
function ndarray2array( arr ) {
if ( !isndarrayLike( arr ) ) {
throw new TypeError( format( 'invalid argument. Must provide an ndarray. Value: `%s`.', arr ) );
function ndarray2array( x ) {
if ( !isndarrayLike( x ) ) {
throw new TypeError( format( 'invalid argument. Must provide an ndarray. Value: `%s`.', x ) );
}
return toArray( arr.data, arr.shape, arr.strides, arr.offset, arr.order );
return toArray( getData( x ), getShape( x ), getStrides( x ), getOffset( x ), getOrder( x ) ); // eslint-disable-line max-len
}


Expand Down
3 changes: 0 additions & 3 deletions zeros-like/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ function zerosLike( x ) {
ndims = sh.length;
if ( ndims > 0 ) {
len = numel( sh );
if ( len < 0 ) {
len = 0; // note: we should only get here if an inferred shape is invalid (i.e., contains negative dimension sizes)
}
st = shape2strides( sh, order );
} else {
// For 0-dimensional arrays, the buffer should contain a single element...
Expand Down

0 comments on commit 68e140a

Please sign in to comment.