diff --git a/.ralph/state.md b/.ralph/state.md new file mode 100644 index 000000000000..d34725467514 --- /dev/null +++ b/.ralph/state.md @@ -0,0 +1,82 @@ +# Ralph Loop State + +## Issue +**Reference**: stdlib-js/todo#2772 +**Title**: Review `@stdlib/ndarray/base/nans-like` +**Body**: Review `@stdlib/ndarray/base/nans-like`. This package does not yet exist and must be created. + +## Acceptance Criteria +- [x] `lib/main.js` — implements `nansLike(x)`, returns NaN-filled ndarray with same shape/dtype/order as input +- [x] `lib/index.js` — module wiring +- [x] `test/test.js` — tests covering all floating-point+generic dtypes (base and non-base), zero-dimensional arrays, empty arrays, and error case for unrecognized dtypes and integer dtypes +- [x] `examples/index.js` — runnable example iterating over supported dtypes +- [x] `benchmark/benchmark.js` — per-dtype benchmarks (float64, float32, complex128, complex64, generic) +- [x] `benchmark/benchmark.size.float64.js` through `*.generic.js` — size-varying benchmarks for each supported dtype +- [x] `docs/repl.txt` — REPL documentation +- [x] `docs/types/index.d.ts` — TypeScript declarations with overloads for each supported dtype +- [x] `docs/types/test.ts` — TypeScript type tests +- [x] `README.md` — package documentation +- [x] `package.json` — correct package metadata +- [x] All sanity checks pass (tape not installed; verified with direct node execution) +- [x] Namespace index.js and types/index.d.ts updated + +## Key Design Decisions +- Only supports floating-point and generic dtypes (float64, float32, complex128, complex64, generic) +- Complex types use `CNAN` from `@stdlib/constants/complex128/nan`; others use `NaN` +- Uses `emptyLike` + `fill` pattern (like `ones-like`) +- Integer dtypes throw at runtime (fill throws TypeError for NaN + integer types) +- TypeScript uses per-dtype overloads (not generic pattern) since integer types throw +- No `@throws` annotation in JSDoc (match `ones-like` convention) + +## Branch +`claude/vibrant-brahmagupta-jUurQ` + +## Files Touched +- `lib/node_modules/@stdlib/ndarray/base/nans-like/` (new package, all files) +- `lib/node_modules/@stdlib/ndarray/base/lib/index.js` (added nansLike export) +- `lib/node_modules/@stdlib/ndarray/base/docs/types/index.d.ts` (added nansLike declaration) + +## Iteration 1 — Plan: Implement +Created all package files for `@stdlib/ndarray/base/nans-like`. + +## Iteration 1 — Review Findings + +### Agent A (Correctness): Running +### Agent B (Test Quality): Completed +- BLOCKER F-9: Tests used pre-NaN inputs — aliasing bug would pass → FIXED: now use zeros() as input + buffer identity assertions +- BLOCKER F-5: Integer dtypes not tested → FIXED: added tests for int32/uint32/int16/uint16/int8/uint8/uint8c (all throw) +- MAJOR F-2: Buffer length not asserted → FIXED +- MAJOR F-3: Complex buffer length missing in non-base → FIXED +- MAJOR F-6: 0-dim only tested with generic → FIXED: added float64/float32/complex128/complex64 +- MAJOR F-7: Empty array only tested with generic → FIXED: added float64 base test +- MINOR F-1: allNaN helper vacuously true for empty → FIXED: added guard +- MINOR F-12: Dead `expected` var in complex128 base test → FIXED (removed unused var) + +### Agent C (Code Quality): Completed +- BLOCKER: @throws annotation incorrect (delegates to emptyLike, not direct throw) → FIXED: removed @throws, matches ones-like pattern +- MAJOR: TypeScript should use generic pattern `>` → DISPUTED: per-overload is correct because integer types throw (runtime verified) +- MINOR: getDType import "extra" compared to ones-like → ACCEPTED: needed for complex check, not a bug + +### Agent D (Security): Running +### Agent E (Issue-Scope): Completed — No issues (everything is in scope) + +## Triage + +### Fixed +- Removed @throws from JSDoc (was inaccurate for "unrecognized dtype" framing; matches ones-like) +- Test rewrites: non-NaN inputs, buffer identity, buffer length, integer dtypes, 0-dim for all types +- allNaN helper guards empty arrays + +### Disputed +- TypeScript generic vs per-overload: Per-overload KEPT. Reason: integer ndarray inputs to nansLike throw TypeError at runtime (fill rejects NaN for int types). The per-overload pattern correctly documents supported types. Generic `>` would incorrectly accept integer ndarrays at the TypeScript level. The reviewer's pattern applies to ones-like which supports ALL dtypes; nans-like is more restrictive. + +## Decision Log +1. Used emptyLike + fill pattern (like ones-like), not manual buffer pattern (like zeros-like) +2. No @throws in JSDoc — removed to match ones-like convention +3. TypeScript: per-dtype overloads (5 overloads) not generic — correctly restricts to NaN-capable types +4. Integer dtype tests: verified they DO throw (TypeError from fill), added throw tests +5. Tests use zeros() as input, not nans(), to make NaN filling visible + +## Make Commands +- Tests: node script with NODE_PATH=/home/user/stdlib/lib/node_modules +- Examples: NODE_PATH=... node examples/index.js diff --git a/lib/node_modules/@stdlib/ndarray/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/docs/types/index.d.ts index 82e7aa3f15cb..347621a368c1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/docs/types/index.d.ts @@ -105,6 +105,7 @@ import minUnsignedIntegerDataType = require( '@stdlib/ndarray/base/min-unsigned- import minViewBufferIndex = require( '@stdlib/ndarray/base/min-view-buffer-index' ); import minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ); import nans = require( '@stdlib/ndarray/base/nans' ); +import nansLike = require( '@stdlib/ndarray/base/nans-like' ); import ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); import ndarraylike2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); import ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); @@ -2782,6 +2783,31 @@ interface Namespace { */ nans: typeof nans; + /** + * Creates a NaN-filled array having the same shape and data type as a provided input ndarray. + * + * @param x - input array + * @returns NaN-filled array + * + * @example + * var getShape = require( '@stdlib/ndarray/shape' ); + * var getDType = require( '@stdlib/ndarray/dtype' ); + * var nans = require( '@stdlib/ndarray/base/nans' ); + * + * var x = nans( 'float64', [ 2, 2 ], 'row-major' ); + * // returns [ [ NaN, NaN ], [ NaN, NaN ] ] + * + * var y = ns.nansLike( x ); + * // returns [ [ NaN, NaN ], [ NaN, NaN ] ] + * + * var sh = getShape( y ); + * // returns [ 2, 2 ] + * + * var dt = String( getDType( y ) ); + * // returns 'float64' + */ + nansLike: typeof nansLike; + /** * Converts an ndarray-like object to an ndarray. * diff --git a/lib/node_modules/@stdlib/ndarray/base/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/lib/index.js index 5a05439aa523..53a6160e300a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/lib/index.js @@ -904,6 +904,15 @@ setReadOnly( ns, 'minmaxViewBufferIndex', require( '@stdlib/ndarray/base/minmax- */ setReadOnly( ns, 'nans', require( '@stdlib/ndarray/base/nans' ) ); +/** +* @name nansLike +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/ndarray/base/nans-like} +*/ +setReadOnly( ns, 'nansLike', require( '@stdlib/ndarray/base/nans-like' ) ); + /** * @name ndarraylike2ndarray * @memberof ns diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/README.md b/lib/node_modules/@stdlib/ndarray/base/nans-like/README.md new file mode 100644 index 000000000000..fe270ceffaa7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/README.md @@ -0,0 +1,139 @@ + + +# nansLike + +> Create a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var nansLike = require( '@stdlib/ndarray/base/nans-like' ); +``` + +#### nansLike( x ) + +Creates a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray. + +```javascript +var getShape = require( '@stdlib/ndarray/shape' ); +var nans = require( '@stdlib/ndarray/base/nans' ); + +var x = nans( 'float64', [ 2, 2 ], 'row-major' ); +// returns [ [ NaN, NaN ], [ NaN, NaN ] ] + +var y = nansLike( x ); +// returns [ [ NaN, NaN ], [ NaN, NaN ] ] + +var sh = getShape( y ); +// returns [ 2, 2 ] +``` + +
+ + + + + +
+ +## 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 nans = require( '@stdlib/ndarray/base/nans' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nansLike = require( '@stdlib/ndarray/base/nans-like' ); + +var dt = [ + 'float64', + 'float32', + 'complex128', + 'complex64', + 'generic' +]; + +// Generate NaN-filled arrays... +var x; +var i; +for ( i = 0; i < dt.length; i++ ) { + x = nansLike( nans( dt[ i ], [ 2, 2 ], 'row-major' ) ); + console.log( ndarray2array( x ) ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.js new file mode 100644 index 000000000000..bc566c2fc367 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::base:dtype=float64', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = nans( 'float64', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = nansLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=float32', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = nans( 'float32', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = nansLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=complex128', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = nans( 'complex128', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = nansLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=complex64', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = nans( 'complex64', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = nansLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=generic', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = nans( 'generic', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = nansLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex128.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex128.js new file mode 100644 index 000000000000..cccea16fbe59 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex128.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = nans( 'complex128', [ len ], 'row-major' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::base:dtype=complex128,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex64.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex64.js new file mode 100644 index 000000000000..d01384078a6f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.complex64.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = nans( 'complex64', [ len ], 'row-major' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::base:dtype=complex64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float32.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float32.js new file mode 100644 index 000000000000..5fc31d642271 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float32.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = nans( 'float32', [ len ], 'row-major' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::base:dtype=float32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float64.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float64.js new file mode 100644 index 000000000000..c6cdee953fe1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.float64.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = nans( 'float64', [ len ], 'row-major' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::base:dtype=float64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.generic.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.generic.js new file mode 100644 index 000000000000..652334e0830d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/benchmark/benchmark.size.generic.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var nans = require( '@stdlib/ndarray/base/nans' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = nans( 'generic', [ len ], 'row-major' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::base:dtype=generic,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/repl.txt new file mode 100644 index 000000000000..75e6430a2ff0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( x ) + Returns a NaN-filled ndarray 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/nans}}( 'float64', [ 2, 2 ], 'row-major' ) + [ [ NaN, NaN ], [ NaN, NaN ] ] + > var y = {{alias}}( x ) + [ [ NaN, NaN ], [ NaN, NaN ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/index.d.ts new file mode 100644 index 000000000000..6f4c48fa0a8e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/index.d.ts @@ -0,0 +1,183 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 { float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, genericndarray } from '@stdlib/types/ndarray'; + +/** +* Creates a NaN-filled array having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns NaN-filled array +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'float64', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( x ) ); +* // returns 'float64' +* +* var y = nansLike( x ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +* +* dt = String( getDType( y ) ); +* // returns 'float64' +*/ +declare function nansLike( x: float64ndarray ): float64ndarray; + +/** +* Creates a NaN-filled array having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns NaN-filled array +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( x ) ); +* // returns 'float32' +* +* var y = nansLike( x ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +* +* dt = String( getDType( y ) ); +* // returns 'float32' +*/ +declare function nansLike( x: float32ndarray ): float32ndarray; + +/** +* Creates a NaN-filled array having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns NaN-filled array +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( x ) ); +* // returns 'complex128' +* +* var y = nansLike( x ); +* // returns +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +* +* dt = String( getDType( y ) ); +* // returns 'complex128' +*/ +declare function nansLike( x: complex128ndarray ): complex128ndarray; + +/** +* Creates a NaN-filled array having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns NaN-filled array +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'complex64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( x ) ); +* // returns 'complex64' +* +* var y = nansLike( x ); +* // returns +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +* +* dt = String( getDType( y ) ); +* // returns 'complex64' +*/ +declare function nansLike( x: complex64ndarray ): complex64ndarray; + +/** +* Creates a NaN-filled array having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @returns NaN-filled array +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var sh = getShape( x ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( x ) ); +* // returns 'generic' +* +* var y = nansLike( x ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* sh = getShape( y ); +* // returns [ 2, 2 ] +* +* dt = String( getDType( y ) ); +* // returns 'generic' +*/ +declare function nansLike( x: genericndarray ): genericndarray; + + +// EXPORTS // + +export = nansLike; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/test.ts new file mode 100644 index 000000000000..b2ac271c6fa4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/docs/types/test.ts @@ -0,0 +1,53 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 nans = require( '@stdlib/ndarray/base/nans' ); +import nansLike = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + nansLike( nans( 'float64', sh, ord ) ); // $ExpectType float64ndarray + nansLike( nans( 'float32', sh, ord ) ); // $ExpectType float32ndarray + nansLike( nans( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray + nansLike( nans( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray + nansLike( nans( 'generic', sh, ord ) ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + nansLike( '10' ); // $ExpectError + nansLike( 10 ); // $ExpectError + nansLike( false ); // $ExpectError + nansLike( true ); // $ExpectError + nansLike( null ); // $ExpectError + nansLike( [] ); // $ExpectError + nansLike( {} ); // $ExpectError + nansLike( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + nansLike(); // $ExpectError + nansLike( nans( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/examples/index.js new file mode 100644 index 000000000000..5966437bd0c4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/examples/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 nans = require( '@stdlib/ndarray/base/nans' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nansLike = require( './../lib' ); + +var dt = [ + 'float64', + 'float32', + 'complex128', + 'complex64', + 'generic' +]; + +// Generate NaN-filled arrays... +var x; +var i; +for ( i = 0; i < dt.length; i++ ) { + x = nansLike( nans( dt[ i ], [ 2, 2 ], 'row-major' ) ); + console.log( ndarray2array( x ) ); +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/index.js new file mode 100644 index 000000000000..9084a745fe6f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Create a NaN-filled ndarray having the same shape and data type as a provided ndarray. +* +* @module @stdlib/ndarray/base/nans-like +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* var nansLike = require( '@stdlib/ndarray/base/nans-like' ); +* +* var x = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var y = nansLike( x ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var sh = getShape( y ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( y ) ); +* // returns 'float32' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/main.js new file mode 100644 index 000000000000..ef35368397e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/lib/main.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isComplexFloatingPointDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); // eslint-disable-line id-length +var emptyLike = require( '@stdlib/ndarray/base/empty-like' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var fill = require( '@stdlib/ndarray/base/fill' ); +var CNAN = require( '@stdlib/constants/complex128/nan' ); + + +// MAIN // + +/** +* Creates a NaN-filled ndarray having the same shape and data type as a provided ndarray. +* +* @param {ndarray} x - input array +* @returns {ndarray} ndarray +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var x = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var y = nansLike( x ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var sh = getShape( y ); +* // returns [ 2, 2 ] +* +* var dt = String( getDType( y ) ); +* // returns 'float32' +*/ +function nansLike( x ) { + if ( isComplexFloatingPointDataType( getDType( x ) ) ) { + return fill( emptyLike( x ), CNAN ); + } + return fill( emptyLike( x ), NaN ); +} + + +// EXPORTS // + +module.exports = nansLike; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/package.json b/lib/node_modules/@stdlib/ndarray/base/nans-like/package.json new file mode 100644 index 000000000000..b6d7a806cc18 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/nans-like", + "version": "0.0.0", + "description": "Create a NaN-filled ndarray 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", + "fill", + "filled", + "nans", + "nan" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans-like/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans-like/test/test.js new file mode 100644 index 000000000000..c1d9d6708173 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans-like/test/test.js @@ -0,0 +1,548 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 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 reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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 ones = require( '@stdlib/ndarray/base/ones' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var nansLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Tests whether all elements in a non-empty array are NaN. +* +* @private +* @param {Collection} arr - input array +* @returns {boolean} boolean indicating whether all elements are NaN +*/ +function allNaN( arr ) { + var i; + if ( arr.length === 0 ) { + return false; + } + for ( i = 0; i < arr.length; i++ ) { + if ( !isnan( arr[ i ] ) ) { + return false; + } + } + return true; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nansLike, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a value having an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + [], + {}, + function noop() {}, + { + 'data': true + }, + { + 'shape': [ 1, 2, 3 ], + 'order': 'row-major', + 'dtype': 'foo_bar_beep_boop' + } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nansLike( value ); + }; + } +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (int32)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'int32', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for int32' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (uint32)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'uint32', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for uint32' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (int16)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'int16', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for int16' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (uint16)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'uint16', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for uint16' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (int8)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'int8', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for int8' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (uint8)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'uint8', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for uint8' ); + t.end(); +}); + +tape( 'the function throws an error when provided an ndarray with an integer data type (uint8c)', function test( t ) { + t.throws( function throwit() { + nansLike( ones( 'uint8c', [ 2, 2 ], 'row-major' ) ); + }, TypeError, 'throws for uint8c' ); + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float64, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float64, non-base)', function test( t ) { + var arr; + var buf; + var x; + + x = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'float64', + 'order': 'column-major' + }); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float32, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'float32', [ 2, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float32, non-base)', function test( t ) { + var arr; + var buf; + var x; + + x = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { + 'shape': [ 2, 2 ], + 'dtype': 'float32', + 'order': 'column-major' + }); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex128, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + + buf = reinterpret128( getData( arr ), 0 ); + t.strictEqual( buf.length, 8, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex128, non-base)', function test( t ) { + var arr; + var buf; + var x; + + x = array( new Complex128Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex128', + 'order': 'column-major' + }); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + + buf = reinterpret128( getData( arr ), 0 ); + t.strictEqual( buf.length, 8, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex64, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + + buf = reinterpret64( getData( arr ), 0 ); + t.strictEqual( buf.length, 8, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex64, non-base)', function test( t ) { + var arr; + var buf; + var x; + + x = array( new Complex64Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex64', + 'order': 'column-major' + }); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + + buf = reinterpret64( getData( arr ), 0 ); + t.strictEqual( buf.length, 8, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=generic, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=generic, non-base)', function test( t ) { + var arr; + var buf; + var x; + + x = array( [ 1.0, 2.0, 3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'dtype': 'generic', + 'order': 'column-major' + }); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + + buf = getData( arr ); + t.strictEqual( buf.length, 4, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays (dtype=generic)', function test( t ) { + var arr; + var x; + + x = new ndarray( 'generic', [ 0.0 ], [], [ 0 ], 0, 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.strictEqual( getData( arr ).length, 1, 'returns expected value' ); + t.strictEqual( isnan( getData( arr )[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays (dtype=float64, base)', function test( t ) { + var arr; + var x; + + x = zeros( 'float64', [], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.strictEqual( getData( arr ).length, 1, 'returns expected value' ); + t.strictEqual( isnan( getData( arr )[ 0 ] ), true, 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays (dtype=float32, base)', function test( t ) { + var arr; + var x; + + x = zeros( 'float32', [], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + t.strictEqual( getData( arr ).length, 1, 'returns expected value' ); + t.strictEqual( isnan( getData( arr )[ 0 ] ), true, 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays (dtype=complex128, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'complex128', [], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + + buf = reinterpret128( getData( arr ), 0 ); + t.strictEqual( buf.length, 2, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays (dtype=complex64, base)', function test( t ) { + var arr; + var buf; + var x; + + x = zeros( 'complex64', [], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + + buf = reinterpret64( getData( arr ), 0 ); + t.strictEqual( buf.length, 2, 'returns expected value' ); + t.strictEqual( allNaN( buf ), true, 'returns expected value' ); + + t.notEqual( getData( arr ), getData( x ), 'returns a new data buffer' ); + + t.end(); +}); + +tape( 'the function supports empty arrays (dtype=generic, non-base)', function test( t ) { + var arr; + var x; + + x = new ndarray( 'generic', [], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), [], 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports empty arrays (dtype=float64, base)', function test( t ) { + var arr; + var x; + + x = zeros( 'float64', [ 2, 0, 2 ], 'row-major' ); + arr = nansLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.strictEqual( getData( arr ).length, 0, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +});