From d8c9867d45d114c34542b220859074b6268df900 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 02:13:30 +0500 Subject: [PATCH 1/6] feat: add ndarray/base/nans --- .../@stdlib/ndarray/base/nans/README.md | 133 ++++++++++ .../ndarray/base/nans/benchmark/benchmark.js | 102 +++++++ .../benchmark/benchmark.size.complex128.js | 94 +++++++ .../benchmark/benchmark.size.complex64.js | 94 +++++++ .../nans/benchmark/benchmark.size.float32.js | 94 +++++++ .../nans/benchmark/benchmark.size.float64.js | 94 +++++++ .../@stdlib/ndarray/base/nans/docs/repl.txt | 29 ++ .../ndarray/base/nans/docs/types/index.d.ts | 123 +++++++++ .../ndarray/base/nans/docs/types/test.ts | 80 ++++++ .../ndarray/base/nans/examples/index.js | 37 +++ .../@stdlib/ndarray/base/nans/lib/index.js | 44 ++++ .../@stdlib/ndarray/base/nans/lib/main.js | 59 +++++ .../@stdlib/ndarray/base/nans/package.json | 66 +++++ .../@stdlib/ndarray/base/nans/test/test.js | 249 ++++++++++++++++++ 14 files changed, 1298 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex128.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex64.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float32.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float64.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/README.md b/lib/node_modules/@stdlib/ndarray/base/nans/README.md new file mode 100644 index 000000000000..854302d1ebe2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/README.md @@ -0,0 +1,133 @@ + + +# nans + +> Create a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var nans = require( '@stdlib/ndarray/base/nans' ); +``` + +#### nans( dtype, shape, order ) + +Creates a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and floating-point [data type][@stdlib/ndarray/dtypes]. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); + +var arr = nans( 'float64', [ 2, 2 ], 'row-major' ); +// returns [ [ NaN, NaN ], [ NaN, NaN ] ] + +var dt = String( getDType( arr ) ); +// returns 'float64' +``` + +The function accepts the following arguments: + +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a floating-point [data type][@stdlib/ndarray/dtypes]. +- **shape**: array shape. +- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nans = require( '@stdlib/ndarray/base/nans' ); + +var dt = [ + 'float64', + 'float32', + 'complex128', + 'complex64' +]; + +// Generate NaN-filled arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = nans( dt[ i ], [ 2, 2 ], 'row-major' ); + console.log( ndarray2array( arr ) ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js new file mode 100644 index 000000000000..b500206d65eb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nans( 'float64', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nans( 'float32', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nans( 'complex128', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nans( 'complex64', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex128.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex128.js new file mode 100644 index 000000000000..2a2dbeecb547 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex128.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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 = nans( 'complex128', [ len ], 'row-major' ); + 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:dtype=complex128,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex64.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex64.js new file mode 100644 index 000000000000..aa7d6812a2aa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.complex64.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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 = nans( 'complex64', [ len ], 'row-major' ); + 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:dtype=complex64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float32.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float32.js new file mode 100644 index 000000000000..c7db65e458fb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float32.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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 = nans( 'float32', [ len ], 'row-major' ); + 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:dtype=float32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float64.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float64.js new file mode 100644 index 000000000000..0deeb880e096 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.float64.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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 = nans( 'float64', [ len ], 'row-major' ); + 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:dtype=float64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt new file mode 100644 index 000000000000..9e73544f9171 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( dtype, shape, order ) + Returns a NaN-filled ndarray having a specified shape and data type. + + Parameters + ---------- + dtype: string|DataType + Underlying data type. Must be a floating-point data type. + + shape: ArrayLikeObject + Array shape. + + order: string + Specifies whether an array is row-major (C-style) or column-major + (Fortran-style). + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var arr = {{alias}}( 'float64', [ 2, 2 ], 'row-major' ) + [ [ NaN, NaN ], [ NaN, NaN ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts new file mode 100644 index 000000000000..801e6480deb6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts @@ -0,0 +1,123 @@ +/* +* @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 { Shape, Order, typedndarray, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, FloatingPointDataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType } from '@stdlib/types/ndarray'; + +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'float64', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float64' +*/ +declare function nans( dtype: Float64DataType, shape: Shape, order: Order ): float64ndarray; + +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float32' +*/ +declare function nans( dtype: Float32DataType, shape: Shape, order: Order ): float32ndarray; + +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns +* +* var dt = String( getDType( arr ) ); +* // returns 'complex128' +*/ +declare function nans( dtype: Complex128DataType, shape: Shape, order: Order ): complex128ndarray; + +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'complex64', [ 2, 2 ], 'row-major' ); +* // returns +* +* var dt = String( getDType( arr ) ); +* // returns 'complex64' +*/ +declare function nans( dtype: Complex64DataType, shape: Shape, order: Order ): complex64ndarray; + +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'float64', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float64' +*/ +declare function nans( dtype: FloatingPointDataType, shape: Shape, order: Order ): typedndarray; + + +// EXPORTS // + +export = nans; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts new file mode 100644 index 000000000000..718f225c87d4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts @@ -0,0 +1,80 @@ +/* +* @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( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + nans( 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray + nans( 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray + nans( 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray + nans( 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray + + nans( 'float64', [ 2, 2 ], 'column-major' ); // $ExpectType float64ndarray + nans( 'float32', [ 2, 2 ], 'column-major' ); // $ExpectType float32ndarray + nans( 'complex128', [ 2, 2 ], 'column-major' ); // $ExpectType complex128ndarray + nans( 'complex64', [ 2, 2 ], 'column-major' ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is an unrecognized/unsupported data type... +{ + nans( '10', [ 2, 2 ], 'row-major' ); // $ExpectError + nans( 10, [ 2, 2 ], 'row-major' ); // $ExpectError + nans( false, [ 2, 2 ], 'row-major' ); // $ExpectError + nans( true, [ 2, 2 ], 'row-major' ); // $ExpectError + nans( null, [ 2, 2 ], 'row-major' ); // $ExpectError + nans( [], [ 2, 2 ], 'row-major' ); // $ExpectError + nans( {}, [ 2, 2 ], 'row-major' ); // $ExpectError + nans( ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid shape for the second argument... +{ + nans( 'float32', '10', 'row-major' ); // $ExpectError + nans( 'float32', 10, 'row-major' ); // $ExpectError + nans( 'float32', false, 'row-major' ); // $ExpectError + nans( 'float32', true, 'row-major' ); // $ExpectError + nans( 'float32', null, 'row-major' ); // $ExpectError + nans( 'float32', undefined, 'row-major' ); // $ExpectError + nans( 'float32', [ '5' ], 'row-major' ); // $ExpectError + nans( 'float32', {}, 'row-major' ); // $ExpectError + nans( 'float32', ( x: number ): number => x, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid order for the third argument... +{ + nans( 'float32', [ 2, 2 ], '10' ); // $ExpectError + nans( 'float32', [ 2, 2 ], 10 ); // $ExpectError + nans( 'float32', [ 2, 2 ], false ); // $ExpectError + nans( 'float32', [ 2, 2 ], true ); // $ExpectError + nans( 'float32', [ 2, 2 ], null ); // $ExpectError + nans( 'float32', [ 2, 2 ], undefined ); // $ExpectError + nans( 'float32', [ 2, 2 ], [ '5' ] ); // $ExpectError + nans( 'float32', [ 2, 2 ], {} ); // $ExpectError + nans( 'float32', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + nans( 'float64' ); // $ExpectError + nans( 'float64', [ 2, 2 ] ); // $ExpectError + nans( 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js new file mode 100644 index 000000000000..1686a7ea7ba9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nans = require( './../lib' ); + +var dt = [ + 'float64', + 'float32', + 'complex128', + 'complex64' +]; + +// Generate NaN-filled arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = nans( dt[ i ], [ 2, 2 ], 'row-major' ); + console.log( ndarray2array( arr ) ); +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/nans/lib/index.js new file mode 100644 index 000000000000..0fcebefecd3c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 a specified shape and data type. +* +* @module @stdlib/ndarray/base/nans +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nans = require( '@stdlib/ndarray/base/nans' ); +* +* var arr = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float32' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js new file mode 100644 index 000000000000..b5021cf2ecbc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js @@ -0,0 +1,59 @@ +/** +* @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 empty = require( '@stdlib/ndarray/base/empty' ); +var fill = require( '@stdlib/ndarray/base/fill' ); +var CNAN = require( '@stdlib/constants/complex128/nan' ); + + +// MAIN // + +/** +* Creates a NaN-filled ndarray having a specified shape and data type. +* +* @param {*} dtype - floating-point data type +* @param {NonNegativeIntegerArray} shape - array shape +* @param {string} order - array order +* @throws {TypeError} first argument must be a recognized data type +* @returns {ndarray} ndarray +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float32' +*/ +function nans( dtype, shape, order ) { + if ( isComplexFloatingPointDataType( dtype ) ) { + return fill( empty( dtype, shape, order ), CNAN ); + } + return fill( empty( dtype, shape, order ), NaN ); +} + + +// EXPORTS // + +module.exports = nans; diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/package.json b/lib/node_modules/@stdlib/ndarray/base/nans/package.json new file mode 100644 index 000000000000..71aaf719c026 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/nans", + "version": "0.0.0", + "description": "Create a NaN-filled ndarray having a specified 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", + "fill", + "filled", + "nans", + "nan" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js new file mode 100644 index 000000000000..ce9d1ddeccef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js @@ -0,0 +1,249 @@ +/** +* @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 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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +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 nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Tests whether all elements in an array are NaN. +* +* @private +* @param {Collection} arr - input array +* @returns {boolean} boolean indicating whether all elements are NaN +*/ +function allNaN( arr ) { + var i; + 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 nans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'nans', + 'int32', + 'uint32', + 'int16', + 'uint16', + 'int8', + 'uint8', + 'uint8c', + 'binary', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32', + 'GENERIC' + ]; + + 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() { + nans( value, 10, 'row-major' ); + }; + } +}); + +tape( 'the function returns a NaN-filled array (dtype=float64, order=row-major)', function test( t ) { + var arr; + + arr = nans( 'float64', [ 2, 2 ], 'row-major' ); + 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' ); + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float64, order=column-major)', function test( t ) { + var arr; + + arr = nans( 'float64', [ 2, 2 ], 'column-major' ); + 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' ); + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float32, order=row-major)', function test( t ) { + var arr; + + arr = nans( 'float32', [ 2, 2 ], 'row-major' ); + 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' ); + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float32, order=column-major)', function test( t ) { + var arr; + + arr = nans( 'float32', [ 2, 2 ], 'column-major' ); + 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' ); + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex128, order=row-major)', function test( t ) { + var arr; + + arr = nans( 'complex128', [ 2, 2 ], 'row-major' ); + 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' ); + t.strictEqual( allNaN( reinterpret128( getData( arr ), 0 ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex128, order=column-major)', function test( t ) { + var arr; + + arr = nans( 'complex128', [ 2, 2 ], 'column-major' ); + 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' ); + t.strictEqual( allNaN( reinterpret128( getData( arr ), 0 ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex64, order=row-major)', function test( t ) { + var arr; + + arr = nans( 'complex64', [ 2, 2 ], 'row-major' ); + 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' ); + t.strictEqual( allNaN( reinterpret64( getData( arr ), 0 ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=complex64, order=column-major)', function test( t ) { + var arr; + + arr = nans( 'complex64', [ 2, 2 ], 'column-major' ); + 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' ); + t.strictEqual( allNaN( reinterpret64( getData( arr ), 0 ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays', function test( t ) { + var arr; + + arr = nans( 'float64', [], 'row-major' ); + t.strictEqual( instanceOf( arr, ndarray ), 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( allNaN( getData( arr ) ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports empty arrays', function test( t ) { + var arr; + + arr = nans( 'float64', [ 2, 0, 2 ], 'row-major' ); + t.strictEqual( instanceOf( arr, ndarray ), 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(); +}); From 5b996f9fea65efc60147729d0149396909985bc2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 09:31:07 +0500 Subject: [PATCH 2/6] fix: apply suggestions from code review --- .../@stdlib/ndarray/base/nans/README.md | 5 +- .../ndarray/base/nans/benchmark/benchmark.js | 18 ++++ .../nans/benchmark/benchmark.size.generic.js | 94 +++++++++++++++++++ .../@stdlib/ndarray/base/nans/docs/repl.txt | 3 +- .../ndarray/base/nans/docs/types/index.d.ts | 23 ++++- .../ndarray/base/nans/docs/types/test.ts | 2 + .../ndarray/base/nans/examples/index.js | 3 +- .../@stdlib/ndarray/base/nans/lib/main.js | 2 +- .../@stdlib/ndarray/base/nans/test/test.js | 41 +++++++- 9 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.generic.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/README.md b/lib/node_modules/@stdlib/ndarray/base/nans/README.md index 854302d1ebe2..5339385037e5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/nans/README.md @@ -56,7 +56,7 @@ var dt = String( getDType( arr ) ); The function accepts the following arguments: -- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a floating-point [data type][@stdlib/ndarray/dtypes]. +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. - **shape**: array shape. - **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). @@ -88,7 +88,8 @@ var dt = [ 'float64', 'float32', 'complex128', - 'complex64' + 'complex64', + 'generic' ]; // Generate NaN-filled arrays... diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js index b500206d65eb..36d8cf533197 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.js @@ -100,3 +100,21 @@ bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) { b.pass( 'benchmark finished' ); b.end(); }); + +bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nans( 'generic', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.generic.js b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.generic.js new file mode 100644 index 000000000000..17521b520be4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nans/benchmark/benchmark.size.generic.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nans = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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 = nans( 'generic', [ len ], 'row-major' ); + 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:dtype=generic,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt index 9e73544f9171..828f319f047e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/repl.txt @@ -5,7 +5,8 @@ Parameters ---------- dtype: string|DataType - Underlying data type. Must be a floating-point data type. + Underlying data type. Must be a floating-point or "generic" data + type. shape: ArrayLikeObject Array shape. diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts index 801e6480deb6..414530cb74b6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { Shape, Order, typedndarray, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, FloatingPointDataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType } from '@stdlib/types/ndarray'; +import { Shape, Order, typedndarray, genericndarray, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, FloatingPointAndGenericDataType, GenericDataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType } from '@stdlib/types/ndarray'; /** * Creates a NaN-filled array having a specified shape and data type. @@ -98,6 +98,25 @@ declare function nans( dtype: Complex128DataType, shape: Shape, order: Order ): */ declare function nans( dtype: Complex64DataType, shape: Shape, order: Order ): complex64ndarray; +/** +* Creates a NaN-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns NaN-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nans( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ NaN, NaN ], [ NaN, NaN ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'generic' +*/ +declare function nans( dtype: GenericDataType, shape: Shape, order: Order ): genericndarray; + /** * Creates a NaN-filled array having a specified shape and data type. * @@ -115,7 +134,7 @@ declare function nans( dtype: Complex64DataType, shape: Shape, order: Order ): c * var dt = String( getDType( arr ) ); * // returns 'float64' */ -declare function nans( dtype: FloatingPointDataType, shape: Shape, order: Order ): typedndarray; +declare function nans( dtype: FloatingPointAndGenericDataType, shape: Shape, order: Order ): typedndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts index 718f225c87d4..612bcf4e4309 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/nans/docs/types/test.ts @@ -27,11 +27,13 @@ import nans = require( './index' ); nans( 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray nans( 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray nans( 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray + nans( 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType genericndarray nans( 'float64', [ 2, 2 ], 'column-major' ); // $ExpectType float64ndarray nans( 'float32', [ 2, 2 ], 'column-major' ); // $ExpectType float32ndarray nans( 'complex128', [ 2, 2 ], 'column-major' ); // $ExpectType complex128ndarray nans( 'complex64', [ 2, 2 ], 'column-major' ); // $ExpectType complex64ndarray + nans( 'generic', [ 2, 2 ], 'column-major' ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument which is an unrecognized/unsupported data type... diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js index 1686a7ea7ba9..31c65670552a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/examples/index.js @@ -25,7 +25,8 @@ var dt = [ 'float64', 'float32', 'complex128', - 'complex64' + 'complex64', + 'generic' ]; // Generate NaN-filled arrays... diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js index b5021cf2ecbc..fc9f82273a13 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/lib/main.js @@ -31,7 +31,7 @@ var CNAN = require( '@stdlib/constants/complex128/nan' ); /** * Creates a NaN-filled ndarray having a specified shape and data type. * -* @param {*} dtype - floating-point data type +* @param {*} dtype - floating-point or generic data type * @param {NonNegativeIntegerArray} shape - array shape * @param {string} order - array order * @throws {TypeError} first argument must be a recognized data type diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js index ce9d1ddeccef..0bf0d8ffe8e6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js @@ -92,8 +92,7 @@ tape( 'the function throws an error if provided an unrecognized data type', func 'Float64', 'Float32', 'FLOAT64', - 'FLOAT32', - 'GENERIC' + 'FLOAT32' ]; for ( i = 0; i < values.length; i++ ) { @@ -220,6 +219,44 @@ tape( 'the function returns a NaN-filled array (dtype=complex64, order=column-ma t.end(); }); +tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)', function test( t ) { + var arr; + var buf; + var i; + + arr = nans( 'generic', [ 2, 2 ], 'row-major' ); + 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 ); + for ( i = 0; i < buf.length; i++ ) { + t.strictEqual( isnan( buf[ i ] ), true, 'returns expected value' ); + } + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=generic, order=column-major)', function test( t ) { + var arr; + var buf; + var i; + + arr = nans( 'generic', [ 2, 2 ], 'column-major' ); + 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 ); + for ( i = 0; i < buf.length; i++ ) { + t.strictEqual( isnan( buf[ i ] ), true, 'returns expected value' ); + } + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports zero-dimensional arrays', function test( t ) { var arr; From bcf4efcca5944c38692d6b98717a2ed488066320 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 22:25:34 -0700 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ndarray/base/nans/test/test.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js index 0bf0d8ffe8e6..695087354ad6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js @@ -221,7 +221,6 @@ tape( 'the function returns a NaN-filled array (dtype=complex64, order=column-ma tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)', function test( t ) { var arr; - var buf; var i; arr = nans( 'generic', [ 2, 2 ], 'row-major' ); @@ -229,10 +228,7 @@ tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)' 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 ); - for ( i = 0; i < buf.length; i++ ) { - t.strictEqual( isnan( buf[ i ] ), true, 'returns expected value' ); - } + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); t.end(); @@ -240,7 +236,6 @@ tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)' tape( 'the function returns a NaN-filled array (dtype=generic, order=column-major)', function test( t ) { var arr; - var buf; var i; arr = nans( 'generic', [ 2, 2 ], 'column-major' ); @@ -248,10 +243,7 @@ tape( 'the function returns a NaN-filled array (dtype=generic, order=column-majo 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 ); - for ( i = 0; i < buf.length; i++ ) { - t.strictEqual( isnan( buf[ i ] ), true, 'returns expected value' ); - } + t.strictEqual( allNaN( getData( arr ) ), true, 'returns expected value' ); t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); t.end(); From bedaa664eda9d941ab3b4f387e22d397f46148b3 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 22:26:21 -0700 Subject: [PATCH 4/6] Apply suggestion from @kgryte Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/nans/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js index 695087354ad6..2f2de4b2b213 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js @@ -65,7 +65,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { +tape( 'the function throws an error if provided an unrecognized/unsupported data type', function test( t ) { var values; var i; From 939375c2ddc8ebeacfefec4695fec09bd822a4b0 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 22:27:19 -0700 Subject: [PATCH 5/6] Apply suggestion from @kgryte Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/nans/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/README.md b/lib/node_modules/@stdlib/ndarray/base/nans/README.md index 5339385037e5..f0fd315dc627 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/nans/README.md @@ -42,7 +42,7 @@ var nans = require( '@stdlib/ndarray/base/nans' ); #### nans( dtype, shape, order ) -Creates a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and floating-point [data type][@stdlib/ndarray/dtypes]. +Creates a NaN-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes]. ```javascript var getDType = require( '@stdlib/ndarray/dtype' ); From ffffe83b9601f7197ba08da18fa250e8d8a0efd2 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 22:29:38 -0700 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/nans/test/test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js index 2f2de4b2b213..06f5fac44bae 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/nans/test/test.js @@ -221,7 +221,6 @@ tape( 'the function returns a NaN-filled array (dtype=complex64, order=column-ma tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)', function test( t ) { var arr; - var i; arr = nans( 'generic', [ 2, 2 ], 'row-major' ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); @@ -236,7 +235,6 @@ tape( 'the function returns a NaN-filled array (dtype=generic, order=row-major)' tape( 'the function returns a NaN-filled array (dtype=generic, order=column-major)', function test( t ) { var arr; - var i; arr = nans( 'generic', [ 2, 2 ], 'column-major' ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );