From b22ea035c1fea5d642891da8e250483324fa5e78 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 31 Oct 2025 13:30:16 +0500 Subject: [PATCH 1/4] feat: add ndarray/base/copy --- .../@stdlib/ndarray/base/copy/README.md | 140 ++++++ .../ndarray/base/copy/benchmark/benchmark.js | 57 +++ .../@stdlib/ndarray/base/copy/docs/repl.txt | 37 ++ .../ndarray/base/copy/docs/types/index.d.ts | 405 +++++++++++++++++ .../ndarray/base/copy/docs/types/test.ts | 62 +++ .../ndarray/base/copy/examples/index.js | 38 ++ .../@stdlib/ndarray/base/copy/lib/index.js | 50 ++ .../@stdlib/ndarray/base/copy/lib/main.js | 59 +++ .../@stdlib/ndarray/base/copy/package.json | 64 +++ .../@stdlib/ndarray/base/copy/test/test.js | 426 ++++++++++++++++++ 10 files changed, 1338 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/copy/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/README.md b/lib/node_modules/@stdlib/ndarray/base/copy/README.md new file mode 100644 index 000000000000..4171df17e171 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/README.md @@ -0,0 +1,140 @@ + + +# copy + +> Return an ndarray copy having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var copy = require( '@stdlib/ndarray/base/copy' ); +``` + +#### copy( x ) + +Returns an ndarray copy having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. + +```javascript +var zeros = require( '@stdlib/ndarray/base/zeros' ); + +var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); +// returns + +var y = copy( x ); +// returns + +var sh = y.shape; +// returns [ 2, 2 ] + +var dt = y.dtype; +// returns 'float64' +``` + +
+ + + + + +
+ +## Notes + +- Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor]. + +
+ + + + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var copy = require( '@stdlib/ndarray/base/copy' ); + +var x = { + 'dtype': 'generic', + 'data': bernoulli( 10, 0.9, { + 'dtype': 'generic' + }), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var o = copy( [ x ] ); +console.log( ndarray2array( o.data, o.shape, o.strides, o.offset, o.order ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/copy/benchmark/benchmark.js new file mode 100644 index 000000000000..9c06e5e58145 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarray = require( '@stdlib/assert/is-ndarray-like' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var pkg = require( './../package.json' ).name; +var copy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + zeros( 'float64', [ 10 ], 'row-major' ), + zeros( 'float32', [ 5, 5 ], 'row-major' ), + zeros( 'int32', [ 3, 3, 3 ], 'row-major' ), + zeros( 'uint32', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = copy( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarray( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt new file mode 100644 index 000000000000..f4ace53f9c24 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt @@ -0,0 +1,37 @@ + +{{alias}}( x ) + Returns an ndarray copy having the same shape and data type as a provided + input ndarray. + + Along with data type, shape, and order, the function infers the "class" of + the returned ndarray from the provided ndarray. For example, if provided a + "base" ndarray, the function returns a base ndarray. If provided a non-base + ndarray, the function returns a non-base ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/base/zeros}}( 'float64', [ 2, 2 ], 'row-major' ) + + > var sh = x.shape + [ 2, 2 ] + > var dt = x.dtype + 'float64' + > var y = {{alias}}( x ) + + > sh = y.shape + [ 2, 2 ] + > dt = y.dtype + 'float64' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts new file mode 100644 index 000000000000..10cf4ee8dbf1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts @@ -0,0 +1,405 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'float64' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'float64' +*/ +declare function copy( x: float64ndarray ): float64ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'float32' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'float32' +*/ +declare function copy( x: float32ndarray ): float32ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'complex128' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'complex128' +*/ +declare function copy( x: complex128ndarray ): complex128ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'complex64' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'complex64' +*/ +declare function copy( x: complex64ndarray ): complex64ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'int32', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'int32' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'int32' +*/ +declare function copy( x: int32ndarray ): int32ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'int16', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'int16' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'int16' +*/ +declare function copy( x: int16ndarray ): int16ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'int8', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'int8' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'int8' +*/ +declare function copy( x: int8ndarray ): int8ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'uint32', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'uint32' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'uint32' +*/ +declare function copy( x: uint32ndarray ): uint32ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'uint16', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'uint16' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'uint16' +*/ +declare function copy( x: uint16ndarray ): uint16ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'uint8', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'uint8' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'uint8' +*/ +declare function copy( x: uint8ndarray ): uint8ndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'uint8c', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'uint8c' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'uint8c' +*/ +declare function copy( x: uint8cndarray ): uint8cndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var empty = require( '@stdlib/ndarray/base/empty' ); +* +* var x = empty( 'bool', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'bool' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'bool' +*/ +declare function copy( x: boolndarray ): boolndarray; + +/** +* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns output array +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'generic', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 2, 2 ] +* +* var dt = x.dtype; +* // returns 'generic' +* +* var y = copy( x ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* dt = y.dtype; +* // returns 'generic' +*/ +declare function copy( x: typedndarray ): typedndarray; + + +// EXPORTS // + +export = copy; diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts new file mode 100644 index 000000000000..2905f9860955 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts @@ -0,0 +1,62 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import empty = require( '@stdlib/ndarray/base/empty' ); +import copy = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + copy( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray + copy( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray + copy( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray + copy( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray + copy( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray + copy( zeros( 'int16', sh, ord ) ); // $ExpectType int16ndarray + copy( zeros( 'int8', sh, ord ) ); // $ExpectType int8ndarray + copy( zeros( 'uint32', sh, ord ) ); // $ExpectType uint32ndarray + copy( zeros( 'uint16', sh, ord ) ); // $ExpectType uint16ndarray + copy( zeros( 'uint8', sh, ord ) ); // $ExpectType uint8ndarray + copy( zeros( 'uint8c', sh, ord ) ); // $ExpectType uint8cndarray + copy( empty( 'bool', sh, ord ) ); // $ExpectType boolndarray + copy( zeros( 'generic', sh, ord ) ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument is not an ndarray which has a recognized/supported data type... +{ + copy( '10' ); // $ExpectError + copy( 10 ); // $ExpectError + copy( false ); // $ExpectError + copy( true ); // $ExpectError + copy( null ); // $ExpectError + copy( [] ); // $ExpectError + copy( {} ); // $ExpectError + copy( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + copy(); // $ExpectError + copy( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js new file mode 100644 index 000000000000..39e0b92c4427 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var copy = require( './../lib' ); + +var x = { + 'dtype': 'generic', + 'data': bernoulli( 10, 0.9, { + 'dtype': 'generic' + }), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var o = copy( x ); +console.log( ndarray2array( o.data, o.shape, o.strides, o.offset, o.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js new file mode 100644 index 000000000000..d9a2c8ba265c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return an ndarray copy having the same shape and data type as a provided ndarray. +* +* @module @stdlib/ndarray/base/copy +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var copy = require( '@stdlib/ndarray/base/copy' ); +* +* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var y = copy( x ); +* // returns +* +* var sh = y.shape; +* // returns [ 2, 2 ] +* +* var dt = y.dtype; +* // returns 'float64' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js new file mode 100644 index 000000000000..f241ba035c18 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var emptyLike = require( '@stdlib/ndarray/base/empty-like' ); +var assign = require( '@stdlib/ndarray/base/assign' ); + + +// MAIN // + +/** +* Returns an ndarray copy having the same shape and data type as a provided ndarray. +* +* @param {ndarray} x - input ndarray +* @returns {ndarray} output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* +* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var y = copy( x ); +* // returns +* +* var sh = y.shape; +* // returns [ 2, 2 ] +* +* var dt = y.dtype; +* // returns 'float64' +*/ +function copy( x ) { + var out = emptyLike( x ); + assign( [ x, out ] ); + return out; +} + + +// EXPORTS // + +module.exports = copy; diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/package.json b/lib/node_modules/@stdlib/ndarray/base/copy/package.json new file mode 100644 index 000000000000..86a1b621fe35 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/copy", + "version": "0.0.0", + "description": "Return an ndarray copy having the same shape and data type as a provided ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "copy", + "duplicate" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js new file mode 100644 index 000000000000..2b88bd0bdbbf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js @@ -0,0 +1,426 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WactualANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32array = require( '@stdlib/array/int32' ); +var Uint32array = require( '@stdlib/array/uint32' ); +var Int16array = require( '@stdlib/array/int16' ); +var Uint16array = require( '@stdlib/array/uint16' ); +var Int8array = require( '@stdlib/array/int8' ); +var Uint8array = require( '@stdlib/array/uint8' ); +var Uint8Clampedarray = require( '@stdlib/array/uint8c' ); +var Complex64array = require( '@stdlib/array/complex64' ); +var Complex128array = require( '@stdlib/array/complex128' ); +var Booleanarray = require( '@stdlib/array/bool' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var base = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var copy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof copy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=float64, base)', function test( t ) { + var expected; + var actual; + var x; + + x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + actual = copy( x ); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( actual.order, 'row-major', 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=float64, non-base)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'float64', + 'order': 'column-major' + }); + + actual = copy( x ); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( instanceOf( actual, ndarray ), true, 'returns expected value' ); + t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Float64Array ), true, 'returns expected value' ); + t.strictEqual( actual.order, 'column-major', 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=float32)', function test( t ) { + var expected; + var actual; + var x; + + x = zeros( 'float32', [ 2, 2 ], 'row-major' ); + + actual = copy( x ); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + t.strictEqual( instanceOf( actual, base ), true, 'returns expected value' ); + t.strictEqual( actual.dtype, 'float32', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Float32Array ), true, 'returns expected value' ); + t.strictEqual( actual.order, 'row-major', 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=int32)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Int32array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'int32', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'int32', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Int32array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=uint32)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Uint32array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint32', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'uint32', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Uint32array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=int16)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Int16array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'int16', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'int16', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Int16array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=uint16)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Uint16array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint16', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'uint16', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Uint16array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=int8)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Int8array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'int8', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'int8', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Int8array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=uint8)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Uint8array( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint8', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'uint8', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Uint8array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=uint8c)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Uint8Clampedarray( [ 1, 2, 3, 4 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint8c', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.strictEqual( actual.dtype, 'uint8c', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Uint8Clampedarray ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=complex128)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Complex128array( [ 1.0, 2.0, 3.0, 4.0 ] ), { + 'shape': [ 2, 1 ], + 'dtype': 'complex128', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ + [{ + 'im': 2.0, + 're': 1.0 + }], + [ + { + 'im': 4.0, + 're': 3.0 + } + ] + ]; + + t.strictEqual( actual.dtype, 'complex128', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Complex128array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=complex64)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Complex64array( [ 1.0, 2.0, 3.0, 4.0 ] ), { + 'shape': [ 2, 1 ], + 'dtype': 'complex64', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ + [{ + 'im': 2.0, + 're': 1.0 + }], + [ + { + 'im': 4.0, + 're': 3.0 + } + ] + ]; + + t.strictEqual( actual.dtype, 'complex64', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Complex64array ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (dtype=bool)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Booleanarray( [ true, false, true, false ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'bool', + 'order': 'row-major' + }); + actual = copy( x ); + expected = [ [ true, false ], [ true, false ] ]; + + t.strictEqual( actual.dtype, 'bool', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( actual.data, Booleanarray ), true, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (0d array)', function test( t ) { + var actual; + var x; + + x = zeros( 'float64', [], 'row-major' ); + x.set( 5.0 ); + + actual = copy( x ); + + t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); + t.deepEqual( actual.shape, [], 'returns expected value' ); + t.strictEqual( actual.get(), 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (1d array)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Float64Array( [ 1.0, 2.0, 3.0 ] ), { + 'shape': [ 3 ], + 'dtype': 'float64', + 'order': 'row-major' + }); + actual = copy( x ); + expected = [ 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); + t.deepEqual( actual.shape, [ 3 ], 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a copy with the same shape and data type (3d array)', function test( t ) { + var expected; + var actual; + var x; + + x = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), { + 'shape': [ 2, 2, 2 ], + 'dtype': 'float64', + 'order': 'row-major' + }); + + actual = copy( x ); + expected = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ]; // eslint-disable-line max-len + + t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + + t.end(); +}); From bdacdad5ac88bc9ea439b53a4acba26f832d55b5 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 31 Oct 2025 13:43:59 +0500 Subject: [PATCH 2/4] fix: lint errors --- lib/node_modules/@stdlib/ndarray/base/copy/README.md | 12 +++++++----- .../@stdlib/ndarray/base/copy/examples/index.js | 12 +++++++----- .../@stdlib/ndarray/base/copy/test/test.js | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/README.md b/lib/node_modules/@stdlib/ndarray/base/copy/README.md index 4171df17e171..e013a7e1d354 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/copy/README.md @@ -86,19 +86,21 @@ var dt = y.dtype; ```javascript var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var copy = require( '@stdlib/ndarray/base/copy' ); -var x = { +var xbuf = bernoulli( 10, 0.9, { + 'dtype': 'generic' +}); +var x = array({ 'dtype': 'generic', - 'data': bernoulli( 10, 0.9, { - 'dtype': 'generic' - }), + 'data': xbuf, 'shape': [ 5, 2 ], 'strides': [ 2, 1 ], 'offset': 0, 'order': 'row-major' -}; +}); console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); var o = copy( [ x ] ); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js index 39e0b92c4427..1a97dd73329d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js @@ -19,19 +19,21 @@ 'use strict'; var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var copy = require( './../lib' ); -var x = { +var xbuf = bernoulli( 10, 0.9, { + 'dtype': 'generic' +}); +var x = array({ 'dtype': 'generic', - 'data': bernoulli( 10, 0.9, { - 'dtype': 'generic' - }), + 'data': xbuf, 'shape': [ 5, 2 ], 'strides': [ 2, 1 ], 'offset': 0, 'order': 'row-major' -}; +}); console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); var o = copy( x ); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js index 2b88bd0bdbbf..a39cea3c2f28 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js @@ -11,7 +11,7 @@ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WactualANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ From 04f693bfec8ef08b9ad34920239588c2392ab49c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 31 Oct 2025 13:48:56 +0500 Subject: [PATCH 3/4] fix: lint errors --- lib/node_modules/@stdlib/ndarray/base/copy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/README.md b/lib/node_modules/@stdlib/ndarray/base/copy/README.md index e013a7e1d354..e0d7bfb61cd7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/copy/README.md @@ -103,7 +103,7 @@ var x = array({ }); console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -var o = copy( [ x ] ); +var o = copy( x ); console.log( ndarray2array( o.data, o.shape, o.strides, o.offset, o.order ) ); ``` From 2ee01f7af21213170eb469e1adb7fdb98770715e Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 31 Oct 2025 19:57:15 -0700 Subject: [PATCH 4/4] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/copy/README.md | 17 +- .../@stdlib/ndarray/base/copy/docs/repl.txt | 15 +- .../ndarray/base/copy/docs/types/index.d.ts | 368 +----------------- .../ndarray/base/copy/docs/types/test.ts | 4 +- .../ndarray/base/copy/examples/index.js | 6 +- .../@stdlib/ndarray/base/copy/lib/index.js | 8 +- .../@stdlib/ndarray/base/copy/lib/main.js | 8 +- .../@stdlib/ndarray/base/copy/package.json | 2 +- .../@stdlib/ndarray/base/copy/test/test.js | 192 ++++----- 9 files changed, 138 insertions(+), 482 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/README.md b/lib/node_modules/@stdlib/ndarray/base/copy/README.md index e0d7bfb61cd7..2a3ff20ffd3c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/copy/README.md @@ -20,7 +20,7 @@ limitations under the License. # copy -> Return an ndarray copy having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. +> Copy an input ndarray to a new ndarray having the same shape and [data type][@stdlib/ndarray/dtypes]. @@ -42,9 +42,10 @@ var copy = require( '@stdlib/ndarray/base/copy' ); #### copy( x ) -Returns an ndarray copy having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. +Copies an input ndarray to a new ndarray having the same shape and [data type][@stdlib/ndarray/dtypes]. ```javascript +var getShape = require( '@stdlib/ndarray/shape' ); var zeros = require( '@stdlib/ndarray/base/zeros' ); var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); @@ -53,11 +54,8 @@ var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); var y = copy( x ); // returns -var sh = y.shape; +var sh = getShape( y ); // returns [ 2, 2 ] - -var dt = y.dtype; -// returns 'float64' ``` @@ -70,6 +68,7 @@ var dt = y.dtype; ## Notes +- The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer. - Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor]. @@ -87,7 +86,7 @@ var dt = y.dtype; ```javascript var bernoulli = require( '@stdlib/random/array/bernoulli' ); var array = require( '@stdlib/ndarray/array' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var copy = require( '@stdlib/ndarray/base/copy' ); var xbuf = bernoulli( 10, 0.9, { @@ -101,10 +100,10 @@ var x = array({ 'offset': 0, 'order': 'row-major' }); -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( x ) ); var o = copy( x ); -console.log( ndarray2array( o.data, o.shape, o.strides, o.offset, o.order ) ); +console.log( ndarray2array( o ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt index f4ace53f9c24..d67078161770 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt @@ -1,7 +1,10 @@ {{alias}}( x ) - Returns an ndarray copy having the same shape and data type as a provided - input ndarray. + Copies an input ndarray to a new ndarray having the same shape and data + type. + + The function performs a full copy in which an ndarray's underlying data is + copied to a new underlying data buffer. Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a @@ -22,16 +25,12 @@ -------- > var x = {{alias:@stdlib/ndarray/base/zeros}}( 'float64', [ 2, 2 ], 'row-major' ) - > var sh = x.shape + > var sh = {{alias:@stdlib/ndarray/shape}}( x ) [ 2, 2 ] - > var dt = x.dtype - 'float64' > var y = {{alias}}( x ) - > sh = y.shape + > sh = {{alias:@stdlib/ndarray/shape}}( y ) [ 2, 2 ] - > dt = y.dtype - 'float64' See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts index 10cf4ee8dbf1..b6025c951b60 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts @@ -20,384 +20,36 @@ /// -import { typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { ndarray } from '@stdlib/types/ndarray'; /** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* Copies an input ndarray to a new ndarray having the same shape and data type. * -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); -* // returns +* ## Notes * -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'float64' -*/ -declare function copy( x: float64ndarray ): float64ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. +* - The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer. * * @param x - input array * @returns output array * * @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * var zeros = require( '@stdlib/ndarray/base/zeros' ); * -* var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'float32' -*/ -declare function copy( x: float32ndarray ): float32ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'complex128' -*/ -declare function copy( x: complex128ndarray ): complex128ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'complex64' -*/ -declare function copy( x: complex64ndarray ): complex64ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'int32' -*/ -declare function copy( x: int32ndarray ): int32ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'int16' -*/ -declare function copy( x: int16ndarray ): int16ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'int8' -*/ -declare function copy( x: int8ndarray ): int8ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'uint32' -*/ -declare function copy( x: uint32ndarray ): uint32ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'uint16' -*/ -declare function copy( x: uint16ndarray ): uint16ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'uint8' -*/ -declare function copy( x: uint8ndarray ): uint8ndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'uint8c' -*/ -declare function copy( x: uint8cndarray ): uint8cndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var empty = require( '@stdlib/ndarray/base/empty' ); -* -* var x = empty( 'bool', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'bool' -* -* var y = copy( x ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'bool' -*/ -declare function copy( x: boolndarray ): boolndarray; - -/** -* Returns an ndarray copy having the same shape and data type as a provided input ndarray. -* -* @param x - input array -* @returns output array -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* -* var x = zeros( 'generic', [ 2, 2 ], 'row-major' ); +* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); * // returns * -* var sh = x.shape; +* var sh = getShape( x ); * // returns [ 2, 2 ] * -* var dt = x.dtype; -* // returns 'generic' -* * var y = copy( x ); * // returns * -* sh = y.shape; +* sh = getShape( y ); * // returns [ 2, 2 ] -* -* dt = y.dtype; -* // returns 'generic' */ -declare function copy( x: typedndarray ): typedndarray; +declare function copy( x: T ): T; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts index 2905f9860955..28cc5ccc8d79 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/test.ts @@ -40,10 +40,10 @@ import copy = require( './index' ); copy( zeros( 'uint8', sh, ord ) ); // $ExpectType uint8ndarray copy( zeros( 'uint8c', sh, ord ) ); // $ExpectType uint8cndarray copy( empty( 'bool', sh, ord ) ); // $ExpectType boolndarray - copy( zeros( 'generic', sh, ord ) ); // $ExpectType typedndarray + copy( zeros( 'generic', sh, ord ) ); // $ExpectType genericndarray } -// The compiler throws an error if the function is provided a first argument is not an ndarray which has a recognized/supported data type... +// The compiler throws an error if the function is provided a first argument is not an ndarray... { copy( '10' ); // $ExpectError copy( 10 ); // $ExpectError diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js index 1a97dd73329d..8160908faa0d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js @@ -20,7 +20,7 @@ var bernoulli = require( '@stdlib/random/array/bernoulli' ); var array = require( '@stdlib/ndarray/array' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var copy = require( './../lib' ); var xbuf = bernoulli( 10, 0.9, { @@ -34,7 +34,7 @@ var x = array({ 'offset': 0, 'order': 'row-major' }); -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +console.log( ndarray2array( x ) ); var o = copy( x ); -console.log( ndarray2array( o.data, o.shape, o.strides, o.offset, o.order ) ); +console.log( ndarray2array( o ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js index d9a2c8ba265c..13e99922b585 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an ndarray copy having the same shape and data type as a provided ndarray. +* Copy an input ndarray to a new ndarray having the same shape and data type. * * @module @stdlib/ndarray/base/copy * @@ -32,12 +32,6 @@ * * var y = copy( x ); * // returns -* -* var sh = y.shape; -* // returns [ 2, 2 ] -* -* var dt = y.dtype; -* // returns 'float64' */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js index f241ba035c18..35b58faa99db 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js @@ -27,7 +27,7 @@ var assign = require( '@stdlib/ndarray/base/assign' ); // MAIN // /** -* Returns an ndarray copy having the same shape and data type as a provided ndarray. +* Copies an input ndarray to a new ndarray having the same shape and data type. * * @param {ndarray} x - input ndarray * @returns {ndarray} output ndarray @@ -40,12 +40,6 @@ var assign = require( '@stdlib/ndarray/base/assign' ); * * var y = copy( x ); * // returns -* -* var sh = y.shape; -* // returns [ 2, 2 ] -* -* var dt = y.dtype; -* // returns 'float64' */ function copy( x ) { var out = emptyLike( x ); diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/package.json b/lib/node_modules/@stdlib/ndarray/base/copy/package.json index 86a1b621fe35..0e371900fea3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/copy/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/copy", "version": "0.0.0", - "description": "Return an ndarray copy having the same shape and data type as a provided ndarray.", + "description": "Copy an input ndarray to a new ndarray having the same shape and data type.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js index a39cea3c2f28..18b4db81dd9b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var Int32array = require( '@stdlib/array/int32' ); @@ -38,7 +39,11 @@ var base = require( '@stdlib/ndarray/base/ctor' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var array = require( '@stdlib/ndarray/array' ); var zeros = require( '@stdlib/ndarray/base/zeros' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var copy = require( './../lib' ); @@ -60,11 +65,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=floa actual = copy( x ); expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; - t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.order, 'row-major', 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -84,12 +89,12 @@ tape( 'the function returns a copy with the same shape and data type (dtype=floa expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( instanceOf( actual, ndarray ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Float64Array ), true, 'returns expected value' ); - t.strictEqual( actual.order, 'column-major', 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Float64Array ), true, 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -105,12 +110,12 @@ tape( 'the function returns a copy with the same shape and data type (dtype=floa expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; t.strictEqual( instanceOf( actual, base ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, 'float32', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Float32Array ), true, 'returns expected value' ); - t.strictEqual( actual.order, 'row-major', 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Float32Array ), true, 'returns expected value' ); + t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -129,11 +134,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=int3 actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'int32', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Int32array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Int32array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -152,11 +157,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=uint actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Uint32array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Uint32array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -175,11 +180,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=int1 actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'int16', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Int16array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Int16array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -198,11 +203,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=uint actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Uint16array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Uint16array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -221,11 +226,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=int8 actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'int8', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Int8array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Int8array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -244,11 +249,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=uint actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Uint8array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Uint8array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -267,11 +272,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=uint actual = copy( x ); expected = [ [ 1, 2 ], [ 3, 4 ] ]; - t.strictEqual( actual.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Uint8Clampedarray ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Uint8Clampedarray ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -289,10 +294,12 @@ tape( 'the function returns a copy with the same shape and data type (dtype=comp actual = copy( x ); expected = [ - [{ - 'im': 2.0, - 're': 1.0 - }], + [ + { + 'im': 2.0, + 're': 1.0 + } + ], [ { 'im': 4.0, @@ -301,11 +308,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=comp ] ]; - t.strictEqual( actual.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Complex128array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Complex128array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -323,10 +330,12 @@ tape( 'the function returns a copy with the same shape and data type (dtype=comp actual = copy( x ); expected = [ - [{ - 'im': 2.0, - 're': 1.0 - }], + [ + { + 'im': 2.0, + 're': 1.0 + } + ], [ { 'im': 4.0, @@ -335,11 +344,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=comp ] ]; - t.strictEqual( actual.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Complex64array ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Complex64array ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -357,11 +366,11 @@ tape( 'the function returns a copy with the same shape and data type (dtype=bool actual = copy( x ); expected = [ [ true, false ], [ true, false ] ]; - t.strictEqual( actual.dtype, 'bool', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( actual.data, Booleanarray ), true, 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( actual ), Booleanarray ), true, 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -375,8 +384,8 @@ tape( 'the function returns a copy with the same shape and data type (0d array)' actual = copy( x ); - t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); - t.deepEqual( actual.shape, [], 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); t.strictEqual( actual.get(), 5.0, 'returns expected value' ); t.end(); @@ -395,10 +404,10 @@ tape( 'the function returns a copy with the same shape and data type (1d array)' actual = copy( x ); expected = [ 1.0, 2.0, 3.0 ]; - t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); - t.deepEqual( actual.shape, [ 3 ], 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3 ], 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); }); @@ -415,12 +424,21 @@ tape( 'the function returns a copy with the same shape and data type (3d array)' }); actual = copy( x ); - expected = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ]; // eslint-disable-line max-len + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ] + ]; - t.strictEqual( actual.dtype, 'float64', 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.notEqual( actual.data, x.data, 'returns expected value' ); - t.deepEqual( ndarray2array( actual.data, actual.shape, actual.strides, actual.offset, actual.order ), expected, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2, 2 ], 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); });