Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jan 14, 2024
1 parent b7621c1 commit 03e3341
Show file tree
Hide file tree
Showing 15 changed files with 746 additions and 37 deletions.
153 changes: 153 additions & 0 deletions base/assert/is-complex128array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# isComplex128Array

> Test if a value is a [`Complex128Array`][@stdlib/array/complex128].
<section class="intro">

</section>

<!-- ./intro -->

<section class="usage">

## Usage

```javascript
var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
```

#### isComplex128Array( value )

Tests if a value is a [`Complex128Array`][@stdlib/array/complex128].

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var arr = new Complex128Array( 10 );
var bool = isComplex128Array( arr );
// returns true
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- This function is not robust and that is intentional. This function provides a lower cost way to reasonably determine whether an input value is a [`Complex128Array`][@stdlib/array/complex128] in order to avoid walking the prototype chain and resolving constructors, which is necessary for robust identification of cross-realm instances. For more robust validation, see [`@stdlib/assert/is-complex128array`][@stdlib/assert/is-complex128array].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint-disable object-curly-newline -->

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

```javascript
var Int8Array = require( '@stdlib/array/int8' );
var Uint8Array = require( '@stdlib/array/uint8' );
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
var Int16Array = require( '@stdlib/array/int16' );
var Uint16Array = require( '@stdlib/array/uint16' );
var Int32Array = require( '@stdlib/array/int32' );
var Uint32Array = require( '@stdlib/array/uint32' );
var Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var Complex128Array = require( '@stdlib/array/complex128' );
var Complex64Array = require( '@stdlib/array/complex64' );
var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );

var bool = isComplex128Array( new Complex128Array( 10 ) );
// returns true

bool = isComplex128Array( new Complex64Array( 10 ) );
// returns false

bool = isComplex128Array( [] );
// returns false

bool = isComplex128Array( new Float64Array( 10 ) );
// returns false

bool = isComplex128Array( new Float32Array( 10 ) );
// returns false

bool = isComplex128Array( new Int32Array( 10 ) );
// returns false

bool = isComplex128Array( new Uint32Array( 10 ) );
// returns false

bool = isComplex128Array( new Int16Array( 10 ) );
// returns false

bool = isComplex128Array( new Uint16Array( 10 ) );
// returns false

bool = isComplex128Array( new Int8Array( 10 ) );
// returns false

bool = isComplex128Array( new Uint8Array( 10 ) );
// returns false

bool = isComplex128Array( new Uint8ClampedArray( 10 ) );
// returns false

bool = isComplex128Array( { 'length': 0 } );
// 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/array/complex128]: https://github.com/stdlib-js/array/tree/main/complex128

[@stdlib/assert/is-complex128array]: https://github.com/stdlib-js/stdlib

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
135 changes: 135 additions & 0 deletions base/assert/is-complex128array/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 Float64Array = require( './../../../../float64' );
var Complex128Array = require( './../../../../complex128' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isComplex128Array = require( './../lib' );


// MAIN //

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
obj = [ i, i+1 ];
bool = isComplex128Array( obj );
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+'::real_typed_array', function benchmark( b ) {
var values;
var bool;
var obj;
var N;
var i;

values = [
new Float64Array( [ 1.0, 2.0 ] ),
new Float64Array( [ 3.0, 4.0 ] )
];
N = values.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
obj = values[ i%N ];
bool = isComplex128Array( obj );
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+'::complex_typed_array', function benchmark( b ) {
var values;
var bool;
var obj;
var N;
var i;

values = [
new Complex128Array( [ 1.0, 2.0 ] ),
new Complex128Array( [ 3.0, 4.0 ] )
];
N = values.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
obj = values[ i%N ];
bool = isComplex128Array( obj );
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+'::array_like_object', function benchmark( b ) {
var bool;
var obj;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
obj = {
'length': 2,
'0': i,
'1': i + 1
};
bool = isComplex128Array( obj );
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();
});
26 changes: 26 additions & 0 deletions base/assert/is-complex128array/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

{{alias}}( value )
Tests if a value is a Complex128Array.

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

Returns
-------
bool: boolean
Boolean indicating whether a value is a Complex128Array.

Examples
--------
> var bool = {{alias}}( new {{alias:@stdlib/array/complex128}}( 10 ) )
true
> bool = {{alias}}( [] )
false
> bool = {{alias}}( { 'length': 0 } )
false

See Also
--------

47 changes: 47 additions & 0 deletions base/assert/is-complex128array/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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

/// <reference types="@stdlib/types"/>

import { Collection, Complex128Array } from '@stdlib/types/array';

/**
* Tests if a value is a `Complex128Array`.
*
* @param value - value to test
* @returns boolean indicating whether a value is a `Complex128Array`
*
* @example
* var Complex128Array = require( '@stdlib/array/complex128' );
*
* var arr = new Complex128Array( 10 );
* var bool = isComplex128Array( arr );
* // returns true
*
* @example
* var bool = isComplex128Array( [] );
* // returns false
*/
declare function isComplex128Array( value: Collection | Complex128Array ): value is Complex128Array;


// EXPORTS //

export = isComplex128Array;
33 changes: 33 additions & 0 deletions base/assert/is-complex128array/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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 isComplex128Array = require( './index' );


// TESTS //

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

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isComplex128Array(); // $ExpectError
isComplex128Array( [], 123 ); // $ExpectError
}
Loading

0 comments on commit 03e3341

Please sign in to comment.