Skip to content

Commit ad1f6b5

Browse files
committed
Auto-generated commit
1 parent 8e5cc65 commit ad1f6b5

9 files changed

Lines changed: 211 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`bd39888`](https://github.com/stdlib-js/stdlib/commit/bd3988874fec8e11dcb2ea04afc3e9c2a45207e5) - add float16 dtype support to `array/nans-like` [(#14122)](https://github.com/stdlib-js/stdlib/pull/14122)
1314
- [`0078b7e`](https://github.com/stdlib-js/stdlib/commit/0078b7ed60fc8040a9d11a6d1c4d94bc34e4df5a) - add float16 dtype support to `array/ones-like` [(#14124)](https://github.com/stdlib-js/stdlib/pull/14124)
1415
- [`2e31902`](https://github.com/stdlib-js/stdlib/commit/2e31902b44dfa195f9caa5ece57b1649a000e47a) - add float16 dtype support to `array/ones` [(#14123)](https://github.com/stdlib-js/stdlib/pull/14123)
1516
- [`4d0ce60`](https://github.com/stdlib-js/stdlib/commit/4d0ce60011997633aac407dbba435da1763a2550) - add float16 dtype support to `array/convert-same` [(#14126)](https://github.com/stdlib-js/stdlib/pull/14126)
@@ -88,6 +89,7 @@ This release closes the following issue:
8889

8990
<details>
9091

92+
- [`bd39888`](https://github.com/stdlib-js/stdlib/commit/bd3988874fec8e11dcb2ea04afc3e9c2a45207e5) - **feat:** add float16 dtype support to `array/nans-like` [(#14122)](https://github.com/stdlib-js/stdlib/pull/14122) _(by Gururaj Gurram, Athan Reines)_
9193
- [`e805b48`](https://github.com/stdlib-js/stdlib/commit/e805b48af03299edd06969a72e9bf03ccb344aa5) - **bench:** fix assignment operation _(by Athan Reines)_
9294
- [`3fdf0b9`](https://github.com/stdlib-js/stdlib/commit/3fdf0b943c342271e5ee4b80d7bf30cb2b5de1e1) - **bench:** reassign variable _(by Athan Reines)_
9395
- [`075283f`](https://github.com/stdlib-js/stdlib/commit/075283f8cdb22dd49286c6fa7ddc874b584af48d) - **bench:** reassign variable _(by Athan Reines)_

nans-like/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The function supports the following data types:
5555

5656
- `float64`: double-precision floating-point numbers (IEEE 754)
5757
- `float32`: single-precision floating-point numbers (IEEE 754)
58+
- `float16`: half-precision floating-point numbers (IEEE 754)
5859
- `complex128`: double-precision complex floating-point numbers
5960
- `complex64`: single-precision complex floating-point numbers
6061
- `generic`: generic JavaScript values

nans-like/benchmark/benchmark.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,28 @@ bench( format( '%s:dtype=%s', pkg, 'float32' ), function benchmark( b ) {
9797
b.end();
9898
});
9999

100+
bench( format( '%s:dtype=%s', pkg, 'float16' ), function benchmark( b ) {
101+
var arr;
102+
var x;
103+
var i;
104+
105+
x = empty( 0, 'float16' );
106+
107+
b.tic();
108+
for ( i = 0; i < b.iterations; i++ ) {
109+
arr = nansLike( x );
110+
if ( arr.length !== 0 ) {
111+
b.fail( 'should have length 0' );
112+
}
113+
}
114+
b.toc();
115+
if ( !isTypedArrayLike( arr ) ) {
116+
b.fail( 'should return a typed array' );
117+
}
118+
b.pass( 'benchmark finished' );
119+
b.end();
120+
});
121+
100122
bench( format( '%s:dtype=%s', pkg, 'complex128' ), function benchmark( b ) {
101123
var arr;
102124
var x;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
26+
var empty = require( './../../empty' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var nansLike = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = empty( len, 'float16' );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var arr;
53+
var i;
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
arr = nansLike( x );
58+
if ( arr.length !== len ) {
59+
b.fail( 'unexpected length' );
60+
}
61+
}
62+
b.toc();
63+
if ( !isTypedArray( arr ) ) {
64+
b.fail( 'should return a typed array' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
}
69+
}
70+
71+
72+
// MAIN //
73+
74+
/**
75+
* Main execution sequence.
76+
*
77+
* @private
78+
*/
79+
function main() {
80+
var len;
81+
var min;
82+
var max;
83+
var f;
84+
var i;
85+
86+
min = 1; // 10^min
87+
max = 6; // 10^max
88+
89+
for ( i = min; i <= max; i++ ) {
90+
len = pow( 10, i );
91+
f = createBenchmark( len );
92+
bench( format( '%s:dtype=%s,len=%d', pkg, 'float16', len ), f );
93+
}
94+
}
95+
96+
main();

nans-like/docs/repl.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
- float64: double-precision floating-point numbers (IEEE 754).
99
- float32: single-precision floating-point numbers (IEEE 754).
10+
- float16: half-precision floating-point numbers (IEEE 754).
1011
- complex128: double-precision complex floating-point numbers.
1112
- complex64: single-precision complex floating-point numbers.
1213
- generic: generic JavaScript values.

nans-like/docs/types/index.d.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { Complex128Array, Complex64Array, AnyArray, FloatingPointDataType } from '@stdlib/types/array';
23+
import { Complex128Array, Complex64Array, Float16Array, AnyArray, FloatingPointDataType } from '@stdlib/types/array';
2424

2525
/**
2626
* Data type.
@@ -63,6 +63,24 @@ declare function nansLike( x: AnyArray, dtype: 'float64' ): Float64Array;
6363
*/
6464
declare function nansLike( x: AnyArray, dtype: 'float32' ): Float32Array;
6565

66+
/**
67+
* Creates an array filled with NaNs and having the same length as a provided input array.
68+
*
69+
* @param x - input array from which to derive the output array length
70+
* @param dtype - data type
71+
* @returns filled array
72+
*
73+
* @example
74+
* var zeros = require( '@stdlib/array/zeros' );
75+
*
76+
* var x = zeros( 2, 'float64' );
77+
* // returns <Float64Array>[ 0.0, 0.0 ]
78+
*
79+
* var y = nansLike( x, 'float16' );
80+
* // returns <Float16Array>[ NaN, NaN ]
81+
*/
82+
declare function nansLike( x: AnyArray, dtype: 'float16' ): Float16Array;
83+
6684
/**
6785
* Creates an array filled with NaNs and having the same length as a provided input array.
6886
*
@@ -177,6 +195,33 @@ declare function nansLike( x: Float64Array, dtype?: DataType ): Float64Array;
177195
*/
178196
declare function nansLike( x: Float32Array, dtype?: DataType ): Float32Array;
179197

198+
/**
199+
* Creates an array filled with NaNs and having the same length and data type as a provided input array.
200+
*
201+
* The function supports the following data types:
202+
*
203+
* - `float64`: double-precision floating-point numbers (IEEE 754)
204+
* - `float32`: single-precision floating-point numbers (IEEE 754)
205+
* - `float16`: half-precision floating-point numbers (IEEE 754)
206+
* - `complex128`: double-precision complex floating-point numbers
207+
* - `complex64`: single-precision complex floating-point numbers
208+
* - `generic`: generic JavaScript values
209+
*
210+
* @param x - input array from which to derive the output array length
211+
* @param dtype - data type
212+
* @returns filled array
213+
*
214+
* @example
215+
* var zeros = require( '@stdlib/array/zeros' );
216+
*
217+
* var x = zeros( 2, 'float16' );
218+
* // returns <Float16Array>[ 0.0, 0.0 ]
219+
*
220+
* var y = nansLike( x );
221+
* // returns <Float16Array>[ NaN, NaN ]
222+
*/
223+
declare function nansLike( x: Float16Array, dtype?: DataType ): Float16Array;
224+
180225
/**
181226
* Creates an array filled with NaNs and having the same length and data type as a provided input array.
182227
*

nans-like/docs/types/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import Complex128Array = require( './../../../complex128' );
2020
import Complex64Array = require( './../../../complex64' );
21+
import Float16Array = require( './../../../float16' );
2122
import nansLike = require( './index' );
2223

2324

@@ -28,11 +29,13 @@ import nansLike = require( './index' );
2829
nansLike( [ 0, 0 ] ); // $ExpectType number[]
2930
nansLike( new Float64Array( [ 0, 0 ] ) ); // $ExpectType Float64Array
3031
nansLike( new Float32Array( [ 0, 0 ] ) ); // $ExpectType Float32Array
32+
nansLike( new Float16Array( [ 0, 0 ] ) ); // $ExpectType Float16ArrayFallback
3133
nansLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array
3234
nansLike( new Complex64Array( [ 0, 0 ] ) ); // $ExpectType Complex64Array
3335

3436
nansLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array
3537
nansLike( [ 0, 0 ], 'float32' ); // $ExpectType Float32Array
38+
nansLike( [ 0, 0 ], 'float16' ); // $ExpectType Float16ArrayFallback
3639
nansLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array
3740
nansLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array
3841
nansLike( [ 0, 0 ], 'generic' ); // $ExpectType number[]

nans-like/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"matrix",
6464
"float64array",
6565
"float32array",
66+
"float16array",
6667
"complex128array",
6768
"complex64array",
6869
"complex128",
@@ -77,6 +78,9 @@
7778
"float",
7879
"single-precision",
7980
"float32",
81+
"half",
82+
"half-precision",
83+
"float16",
8084
"ieee754",
8185
"generic",
8286
"fill",

nans-like/test/test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var isnanf16 = require( '@stdlib/number/float16/base/assert/is-nan' );
2627
var Float64Array = require( './../../float64' );
2728
var Float32Array = require( './../../float32' );
29+
var Float16Array = require( './../../float16' );
2830
var Complex64Array = require( './../../complex64' );
2931
var Complex128Array = require( './../../complex128' );
3032
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
@@ -202,6 +204,40 @@ tape( 'the function returns a NaN-filled array (dtype=float32)', function test(
202204
t.end();
203205
});
204206

207+
tape( 'the function returns a NaN-filled array (float16)', function test( t ) {
208+
var arr;
209+
var x;
210+
var i;
211+
212+
x = new Float16Array( 5 );
213+
214+
arr = nansLike( x );
215+
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
216+
t.strictEqual( arr.length, x.length, 'returns expected value' );
217+
218+
for ( i = 0; i < arr.length; i++ ) {
219+
t.strictEqual( isnanf16( arr[ i ] ), true, 'returns expected value for element '+i );
220+
}
221+
t.end();
222+
});
223+
224+
tape( 'the function returns a NaN-filled array (dtype=float16)', function test( t ) {
225+
var arr;
226+
var x;
227+
var i;
228+
229+
x = new Float64Array( 5 );
230+
231+
arr = nansLike( x, 'float16' );
232+
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
233+
t.strictEqual( arr.length, x.length, 'returns expected value' );
234+
235+
for ( i = 0; i < arr.length; i++ ) {
236+
t.strictEqual( isnanf16( arr[ i ] ), true, 'returns expected value for element '+i );
237+
}
238+
t.end();
239+
});
240+
205241
tape( 'the function returns a NaN-filled array (complex128)', function test( t ) {
206242
var arr;
207243
var x;

0 commit comments

Comments
 (0)