Skip to content

Commit 4e48d21

Browse files
committed
feat: add array/float16
1 parent a61496d commit 4e48d21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+7803
-0
lines changed

lib/node_modules/@stdlib/array/float16/README.md

Lines changed: 1489 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 pkg = require( './../package.json' ).name;
25+
var Float16Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':copyWithin', function benchmark( b ) {
31+
var arr;
32+
var i;
33+
34+
arr = new Float16Array( 2 );
35+
36+
b.tic();
37+
for ( i = 0; i < b.iterations; i++ ) {
38+
arr[ 0 ] = i;
39+
arr = arr.copyWithin( 1, 0 );
40+
if ( arr[ 0 ] !== i ) {
41+
b.fail( 'unexpected result' );
42+
}
43+
}
44+
b.toc();
45+
if ( arr[ 0 ] !== arr[ 0 ] ) {
46+
b.fail( 'should not be NaN' );
47+
}
48+
b.pass( 'benchmark finished' );
49+
b.end();
50+
});
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 pow = require( '@stdlib/math/base/special/pow' );
25+
var pkg = require( './../package.json' ).name;
26+
var Float16Array = require( './../lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Creates a benchmark function.
33+
*
34+
* @private
35+
* @param {PositiveInteger} len - array length
36+
* @returns {Function} benchmark function
37+
*/
38+
function createBenchmark( len ) {
39+
var arr = new Float16Array( len );
40+
return benchmark;
41+
42+
/**
43+
* Benchmark function.
44+
*
45+
* @private
46+
* @param {Benchmark} b - benchmark instance
47+
*/
48+
function benchmark( b ) {
49+
var i;
50+
51+
b.tic();
52+
for ( i = 0; i < b.iterations; i++ ) {
53+
arr[ 0 ] = i;
54+
arr = arr.copyWithin( 1, 0 );
55+
if ( arr[ 0 ] !== i ) {
56+
b.fail( 'unexpected result' );
57+
}
58+
}
59+
b.toc();
60+
if ( arr[ 0 ] !== arr[ 0 ] ) {
61+
b.fail( 'should not be NaN' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
}
66+
}
67+
68+
69+
// MAIN //
70+
71+
/**
72+
* Main execution sequence.
73+
*
74+
* @private
75+
*/
76+
function main() {
77+
var len;
78+
var min;
79+
var max;
80+
var f;
81+
var i;
82+
83+
min = 1; // 10^min
84+
max = 6; // 10^max
85+
86+
for ( i = min; i <= max; i++ ) {
87+
len = pow( 10, i );
88+
f = createBenchmark( len );
89+
bench( pkg+':copyWithin:len='+len, f );
90+
}
91+
}
92+
93+
main();
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 pkg = require( './../package.json' ).name;
25+
var Float16Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+'::get,index', function benchmark( b ) {
31+
var arr;
32+
var N;
33+
var v;
34+
var i;
35+
36+
arr = new Float16Array( 2 );
37+
N = arr.length;
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = arr[ i%N ];
42+
if ( v !== v ) {
43+
b.fail( 'should not return NaN' );
44+
}
45+
}
46+
b.toc();
47+
if ( v !== v ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});
53+
54+
bench( pkg+'::set,index', function benchmark( b ) {
55+
var arr;
56+
var N;
57+
var i;
58+
59+
arr = new Float16Array( 2 );
60+
N = arr.length;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
arr[ i%N ] = i;
65+
if ( arr[ 0 ] !== arr[ 0 ] ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
}
69+
b.toc();
70+
if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) {
71+
b.fail( 'should not return NaN' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 pkg = require( './../package.json' ).name;
25+
var Float16Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':entries', function benchmark( b ) {
31+
var iter;
32+
var arr;
33+
var i;
34+
35+
arr = new Float16Array( [ 1.0, 2.0 ] );
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
iter = arr.entries();
40+
if ( typeof iter !== 'object' ) {
41+
b.fail( 'should return an object' );
42+
}
43+
}
44+
b.toc();
45+
if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) {
46+
b.fail( 'should return an iterator protocol-compliant object' );
47+
}
48+
b.pass( 'benchmark finished' );
49+
b.end();
50+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var Float16Array = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':every', function benchmark( b ) {
32+
var bool;
33+
var arr;
34+
var i;
35+
36+
arr = new Float16Array( 2 );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
bool = arr.every( predicate );
41+
if ( typeof bool !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( bool ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return v >= 0.0;
54+
}
55+
});
56+
57+
bench( pkg+'::this_context:every', function benchmark( b ) {
58+
var bool;
59+
var arr;
60+
var i;
61+
62+
arr = new Float16Array( 2 );
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
bool = arr.every( predicate, {} );
67+
if ( typeof bool !== 'boolean' ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
}
71+
b.toc();
72+
if ( !isBoolean( bool ) ) {
73+
b.fail( 'should return a boolean' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
78+
function predicate( v ) {
79+
return v >= 0.0;
80+
}
81+
});

0 commit comments

Comments
 (0)