Skip to content

Commit cd33708

Browse files
committed
Add utility to return an array of complex number data types
1 parent 9e75d11 commit cd33708

File tree

11 files changed

+523
-0
lines changed

11 files changed

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

0 commit comments

Comments
 (0)