Skip to content

Commit e6b98b0

Browse files
committed
Add pkg to return a complex typed array constructor
1 parent f1d2708 commit e6b98b0

File tree

9 files changed

+536
-0
lines changed

9 files changed

+536
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# Constructors
22+
23+
> Complex typed array constructors.
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 ctors = require( '@stdlib/array/typed-complex-ctors' );
41+
```
42+
43+
#### ctors( dtype )
44+
45+
Returns a complex typed array constructor for a specified data type.
46+
47+
```javascript
48+
var ctor = ctors( 'complex128' );
49+
// returns <Function>
50+
```
51+
52+
The function returns constructors for the following data types:
53+
54+
- `complex64`: single-precision floating-point complex numbers.
55+
- `complex128`: double-precision floating-point complex numbers.
56+
57+
If provided an unknown or unsupported data type, the function returns `null`.
58+
59+
```javascript
60+
var ctor = ctors( 'float64' );
61+
// returns null
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
69+
70+
<section class="notes">
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var dtypes = require( '@stdlib/array/typed-complex-dtypes' );
86+
var ctors = require( '@stdlib/array/typed-complex-ctors' );
87+
88+
var DTYPES = dtypes();
89+
var ctor;
90+
var i;
91+
92+
for ( i = 0; i < DTYPES.length; i++ ) {
93+
ctor = ctors( DTYPES[ i ] );
94+
console.log( ctor );
95+
}
96+
```
97+
98+
</section>
99+
100+
<!-- /.examples -->
101+
102+
<!-- 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. -->
103+
104+
<section class="references">
105+
106+
</section>
107+
108+
<!-- /.references -->
109+
110+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
111+
112+
<section class="links">
113+
114+
</section>
115+
116+
<!-- /.links -->
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 dtypes = require( '@stdlib/array/typed-complex-dtypes' );
25+
var isFunction = require( '@stdlib/assert/is-function' );
26+
var pkg = require( './../package.json' ).name;
27+
var ctors = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var DTYPES = dtypes();
33+
34+
35+
// MAIN //
36+
37+
bench( pkg, function benchmark( b ) {
38+
var ctor;
39+
var i;
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
ctor = ctors( DTYPES[ i%DTYPES.length ] );
44+
if ( typeof ctor !== 'function' ) {
45+
b.fail( 'should return a function' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isFunction( ctor ) ) {
50+
b.fail( 'should return a function' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( dtype )
3+
Returns a complex typed array constructor.
4+
5+
The function returns constructors for the following data types:
6+
7+
- complex64: single-precision floating-point complex numbers.
8+
- complex128: double-precision floating-point complex numbers.
9+
10+
Parameters
11+
----------
12+
dtype: string
13+
Data type.
14+
15+
Returns
16+
-------
17+
out: Function|null
18+
Complex typed array constructor.
19+
20+
Examples
21+
--------
22+
> var ctor = {{alias}}( 'complex64' )
23+
<Function>
24+
> ctor = {{alias}}( 'float32' )
25+
null
26+
27+
See Also
28+
--------
29+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 dtypes = require( '@stdlib/array/typed-complex-dtypes' );
22+
var ctors = require( './../lib' );
23+
24+
var DTYPES = dtypes();
25+
var ctor;
26+
var i;
27+
28+
for ( i = 0; i < DTYPES.length; i++ ) {
29+
ctor = ctors( DTYPES[ i ] );
30+
console.log( ctor );
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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+
// MAIN //
22+
23+
// Mapping from data types to constructors...
24+
var ctors = {
25+
'complex128': require( '@stdlib/array/complex128' ),
26+
'complex64': require( '@stdlib/array/complex64' )
27+
};
28+
29+
30+
// EXPORTS //
31+
32+
module.exports = ctors;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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+
* Complex typed array constructors.
23+
*
24+
* @module @stdlib/array/typed-complex-ctors
25+
*
26+
* @example
27+
* var ctors = require( '@stdlib/array/typed-complex-ctors' );
28+
*
29+
* var ctor = ctors( 'complex128' );
30+
* // returns <Function>
31+
*
32+
* ctor = ctors( 'float64' );
33+
* // returns null
34+
*/
35+
36+
// MODULES //
37+
38+
var ctors = require( './main.js' );
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = ctors;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 table = require( './ctors.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Returns a complex typed array constructor.
30+
*
31+
* @param {string} dtype - data type
32+
* @returns {(Function|null)} constructor or null
33+
*
34+
* @example
35+
* var ctor = ctors( 'complex128' );
36+
* // returns <Function>
37+
*
38+
* @example
39+
* var ctor = ctors( 'float64' );
40+
* // returns null
41+
*/
42+
function ctors( dtype ) {
43+
return table[ dtype ] || null;
44+
}
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = ctors;

0 commit comments

Comments
 (0)