Skip to content

Commit 38e466c

Browse files
committed
feat: add assert/is-complex64vector-like
1 parent 98d82b5 commit 38e466c

File tree

10 files changed

+627
-0
lines changed

10 files changed

+627
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# isComplex64VectorLike
22+
23+
> Test if a value is a 1-dimensional [ndarray][@stdlib/ndarray/ctor]-like object containing single-precision complex floating-point numbers.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isComplex64VectorLike = require( '@stdlib/assert/is-complex64vector-like' );
31+
```
32+
33+
#### isComplex64VectorLike( value )
34+
35+
Tests if a value is a 1-dimensional [ndarray][@stdlib/ndarray/ctor]-like object whose underlying data type is `complex64`.
36+
37+
```javascript
38+
var Complex64Array = require( '@stdlib/array/complex64' );
39+
var ndarray = require( '@stdlib/ndarray/ctor' );
40+
41+
var arr = ndarray( 'complex64', new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
42+
43+
var bool = isComplex64VectorLike( arr );
44+
// returns true
45+
```
46+
47+
</section>
48+
49+
<!-- /.usage -->
50+
51+
<section class="examples">
52+
53+
## Examples
54+
55+
<!-- eslint no-undef: "error" -->
56+
57+
```javascript
58+
var ndarray = require( '@stdlib/ndarray/ctor' );
59+
var Complex64Array = require( '@stdlib/array/complex64' );
60+
var isComplex64VectorLike = require( '@stdlib/assert/is-complex64vector-like' );
61+
62+
var buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
63+
var arr = ndarray( 'complex64', buffer, [ 4 ], [ 1 ], 0, 'row-major' );
64+
65+
var out = isComplex64VectorLike( arr );
66+
// returns true
67+
68+
out = isComplex64VectorLike( [ 1, 2, 3, 4 ] );
69+
// returns false
70+
71+
out = isComplex64VectorLike( {} );
72+
// returns false
73+
74+
out = isComplex64VectorLike( null );
75+
// returns false
76+
```
77+
78+
</section>
79+
80+
<!-- /.examples -->
81+
82+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
83+
84+
<section class="related">
85+
86+
</section>
87+
88+
<!-- /.related -->
89+
90+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
91+
92+
<section class="links">
93+
94+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor
95+
96+
</section>
97+
98+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var ndarray = require( '@stdlib/ndarray/ctor' );
26+
var Complex64Array = require( '@stdlib/array/complex64' );
27+
var pkg = require( './../package.json' ).name;
28+
var isComplex64VectorLike = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+'::true', function benchmark( b ) {
34+
var strides;
35+
var offset;
36+
var buffer;
37+
var values;
38+
var shape;
39+
var order;
40+
var bool;
41+
var arr;
42+
var i;
43+
44+
buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
45+
shape = [ 4 ];
46+
strides = [ 1 ];
47+
offset = 0;
48+
order = 'row-major';
49+
50+
arr = ndarray( 'complex64', buffer, shape, strides, offset, order );
51+
52+
values = [
53+
arr,
54+
arr
55+
];
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
bool = isComplex64VectorLike( values[ i%values.length ] );
60+
if ( typeof bool !== 'boolean' ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isBoolean( bool ) ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});
71+
72+
bench( pkg+'::false', function benchmark( b ) {
73+
var values;
74+
var bool;
75+
var i;
76+
77+
values = [
78+
[ 1, 2, 3 ],
79+
null,
80+
5,
81+
'beep'
82+
];
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
bool = isComplex64VectorLike( values[ i%values.length ] );
87+
if ( typeof bool !== 'boolean' ) {
88+
b.fail( 'should return a boolean' );
89+
}
90+
}
91+
b.toc();
92+
if ( !isBoolean( bool ) ) {
93+
b.fail( 'should return a boolean' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is a 1-dimensional ndarray-like object containing single-
4+
precision complex floating-point numbers.
5+
6+
Parameters
7+
----------
8+
value: any
9+
Value to test.
10+
11+
Returns
12+
-------
13+
bool: boolean
14+
Boolean indicating whether a value is a 1-dimensional ndarray-like
15+
object containing single-precision complex floating-point numbers.
16+
17+
Examples
18+
--------
19+
> var M = {};
20+
> M.data = new {{alias:@stdlib/array/complex64}}( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
21+
> M.ndims = 1;
22+
> M.shape = [ 4 ];
23+
> M.strides = [ 1 ];
24+
> M.offset = 0;
25+
> M.order = 'row-major';
26+
> M.dtype = 'complex64';
27+
> M.length = 4;
28+
> M.flags = {};
29+
> M.get = function get( i, j ) {};
30+
> M.set = function set( i, j ) {};
31+
> var bool = {{alias}}( M )
32+
true
33+
> bool = {{alias}}( [ 1, 2, 3, 4 ] )
34+
false
35+
> bool = {{alias}}( 3.14 )
36+
false
37+
> bool = {{alias}}( {} )
38+
false
39+
40+
See Also
41+
--------
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
/**
22+
* Tests if a value is a 1-dimensional ndarray-like object whose underlying data type is `complex64`.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating if a value is a 1-dimensional ndarray-like object whose underlying data type is `complex64`
26+
*
27+
* @example
28+
* var Complex64Array = require( `@stdlib/array/complex64` );
29+
* var ndarray = require( `@stdlib/ndarray/ctor` );
30+
*
31+
* var arr = ndarray( 'complex64', new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 4 ], [ 1 ], 0, 'row-major' );
32+
*
33+
* var bool = isComplex64VectorLike( arr );
34+
* // returns true
35+
*
36+
* bool = isComplex64VectorLike( [] );
37+
* // returns false
38+
*/
39+
declare function isComplex64VectorLike( v: any ): boolean;
40+
41+
42+
// EXPORTS //
43+
44+
export = isComplex64VectorLike;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isComplex64VectorLike = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isComplex64VectorLike( [] ); // $ExpectType boolean
27+
}
28+
29+
// The compiler throws an error if the function is provided an unsupported number of arguments...
30+
{
31+
isComplex64VectorLike(); // $ExpectError
32+
isComplex64VectorLike( 'abc', 123 ); // $ExpectError
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 ndarray = require( '@stdlib/ndarray/ctor' );
22+
var Complex64Array = require( '@stdlib/array/complex64' );
23+
var isComplex64VectorLike = require( './../lib' );
24+
25+
var buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
26+
var arr = ndarray( 'complex64', buffer, [ 4 ], [ 1 ], 0, 'row-major' );
27+
28+
console.log( isComplex64VectorLike( arr ) );
29+
// => true
30+
31+
console.log( isComplex64VectorLike( [ 1, 2, 3, 4 ] ) );
32+
// => false
33+
34+
console.log( isComplex64VectorLike( {} ) );
35+
// => false
36+
37+
console.log( isComplex64VectorLike( null ) );
38+
// => false

0 commit comments

Comments
 (0)