You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@
10
10
11
11
### Features
12
12
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)
13
14
-[`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)
14
15
-[`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)
15
16
-[`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:
89
90
90
91
<details>
91
92
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)_
92
94
-[`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)_
// 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...
61
74
if(
62
-
value>-FLOAT32_SMALLEST_SUBNORMAL&&
63
-
value<FLOAT32_SMALLEST_SUBNORMAL
75
+
value>-FLOAT16_SMALLEST_SUBNORMAL&&
76
+
value<FLOAT16_SMALLEST_SUBNORMAL
64
77
){
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';
66
88
}
67
89
// 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)...
68
90
return'float32';
@@ -79,7 +101,7 @@ function minFloatDataType( value ) {
79
101
*
80
102
* @example
81
103
* var dt = minDataType( 3.141592653589793 );
82
-
* // returns 'float32'
104
+
* // returns 'float16'
83
105
*
84
106
* @example
85
107
* var dt = minDataType( 3 );
@@ -99,11 +121,11 @@ function minDataType( value ) {
99
121
return'generic';
100
122
}
101
123
if(value!==value||value===PINF||value===NINF){
102
-
return'float32';
124
+
return'float16';
103
125
}
104
126
if(isInteger(value)){
105
127
if(value===0&&isNegativeZero(value)){
106
-
return'float32';
128
+
return'float16';
107
129
}
108
130
if(value<0){
109
131
if(value>=INT8_MIN){
@@ -128,12 +150,21 @@ function minDataType( value ) {
128
150
}
129
151
return'float64';
130
152
}
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...
132
154
if(
133
-
value>-FLOAT32_SMALLEST_SUBNORMAL&&
134
-
value<FLOAT32_SMALLEST_SUBNORMAL
155
+
value>-FLOAT16_SMALLEST_SUBNORMAL&&
156
+
value<FLOAT16_SMALLEST_SUBNORMAL
135
157
){
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';
137
168
}
138
169
// 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)...
Copy file name to clipboardExpand all lines: min-dtype/test/test.js
+98-28Lines changed: 98 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ tape( 'main export is a function', function test( t ) {
36
36
t.end();
37
37
});
38
38
39
-
tape('the function returns the minimum array data type of the closest "kind" necessary for storing a provided scalar value',functiontest(t){
39
+
tape('the function returns the minimum array data type of the closest "kind" necessary for storing a provided real scalar value',functiontest(t){
40
40
varexpected;
41
41
varactual;
42
42
varvalues;
@@ -57,8 +57,14 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
57
57
-4294967297,
58
58
3.14,
59
59
-3.14,
60
+
70000.5,
61
+
-70000.5,
62
+
1.0e20,// >10**5
63
+
-1.0e20,
60
64
1.0e40,// >10**38
61
65
-1.0e40,
66
+
-1.0e-10,// <10**-7
67
+
1.0e-10,
62
68
-1.0e-46,// <10**-45
63
69
1.0e-46,
64
70
PINF,
@@ -67,7 +73,55 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
67
73
{},
68
74
true,
69
75
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',functiontest(t){
119
+
varexpected;
120
+
varactual;
121
+
varvalues;
122
+
vari;
123
+
124
+
values=[
71
125
newComplex64(3.0,5.0),
72
126
newComplex128(3.0,5.0),
73
127
newComplex64(1.0,1.0),
@@ -94,6 +148,22 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
94
148
newComplex128(1.0e40,1.0),
95
149
newComplex128(1.0,-1.0e40),
96
150
newComplex128(1.0,1.0e40),
151
+
newComplex128(-1.0e10,1.0),
152
+
newComplex128(1.0e10,1.0),
153
+
newComplex128(1.0,-1.0e10),
154
+
newComplex128(1.0,1.0e10),
155
+
newComplex128(-1.0e-10,1.0),
156
+
newComplex128(1.0e-10,1.0),
157
+
newComplex128(1.0,-1.0e-10),
158
+
newComplex128(1.0,1.0e-10),
159
+
newComplex128(-70000.5,1.0),
160
+
newComplex128(70000.5,1.0),
161
+
newComplex128(1.0,-70000.5),
162
+
newComplex128(1.0,70000.5),
163
+
newComplex128(-30000.0,1.0),
164
+
newComplex128(30000.0,1.0),
165
+
newComplex128(1.0,-30000.0),
166
+
newComplex128(1.0,30000.0),
97
167
98
168
{
99
169
're': 3.0,
@@ -154,34 +224,17 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
154
224
{
155
225
're': 3.0,
156
226
'im': 3.14
227
+
},
228
+
{
229
+
're': 70000.5,
230
+
'im': 5.0
231
+
},
232
+
{
233
+
're': 3.0,
234
+
'im': 70000.5
157
235
}
158
236
];
159
237
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',
185
238
'complex64',
186
239
'complex64',
187
240
'complex64',
@@ -208,6 +261,22 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
208
261
'complex128',
209
262
'complex128',
210
263
'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',
211
280
212
281
'complex64',
213
282
'complex128',
@@ -223,8 +292,9 @@ tape( 'the function returns the minimum array data type of the closest "kind" ne
0 commit comments