Skip to content

feat: add assert/is-float16array #7273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions lib/node_modules/@stdlib/assert/is-float16array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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.

-->

# isFloat16Array

> Test if a value is a [Float16Array][mdn-float16array].

<section class="usage">

## Usage

```javascript
var isFloat16Array = require( '@stdlib/assert/is-float16array' );
```

#### isFloat16Array( value )

Tests if a value is a [`Float16Array`][mdn-float16array].

```javascipt
var Float16Array = require( '@stdlib/array/float16' );

var bool = isFloat16Array( new Float16Array( 10 ) );
// returns true

bool = isFloat16Array( [] );
// returns false
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- 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 Float16Array = require( '@stdlib/array/float16' );
var isFloat16Array = require( '@stdlib/assert/is-float16array' );

var bool = isFloat16Array( new Float16Array( 10 ) );
// returns true

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

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

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

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

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

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

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

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

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

bool = isFloat16Array( new Array( 10 ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line causes the lint error, I am not sure with the solution, maybe removing this be a option, maybe there be a better option, not sure about it.

// returns false

bool = isFloat16Array( {} );
// returns false

bool = isFloat16Array( null );
// returns false
```

</section>

<!-- /.examples -->

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

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/assert/is-float64array`][@stdlib/assert/is-float64array]</span><span class="delimiter">: </span><span class="description">test if a value is a Float64Array.</span>
- <span class="package-name">[`@stdlib/assert/is-float32array`][@stdlib/assert/is-float32array]</span><span class="delimiter">: </span><span class="description">test if a value is a Float32Array.</span>

</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">

[mdn-float16array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array

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

[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array

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

[@stdlib/assert/is-float64array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-float64array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[@stdlib/assert/is-float64array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-float64array
[@stdlib/assert/is-float64array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-float64array
[@stdlib/assert/is-float32array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-float32array

[@stdlib/assert/is-float32array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-float32array

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

</section>

<!-- /.links -->
132 changes: 132 additions & 0 deletions lib/node_modules/@stdlib/assert/is-float16array/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isFloat16Array = require( './../lib' );
var Float16Array = globalThis[ Symbol.for( '@@stdlib/array/float16' ) ];

var opts = {
skip: ( typeof Float16Array !== 'function' )
};

// MAIN //
Comment on lines +36 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var Float16Array = globalThis[ Symbol.for( '@@stdlib/array/float16' ) ];
var opts = {
skip: ( typeof Float16Array !== 'function' )
};
// MAIN //
var Float16Array = globalThis[ Symbol.for( '@@stdlib/array/float16' ) ];
// VARIABLES //
var opts = {
skip: ( typeof Float16Array !== 'function' )
};
// MAIN //


bench( pkg, opts, function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Float64Array( 10 ),
new Float16Array( 10 ),
new Float32Array( 10 ),
new Int32Array( 10 ),
new Uint32Array( 10 ),
new Int16Array( 10 ),
new Uint16Array( 10 ),
new Int8Array( 10 ),
new Uint8Array( 10 ),
new Uint8ClampedArray( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isFloat16Array( 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+'::true', opts, function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Float16Array( 10 ),
new Float16Array( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isFloat16Array( 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', opts, function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Float64Array( 10 ),
new Float32Array( 10 ),
new Int32Array( 10 ),
new Uint32Array( 10 ),
new Int16Array( 10 ),
new Uint16Array( 10 ),
new Int8Array( 10 ),
new Uint8Array( 10 ),
new Uint8ClampedArray( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isFloat16Array( 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();
});
22 changes: 22 additions & 0 deletions lib/node_modules/@stdlib/assert/is-float16array/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{alias}}( value )
Tests if a value is a Float16Array.

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

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

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

See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 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

import Float16Array = require( '@stdlib/array/float16' );

/**
* Tests if a value is a Float16Array.
*
* @param value - value to test
* @returns boolean indicating whether value is a Float16Array
*
* @example
*
* var bool = isFloat16Array( new Float16Array( 10 ) );
* // returns true
*
* @example
* var bool = isFloat16Array( [] );
* // returns false
*/
declare function isFloat16Array( value: any ): value is Float16Array;

Check warning on line 38 in lib/node_modules/@stdlib/assert/is-float16array/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

// EXPORTS //

export = isFloat16Array;
34 changes: 34 additions & 0 deletions lib/node_modules/@stdlib/assert/is-float16array/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 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 isFloat16Array = require( './index' );


// TESTS //

// The function returns a boolean...
{
isFloat16Array( new Float16Array( 10 ) ); // $ExpectType boolean
isFloat16Array( [] ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isFloat16Array(); // $ExpectError
isFloat16Array( new Float16Array( 10 ), 123 ); // $ExpectError
}
Loading
Loading