Skip to content

Commit e2ef372

Browse files
udaykakade25kgrytegururaj1512
authored
feat: add array/float16
PR-URL: stdlib-js#7435 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: Gururaj Gurram <gururajgurram1512@gmail.com> Reviewed-by: Gururaj Gurram <gururajgurram1512@gmail.com>
1 parent 3e87387 commit e2ef372

211 files changed

Lines changed: 32490 additions & 0 deletions

File tree

Some content is hidden

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

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

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

0 commit comments

Comments
 (0)