From 6310b0d25127d5893da8f55903754a54c73f0c16 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 22 Jun 2026 16:29:29 +0530 Subject: [PATCH 1/4] feat: add float16 dtype support to array/types --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../array/typed/benchmark/benchmark.js | 18 ++++ .../benchmark/benchmark.length.float16.js | 94 +++++++++++++++++++ .../@stdlib/array/typed/lib/main.js | 4 + .../@stdlib/array/typed/test/test.js | 8 ++ 4 files changed, 124 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js diff --git a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js index 8661d35b3202..5198dce9daac 100644 --- a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js @@ -85,6 +85,24 @@ bench( format( '%s:dtype=%s', pkg, 'float32' ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=%s', pkg, 'float16' ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = typedarray( 0, 'float16' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s:dtype=%s', pkg, 'complex128' ), function benchmark( b ) { var arr; var i; diff --git a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..0c6ac39db6ce --- /dev/null +++ b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var typedarray = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = typedarray( len, 'float16' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, 'float32', len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/typed/lib/main.js b/lib/node_modules/@stdlib/array/typed/lib/main.js index d8f75e2c1379..f558d09da54a 100644 --- a/lib/node_modules/@stdlib/array/typed/lib/main.js +++ b/lib/node_modules/@stdlib/array/typed/lib/main.js @@ -25,6 +25,7 @@ var ctors = require( '@stdlib/array/typed-ctors' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); +var reinterpretFloat16 = require( '@stdlib/strided/base/reinterpret-float16' ); var defaults = require( '@stdlib/array/defaults' ); var format = require( '@stdlib/string/format' ); @@ -35,6 +36,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); var Complex64Array = ctors( 'complex64' ); var Complex128Array = ctors( 'complex128' ); var BooleanArray = ctors( 'bool' ); +var Float16Array = ctors( 'float16' ); // MAIN // @@ -151,6 +153,8 @@ function typedarray() { arg = reinterpret128( arg, 0 ); } else if ( arg instanceof BooleanArray ) { arg = reinterpretBoolean( arg, 0 ); + } else if ( arg instanceof Float16Array ) { + arg = reinterpretFloat16( arg, 0 ); } return new ctor( arg ); } diff --git a/lib/node_modules/@stdlib/array/typed/test/test.js b/lib/node_modules/@stdlib/array/typed/test/test.js index 401c56f4473c..e26598c8e0fc 100644 --- a/lib/node_modules/@stdlib/array/typed/test/test.js +++ b/lib/node_modules/@stdlib/array/typed/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); +var Float16Array = require( '@stdlib/array/float16' ); var Int32Array = require( '@stdlib/array/int32' ); var Uint32Array = require( '@stdlib/array/uint32' ); var Int16Array = require( '@stdlib/array/int16' ); @@ -308,6 +309,13 @@ tape( 'the function returns a typed array (dtype=float32)', function test( t ) { t.end(); }); +tape( 'the function returns a typed array (dtype=float16)', function test( t ) { + var arr = typedarray( 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { var arr = typedarray( 'complex128' ); t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); From 88fd829f5822c28bbc03397e9a60946e59a87b29 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 22 Jun 2026 11:28:30 +0000 Subject: [PATCH 2/4] chore: update copyright years --- .../@stdlib/array/typed/benchmark/benchmark.length.float16.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js index 0c6ac39db6ce..1472af02822b 100644 --- a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js +++ b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.float16.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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. From 9d191b8ddc93b13084f2ac1933c0161411589cff Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 14:42:51 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/array/typed/lib/main.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/typed/lib/main.js b/lib/node_modules/@stdlib/array/typed/lib/main.js index f558d09da54a..d8f75e2c1379 100644 --- a/lib/node_modules/@stdlib/array/typed/lib/main.js +++ b/lib/node_modules/@stdlib/array/typed/lib/main.js @@ -25,7 +25,6 @@ var ctors = require( '@stdlib/array/typed-ctors' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); -var reinterpretFloat16 = require( '@stdlib/strided/base/reinterpret-float16' ); var defaults = require( '@stdlib/array/defaults' ); var format = require( '@stdlib/string/format' ); @@ -36,7 +35,6 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); var Complex64Array = ctors( 'complex64' ); var Complex128Array = ctors( 'complex128' ); var BooleanArray = ctors( 'bool' ); -var Float16Array = ctors( 'float16' ); // MAIN // @@ -153,8 +151,6 @@ function typedarray() { arg = reinterpret128( arg, 0 ); } else if ( arg instanceof BooleanArray ) { arg = reinterpretBoolean( arg, 0 ); - } else if ( arg instanceof Float16Array ) { - arg = reinterpretFloat16( arg, 0 ); } return new ctor( arg ); } From b17a20251f49794e2c39d929384992614eb0cb3d Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 14:46:46 -0700 Subject: [PATCH 4/4] test: add missing tests Signed-off-by: Athan --- .../@stdlib/array/typed/test/test.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/lib/node_modules/@stdlib/array/typed/test/test.js b/lib/node_modules/@stdlib/array/typed/test/test.js index e26598c8e0fc..c84fe8614a1c 100644 --- a/lib/node_modules/@stdlib/array/typed/test/test.js +++ b/lib/node_modules/@stdlib/array/typed/test/test.js @@ -407,6 +407,13 @@ tape( 'the function returns a typed array (dtype=float32, length)', function tes t.end(); }); +tape( 'the function returns a typed array (dtype=float16, length)', function test( t ) { + var arr = typedarray( 10, 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { var arr = typedarray( 10, 'complex128' ); t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); @@ -510,6 +517,17 @@ tape( 'the function returns a typed array (dtype=float32, array)', function test t.end(); }); +tape( 'the function returns a typed array (dtype=float16, array)', function test( t ) { + var arr = [ 1.0, 2.0, 3.0 ]; + var out = typedarray( arr, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { var view; var arr; @@ -677,6 +695,17 @@ tape( 'the function returns a typed array (dtype=float32, typed array)', functio t.end(); }); +tape( 'the function returns a typed array (dtype=float16, typed array)', function test( t ) { + var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + var out = typedarray( arr, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { var view; var arr; @@ -1091,6 +1120,16 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer)', functio t.end(); }); +tape( 'the function returns a typed array (dtype=float16, arraybuffer)', function test( t ) { + var buf = new ArrayBuffer( 4 ); + var out = typedarray( buf, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, arraybuffer)', function test( t ) { var view; var buf; @@ -1267,6 +1306,17 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffse t.end(); }); +tape( 'the function returns a typed array (dtype=float16, arraybuffer, byteoffset)', function test( t ) { + var buf = new ArrayBuffer( 10 ); + var out = typedarray( buf, 4, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 3, 'returns expected value' ); + t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, arraybuffer, byteoffset)', function test( t ) { var view; var buf; @@ -1457,6 +1507,16 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffse t.end(); }); +tape( 'the function returns a typed array (dtype=float16, arraybuffer, byteoffset, length)', function test( t ) { + var buf = new ArrayBuffer( 16 ); + var out = typedarray( buf, 4, 2, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=complex128, arraybuffer, byteoffset, length)', function test( t ) { var view; var buf;