File tree 6 files changed +297
-4
lines changed
lib/node_modules/@stdlib/ndarray/dtypes
6 files changed +297
-4
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,13 @@ The function supports the following data type kinds:
87
87
- ` typed ` : typed data types.
88
88
- ` all ` : all data types.
89
89
90
+ Additionally, the function supports extending the "kinds" listed above by appending an ` _and_generic ` suffix to the kind name (e.g., ` real_and_generic ` ).
91
+
92
+ ``` javascript
93
+ var out = dtypes ( ' floating_point_and_generic' );
94
+ // returns [...]
95
+ ```
96
+
90
97
</section >
91
98
92
99
<!-- /.usage -->
Original file line number Diff line number Diff line change @@ -71,3 +71,29 @@ bench( pkg+'::kind', function benchmark( b ) {
71
71
b . pass ( 'benchmark finished' ) ;
72
72
b . end ( ) ;
73
73
} ) ;
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
+ 'boolean_and_generic'
84
+ ] ;
85
+
86
+ b . tic ( ) ;
87
+ for ( i = 0 ; i < b . iterations ; i ++ ) {
88
+ out = dtypes ( values [ i % values . length ] ) ;
89
+ if ( out . length === 0 ) {
90
+ b . fail ( 'should return a non-empty array' ) ;
91
+ }
92
+ }
93
+ b . toc ( ) ;
94
+ if ( ! isStringArray ( out ) ) {
95
+ b . fail ( 'should return an array of strings' ) ;
96
+ }
97
+ b . pass ( 'benchmark finished' ) ;
98
+ b . end ( ) ;
99
+ } ) ;
Original file line number Diff line number Diff line change 2
2
{{alias}}( [kind] )
3
3
Returns a list of ndarray data types.
4
4
5
+ When not provided a data type "kind", the function returns an array
6
+ containing the following data types:
7
+
8
+ - float32: single-precision floating-point numbers.
9
+ - float64: double-precision floating-point numbers.
10
+ - complex64: single-precision complex floating-point numbers.
11
+ - complex128: double-precision complex floating-point numbers.
12
+ - bool: boolean values.
13
+ - generic: values of any type.
14
+ - int16: signed 16-bit integers.
15
+ - int32: signed 32-bit integers.
16
+ - int8: signed 8-bit integers.
17
+ - uint16: unsigned 16-bit integers.
18
+ - uint32: unsigned 32-bit integers.
19
+ - uint8: unsigned 8-bit integers.
20
+ - uint8c: unsigned clamped 8-bit integers.
21
+ - binary: binary.
22
+
5
23
The function supports the following data type "kinds":
6
24
7
25
- floating_point: floating-point data types.
16
34
- typed: typed data types.
17
35
- all: all data types.
18
36
37
+ Additionally, the function supports extending the "kinds" listed above by
38
+ appending a '_and_generic' suffix to the kind name (e.g., real_and_generic).
39
+
19
40
Parameters
20
41
----------
21
42
kind: string (optional)
29
50
Examples
30
51
--------
31
52
> var out = {{alias}}()
32
- <Array>
53
+ [...]
33
54
> out = {{alias}}( 'floating_point' )
34
- <Array>
55
+ [...]
56
+ > out = {{alias}}( 'floating_point_and_generic' )
57
+ [...]
35
58
36
59
See Also
37
60
--------
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import dtypes = require( './index' );
25
25
{
26
26
dtypes ( ) ; // $ExpectType DataType[]
27
27
dtypes ( 'floating_point' ) ; // $ExpectType DataType[]
28
+ dtypes ( 'floating_point_and_generic' ) ; // $ExpectType DataType[]
28
29
}
29
30
30
31
// The compiler throws an error if the function is provided an unsupported number of arguments...
Original file line number Diff line number Diff line change 20
20
21
21
// MODULES //
22
22
23
+ var replace = require ( '@stdlib/string/base/replace' ) ;
23
24
var DTYPES = require ( './dtypes.json' ) ;
24
25
25
26
27
+ // VARIABLES //
28
+
29
+ var RE_SUFFIX = / _ a n d _ g e n e r i c $ / ;
30
+
31
+
26
32
// MAIN //
27
33
28
34
/**
@@ -40,12 +46,26 @@ var DTYPES = require( './dtypes.json' );
40
46
* // returns [...]
41
47
*/
42
48
function dtypes ( ) {
49
+ var kind ;
43
50
var out ;
51
+ var FLG ;
44
52
if ( arguments . length === 0 ) {
45
53
return DTYPES . all . slice ( ) ;
46
54
}
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 ;
49
69
}
50
70
51
71
You can’t perform that action at this time.
0 commit comments