Skip to content

Commit 99146bb

Browse files
committed
feat: add support for returning a subset of data types
1 parent 9363dc3 commit 99146bb

File tree

8 files changed

+304
-25
lines changed

8 files changed

+304
-25
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ limitations under the License.
4040
var dtypes = require( '@stdlib/ndarray/dtypes' );
4141
```
4242

43-
#### dtypes()
43+
#### dtypes( \[kind] )
4444

4545
Returns a list of ndarray data types.
4646

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

52-
The output `array` contains the following data types:
52+
When not provided a data type "kind", the function returns an array containing the following data types:
5353

5454
- `binary`: binary.
5555
- `complex64`: single-precision complex floating-point numbers.
@@ -65,6 +65,24 @@ The output `array` contains the following data types:
6565
- `uint8`: unsigned 8-bit integers.
6666
- `uint8c`: unsigned clamped 8-bit integers.
6767

68+
To return the subset of data types belonging to a specified data type kind, provide a `kind` argument.
69+
70+
```javascript
71+
var out = dtypes( 'floating_point' );
72+
// returns [...]
73+
```
74+
75+
The function supports the following data type kinds:
76+
77+
- `floating_point`: floating-point data types.
78+
- `real_floating_point`: real-valued floating-point data types.
79+
- `complex_floating_point`: complex-valued floating-point data types.
80+
- `integral`: integer data types.
81+
- `signed_integer`: signed integer data types.
82+
- `unsigned_integer`: unsigned integer data types.
83+
- `numeric`: numeric data types.
84+
- `all`: all data types.
85+
6886
</section>
6987

7088
<!-- /.usage -->

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,28 @@ bench( pkg, function benchmark( b ) {
4646
b.pass( 'benchmark finished' );
4747
b.end();
4848
});
49+
50+
bench( pkg+'::kind', function benchmark( b ) {
51+
var values;
52+
var out;
53+
var i;
54+
55+
values = [
56+
'floating_point',
57+
'integral'
58+
];
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
out = dtypes( values[ i%values.length ] );
63+
if ( out.length === 0 ) {
64+
b.fail( 'should return a non-empty array' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isStringArray( out ) ) {
69+
b.fail( 'should return an array of strings' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
});

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2-
{{alias}}()
2+
{{alias}}( [kind] )
33
Returns a list of ndarray data types.
44

5-
The output array contains the following data types:
5+
When not provided a data type "kind", the function returns an array
6+
containing the following data types:
67

78
- binary: binary.
89
- complex64: single-precision complex floating-point numbers.
@@ -18,6 +19,22 @@
1819
- uint8: unsigned 8-bit integers.
1920
- uint8c: unsigned clamped 8-bit integers.
2021

22+
The function supports the following data type "kinds":
23+
24+
- floating_point: floating-point data types.
25+
- real_floating_point: real-valued floating-point data types.
26+
- complex_floating_point: complex-valued floating-point data types.
27+
- integral: integer data types.
28+
- signed_integer: signed integer data types.
29+
- unsigned_integer: unsigned integer data types.
30+
- numeric: numeric data types.
31+
- all: all data types.
32+
33+
Parameters
34+
----------
35+
kind: string (optional)
36+
Data type kind.
37+
2138
Returns
2239
-------
2340
out: Array<string>
@@ -27,6 +44,8 @@
2744
--------
2845
> var out = {{alias}}()
2946
<Array>
47+
> out = {{alias}}( 'floating_point' )
48+
<Array>
3049

3150
See Also
3251
--------

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818

1919
// TypeScript Version: 2.0
2020

21+
/**
22+
* Data type kind.
23+
*/
24+
type Kind = 'all' | 'numeric' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integral' | 'signed_integer' | 'unsigned_integer'; // tslint-disable-line max-line-length
25+
2126
/**
2227
* Returns a list of ndarray data types.
2328
*
2429
* ## Notes
2530
*
26-
* - The output array contains the following data types:
31+
* - When not provided a data type "kind", the function returns an array containing the following data types:
2732
*
2833
* - `binary`: binary.
2934
* - `complex64`: single-precision complex floating-point numbers.
@@ -39,13 +44,18 @@
3944
* - `uint8`: unsigned 8-bit integers.
4045
* - `uint8c`: unsigned clamped 8-bit integers.
4146
*
47+
* @param kind - data type kind
4248
* @returns list of ndarray data types
4349
*
4450
* @example
4551
* var list = dtypes();
4652
* // returns [...]
53+
*
54+
* @example
55+
* var list = dtypes( 'floating_point' );
56+
* // returns [...]
4757
*/
48-
declare function dtypes(): Array<string>;
58+
declare function dtypes( kind?: Kind ): Array<string>;
4959

5060

5161
// EXPORTS //

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import dtypes = require( './index' );
2424
// The function returns an array of strings...
2525
{
2626
dtypes(); // $ExpectType string[]
27+
dtypes( 'floating_point' ); // $ExpectType string[]
2728
}
2829

29-
// The compiler throws an error if the function is provided any arguments...
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
3031
{
31-
dtypes( 9 ); // $ExpectError
32+
dtypes( 'floating_point', 2 ); // $ExpectError
3233
}
Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,64 @@
1-
[
2-
"binary",
3-
"complex64",
4-
"complex128",
5-
"float32",
6-
"float64",
7-
"generic",
8-
"int16",
9-
"int32",
10-
"int8",
11-
"uint16",
12-
"uint32",
13-
"uint8",
14-
"uint8c"
15-
]
1+
{
2+
"all": [
3+
"binary",
4+
"complex64",
5+
"complex128",
6+
"float32",
7+
"float64",
8+
"generic",
9+
"int16",
10+
"int32",
11+
"int8",
12+
"uint16",
13+
"uint32",
14+
"uint8",
15+
"uint8c"
16+
],
17+
"floating_point": [
18+
"complex64",
19+
"complex128",
20+
"float32",
21+
"float64"
22+
],
23+
"real_floating_point": [
24+
"float32",
25+
"float64"
26+
],
27+
"complex_floating_point": [
28+
"complex64",
29+
"complex128"
30+
],
31+
"integral": [
32+
"int16",
33+
"int32",
34+
"int8",
35+
"uint16",
36+
"uint32",
37+
"uint8",
38+
"uint8c"
39+
],
40+
"signed_integer": [
41+
"int16",
42+
"int32",
43+
"int8"
44+
],
45+
"unsigned_integer": [
46+
"uint16",
47+
"uint32",
48+
"uint8",
49+
"uint8c"
50+
],
51+
"numeric": [
52+
"complex64",
53+
"complex128",
54+
"float32",
55+
"float64",
56+
"int16",
57+
"int32",
58+
"int8",
59+
"uint16",
60+
"uint32",
61+
"uint8",
62+
"uint8c"
63+
]
64+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@ var DTYPES = require( './dtypes.json' );
2828
/**
2929
* Returns a list of ndarray data types.
3030
*
31+
* @param {string} [kind] - data type kind
3132
* @returns {StringArray} list of ndarray data types
3233
*
3334
* @example
3435
* var list = dtypes();
3536
* // returns [...]
37+
*
38+
* @example
39+
* var list = dtypes( 'floating_point' );
40+
* // returns [...]
3641
*/
3742
function dtypes() {
38-
return DTYPES.slice();
43+
var out;
44+
if ( arguments.length === 0 ) {
45+
return DTYPES.all.slice();
46+
}
47+
out = DTYPES[ arguments[ 0 ] ];
48+
return ( out ) ? out.slice() : [];
3949
}
4050

4151

0 commit comments

Comments
 (0)