Skip to content

Commit 8e2c3fe

Browse files
committed
feat: add support for extending data type kind subsets with a "generic" data type
1 parent a37ebf5 commit 8e2c3fe

File tree

7 files changed

+239
-7
lines changed

7 files changed

+239
-7
lines changed

lib/node_modules/@stdlib/array/dtypes/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Returns a list of array data types.
4646

4747
```javascript
4848
var out = dtypes();
49-
// e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
49+
// e.g., returns [ 'float32', 'float64', ... ]
5050
```
5151

5252
When not provided a data type "kind", the function returns an array containing the following data types:
@@ -83,6 +83,13 @@ The function supports the following data type kinds:
8383
- `numeric`: numeric data types.
8484
- `all`: all data types.
8585

86+
Additionally, the function supports extending the "kinds" listed above by appending an `_and_generic` suffix to the kind name (e.g., `real_and_generic`).
87+
88+
```javascript
89+
var out = dtypes( 'floating_point_and_generic' );
90+
// returns [...]
91+
```
92+
8693
</section>
8794

8895
<!-- /.usage -->

lib/node_modules/@stdlib/array/dtypes/benchmark/benchmark.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,28 @@ bench( pkg+'::kind', function benchmark( b ) {
7171
b.pass( 'benchmark finished' );
7272
b.end();
7373
});
74+
75+
bench( pkg+'::kind,generic', function benchmark( b ) {
76+
var values;
77+
var out;
78+
var i;
79+
80+
values = [
81+
'floating_point_and_generic',
82+
'integer_and_generic'
83+
];
84+
85+
b.tic();
86+
for ( i = 0; i < b.iterations; i++ ) {
87+
out = dtypes( values[ i%values.length ] );
88+
if ( out.length === 0 ) {
89+
b.fail( 'should return a non-empty array' );
90+
}
91+
}
92+
b.toc();
93+
if ( !isStringArray( out ) ) {
94+
b.fail( 'should return an array of strings' );
95+
}
96+
b.pass( 'benchmark finished' );
97+
b.end();
98+
});

lib/node_modules/@stdlib/array/dtypes/docs/repl.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
- numeric: numeric data types.
3131
- all: all data types.
3232

33+
Additionally, the function supports extending the "kinds" listed above by
34+
appending a '_and_generic' suffix to the kind name (e.g., real_and_generic).
35+
3336
Parameters
3437
----------
3538
kind: string (optional)
@@ -43,9 +46,11 @@
4346
Examples
4447
--------
4548
> var out = {{alias}}()
46-
<Array>
49+
[...]
4750
> out = {{alias}}( 'floating_point' )
48-
<Array>
51+
[...]
52+
> out = {{alias}}( 'floating_point_and_generic' )
53+
[...]
4954

5055
See Also
5156
--------

lib/node_modules/@stdlib/array/dtypes/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { DataType, DataTypeKind } from '@stdlib/types/array';
3030
*
3131
* @example
3232
* var list = dtypes();
33-
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
33+
* // e.g., returns [ 'float32', 'float64', ... ]
3434
*
3535
* @example
3636
* var list = dtypes( 'floating_point' );

lib/node_modules/@stdlib/array/dtypes/docs/types/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import dtypes = require( './index' );
2525
{
2626
dtypes(); // $ExpectType DataType[]
2727
dtypes( 'floating_point' ); // $ExpectType DataType[]
28+
dtypes( 'floating_point_and_generic' ); // $ExpectType DataType[]
2829
}
2930

3031
// The compiler throws an error if the function is provided an unsupported number of arguments...

lib/node_modules/@stdlib/array/dtypes/lib/main.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020

2121
// MODULES //
2222

23+
var replace = require( '@stdlib/string/base/replace' );
2324
var DTYPES = require( './dtypes.json' );
2425

2526

27+
// VARIABLES //
28+
29+
var RE_SUFFIX = /_and_generic$/;
30+
31+
2632
// MAIN //
2733

2834
/**
@@ -33,19 +39,33 @@ var DTYPES = require( './dtypes.json' );
3339
*
3440
* @example
3541
* var list = dtypes();
36-
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
42+
* // e.g., returns [ 'float32', 'float64', ... ]
3743
*
3844
* @example
3945
* var list = dtypes( 'floating_point' );
4046
* // returns [...]
4147
*/
4248
function dtypes() {
49+
var kind;
4350
var out;
51+
var FLG;
4452
if ( arguments.length === 0 ) {
4553
return DTYPES.all.slice();
4654
}
47-
out = DTYPES[ arguments[ 0 ] ];
48-
return ( out ) ? out.slice() : [];
55+
FLG = false;
56+
kind = arguments[ 0 ];
57+
if ( RE_SUFFIX.test( kind ) ) {
58+
kind = replace( kind, RE_SUFFIX, '' );
59+
if ( kind !== 'all' ) {
60+
FLG = true;
61+
}
62+
}
63+
out = DTYPES[ kind ];
64+
out = ( out ) ? out.slice() : [];
65+
if ( FLG && out.length > 0 ) {
66+
out.push( 'generic' );
67+
}
68+
return out;
4969
}
5070

5171

lib/node_modules/@stdlib/array/dtypes/test/test.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ tape( 'the function supports returning a list of array data types (all)', functi
8080
t.end();
8181
});
8282

83+
tape( 'the function supports returning a list of array data types (all, including "generic")', function test( t ) {
84+
var expected;
85+
var actual;
86+
87+
expected = [
88+
'complex64',
89+
'complex128',
90+
'float32',
91+
'float64',
92+
'generic',
93+
'int16',
94+
'int32',
95+
'int8',
96+
'uint16',
97+
'uint32',
98+
'uint8',
99+
'uint8c'
100+
];
101+
actual = dtypes( 'all_and_generic' );
102+
103+
t.deepEqual( actual, expected, 'returns expected value' );
104+
t.end();
105+
});
106+
83107
tape( 'the function supports returning a list of floating-point array data types', function test( t ) {
84108
var expected;
85109
var actual;
@@ -96,6 +120,23 @@ tape( 'the function supports returning a list of floating-point array data types
96120
t.end();
97121
});
98122

123+
tape( 'the function supports returning a list of floating-point array data types (including "generic")', function test( t ) {
124+
var expected;
125+
var actual;
126+
127+
expected = [
128+
'complex64',
129+
'complex128',
130+
'float32',
131+
'float64',
132+
'generic'
133+
];
134+
actual = dtypes( 'floating_point_and_generic' );
135+
136+
t.deepEqual( actual, expected, 'returns expected value' );
137+
t.end();
138+
});
139+
99140
tape( 'the function supports returning a list of real-valued floating-point array data types', function test( t ) {
100141
var expected;
101142
var actual;
@@ -110,6 +151,21 @@ tape( 'the function supports returning a list of real-valued floating-point arra
110151
t.end();
111152
});
112153

154+
tape( 'the function supports returning a list of real-valued floating-point array data types (including "generic")', function test( t ) {
155+
var expected;
156+
var actual;
157+
158+
expected = [
159+
'float32',
160+
'float64',
161+
'generic'
162+
];
163+
actual = dtypes( 'real_floating_point_and_generic' );
164+
165+
t.deepEqual( actual, expected, 'returns expected value' );
166+
t.end();
167+
});
168+
113169
tape( 'the function supports returning a list of complex-valued floating-point array data types', function test( t ) {
114170
var expected;
115171
var actual;
@@ -124,6 +180,21 @@ tape( 'the function supports returning a list of complex-valued floating-point a
124180
t.end();
125181
});
126182

183+
tape( 'the function supports returning a list of complex-valued floating-point array data types (including "generic")', function test( t ) {
184+
var expected;
185+
var actual;
186+
187+
expected = [
188+
'complex64',
189+
'complex128',
190+
'generic'
191+
];
192+
actual = dtypes( 'complex_floating_point_and_generic' );
193+
194+
t.deepEqual( actual, expected, 'returns expected value' );
195+
t.end();
196+
});
197+
127198
tape( 'the function supports returning a list of integer array data types', function test( t ) {
128199
var expected;
129200
var actual;
@@ -143,6 +214,26 @@ tape( 'the function supports returning a list of integer array data types', func
143214
t.end();
144215
});
145216

217+
tape( 'the function supports returning a list of integer array data types (including "generic")', function test( t ) {
218+
var expected;
219+
var actual;
220+
221+
expected = [
222+
'int16',
223+
'int32',
224+
'int8',
225+
'uint16',
226+
'uint32',
227+
'uint8',
228+
'uint8c',
229+
'generic'
230+
];
231+
actual = dtypes( 'integer_and_generic' );
232+
233+
t.deepEqual( actual, expected, 'returns expected value' );
234+
t.end();
235+
});
236+
146237
tape( 'the function supports returning a list of signed integer array data types', function test( t ) {
147238
var expected;
148239
var actual;
@@ -158,6 +249,22 @@ tape( 'the function supports returning a list of signed integer array data types
158249
t.end();
159250
});
160251

252+
tape( 'the function supports returning a list of signed integer array data types (including "generic")', function test( t ) {
253+
var expected;
254+
var actual;
255+
256+
expected = [
257+
'int16',
258+
'int32',
259+
'int8',
260+
'generic'
261+
];
262+
actual = dtypes( 'signed_integer_and_generic' );
263+
264+
t.deepEqual( actual, expected, 'returns expected value' );
265+
t.end();
266+
});
267+
161268
tape( 'the function supports returning a list of unsigned integer array data types', function test( t ) {
162269
var expected;
163270
var actual;
@@ -174,6 +281,23 @@ tape( 'the function supports returning a list of unsigned integer array data typ
174281
t.end();
175282
});
176283

284+
tape( 'the function supports returning a list of unsigned integer array data types (including "generic")', function test( t ) {
285+
var expected;
286+
var actual;
287+
288+
expected = [
289+
'uint16',
290+
'uint32',
291+
'uint8',
292+
'uint8c',
293+
'generic'
294+
];
295+
actual = dtypes( 'unsigned_integer_and_generic' );
296+
297+
t.deepEqual( actual, expected, 'returns expected value' );
298+
t.end();
299+
});
300+
177301
tape( 'the function supports returning a list of real-valued array data types', function test( t ) {
178302
var expected;
179303
var actual;
@@ -195,6 +319,28 @@ tape( 'the function supports returning a list of real-valued array data types',
195319
t.end();
196320
});
197321

322+
tape( 'the function supports returning a list of real-valued array data types (including "generic")', function test( t ) {
323+
var expected;
324+
var actual;
325+
326+
expected = [
327+
'float32',
328+
'float64',
329+
'int16',
330+
'int32',
331+
'int8',
332+
'uint16',
333+
'uint32',
334+
'uint8',
335+
'uint8c',
336+
'generic'
337+
];
338+
actual = dtypes( 'real_and_generic' );
339+
340+
t.deepEqual( actual, expected, 'returns expected value' );
341+
t.end();
342+
});
343+
198344
tape( 'the function supports returning a list of numeric array data types', function test( t ) {
199345
var expected;
200346
var actual;
@@ -218,7 +364,35 @@ tape( 'the function supports returning a list of numeric array data types', func
218364
t.end();
219365
});
220366

367+
tape( 'the function supports returning a list of numeric array data types (including "generic")', function test( t ) {
368+
var expected;
369+
var actual;
370+
371+
expected = [
372+
'complex64',
373+
'complex128',
374+
'float32',
375+
'float64',
376+
'int16',
377+
'int32',
378+
'int8',
379+
'uint16',
380+
'uint32',
381+
'uint8',
382+
'uint8c',
383+
'generic'
384+
];
385+
actual = dtypes( 'numeric_and_generic' );
386+
387+
t.deepEqual( actual, expected, 'returns expected value' );
388+
t.end();
389+
});
390+
221391
tape( 'the function returns an empty array if provided an unrecognized data type kind', function test( t ) {
222392
t.deepEqual( dtypes( 'beep' ), [], 'returns expected value' );
393+
t.deepEqual( dtypes( 'beep_and_generic' ), [], 'returns expected value' );
394+
t.deepEqual( dtypes( 'generic' ), [], 'returns expected value' );
395+
t.deepEqual( dtypes( '_and_generic' ), [], 'returns expected value' );
396+
t.deepEqual( dtypes( '' ), [], 'returns expected value' );
223397
t.end();
224398
});

0 commit comments

Comments
 (0)