From 10e580403bf59ce515d0e954dfeb722080d00cd1 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 15:38:03 -0700 Subject: [PATCH 01/10] docs: fix typo --- .../@stdlib/slice/base/reduced-dimensions/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/slice/base/reduced-dimensions/lib/main.js b/lib/node_modules/@stdlib/slice/base/reduced-dimensions/lib/main.js index 012a7df5333..112f9d8f4ec 100644 --- a/lib/node_modules/@stdlib/slice/base/reduced-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/slice/base/reduced-dimensions/lib/main.js @@ -21,7 +21,7 @@ // MAIN // /** -* Returns a list of nreduced dimensions in an un-normalized multi-slice. +* Returns a list of reduced dimensions in an un-normalized multi-slice. * * @param {MultiSlice} slice - input slice * @returns {NonNegativeIntegerArray} list of reduced dimensions From 0c2ab4cb17253856ebe8fdc07a69032e04851693 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 16:55:15 -0700 Subject: [PATCH 02/10] refactor: use accessor utilities --- .../@stdlib/ndarray/array/lib/main.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/array/lib/main.js b/lib/node_modules/@stdlib/ndarray/array/lib/main.js index 07a6d5b33f0..039746f9947 100644 --- a/lib/node_modules/@stdlib/ndarray/array/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/array/lib/main.js @@ -36,7 +36,13 @@ var isOrder = require( '@stdlib/ndarray/base/assert/is-order' ); var isCastingMode = require( '@stdlib/ndarray/base/assert/is-casting-mode' ); var isAllowedCast = require( '@stdlib/ndarray/base/assert/is-allowed-data-type-cast' ); var createBuffer = require( '@stdlib/ndarray/base/buffer' ); -var getType = require( '@stdlib/ndarray/base/buffer-dtype' ); +var getBufferDType = require( '@stdlib/ndarray/base/buffer-dtype' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); var arrayShape = require( '@stdlib/array/shape' ); var flatten = require( '@stdlib/array/base/flatten' ); var format = require( '@stdlib/string/format' ); @@ -156,10 +162,10 @@ function array() { } if ( buffer ) { if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; + btype = getDType( buffer ); FLG = true; } else { - btype = getType( buffer ); + btype = getBufferDType( buffer ); FLG = false; } } @@ -221,18 +227,18 @@ function array() { // If the user indicated that "any" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally "row-major" or "column-major" or configured as such.... if ( order === 'any' ) { // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); + ord = strides2order( getStrides( buffer, false ) ); // If the ndarray can be considered both "row-major" and "column-major", then use the default order; otherwise, use the ndarray's stated layout order... if ( ord === 3 ) { order = defaults.order; } else { - order = buffer.order; + order = getOrder( buffer ); } } // Otherwise, use the same order as the provided ndarray... else if ( order === 'same' ) { - order = buffer.order; + order = getOrder( buffer ); } } else { order = defaults.order; @@ -276,9 +282,9 @@ function array() { len = numel( shape ); } else if ( buffer ) { if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; + shape = getShape( buffer, true ); + ndims = shape.length; + len = numel( shape ); } else if ( opts.flatten && isArray( buffer ) ) { shape = arrayShape( buffer ); osh = shape; // cache a reference to the inferred shape @@ -299,15 +305,15 @@ function array() { } // If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy... if ( FLG ) { - if ( buffer.length !== len ) { + if ( numel( buffer.shape ) !== len ) { throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; + strides = getStrides( buffer, true ); + offset = getOffset( buffer ); + buffer = getData( buffer ); if ( strides.length < ndims ) { // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): strides = expandStrides( ndims, shape, strides, order ); From b5459409877703be84df2e88e2dd2a9617eb05e3 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:03:09 -0700 Subject: [PATCH 03/10] refactor: use top-level accessor packages --- .../@stdlib/ndarray/array/lib/main.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/array/lib/main.js b/lib/node_modules/@stdlib/ndarray/array/lib/main.js index 039746f9947..3b9f5a52073 100644 --- a/lib/node_modules/@stdlib/ndarray/array/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/array/lib/main.js @@ -37,12 +37,12 @@ var isCastingMode = require( '@stdlib/ndarray/base/assert/is-casting-mode' ); var isAllowedCast = require( '@stdlib/ndarray/base/assert/is-allowed-data-type-cast' ); var createBuffer = require( '@stdlib/ndarray/base/buffer' ); var getBufferDType = require( '@stdlib/ndarray/base/buffer-dtype' ); -var getDType = require( '@stdlib/ndarray/base/dtype' ); -var getShape = require( '@stdlib/ndarray/base/shape' ); -var getStrides = require( '@stdlib/ndarray/base/strides' ); -var getOffset = require( '@stdlib/ndarray/base/offset' ); -var getOrder = require( '@stdlib/ndarray/base/order' ); -var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +var getOffset = require( '@stdlib/ndarray/offset' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); var arrayShape = require( '@stdlib/array/shape' ); var flatten = require( '@stdlib/array/base/flatten' ); var format = require( '@stdlib/string/format' ); @@ -227,7 +227,7 @@ function array() { // If the user indicated that "any" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally "row-major" or "column-major" or configured as such.... if ( order === 'any' ) { // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer, false ) ); + ord = strides2order( getStrides( buffer ) ); // If the ndarray can be considered both "row-major" and "column-major", then use the default order; otherwise, use the ndarray's stated layout order... if ( ord === 3 ) { @@ -282,7 +282,7 @@ function array() { len = numel( shape ); } else if ( buffer ) { if ( FLG ) { - shape = getShape( buffer, true ); + shape = getShape( buffer ); ndims = shape.length; len = numel( shape ); } else if ( opts.flatten && isArray( buffer ) ) { @@ -311,7 +311,7 @@ function array() { if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); } else { - strides = getStrides( buffer, true ); + strides = getStrides( buffer ); offset = getOffset( buffer ); buffer = getData( buffer ); if ( strides.length < ndims ) { From 693a93d5511cba4f5ad0255bba8415e603e65816 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:04:15 -0700 Subject: [PATCH 04/10] refactor: use accessor utilities --- .../@stdlib/ndarray/broadcast-array/lib/main.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/broadcast-array/lib/main.js b/lib/node_modules/@stdlib/ndarray/broadcast-array/lib/main.js index 3070d75a912..d9657a62e11 100644 --- a/lib/node_modules/@stdlib/ndarray/broadcast-array/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/broadcast-array/lib/main.js @@ -24,6 +24,12 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var isCollection = require( '@stdlib/assert/is-collection' ); var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; var copy = require( '@stdlib/array/base/copy-indexed' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +var getOffset = require( '@stdlib/ndarray/offset' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); var format = require( '@stdlib/string/format' ); @@ -105,7 +111,7 @@ function broadcastArray( x, shape ) { throw new TypeError( format( 'invalid argument. Second argument must be an array of nonnegative integers. Value: `%s`.', shape ) ); } N = shape.length; - sh = x.shape; + sh = getShape( x ); M = sh.length; if ( N < M ) { throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); @@ -116,7 +122,7 @@ function broadcastArray( x, shape ) { strides.push( 0 ); } // Determine the output array strides... - st = x.strides; + st = getStrides( x ); for ( i = N-1; i >= 0; i-- ) { j = M - N + i; if ( j < 0 ) { @@ -141,7 +147,7 @@ function broadcastArray( x, shape ) { throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } - return new x.constructor( x.dtype, x.data, copy( shape ), strides, x.offset, x.order, { // eslint-disable-line max-len + return new x.constructor( getDType( x ), getData( x ), copy( shape ), strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len 'readonly': true }); } From 8874562a8e3383393bef0e1220080fb20a99880f Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:12:08 -0700 Subject: [PATCH 05/10] fix: add missing support for minimal ndarray-like objects not supporting a strides property --- .../@stdlib/ndarray/base/strides/lib/main.js | 23 +++- .../@stdlib/ndarray/base/strides/test/test.js | 127 ++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/strides/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/strides/lib/main.js index 90a9c67ae08..5e0337d284e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/strides/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/strides/lib/main.js @@ -20,9 +20,15 @@ // MODULES // +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +// VARIABLES // + +var ROW_MAJOR = 'row-major'; + + // MAIN // /** @@ -39,7 +45,22 @@ var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); * // returns [ 9, 3, 1 ] */ function strides( x, copy ) { - var st = x.strides; + var ord; + var sh; + var st; + + st= x.strides; + if ( typeof st !== 'object' || st === null ) { + sh = x.shape; + if ( sh.length === 0 ) { + return [ 0 ]; + } + ord = x.order; + if ( typeof ord !== 'string' ) { + ord = ROW_MAJOR; + } + return shape2strides( sh, ord ); + } if ( copy ) { return copyIndexed( st ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js b/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js index ebe1049540b..39ef57983a4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js @@ -106,6 +106,133 @@ tape( 'the function accepts minimal ndarray-like objects (strides)', function te t.end(); }); +tape( 'the function accepts minimal ndarray-like objects (shape)', function test( t ) { + var expected; + var values; + var out; + var i; + + values = [ + { + 'shape': [ 3, 3, 3 ] + }, + { + 'shape': [ 1, 1 ] + }, + { + 'shape': [ 3, 3, 0, 3 ] + }, + { + 'shape': [ 1, 2, 3, 4 ] + }, + { + 'shape': [ 5 ] + } + ]; + + expected = [ + [ 9, 3, 1 ], + [ 1, 1 ], + [ 0, 0, 3, 1 ], + [ 24, 12, 4, 1 ], + [ 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + out = strides( values[ i ], false ); + t.deepEqual( out, expected[ i ], 'returns expected value for shape '+values[ i ].shape.join( 'x' ) ); + } + t.end(); +}); + +tape( 'the function accepts minimal ndarray-like objects (shape, order=row-major)', function test( t ) { + var expected; + var values; + var out; + var i; + + values = [ + { + 'shape': [ 3, 3, 3 ], + 'order': 'row-major' + }, + { + 'shape': [ 1, 1 ], + 'order': 'row-major' + }, + { + 'shape': [ 3, 3, 0, 3 ], + 'order': 'row-major' + }, + { + 'shape': [ 1, 2, 3, 4 ], + 'order': 'row-major' + }, + { + 'shape': [ 5 ], + 'order': 'row-major' + } + ]; + + expected = [ + [ 9, 3, 1 ], + [ 1, 1 ], + [ 0, 0, 3, 1 ], + [ 24, 12, 4, 1 ], + [ 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + out = strides( values[ i ], false ); + t.deepEqual( out, expected[ i ], 'returns expected value for shape '+values[ i ].shape.join( 'x' ) ); + } + t.end(); +}); + +tape( 'the function accepts minimal ndarray-like objects (shape, order=column-major)', function test( t ) { + var expected; + var values; + var out; + var i; + + values = [ + { + 'shape': [ 3, 3, 3 ], + 'order': 'column-major' + }, + { + 'shape': [ 1, 1 ], + 'order': 'column-major' + }, + { + 'shape': [ 3, 3, 0, 3 ], + 'order': 'column-major' + }, + { + 'shape': [ 1, 2, 3, 4 ], + 'order': 'column-major' + }, + { + 'shape': [ 5 ], + 'order': 'column-major' + } + ]; + + expected = [ + [ 1, 3, 9 ], + [ 1, 1 ], + [ 1, 3, 9, 0 ], + [ 1, 1, 2, 6 ], + [ 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + out = strides( values[ i ], false ); + t.deepEqual( out, expected[ i ], 'returns expected value for shape '+values[ i ].shape.join( 'x' ) ); + } + t.end(); +}); + tape( 'the function supports returning a guaranteed copy of an input ndarray strides', function test( t ) { var expected; var values; From 836aaf48a1824e3002122cc67aae3d01a17451a5 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:13:32 -0700 Subject: [PATCH 06/10] test: add test case for zero-dimensional ndarray-like object --- .../@stdlib/ndarray/base/strides/test/test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js b/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js index 39ef57983a4..08d5b97b132 100644 --- a/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/strides/test/test.js @@ -38,6 +38,14 @@ tape( 'if provided a zero-dimensional ndarray, the function returns a single-ele t.end(); }); +tape( 'if provided a zero-dimensional minimal ndarray-like object, the function returns a single-element strides array', function test( t ) { + var x = { + 'shape': [] + }; + t.deepEqual( strides( x, false ), [ 0 ], 'returns expected value' ); + t.end(); +}); + tape( 'the function returns the strides of an ndarray', function test( t ) { var expected; var values; From 279034eddb4b9ec511c6001f2c120b9c34bf3cfd Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:20:14 -0700 Subject: [PATCH 07/10] refactor: use accessor utility --- lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js b/lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js index 538ecce8715..75e5724dc1f 100644 --- a/lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js @@ -28,6 +28,7 @@ var isFunction = require( '@stdlib/assert/is-function' ); var isCollection = require( '@stdlib/assert/is-collection' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var format = require( '@stdlib/string/format' ); +var getDType = require( '@stdlib/ndarray/dtype' ); var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -193,7 +194,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { } } arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); + dtypes.push( resolveEnum( getDType( v ) ) ); } // Resolve the ndarray function satisfying the input array types: idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len From 54bec5942986105b25f88fe9a633df91c837623a Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:21:25 -0700 Subject: [PATCH 08/10] refactor: use accessor utility --- lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js index 6b9a98e78cc..04c137eeaf2 100644 --- a/lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js @@ -28,6 +28,7 @@ var isFunction = require( '@stdlib/assert/is-function' ); var isCollection = require( '@stdlib/assert/is-collection' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var format = require( '@stdlib/string/format' ); +var getDType = require( '@stdlib/ndarray/dtype' ); var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -209,7 +210,7 @@ function dispatchBy( fcns, types, data, nargs, nin, nout ) { } } arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); + dtypes.push( resolveEnum( getDType( v ) ) ); } // Resolve the ndarray function satisfying the input array types: idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len From db91a388c5f19d23ca5e09ba090e1b86cf307fb4 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:24:22 -0700 Subject: [PATCH 09/10] refactor: use accessor utilities --- .../@stdlib/ndarray/empty-like/lib/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/empty-like/lib/main.js b/lib/node_modules/@stdlib/ndarray/empty-like/lib/main.js index e875ca9c74e..aee9836e1e6 100644 --- a/lib/node_modules/@stdlib/ndarray/empty-like/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/empty-like/lib/main.js @@ -27,6 +27,9 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); var numel = require( '@stdlib/ndarray/base/numel' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var emptyArray = require( '@stdlib/array/empty' ); var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); @@ -91,7 +94,7 @@ function emptyLike( x ) { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; } else { - dtype = x.dtype; + dtype = getDType( x ); } if ( hasOwnProp( options, 'shape' ) ) { sh = options.shape; @@ -102,12 +105,12 @@ function emptyLike( x ) { throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', sh ) ); } } else { - sh = x.shape; + sh = getShape( x ); } if ( hasOwnProp( options, 'order' ) ) { order = options.order; } else { - order = x.order; + order = getOrder( x ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; @@ -116,9 +119,9 @@ function emptyLike( x ) { opts.submode = options.submode; } } else { - dtype = x.dtype; - sh = x.shape; - order = x.order; + dtype = getDType( x ); + sh = getShape( x ); + order = getOrder( x ); } ndims = sh.length; if ( ndims > 0 ) { From 71d561cc2b942a92983a38c8bde009d35255c5d1 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 9 Oct 2023 17:25:37 -0700 Subject: [PATCH 10/10] refactor: use accessor utilities --- .../@stdlib/ndarray/zeros-like/lib/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/zeros-like/lib/main.js b/lib/node_modules/@stdlib/ndarray/zeros-like/lib/main.js index ec51f6f15bd..c1bb655aaff 100644 --- a/lib/node_modules/@stdlib/ndarray/zeros-like/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/zeros-like/lib/main.js @@ -28,6 +28,9 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); var buffer = require( '@stdlib/ndarray/base/buffer' ); var numel = require( '@stdlib/ndarray/base/numel' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var format = require( '@stdlib/string/format' ); @@ -91,7 +94,7 @@ function zerosLike( x ) { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; } else { - dtype = x.dtype; + dtype = getDType( x ); } if ( hasOwnProp( options, 'shape' ) ) { sh = options.shape; @@ -102,12 +105,12 @@ function zerosLike( x ) { throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', sh ) ); } } else { - sh = x.shape; + sh = getShape( x ); } if ( hasOwnProp( options, 'order' ) ) { order = options.order; } else { - order = x.order; + order = getOrder( x ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; @@ -119,9 +122,9 @@ function zerosLike( x ) { opts.readonly = options.readonly; } } else { - dtype = x.dtype; - sh = x.shape; - order = x.order; + dtype = getDType( x ); + sh = getShape( x ); + order = getOrder( x ); } ndims = sh.length; if ( ndims > 0 ) {