Skip to content

Commit 22211dc

Browse files
committed
Auto-generated commit
1 parent ad1f6b5 commit 22211dc

7 files changed

Lines changed: 150 additions & 46 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`800db1b`](https://github.com/stdlib-js/stdlib/commit/800db1bdcd2d4e3fa76067addd8395f006cea5ad) - add float16 dtype support to `array/min-dtype` [(#14018)](https://github.com/stdlib-js/stdlib/pull/14018)
1314
- [`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)
1415
- [`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)
1516
- [`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)
@@ -89,6 +90,7 @@ This release closes the following issue:
8990

9091
<details>
9192

93+
- [`800db1b`](https://github.com/stdlib-js/stdlib/commit/800db1bdcd2d4e3fa76067addd8395f006cea5ad) - **feat:** add float16 dtype support to `array/min-dtype` [(#14018)](https://github.com/stdlib-js/stdlib/pull/14018) _(by Samarth Kolarkar, Athan Reines, gururaj1512)_
9294
- [`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)_
9395
- [`e805b48`](https://github.com/stdlib-js/stdlib/commit/e805b48af03299edd06969a72e9bf03ccb344aa5) - **bench:** fix assignment operation _(by Athan Reines)_
9496
- [`3fdf0b9`](https://github.com/stdlib-js/stdlib/commit/3fdf0b943c342271e5ee4b80d7bf30cb2b5de1e1) - **bench:** reassign variable _(by Athan Reines)_
@@ -182,12 +184,13 @@ This release closes the following issue:
182184

183185
### Contributors
184186

185-
A total of 5 people contributed to this release. Thank you to the following contributors:
187+
A total of 6 people contributed to this release. Thank you to the following contributors:
186188

187189
- Athan Reines
188190
- Divit Jain
189191
- Gururaj Gurram
190192
- Philipp Burckhardt
193+
- Samarth Kolarkar
191194
- titanniya542-spec
192195

193196
</section>

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 array [data type][@stdlib/array/dtypes] of the closest "kind
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
@@ -35,7 +35,7 @@ import { ComplexLike } from '@stdlib/types/complex';
3535
*
3636
* @example
3737
* var dt = minDataType( 3.141592653589793 );
38-
* // returns 'float32'
38+
* // returns 'float16'
3939
*
4040
* @example
4141
* 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/array/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, 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)...
139170
return 'float32';

min-dtype/test/test.js

Lines changed: 98 additions & 28 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 array data type of the closest "kind" necessary for storing a provided scalar value', function test( t ) {
39+
tape( 'the function returns the minimum array 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 array data type of the closest "kind" ne
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,55 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
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 array 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 = [
71125
new Complex64( 3.0, 5.0 ),
72126
new Complex128( 3.0, 5.0 ),
73127
new Complex64( 1.0, 1.0 ),
@@ -94,6 +148,22 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
94148
new Complex128( 1.0e40, 1.0 ),
95149
new Complex128( 1.0, -1.0e40 ),
96150
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 ),
97167

98168
{
99169
're': 3.0,
@@ -154,34 +224,17 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
154224
{
155225
're': 3.0,
156226
'im': 3.14
227+
},
228+
{
229+
're': 70000.5,
230+
'im': 5.0
231+
},
232+
{
233+
're': 3.0,
234+
'im': 70000.5
157235
}
158236
];
159237
expected = [
160-
'float32',
161-
'uint8',
162-
'uint8',
163-
'float32',
164-
'uint8',
165-
'int8',
166-
'uint16',
167-
'int16',
168-
'uint32',
169-
'int32',
170-
'float64',
171-
'float64',
172-
'float32',
173-
'float32',
174-
'float64',
175-
'float64',
176-
'float64',
177-
'float64',
178-
'float32',
179-
'float32',
180-
'generic',
181-
'generic',
182-
'bool',
183-
'bool',
184-
'generic',
185238
'complex64',
186239
'complex64',
187240
'complex64',
@@ -208,6 +261,22 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
208261
'complex128',
209262
'complex128',
210263
'complex128',
264+
'complex128',
265+
'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',
211280

212281
'complex64',
213282
'complex128',
@@ -223,8 +292,9 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
223292
'complex64',
224293
'complex64',
225294
'complex64',
295+
'complex64',
296+
'complex64',
226297
'complex64'
227-
228298
];
229299
for ( i = 0; i < values.length; i++ ) {
230300
actual = minDataType( values[i] );

0 commit comments

Comments
 (0)