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..2a3ff20ffd3c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/README.md @@ -0,0 +1,141 @@ + + +# copy + +> Copy an input ndarray to a new ndarray having the same shape and [data type][@stdlib/ndarray/dtypes]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var copy = require( '@stdlib/ndarray/base/copy' ); +``` + +#### copy( x ) + +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' ); +// returns + +var y = copy( x ); +// returns + +var sh = getShape( y ); +// returns [ 2, 2 ] +``` + +
+ + + + + +
+ +## 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]. + +
+ + + + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var copy = require( '@stdlib/ndarray/base/copy' ); + +var xbuf = bernoulli( 10, 0.9, { + 'dtype': 'generic' +}); +var x = array({ + 'dtype': 'generic', + 'data': xbuf, + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}); +console.log( ndarray2array( x ) ); + +var o = copy( x ); +console.log( ndarray2array( o ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + 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..d67078161770 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( x ) + 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 + "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 = {{alias:@stdlib/ndarray/shape}}( x ) + [ 2, 2 ] + > var y = {{alias}}( x ) + + > sh = {{alias:@stdlib/ndarray/shape}}( y ) + [ 2, 2 ] + + 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..b6025c951b60 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Copies an input ndarray to a new ndarray having the same shape and data type. +* +* ## Notes +* +* - 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( 'float64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var y = copy( x ); +* // returns +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +*/ +declare function copy( x: T ): T; + + +// 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..28cc5ccc8d79 --- /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 genericndarray +} + +// The compiler throws an error if the function is provided a first argument is not an ndarray... +{ + 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..8160908faa0d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var copy = require( './../lib' ); + +var xbuf = bernoulli( 10, 0.9, { + 'dtype': 'generic' +}); +var x = array({ + 'dtype': 'generic', + 'data': xbuf, + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}); +console.log( ndarray2array( x ) ); + +var o = copy( x ); +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 new file mode 100644 index 000000000000..13e99922b585 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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'; + +/** +* Copy an input ndarray to a new ndarray having the same shape and data type. +* +* @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 +*/ + +// 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..35b58faa99db --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/lib/main.js @@ -0,0 +1,53 @@ +/** +* @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 // + +/** +* Copies an input ndarray to a new ndarray having the same shape and data type. +* +* @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 +*/ +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..0e371900fea3 --- /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": "Copy an input ndarray to a new ndarray having the same shape and data type.", + "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..18b4db81dd9b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/copy/test/test.js @@ -0,0 +1,444 @@ +/** +* @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 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' ); +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 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' ); + + +// 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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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( 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(); +}); + +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 ] + ] + ]; + + 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(); +});