Skip to content

Commit 0e45135

Browse files
committed
Add array utility to return a list of floating-point data types
1 parent cbbe6e2 commit 0e45135

File tree

11 files changed

+528
-0
lines changed

11 files changed

+528
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2022 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 Types
22+
23+
> List of typed array floating-point data types.
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 dtypes = require( '@stdlib/array/typed-float-dtypes' );
41+
```
42+
43+
#### dtypes()
44+
45+
Returns a list of typed array floating-point data types.
46+
47+
```javascript
48+
var out = dtypes();
49+
// e.g., returns [ 'float32', 'float64', 'complex64', 'complex128' ]
50+
```
51+
52+
The output `array` contains the following data types:
53+
54+
- `float32`: single-precision floating-point numbers.
55+
- `float64`: double-precision floating-point numbers.
56+
- `complex64`: single-precision complex floating-point numbers.
57+
- `complex128`: double-precision complex floating-point numbers.
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
64+
65+
<section class="notes">
66+
67+
</section>
68+
69+
<!-- /.notes -->
70+
71+
<!-- Package usage examples. -->
72+
73+
<section class="examples">
74+
75+
## Examples
76+
77+
<!-- eslint no-undef: "error" -->
78+
79+
```javascript
80+
var indexOf = require( '@stdlib/utils/index-of' );
81+
var dtypes = require( '@stdlib/array/typed-float-dtypes' );
82+
83+
var DTYPES = dtypes();
84+
85+
function isdtype( str ) {
86+
if ( indexOf( DTYPES, str ) === -1 ) {
87+
return false;
88+
}
89+
return true;
90+
}
91+
92+
var bool = isdtype( 'float64' );
93+
// returns true
94+
95+
bool = isdtype( 'complex128' );
96+
// returns true
97+
98+
bool = isdtype( 'float32' );
99+
// returns true
100+
101+
bool = isdtype( 'beep' );
102+
// returns false
103+
```
104+
105+
</section>
106+
107+
<!-- /.examples -->
108+
109+
<!-- 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. -->
110+
111+
<section class="references">
112+
113+
</section>
114+
115+
<!-- /.references -->
116+
117+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
118+
119+
<section class="related">
120+
121+
</section>
122+
123+
<!-- /.related -->
124+
125+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="links">
128+
129+
</section>
130+
131+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 <= 2 ) {
39+
b.fail( 'should return an array of strings' );
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+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
{{alias}}()
3+
Returns a list of typed array floating-point data types.
4+
5+
The output array contains the following data types:
6+
7+
- float32: single-precision floating-point numbers.
8+
- float64: double-precision floating-point numbers.
9+
- complex64: single-precision complex floating-point numbers.
10+
- complex128: double-precision complex floating-point numbers.
11+
12+
Returns
13+
-------
14+
out: Array<string>
15+
List of typed array floating-point data types.
16+
17+
Examples
18+
--------
19+
> var out = {{alias}}()
20+
<Array>
21+
22+
See Also
23+
--------
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { FloatOrComplexDataType as DataType } from '@stdlib/types/array';
24+
25+
/**
26+
* Returns a list of typed array floating-point data types.
27+
*
28+
* @returns list of typed array floating-point data types
29+
*
30+
* @example
31+
* var list = dtypes();
32+
* // e.g., returns [ 'float32', 'float64', 'complex64', 'complex128' ]
33+
*/
34+
declare function dtypes(): Array<DataType>;
35+
36+
37+
// EXPORTS //
38+
39+
export = dtypes;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
import dtypes = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a string array..
25+
{
26+
dtypes(); // $ExpectType FloatOrComplexDataType[]
27+
}
28+
29+
// The compiler throws an error if the function is provided arguments...
30+
{
31+
dtypes( 1 ); // $ExpectError
32+
dtypes( 1, 2 ); // $ExpectError
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
var indexOf = require( '@stdlib/utils/index-of' );
22+
var dtypes = require( './../lib' );
23+
24+
var DTYPES = dtypes();
25+
26+
function isdtype( str ) {
27+
if ( indexOf( DTYPES, str ) === -1 ) {
28+
return false;
29+
}
30+
return true;
31+
}
32+
33+
var bool = isdtype( 'float64' );
34+
console.log( bool );
35+
// => true
36+
37+
bool = isdtype( 'complex128' );
38+
console.log( bool );
39+
// => true
40+
41+
bool = isdtype( 'float32' );
42+
console.log( bool );
43+
// => true
44+
45+
bool = isdtype( 'beep' );
46+
console.log( bool );
47+
// => false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"float32",
3+
"float64",
4+
"complex64",
5+
"complex128"
6+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
/**
22+
* Return a list of typed array floating-point data types.
23+
*
24+
* @module @stdlib/array/typed-float-dtypes
25+
*
26+
* @example
27+
* var dtypes = require( '@stdlib/array/typed-float-dtypes' );
28+
*
29+
* var list = dtypes();
30+
* // e.g., returns [ 'float32', 'float64', 'complex64', 'complex128' ]
31+
*/
32+
33+
// MODULES //
34+
35+
var main = require( './main.js' );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = main;

0 commit comments

Comments
 (0)