diff --git a/lib/node_modules/@stdlib/array/nans-like/README.md b/lib/node_modules/@stdlib/array/nans-like/README.md index 7d6edbfd4c8a..6c12b7b76dc8 100644 --- a/lib/node_modules/@stdlib/array/nans-like/README.md +++ b/lib/node_modules/@stdlib/array/nans-like/README.md @@ -55,6 +55,7 @@ The function supports the following data types: - `float64`: double-precision floating-point numbers (IEEE 754) - `float32`: single-precision floating-point numbers (IEEE 754) +- `float16`: half-precision floating-point numbers (IEEE 754) - `complex128`: double-precision complex floating-point numbers - `complex64`: single-precision complex floating-point numbers - `generic`: generic JavaScript values diff --git a/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.js index e4c6cd219763..e39c8ac90414 100644 --- a/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.js @@ -97,6 +97,28 @@ bench( format( '%s:dtype=%s', pkg, 'float32' ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=%s', pkg, 'float16' ), function benchmark( b ) { + var arr; + var x; + var i; + + x = empty( 0, 'float16' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nansLike( x ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s:dtype=%s', pkg, 'complex128' ), function benchmark( b ) { var arr; var x; diff --git a/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..05e4b11d871a --- /dev/null +++ b/lib/node_modules/@stdlib/array/nans-like/benchmark/benchmark.length.float16.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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var empty = require( '@stdlib/array/empty' ); +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 = empty( len, 'float16' ); + 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 ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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=%s,len=%d', pkg, 'float16', len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt b/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt index df99cb07b8cc..0f8e3a362ad6 100644 --- a/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/nans-like/docs/repl.txt @@ -7,6 +7,7 @@ - float64: double-precision floating-point numbers (IEEE 754). - float32: single-precision floating-point numbers (IEEE 754). + - float16: half-precision floating-point numbers (IEEE 754). - complex128: double-precision complex floating-point numbers. - complex64: single-precision complex floating-point numbers. - generic: generic JavaScript values. diff --git a/lib/node_modules/@stdlib/array/nans-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/nans-like/docs/types/index.d.ts index 3c73c3819dfd..cd3a363bdbbc 100644 --- a/lib/node_modules/@stdlib/array/nans-like/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/nans-like/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { Complex128Array, Complex64Array, AnyArray, FloatingPointDataType } from '@stdlib/types/array'; +import { Complex128Array, Complex64Array, Float16Array, AnyArray, FloatingPointDataType } from '@stdlib/types/array'; /** * Data type. @@ -63,6 +63,24 @@ declare function nansLike( x: AnyArray, dtype: 'float64' ): Float64Array; */ declare function nansLike( x: AnyArray, dtype: 'float32' ): Float32Array; +/** +* Creates an array filled with NaNs and having the same length as a provided input array. +* +* @param x - input array from which to derive the output array length +* @param dtype - data type +* @returns filled array +* +* @example +* var zeros = require( '@stdlib/array/zeros' ); +* +* var x = zeros( 2, 'float64' ); +* // returns [ 0.0, 0.0 ] +* +* var y = nansLike( x, 'float16' ); +* // returns [ NaN, NaN ] +*/ +declare function nansLike( x: AnyArray, dtype: 'float16' ): Float16Array; + /** * Creates an array filled with NaNs and having the same length as a provided input array. * @@ -177,6 +195,33 @@ declare function nansLike( x: Float64Array, dtype?: DataType ): Float64Array; */ declare function nansLike( x: Float32Array, dtype?: DataType ): Float32Array; +/** +* Creates an array filled with NaNs and having the same length and data type as a provided input array. +* +* The function supports the following data types: +* +* - `float64`: double-precision floating-point numbers (IEEE 754) +* - `float32`: single-precision floating-point numbers (IEEE 754) +* - `float16`: half-precision floating-point numbers (IEEE 754) +* - `complex128`: double-precision complex floating-point numbers +* - `complex64`: single-precision complex floating-point numbers +* - `generic`: generic JavaScript values +* +* @param x - input array from which to derive the output array length +* @param dtype - data type +* @returns filled array +* +* @example +* var zeros = require( '@stdlib/array/zeros' ); +* +* var x = zeros( 2, 'float16' ); +* // returns [ 0.0, 0.0 ] +* +* var y = nansLike( x ); +* // returns [ NaN, NaN ] +*/ +declare function nansLike( x: Float16Array, dtype?: DataType ): Float16Array; + /** * Creates an array filled with NaNs and having the same length and data type as a provided input array. * diff --git a/lib/node_modules/@stdlib/array/nans-like/docs/types/test.ts b/lib/node_modules/@stdlib/array/nans-like/docs/types/test.ts index fc82ce5293a6..10d43bf5c507 100644 --- a/lib/node_modules/@stdlib/array/nans-like/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/nans-like/docs/types/test.ts @@ -18,6 +18,7 @@ import Complex128Array = require( '@stdlib/array/complex128' ); import Complex64Array = require( '@stdlib/array/complex64' ); +import Float16Array = require( '@stdlib/array/float16' ); import nansLike = require( './index' ); @@ -28,11 +29,13 @@ import nansLike = require( './index' ); nansLike( [ 0, 0 ] ); // $ExpectType number[] nansLike( new Float64Array( [ 0, 0 ] ) ); // $ExpectType Float64Array nansLike( new Float32Array( [ 0, 0 ] ) ); // $ExpectType Float32Array + nansLike( new Float16Array( [ 0, 0 ] ) ); // $ExpectType Float16ArrayFallback nansLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array nansLike( new Complex64Array( [ 0, 0 ] ) ); // $ExpectType Complex64Array nansLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array nansLike( [ 0, 0 ], 'float32' ); // $ExpectType Float32Array + nansLike( [ 0, 0 ], 'float16' ); // $ExpectType Float16ArrayFallback nansLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array nansLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array nansLike( [ 0, 0 ], 'generic' ); // $ExpectType number[] diff --git a/lib/node_modules/@stdlib/array/nans-like/package.json b/lib/node_modules/@stdlib/array/nans-like/package.json index 1af8471720f7..329dd9deedb8 100644 --- a/lib/node_modules/@stdlib/array/nans-like/package.json +++ b/lib/node_modules/@stdlib/array/nans-like/package.json @@ -63,6 +63,7 @@ "matrix", "float64array", "float32array", + "float16array", "complex128array", "complex64array", "complex128", @@ -77,6 +78,9 @@ "float", "single-precision", "float32", + "half", + "half-precision", + "float16", "ieee754", "generic", "fill", diff --git a/lib/node_modules/@stdlib/array/nans-like/test/test.js b/lib/node_modules/@stdlib/array/nans-like/test/test.js index 29bba08774f5..39932a280124 100644 --- a/lib/node_modules/@stdlib/array/nans-like/test/test.js +++ b/lib/node_modules/@stdlib/array/nans-like/test/test.js @@ -23,8 +23,10 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isnanf16 = require( '@stdlib/number/float16/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); +var Float16Array = require( '@stdlib/array/float16' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); @@ -202,6 +204,40 @@ tape( 'the function returns a NaN-filled array (dtype=float32)', function test( t.end(); }); +tape( 'the function returns a NaN-filled array (float16)', function test( t ) { + var arr; + var x; + var i; + + x = new Float16Array( 5 ); + + arr = nansLike( x ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, x.length, 'returns expected value' ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( isnanf16( arr[ i ] ), true, 'returns expected value for element '+i ); + } + t.end(); +}); + +tape( 'the function returns a NaN-filled array (dtype=float16)', function test( t ) { + var arr; + var x; + var i; + + x = new Float64Array( 5 ); + + arr = nansLike( x, 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, x.length, 'returns expected value' ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( isnanf16( arr[ i ] ), true, 'returns expected value for element '+i ); + } + t.end(); +}); + tape( 'the function returns a NaN-filled array (complex128)', function test( t ) { var arr; var x;