Skip to content

Commit

Permalink
feat: add assert/is-complex64ndarray-like
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Dec 2, 2023
1 parent df4de54 commit ae603fb
Show file tree
Hide file tree
Showing 10 changed files with 621 additions and 0 deletions.
98 changes: 98 additions & 0 deletions lib/node_modules/@stdlib/assert/is-complex64ndarray-like/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!--
@license Apache-2.0
Copyright (c) 2023 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# isComplex64ndarrayLike

> Test if a value is an [ndarray][@stdlib/ndarray/ctor]-like object containing single-precision complex floating-point numbers.
<section class="usage">

## Usage

```javascript
var isComplex64ndarrayLike = require( '@stdlib/assert/is-complex64ndarray-like' );
```

#### isComplex64ndarrayLike( value )

Tests if a value is an [ndarray][@stdlib/ndarray/ctor]-like object whose underlying data type is `complex64`.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var ndarray = require( '@stdlib/ndarray/ctor' );

var arr = ndarray( 'complex64', new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );

var bool = isComplex64ndarrayLike( arr );
// returns true
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var ndarray = require( '@stdlib/ndarray/ctor' );
var Complex64Array = require( '@stdlib/array/complex64' );
var isComplex64ndarrayLike = require( '@stdlib/assert/is-complex64ndarray-like' );

var buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
var arr = ndarray( 'complex64', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );

var out = isComplex64ndarrayLike( arr );
// returns true

out = isComplex64ndarrayLike( [ 1, 2, 3, 4 ] );
// returns false

out = isComplex64ndarrayLike( {} );
// returns false

out = isComplex64ndarrayLike( null );
// returns false
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var ndarray = require( '@stdlib/ndarray/ctor' );
var Complex64Array = require( '@stdlib/array/complex64' );
var pkg = require( './../package.json' ).name;
var isComplex64ndarrayLike = require( './../lib' );


// MAIN //

bench( pkg+'::true', function benchmark( b ) {
var strides;
var offset;
var buffer;
var values;
var shape;
var order;
var bool;
var arr;
var i;

buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

arr = ndarray( 'complex64', buffer, shape, strides, offset, order );

values = [
arr,
arr
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isComplex64ndarrayLike( values[ i%values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::false', function benchmark( b ) {
var values;
var bool;
var i;

values = [
[ 1, 2, 3 ],
null,
5,
'beep'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isComplex64ndarrayLike( values[ i%values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

{{alias}}( value )
Tests if a value is an ndarray-like object containing single-precision
complex floating-point numbers.

Parameters
----------
value: any
Value to test.

Returns
-------
bool: boolean
Boolean indicating whether a value is an ndarray-like object containing
single-precision complex floating-point numbers.

Examples
--------
> var M = {};
> M.data = new {{alias:@stdlib/array/complex64}}( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
> M.ndims = 2;
> M.shape = [ 2, 2 ];
> M.strides = [ 2, 1 ];
> M.offset = 0;
> M.order = 'row-major';
> M.dtype = 'complex64';
> M.length = 4;
> M.flags = {};
> M.get = function get( i, j ) {};
> M.set = function set( i, j ) {};
> var bool = {{alias}}( M )
true
> bool = {{alias}}( [ 1, 2, 3, 4 ] )
false
> bool = {{alias}}( 3.14 )
false
> bool = {{alias}}( {} )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Tests if a value is an ndarray-like object whose underlying data type is `complex64`.
*
* @param v - value to test
* @returns boolean indicating if a value is an ndarray-like object whose underlying data type is `complex64`
*
* @example
* var Complex64Array = require( `@stdlib/array/complex64` );
* var ndarray = require( `@stdlib/ndarray/ctor` );
*
* var arr = ndarray( 'complex64', new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
*
* var bool = isComplex64ndarrayLike( arr );
* // returns true
*
* bool = isComplex64ndarrayLike( [] );
* // returns false
*/
declare function isComplex64ndarrayLike( v: any ): boolean;


// EXPORTS //

export = isComplex64ndarrayLike;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import isComplex64ndarrayLike = require( './index' );


// TESTS //

// The function returns a boolean...
{
isComplex64ndarrayLike( [] ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isComplex64ndarrayLike(); // $ExpectError
isComplex64ndarrayLike( 'abc', 123 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var ndarray = require( '@stdlib/ndarray/ctor' );
var Complex64Array = require( '@stdlib/array/complex64' );
var isComplex64ndarrayLike = require( './../lib' );

var buffer = new Complex64Array( [ 0, 0, 0, 0, 0, 0, 0, 0 ] );
var arr = ndarray( 'complex64', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );

console.log( isComplex64ndarrayLike( arr ) );
// => true

console.log( isComplex64ndarrayLike( [ 1, 2, 3, 4 ] ) );
// => false

console.log( isComplex64ndarrayLike( {} ) );
// => false

console.log( isComplex64ndarrayLike( null ) );
// => false
Loading

0 comments on commit ae603fb

Please sign in to comment.