Skip to content

Commit 7107acf

Browse files
committed
Auto-generated commit
1 parent 3f3e4f8 commit 7107acf

8 files changed

Lines changed: 212 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+
- [`83e2790`](https://github.com/stdlib-js/stdlib/commit/83e2790a1e95b65d969b50cbe9da03a7623d98cf) - add float16 dtype support to `ndarray/nans` [(#15251)](https://github.com/stdlib-js/stdlib/pull/15251)
1314
- [`a2aaa2b`](https://github.com/stdlib-js/stdlib/commit/a2aaa2b22422a3b5db27fb5ce0b50ba5c0023fe1) - add float16 dtype support to `ndarray/map` [(#15250)](https://github.com/stdlib-js/stdlib/pull/15250)
1415
- [`24f7b25`](https://github.com/stdlib-js/stdlib/commit/24f7b25084a90d7d02896ae1086b90b6869a9b15) - add float16 dtype support to `ndarray/filter` [(#15232)](https://github.com/stdlib-js/stdlib/pull/15232)
1516
- [`b116ddc`](https://github.com/stdlib-js/stdlib/commit/b116ddc030b397cc478e69e37cec904d41db4fdf) - add float16 dtype support to `ndarray/empty` [(#15181)](https://github.com/stdlib-js/stdlib/pull/15181)
@@ -105,6 +106,7 @@ A total of 4 issues were closed in this release:
105106

106107
<details>
107108

109+
- [`83e2790`](https://github.com/stdlib-js/stdlib/commit/83e2790a1e95b65d969b50cbe9da03a7623d98cf) - **feat:** add float16 dtype support to `ndarray/nans` [(#15251)](https://github.com/stdlib-js/stdlib/pull/15251) _(by Samarth Kolarkar)_
108110
- [`a2aaa2b`](https://github.com/stdlib-js/stdlib/commit/a2aaa2b22422a3b5db27fb5ce0b50ba5c0023fe1) - **feat:** add float16 dtype support to `ndarray/map` [(#15250)](https://github.com/stdlib-js/stdlib/pull/15250) _(by Samarth Kolarkar)_
109111
- [`24f7b25`](https://github.com/stdlib-js/stdlib/commit/24f7b25084a90d7d02896ae1086b90b6869a9b15) - **feat:** add float16 dtype support to `ndarray/filter` [(#15232)](https://github.com/stdlib-js/stdlib/pull/15232) _(by Samarth Kolarkar)_
110112
- [`b116ddc`](https://github.com/stdlib-js/stdlib/commit/b116ddc030b397cc478e69e37cec904d41db4fdf) - **feat:** add float16 dtype support to `ndarray/empty` [(#15181)](https://github.com/stdlib-js/stdlib/pull/15181) _(by Samarth Kolarkar)_

‎nans/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var nans = require( '@stdlib/ndarray/nans' );
128128
var dt = [
129129
'float64',
130130
'float32',
131+
'float16',
131132
'complex128',
132133
'complex64',
133134
'generic'

‎nans/benchmark/benchmark.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
8787
b.end();
8888
});
8989

90+
bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) {
91+
var arr;
92+
var i;
93+
b.tic();
94+
for ( i = 0; i < b.iterations; i++ ) {
95+
arr = nans( [ 0 ], {
96+
'dtype': 'float16'
97+
});
98+
if ( arr.length !== 0 ) {
99+
b.fail( 'should have length 0' );
100+
}
101+
}
102+
b.toc();
103+
if ( !isndarrayLike( arr ) ) {
104+
b.fail( 'should return an ndarray' );
105+
}
106+
b.pass( 'benchmark finished' );
107+
b.end();
108+
});
109+
90110
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
91111
var arr;
92112
var i;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var nans = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var opts;
51+
var arr;
52+
var i;
53+
54+
opts = {
55+
'dtype': 'float16'
56+
};
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
arr = nans( [ len ], opts );
61+
if ( arr.length !== len ) {
62+
b.fail( 'unexpected length' );
63+
}
64+
}
65+
b.toc();
66+
if ( !isndarrayLike( arr ) ) {
67+
b.fail( 'should return an ndarray' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
}
72+
}
73+
74+
75+
// MAIN //
76+
77+
/**
78+
* Main execution sequence.
79+
*
80+
* @private
81+
*/
82+
function main() {
83+
var len;
84+
var min;
85+
var max;
86+
var f;
87+
var i;
88+
89+
min = 1; // 10^min
90+
max = 6; // 10^max
91+
92+
for ( i = min; i <= max; i++ ) {
93+
len = pow( 10, i );
94+
f = createBenchmark( len );
95+
bench( format( '%s:dtype=float16,size=%d', pkg, len ), f );
96+
}
97+
}
98+
99+
main();

‎nans/docs/types/index.d.ts‎

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

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

23-
import { Shape, Order, Mode, typedndarray, float64ndarray, float32ndarray, genericndarray, complex128ndarray, complex64ndarray, FloatingPointAndGenericDataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType, GenericDataType } from '@stdlib/types/ndarray';
23+
import { Shape, Order, Mode, typedndarray, float64ndarray, float32ndarray, float16ndarray, genericndarray, complex128ndarray, complex64ndarray, FloatingPointAndGenericDataType, Float64DataType, Float32DataType, Float16DataType, Complex128DataType, Complex64DataType, GenericDataType } from '@stdlib/types/ndarray';
2424

2525
/**
2626
* Interface describing function options.
@@ -79,6 +79,20 @@ interface Float32Options extends Options {
7979
dtype: Float32DataType;
8080
}
8181

82+
/**
83+
* Interface describing function options.
84+
*/
85+
interface Float16Options extends Options {
86+
/**
87+
* Underlying data type.
88+
*
89+
* ## Notes
90+
*
91+
* - This option overrides the input array's inferred data type.
92+
*/
93+
dtype: Float16DataType;
94+
}
95+
8296
/**
8397
* Interface describing function options.
8498
*/
@@ -193,6 +207,35 @@ declare function nans( shape: Shape | number, options: Float64Options ): float64
193207
*/
194208
declare function nans( shape: Shape | number, options: Float32Options ): float32ndarray;
195209

210+
/**
211+
* Creates a NaN-filled ndarray having a specified shape and data type.
212+
*
213+
* @param shape - array shape
214+
* @param options - options
215+
* @param options.dtype - underlying data type
216+
* @param options.order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major')
217+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
218+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
219+
* @param options.readonly - boolean indicating whether an array should be read-only
220+
* @returns NaN-filled ndarray
221+
*
222+
* @example
223+
* var getShape = require( '@stdlib/ndarray/shape' );
224+
* var getDType = require( '@stdlib/ndarray/dtype' );
225+
*
226+
* var arr = nans( [ 2, 2 ], {
227+
* 'dtype': 'float16'
228+
* });
229+
* // returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
230+
*
231+
* var sh = getShape( arr );
232+
* // returns [ 2, 2 ]
233+
*
234+
* var dt = String( getDType( arr ) );
235+
* // returns 'float16'
236+
*/
237+
declare function nans( shape: Shape | number, options: Float16Options ): float16ndarray;
238+
196239
/**
197240
* Creates a NaN-filled ndarray having a specified shape and data type.
198241
*

‎nans/docs/types/test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import nans = require( './index' );
2727

2828
nans( [ 2, 2 ], { 'dtype': 'float64' } ); // $ExpectType float64ndarray
2929
nans( [ 2, 2 ], { 'dtype': 'float32' } ); // $ExpectType float32ndarray
30+
nans( [ 2, 2 ], { 'dtype': 'float16' } ); // $ExpectType float16ndarray
3031
nans( [ 2, 2 ], { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray
3132
nans( [ 2, 2 ], { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray
3233
nans( [ 2, 2 ], { 'dtype': 'generic' } ); // $ExpectType genericndarray<number>

‎nans/examples/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var nans = require( './../lib' );
2525
var dt = [
2626
'float64',
2727
'float32',
28+
'float16',
2829
'complex128',
2930
'complex64',
3031
'generic'

‎nans/test/test.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ var tape = require( 'tape' );
2424
var isSameArray = require( '@stdlib/assert/is-same-array' );
2525
var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
2626
var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' );
27+
var isSameFloat16Array = require( '@stdlib/assert/is-same-float16array' );
2728
var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' );
2829
var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' );
2930
var Float64Array = require( '@stdlib/array/float64' );
3031
var Float32Array = require( '@stdlib/array/float32' );
32+
var Float16Array = require( '@stdlib/array/float16' );
3133
var Complex64Array = require( '@stdlib/array/complex64' );
3234
var Complex128Array = require( '@stdlib/array/complex128' );
3335
var instanceOf = require( '@stdlib/assert/instance-of' );
@@ -462,6 +464,48 @@ tape( 'the function returns a NaN-filled array (dtype=float32, order=column-majo
462464
t.end();
463465
});
464466

467+
tape( 'the function returns a NaN-filled array (dtype=float16, order=row-major)', function test( t ) {
468+
var expected;
469+
var opts;
470+
var arr;
471+
472+
expected = new Float16Array( [ NaN, NaN, NaN, NaN ] );
473+
474+
opts = {
475+
'dtype': 'float16',
476+
'order': 'row-major'
477+
};
478+
arr = nans( [ 2, 2 ], opts );
479+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
480+
t.strictEqual( String( getDType( arr ) ), opts.dtype, 'returns expected value' );
481+
t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' );
482+
t.strictEqual( isSameFloat16Array( getData( arr ), expected ), true, 'returns expected value' );
483+
t.strictEqual( getOrder( arr ), opts.order, 'returns expected value' );
484+
485+
t.end();
486+
});
487+
488+
tape( 'the function returns a NaN-filled array (dtype=float16, order=column-major)', function test( t ) {
489+
var expected;
490+
var opts;
491+
var arr;
492+
493+
expected = new Float16Array( [ NaN, NaN, NaN, NaN ] );
494+
495+
opts = {
496+
'dtype': 'float16',
497+
'order': 'column-major'
498+
};
499+
arr = nans( [ 2, 2 ], opts );
500+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
501+
t.strictEqual( String( getDType( arr ) ), opts.dtype, 'returns expected value' );
502+
t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' );
503+
t.strictEqual( isSameFloat16Array( getData( arr ), expected ), true, 'returns expected value' );
504+
t.strictEqual( getOrder( arr ), opts.order, 'returns expected value' );
505+
506+
t.end();
507+
});
508+
465509
tape( 'the function returns a NaN-filled array (dtype=complex128, order=row-major)', function test( t ) {
466510
var expected;
467511
var opts;

0 commit comments

Comments
 (0)