Skip to content

Commit 1c38368

Browse files
committed
feat: add ndarray/base/dtype-strings
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 061325b commit 1c38368

File tree

11 files changed

+1410
-0
lines changed

11 files changed

+1410
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Data Type Strings
22+
23+
> List of ndarray data type strings.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var dtypeStrings = require( '@stdlib/ndarray/base/dtype-strings' );
41+
```
42+
43+
#### dtypeStrings( \[kind] )
44+
45+
Returns a list of ndarray data type strings.
46+
47+
```javascript
48+
var out = dtypeStrings();
49+
// e.g., returns [ 'binary', 'complex32', 'complex64', 'complex128', ... ]
50+
```
51+
52+
When not provided a data type "kind", the function returns an array containing the following data type strings:
53+
54+
- `binary`: binary.
55+
- `bool`: boolean values.
56+
- `complex32`: half-precision complex floating-point numbers.
57+
- `complex64`: single-precision complex floating-point numbers.
58+
- `complex128`: double-precision complex floating-point numbers.
59+
- `float16`: half-precision floating-point numbers.
60+
- `float32`: single-precision floating-point numbers.
61+
- `float64`: double-precision floating-point numbers.
62+
- `generic`: values of any type.
63+
- `int16`: signed 16-bit integers.
64+
- `int32`: signed 32-bit integers.
65+
- `int8`: signed 8-bit integers.
66+
- `uint16`: unsigned 16-bit integers.
67+
- `uint32`: unsigned 32-bit integers.
68+
- `uint8`: unsigned 8-bit integers.
69+
- `uint8c`: unsigned clamped 8-bit integers.
70+
71+
To return the subset of data type strings belonging to a specified data type kind, provide a `kind` argument.
72+
73+
```javascript
74+
var out = dtypeStrings( 'floating_point' );
75+
// returns [...]
76+
```
77+
78+
The function supports the following data type kinds:
79+
80+
- `floating_point`: floating-point data types.
81+
- `real_floating_point`: real-valued floating-point data types.
82+
- `complex_floating_point`: complex-valued floating-point data types.
83+
- `boolean`: boolean data types.
84+
- `integer`: integer data types.
85+
- `signed_integer`: signed integer data types.
86+
- `unsigned_integer`: unsigned integer data types.
87+
- `real`: real-valued data types.
88+
- `numeric`: numeric data types.
89+
- `typed`: typed data types.
90+
- `integer_index`: integer index data types.
91+
- `boolean_index`: boolean index data types.
92+
- `mask_index`: mask index data types.
93+
- `typed_index`: typed index data types.
94+
- `index`: index data types.
95+
- `all`: all data types.
96+
97+
Additionally, the function supports extending the "kinds" listed above by appending an `_and_generic` suffix to the kind name (e.g., `real_and_generic`).
98+
99+
```javascript
100+
var out = dtypeStrings( 'floating_point_and_generic' );
101+
// returns [...]
102+
```
103+
104+
</section>
105+
106+
<!-- /.usage -->
107+
108+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
109+
110+
<section class="notes">
111+
112+
</section>
113+
114+
<!-- /.notes -->
115+
116+
<!-- Package usage examples. -->
117+
118+
<section class="examples">
119+
120+
## Examples
121+
122+
<!-- eslint no-undef: "error" -->
123+
124+
```javascript
125+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
126+
var dtypeStrings = require( '@stdlib/ndarray/base/dtype-strings' );
127+
128+
var isdtype = contains( dtypeStrings() );
129+
130+
var bool = isdtype( 'float64' );
131+
// returns true
132+
133+
bool = isdtype( 'int16' );
134+
// returns true
135+
136+
bool = isdtype( 'uint8' );
137+
// returns true
138+
139+
bool = isdtype( 'beep' );
140+
// returns false
141+
```
142+
143+
</section>
144+
145+
<!-- /.examples -->
146+
147+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
148+
149+
<section class="references">
150+
151+
</section>
152+
153+
<!-- /.references -->
154+
155+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
156+
157+
<section class="related">
158+
159+
</section>
160+
161+
<!-- /.related -->
162+
163+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
164+
165+
<section class="links">
166+
167+
</section>
168+
169+
<!-- /.links -->
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
25+
var pkg = require( './../package.json' ).name;
26+
var dtypes = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var out;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
out = dtypes();
38+
if ( out.length === 0 ) {
39+
b.fail( 'should return a non-empty array' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isStringArray( out ) ) {
44+
b.fail( 'should return an array of strings' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
49+
50+
bench( pkg+'::kind', function benchmark( b ) {
51+
var values;
52+
var out;
53+
var i;
54+
55+
values = [
56+
'floating_point',
57+
'integer'
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+
});
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+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
{{alias}}( [kind] )
3+
Returns a list of ndarray data type strings.
4+
5+
When not provided a data type "kind", the function returns an array
6+
containing the following data type strings:
7+
8+
- float16: half-precision floating-point numbers.
9+
- float32: single-precision floating-point numbers.
10+
- float64: double-precision floating-point numbers.
11+
- complex32: half-precision complex floating-point numbers.
12+
- complex64: single-precision complex floating-point numbers.
13+
- complex128: double-precision complex floating-point numbers.
14+
- bool: boolean values.
15+
- generic: values of any type.
16+
- int16: signed 16-bit integers.
17+
- int32: signed 32-bit integers.
18+
- int8: signed 8-bit integers.
19+
- uint16: unsigned 16-bit integers.
20+
- uint32: unsigned 32-bit integers.
21+
- uint8: unsigned 8-bit integers.
22+
- uint8c: unsigned clamped 8-bit integers.
23+
- binary: binary.
24+
25+
The function supports the following data type "kinds":
26+
27+
- floating_point: floating-point data types.
28+
- real_floating_point: real-valued floating-point data types.
29+
- complex_floating_point: complex-valued floating-point data types.
30+
- boolean: boolean data types.
31+
- integer: integer data types.
32+
- signed_integer: signed integer data types.
33+
- unsigned_integer: unsigned integer data types.
34+
- real: real-valued data types.
35+
- numeric: numeric data types.
36+
- typed: typed data types.
37+
- integer_index: integer index data types.
38+
- boolean_index: boolean index data types.
39+
- mask_index: mask index data types.
40+
- typed_index: typed index data types.
41+
- index: index data types.
42+
- all: all data types.
43+
44+
Additionally, the function supports extending the "kinds" listed above by
45+
appending a '_and_generic' suffix to the kind name (e.g., real_and_generic).
46+
47+
Parameters
48+
----------
49+
kind: string (optional)
50+
Data type kind.
51+
52+
Returns
53+
-------
54+
out: Array<string>
55+
List of ndarray data type strings.
56+
57+
Examples
58+
--------
59+
> var out = {{alias}}()
60+
[...]
61+
> out = {{alias}}( 'floating_point' )
62+
[...]
63+
> out = {{alias}}( 'floating_point_and_generic' )
64+
[...]
65+
66+
See Also
67+
--------
68+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { DataTypeString, DataTypeKind } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Returns a list of ndarray data type strings.
27+
*
28+
* @param kind - data type kind
29+
* @returns list of ndarray data type strings
30+
*
31+
* @example
32+
* var list = dtypes();
33+
* // returns [...]
34+
*
35+
* @example
36+
* var list = dtypes( 'floating_point' );
37+
* // returns [...]
38+
*/
39+
declare function dtypes( kind?: DataTypeKind ): Array<DataTypeString>;
40+
41+
42+
// EXPORTS //
43+
44+
export = dtypes;

0 commit comments

Comments
 (0)