Skip to content

Commit 7b3d853

Browse files
committed
Auto-generated commit
1 parent d1def2c commit 7b3d853

7 files changed

Lines changed: 153 additions & 45 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-09-16)
7+
## Unreleased (2026-09-18)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`13c6723`](https://github.com/stdlib-js/stdlib/commit/13c6723b3f9f5cb9aa3169eadaeb88e03be5e23c) - add float16 dtype support to `ndarray/min-dtype` [(#15290)](https://github.com/stdlib-js/stdlib/pull/15290)
1314
- [`abd365a`](https://github.com/stdlib-js/stdlib/commit/abd365a80596e407afc42fe806b2c113857423d4) - add float16 dtype support to `ndarray/filter-map` [(#15234)](https://github.com/stdlib-js/stdlib/pull/15234)
1415
- [`551a13c`](https://github.com/stdlib-js/stdlib/commit/551a13c30bc3e5d0079e2163a759a037481b58ff) - add float16 dtype support to `ndarray/for-each` [(#15236)](https://github.com/stdlib-js/stdlib/pull/15236)
1516
- [`4ba080a`](https://github.com/stdlib-js/stdlib/commit/4ba080a0f00815a1e00c81a0a063724b4cedc268) - add float16 dtype support to `ndarray/nans-like` [(#15252)](https://github.com/stdlib-js/stdlib/pull/15252)
@@ -109,6 +110,7 @@ A total of 4 issues were closed in this release:
109110

110111
<details>
111112

113+
- [`13c6723`](https://github.com/stdlib-js/stdlib/commit/13c6723b3f9f5cb9aa3169eadaeb88e03be5e23c) - **feat:** add float16 dtype support to `ndarray/min-dtype` [(#15290)](https://github.com/stdlib-js/stdlib/pull/15290) _(by Samarth Kolarkar)_
112114
- [`abd365a`](https://github.com/stdlib-js/stdlib/commit/abd365a80596e407afc42fe806b2c113857423d4) - **feat:** add float16 dtype support to `ndarray/filter-map` [(#15234)](https://github.com/stdlib-js/stdlib/pull/15234) _(by Samarth Kolarkar)_
113115
- [`551a13c`](https://github.com/stdlib-js/stdlib/commit/551a13c30bc3e5d0079e2163a759a037481b58ff) - **feat:** add float16 dtype support to `ndarray/for-each` [(#15236)](https://github.com/stdlib-js/stdlib/pull/15236) _(by Samarth Kolarkar)_
114116
- [`4ba080a`](https://github.com/stdlib-js/stdlib/commit/4ba080a0f00815a1e00c81a0a063724b4cedc268) - **feat:** add float16 dtype support to `ndarray/nans-like` [(#15252)](https://github.com/stdlib-js/stdlib/pull/15252) _(by Samarth Kolarkar)_

‎min-dtype/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Returns the minimum ndarray [data type][@stdlib/ndarray/dtypes] of the closest "
4646

4747
```javascript
4848
var dt = minDataType( 3.141592653589793 );
49-
// returns 'float32'
49+
// returns 'float16'
5050

5151
dt = minDataType( -3 );
5252
// returns 'int8'

‎min-dtype/docs/repl.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Examples
2222
--------
2323
> var dt = {{alias}}( 3.141592653589793 )
24-
'float32'
24+
'float16'
2525
> dt = {{alias}}( 3 )
2626
'uint8'
2727
> dt = {{alias}}( -3 )

‎min-dtype/docs/types/index.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @example
2828
* var dt = minDataType( 3.141592653589793 );
29-
* // returns 'float32'
29+
* // returns 'float16'
3030
*
3131
* @example
3232
* var dt = minDataType( 3 );

‎min-dtype/lib/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* var minDataType = require( '@stdlib/ndarray/min-dtype' );
2828
*
2929
* var dt = minDataType( 3.141592653589793 );
30-
* // returns 'float32'
30+
* // returns 'float16'
3131
*
3232
* dt = minDataType( 3 );
3333
* // returns 'uint8'

‎min-dtype/lib/main.js‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2727
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
2828
var PINF = require( '@stdlib/constants/float64/pinf' );
2929
var NINF = require( '@stdlib/constants/float64/ninf' );
30+
var FLOAT16_SMALLEST_SUBNORMAL = require( '@stdlib/constants/float16/smallest-subnormal' ); // eslint-disable-line id-length
31+
var FLOAT16_MAX_SAFE_INTEGER = require( '@stdlib/constants/float16/max-safe-integer' );
32+
var FLOAT16_MIN_SAFE_INTEGER = require( '@stdlib/constants/float16/min-safe-integer' );
33+
var FLOAT16_MAX = require( '@stdlib/constants/float16/max' );
3034
var FLOAT32_SMALLEST_SUBNORMAL = require( '@stdlib/constants/float32/smallest-subnormal' ); // eslint-disable-line id-length
3135
var FLOAT32_MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' );
3236
var FLOAT32_MIN_SAFE_INTEGER = require( '@stdlib/constants/float32/min-safe-integer' );
@@ -49,20 +53,38 @@ var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
4953
*/
5054
function minFloatDataType( value ) {
5155
if ( value !== value || value === PINF || value === NINF ) {
52-
return 'float32';
56+
return 'float16';
5357
}
5458
if ( isInteger( value ) ) {
55-
if ( value >= FLOAT32_MIN_SAFE_INTEGER && value <= FLOAT32_MAX_SAFE_INTEGER ) { // eslint-disable-line max-len
59+
if (
60+
value >= FLOAT16_MIN_SAFE_INTEGER &&
61+
value <= FLOAT16_MAX_SAFE_INTEGER
62+
) {
63+
return 'float16';
64+
}
65+
if (
66+
value >= FLOAT32_MIN_SAFE_INTEGER &&
67+
value <= FLOAT32_MAX_SAFE_INTEGER
68+
) {
5669
return 'float32';
5770
}
5871
return 'float64';
5972
}
60-
// Assume that if we are provided a tiny value, we don't want to underflow to zero by storing as `float32`...
73+
// Assume that if we are provided a tiny value, we don't want to underflow to zero by storing in a smaller precision...
6174
if (
62-
value > -FLOAT32_SMALLEST_SUBNORMAL &&
63-
value < FLOAT32_SMALLEST_SUBNORMAL
75+
value > -FLOAT16_SMALLEST_SUBNORMAL &&
76+
value < FLOAT16_SMALLEST_SUBNORMAL
6477
) {
65-
return 'float64';
78+
if (
79+
value > -FLOAT32_SMALLEST_SUBNORMAL &&
80+
value < FLOAT32_SMALLEST_SUBNORMAL
81+
) {
82+
return 'float64';
83+
}
84+
return 'float32';
85+
}
86+
if ( value >= -FLOAT16_MAX && value <= FLOAT16_MAX ) {
87+
return 'float16';
6688
}
6789
// Any number which reaches this point is less than the maximum single-precision floating-point number, as floating-point format supports a limited number of decimals (e.g., (1.0+EPS)*10**15 => 1000000000000000.2, which is less than ~3.4e38)...
6890
return 'float32';
@@ -79,7 +101,7 @@ function minFloatDataType( value ) {
79101
*
80102
* @example
81103
* var dt = minDataType( 3.141592653589793 );
82-
* // returns 'float32'
104+
* // returns 'float16'
83105
*
84106
* @example
85107
* var dt = minDataType( 3 );
@@ -99,11 +121,11 @@ function minDataType( value ) {
99121
return 'generic';
100122
}
101123
if ( value !== value || value === PINF || value === NINF ) {
102-
return 'float32';
124+
return 'float16';
103125
}
104126
if ( isInteger( value ) ) {
105127
if ( value === 0 && isNegativeZero( value ) ) {
106-
return 'float32';
128+
return 'float16';
107129
}
108130
if ( value < 0 ) {
109131
if ( value >= INT8_MIN ) {
@@ -128,12 +150,21 @@ function minDataType( value ) {
128150
}
129151
return 'float64';
130152
}
131-
// Assume that if we are provided a tiny value, we don't want to underflow to zero by storing as `float32`...
153+
// Assume that if we are provided a tiny value, we don't want to underflow to zero by storing in a smaller precision...
132154
if (
133-
value > -FLOAT32_SMALLEST_SUBNORMAL &&
134-
value < FLOAT32_SMALLEST_SUBNORMAL
155+
value > -FLOAT16_SMALLEST_SUBNORMAL &&
156+
value < FLOAT16_SMALLEST_SUBNORMAL
135157
) {
136-
return 'float64';
158+
if (
159+
value > -FLOAT32_SMALLEST_SUBNORMAL &&
160+
value < FLOAT32_SMALLEST_SUBNORMAL
161+
) {
162+
return 'float64';
163+
}
164+
return 'float32';
165+
}
166+
if ( value >= -FLOAT16_MAX && value <= FLOAT16_MAX ) {
167+
return 'float16';
137168
}
138169
// Any number which reaches this point is less than the maximum single-precision floating-point number, given that floating-point format supports a limited number of decimals (e.g., (1.0+EPS)*10**15 => 1000000000000000.2, which is less than ~3.4e38)...
139170
return 'float32';

‎min-dtype/test/test.js‎

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tape( 'main export is a function', function test( t ) {
3636
t.end();
3737
});
3838

39-
tape( 'the function returns the minimum ndarray data type of the closest "kind" necessary for storing a provided scalar value', function test( t ) {
39+
tape( 'the function returns the minimum ndarray data type of the closest "kind" necessary for storing a provided real scalar value', function test( t ) {
4040
var expected;
4141
var actual;
4242
var values;
@@ -57,8 +57,14 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
5757
-4294967297,
5858
3.14,
5959
-3.14,
60+
70000.5,
61+
-70000.5,
62+
1.0e20, // >10**5
63+
-1.0e20,
6064
1.0e40, // >10**38
6165
-1.0e40,
66+
-1.0e-10, // <10**-7
67+
1.0e-10,
6268
-1.0e-46, // <10**-45
6369
1.0e-46,
6470
PINF,
@@ -67,7 +73,57 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
6773
{},
6874
true,
6975
false,
70-
[],
76+
[]
77+
];
78+
expected = [
79+
'float16',
80+
'uint8',
81+
'uint8',
82+
'float16',
83+
'uint8',
84+
'int8',
85+
'uint16',
86+
'int16',
87+
'uint32',
88+
'int32',
89+
'float64',
90+
'float64',
91+
'float16',
92+
'float16',
93+
'float32',
94+
'float32',
95+
'float64',
96+
'float64',
97+
'float64',
98+
'float64',
99+
'float32',
100+
'float32',
101+
'float64',
102+
'float64',
103+
'float16',
104+
'float16',
105+
'generic',
106+
'generic',
107+
'bool',
108+
'bool',
109+
'generic'
110+
];
111+
for ( i = 0; i < values.length; i++ ) {
112+
actual = minDataType( values[i] );
113+
t.strictEqual( actual, expected[ i ], 'returns expected value when provided '+values[i] );
114+
}
115+
t.end();
116+
});
117+
118+
tape( 'the function returns the minimum ndarray data type of the closest "kind" necessary for storing a provided complex number or other value', function test( t ) {
119+
var expected;
120+
var actual;
121+
var values;
122+
var i;
123+
124+
values = [
125+
new Complex64( 3.0, 5.0 ),
126+
new Complex128( 3.0, 5.0 ),
71127
new Complex64( 1.0, 1.0 ),
72128
new Complex64( NaN, NaN ),
73129
new Complex64( PINF, PINF ),
@@ -92,6 +148,22 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
92148
new Complex128( 1.0e40, 1.0 ),
93149
new Complex128( 1.0, -1.0e40 ),
94150
new Complex128( 1.0, 1.0e40 ),
151+
new Complex128( -1.0e10, 1.0 ),
152+
new Complex128( 1.0e10, 1.0 ),
153+
new Complex128( 1.0, -1.0e10 ),
154+
new Complex128( 1.0, 1.0e10 ),
155+
new Complex128( -1.0e-10, 1.0 ),
156+
new Complex128( 1.0e-10, 1.0 ),
157+
new Complex128( 1.0, -1.0e-10 ),
158+
new Complex128( 1.0, 1.0e-10 ),
159+
new Complex128( -70000.5, 1.0 ),
160+
new Complex128( 70000.5, 1.0 ),
161+
new Complex128( 1.0, -70000.5 ),
162+
new Complex128( 1.0, 70000.5 ),
163+
new Complex128( -30000.0, 1.0 ),
164+
new Complex128( 30000.0, 1.0 ),
165+
new Complex128( 1.0, -30000.0 ),
166+
new Complex128( 1.0, 30000.0 ),
95167

96168
{
97169
're': 3.0,
@@ -152,34 +224,17 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
152224
{
153225
're': 3.0,
154226
'im': 3.14
227+
},
228+
{
229+
're': 70000.5,
230+
'im': 5.0
231+
},
232+
{
233+
're': 3.0,
234+
'im': 70000.5
155235
}
156236
];
157237
expected = [
158-
'float32',
159-
'uint8',
160-
'uint8',
161-
'float32',
162-
'uint8',
163-
'int8',
164-
'uint16',
165-
'int16',
166-
'uint32',
167-
'int32',
168-
'float64',
169-
'float64',
170-
'float32',
171-
'float32',
172-
'float64',
173-
'float64',
174-
'float64',
175-
'float64',
176-
'float32',
177-
'float32',
178-
'generic',
179-
'generic',
180-
'bool',
181-
'bool',
182-
'generic',
183238
'complex64',
184239
'complex64',
185240
'complex64',
@@ -196,6 +251,10 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
196251
'complex64',
197252
'complex64',
198253
'complex64',
254+
'complex64',
255+
'complex64',
256+
'complex128',
257+
'complex128',
199258
'complex128',
200259
'complex128',
201260
'complex128',
@@ -204,6 +263,20 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
204263
'complex128',
205264
'complex128',
206265
'complex128',
266+
'complex128',
267+
'complex128',
268+
'complex64',
269+
'complex64',
270+
'complex64',
271+
'complex64',
272+
'complex64',
273+
'complex64',
274+
'complex64',
275+
'complex64',
276+
'complex64',
277+
'complex64',
278+
'complex64',
279+
'complex64',
207280

208281
'complex64',
209282
'complex128',
@@ -219,6 +292,8 @@ tape( 'the function returns the minimum ndarray data type of the closest "kind"
219292
'complex64',
220293
'complex64',
221294
'complex64',
295+
'complex64',
296+
'complex64',
222297
'complex64'
223298
];
224299
for ( i = 0; i < values.length; i++ ) {

0 commit comments

Comments
 (0)