Skip to content

Commit 522af27

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 9135490 + 77b2415 commit 522af27

File tree

10 files changed

+697
-0
lines changed

10 files changed

+697
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# isFloat16Array
22+
23+
> Test if a value is a [Float16Array][mdn-float16array].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isFloat16Array = require( '@stdlib/assert/is-float16array' );
31+
```
32+
33+
#### isFloat16Array( value )
34+
35+
Tests if a value is a [`Float16Array`][mdn-float16array].
36+
37+
<!-- TODO: update example once `array/float16` is added -->
38+
39+
```javascript
40+
var bool = isFloat16Array( [] );
41+
// returns false
42+
```
43+
44+
</section>
45+
46+
<!-- /.usage -->
47+
48+
<section class="examples">
49+
50+
## Examples
51+
52+
<!-- eslint no-undef: "error" -->
53+
54+
```javascript
55+
var Int8Array = require( '@stdlib/array/int8' );
56+
var Uint8Array = require( '@stdlib/array/uint8' );
57+
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
58+
var Int16Array = require( '@stdlib/array/int16' );
59+
var Uint16Array = require( '@stdlib/array/uint16' );
60+
var Int32Array = require( '@stdlib/array/int32' );
61+
var Uint32Array = require( '@stdlib/array/uint32' );
62+
var Float32Array = require( '@stdlib/array/float32' );
63+
var Float64Array = require( '@stdlib/array/float64' );
64+
var isFloat16Array = require( '@stdlib/assert/is-float16array' );
65+
66+
var bool = isFloat16Array( new Int8Array( 10 ) );
67+
// returns false
68+
69+
bool = isFloat16Array( new Uint8Array( 10 ) );
70+
// returns false
71+
72+
bool = isFloat16Array( new Uint8ClampedArray( 10 ) );
73+
// returns false
74+
75+
bool = isFloat16Array( new Int16Array( 10 ) );
76+
// returns false
77+
78+
bool = isFloat16Array( new Uint16Array( 10 ) );
79+
// returns false
80+
81+
bool = isFloat16Array( new Int32Array( 10 ) );
82+
// returns false
83+
84+
bool = isFloat16Array( new Uint32Array( 10 ) );
85+
// returns false
86+
87+
bool = isFloat16Array( new Float32Array( 10 ) );
88+
// returns false
89+
90+
bool = isFloat16Array( new Float64Array( 10 ) );
91+
// returns false
92+
93+
bool = isFloat16Array( [] );
94+
// returns false
95+
96+
bool = isFloat16Array( {} );
97+
// returns false
98+
99+
bool = isFloat16Array( null );
100+
// returns false
101+
```
102+
103+
</section>
104+
105+
<!-- /.examples -->
106+
107+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
108+
109+
<section class="related">
110+
111+
</section>
112+
113+
<!-- /.related -->
114+
115+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
116+
117+
<section class="links">
118+
119+
[mdn-float16array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array
120+
121+
</section>
122+
123+
<!-- /.links -->
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 Int8Array = require( '@stdlib/array/int8' );
25+
var Uint8Array = require( '@stdlib/array/uint8' );
26+
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
27+
var Int16Array = require( '@stdlib/array/int16' );
28+
var Uint16Array = require( '@stdlib/array/uint16' );
29+
var Int32Array = require( '@stdlib/array/int32' );
30+
var Uint32Array = require( '@stdlib/array/uint32' );
31+
var Float32Array = require( '@stdlib/array/float32' );
32+
var Float64Array = require( '@stdlib/array/float64' );
33+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
34+
var pkg = require( './../package.json' ).name;
35+
var isFloat16Array = require( './../lib' );
36+
37+
38+
// VARIABLES //
39+
40+
// TODO: remove once `array/float16` is added
41+
var Float16Array = ( typeof Float16Array === 'function' ) ? Float16Array : null; // eslint-disable-line no-use-before-define
42+
var opts = {
43+
'skip': ( Float16Array === null )
44+
};
45+
46+
47+
// MAIN //
48+
49+
bench( pkg, function benchmark( b ) {
50+
var values;
51+
var bool;
52+
var i;
53+
54+
values = [
55+
new Float64Array( 10 ),
56+
new Float32Array( 10 ),
57+
new Int32Array( 10 ),
58+
new Uint32Array( 10 ),
59+
new Int16Array( 10 ),
60+
new Uint16Array( 10 ),
61+
new Int8Array( 10 ),
62+
new Uint8Array( 10 ),
63+
new Uint8ClampedArray( 10 )
64+
];
65+
66+
b.tic();
67+
for ( i = 0; i < b.iterations; i++ ) {
68+
bool = isFloat16Array( values[ i%values.length ] );
69+
if ( typeof bool !== 'boolean' ) {
70+
b.fail( 'should return a boolean' );
71+
}
72+
}
73+
b.toc();
74+
if ( !isBoolean( bool ) ) {
75+
b.fail( 'should return a boolean' );
76+
}
77+
b.pass( 'benchmark finished' );
78+
b.end();
79+
});
80+
81+
bench( pkg+'::true', opts, function benchmark( b ) {
82+
var values;
83+
var bool;
84+
var i;
85+
86+
values = [
87+
new Float16Array( 10 ),
88+
new Float16Array( 10 )
89+
];
90+
91+
b.tic();
92+
for ( i = 0; i < b.iterations; i++ ) {
93+
bool = isFloat16Array( values[ i%values.length ] );
94+
if ( typeof bool !== 'boolean' ) {
95+
b.fail( 'should return a boolean' );
96+
}
97+
}
98+
b.toc();
99+
if ( !isBoolean( bool ) ) {
100+
b.fail( 'should return a boolean' );
101+
}
102+
b.pass( 'benchmark finished' );
103+
b.end();
104+
});
105+
106+
bench( pkg+'::false', function benchmark( b ) {
107+
var values;
108+
var bool;
109+
var i;
110+
111+
values = [
112+
new Float64Array( 10 ),
113+
new Float32Array( 10 ),
114+
new Int32Array( 10 ),
115+
new Uint32Array( 10 ),
116+
new Int16Array( 10 ),
117+
new Uint16Array( 10 ),
118+
new Int8Array( 10 ),
119+
new Uint8Array( 10 ),
120+
new Uint8ClampedArray( 10 )
121+
];
122+
123+
b.tic();
124+
for ( i = 0; i < b.iterations; i++ ) {
125+
bool = isFloat16Array( values[ i%values.length ] );
126+
if ( typeof bool !== 'boolean' ) {
127+
b.fail( 'should return a boolean' );
128+
}
129+
}
130+
b.toc();
131+
if ( !isBoolean( bool ) ) {
132+
b.fail( 'should return a boolean' );
133+
}
134+
b.pass( 'benchmark finished' );
135+
b.end();
136+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is a Float16Array.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating whether value is a Float16Array.
14+
15+
Examples
16+
--------
17+
// TODO: update to use `array/float16` once added
18+
> var bool = {{alias}}( new {{alias:@stdlib/array/float32}}( 10 ) )
19+
false
20+
> bool = {{alias}}( [] )
21+
false
22+
23+
See Also
24+
--------
25+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 Float16Array.
23+
*
24+
* @param value - value to test
25+
* @returns boolean indicating whether value is a Float16Array
26+
*
27+
* @example
28+
* var Float16Array = require( '@stdlib/array/float16' );
29+
*
30+
* var bool = isFloat16Array( new Float16Array( 10 ) );
31+
* // returns true
32+
*
33+
* @example
34+
* var bool = isFloat16Array( [] );
35+
* // returns false
36+
*/
37+
declare function isFloat16Array( value: any ): boolean; // TODO: replace with `value is Float16Array` once `array/float16` added
38+
39+
40+
// EXPORTS //
41+
42+
export = isFloat16Array;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isFloat16Array = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isFloat16Array( [] ); // $ExpectType boolean
27+
}
28+
29+
// The compiler throws an error if the function is provided an unsupported number of arguments...
30+
{
31+
isFloat16Array(); // $ExpectError
32+
isFloat16Array( [], 123 ); // $ExpectError
33+
}

0 commit comments

Comments
 (0)