From ac0f85f781da22c08d8ddd36db2f2743da295ff4 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Mon, 17 Aug 2026 13:13:00 +0530 Subject: [PATCH] feat: add float16 dtype support to array/filled-by --- 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: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - 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: passed - task: lint_license_headers status: passed --- --- .../array/filled-by/benchmark/benchmark.js | 22 +++++ .../benchmark/benchmark.length.float16.js | 98 +++++++++++++++++++ .../array/filled-by/docs/types/index.d.ts | 6 ++ .../array/filled-by/docs/types/test.ts | 3 + .../@stdlib/array/filled-by/package.json | 4 + .../@stdlib/array/filled-by/test/test.js | 32 ++++++ 6 files changed, 165 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.length.float16.js diff --git a/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.js index 9b64a0505e7c..6f74be722893 100644 --- a/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.js @@ -99,6 +99,28 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) { + var clbk; + var arr; + var i; + + clbk = constantFunction( 0.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = filledarrayBy( 0, 'float16', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) { var clbk; var arr; diff --git a/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..d079f7ae5e55 --- /dev/null +++ b/lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.length.float16.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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 constantFunction = require( '@stdlib/utils/constant-function' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var filledarray = 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 clbk; + var arr; + var i; + + clbk = constantFunction( 1.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = filledarray( len, 'float16', clbk ); + 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=float16,len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts index 24c064e251ce..5a51f7bfdac9 100644 --- a/lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts @@ -97,6 +97,12 @@ declare function filledarrayBy( length: number, clbk: Callback, thisArg?: any ): * * var arr = filledarrayBy( 5, 'float64', constantFunction( 1.0 ) ); * // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var constantFunction = require( '@stdlib/utils/constant-function' ); +* +* var arr = filledarrayBy( 5, 'float16', constantFunction( 1.0 ) ); +* // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ declare function filledarrayBy( length: number, dtype: DataType, clbk: Callback, thisArg?: any ): ArrayOrTypedArray; diff --git a/lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts index bb876ed20093..479389e61496 100644 --- a/lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts @@ -64,12 +64,15 @@ function clbk( i: number ): number { { filledarrayBy(); // $ExpectType ArrayOrTypedArray filledarrayBy( 'float32' ); // $ExpectType ArrayOrTypedArray + filledarrayBy( 'float16' ); // $ExpectType ArrayOrTypedArray filledarrayBy( 10, clbk ); // $ExpectType ArrayOrTypedArray filledarrayBy( 10, clbk, {} ); // $ExpectType ArrayOrTypedArray filledarrayBy( 10, 'int32', clbk ); // $ExpectType ArrayOrTypedArray filledarrayBy( 10, 'int32', clbk, {} ); // $ExpectType ArrayOrTypedArray + filledarrayBy( 10, 'float16', clbk ); // $ExpectType ArrayOrTypedArray + filledarrayBy( 10, 'float16', clbk, {} ); // $ExpectType ArrayOrTypedArray const x = new Float64Array( 10 ); filledarrayBy( x, clbk ); // $ExpectType ArrayOrTypedArray diff --git a/lib/node_modules/@stdlib/array/filled-by/package.json b/lib/node_modules/@stdlib/array/filled-by/package.json index 13b17ee0d861..c36c81d36715 100644 --- a/lib/node_modules/@stdlib/array/filled-by/package.json +++ b/lib/node_modules/@stdlib/array/filled-by/package.json @@ -63,6 +63,7 @@ "matrix", "float64array", "float32array", + "float16array", "int32array", "uint32array", "int16array", @@ -78,6 +79,9 @@ "float", "single-precision", "float32", + "half", + "half-precision", + "float16", "ieee754", "integer", "int32", diff --git a/lib/node_modules/@stdlib/array/filled-by/test/test.js b/lib/node_modules/@stdlib/array/filled-by/test/test.js index 1a34dba8d6ff..da776e406daa 100644 --- a/lib/node_modules/@stdlib/array/filled-by/test/test.js +++ b/lib/node_modules/@stdlib/array/filled-by/test/test.js @@ -26,6 +26,7 @@ var tape = require( 'tape' ); var proxyquire = require( 'proxyquire' ); 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' ); @@ -1831,6 +1832,20 @@ tape( 'the function returns a filled array (dtype=float32)', function test( t ) t.end(); }); +tape( 'the function returns a filled array (dtype=float16)', function test( t ) { + var expected; + var arr; + + expected = new Float16Array( 0 ); + arr = filledarrayBy( 'float16' ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool)', function test( t ) { var expected; var arr; @@ -2185,6 +2200,23 @@ tape( 'the function returns a filled array (dtype=float32, length)', function te t.end(); }); +tape( 'the function returns a filled array (dtype=float16, length)', function test( t ) { + var expected; + var clbk; + var arr; + + expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + clbk = constantFunction( 1.0 ); + arr = filledarrayBy( 5, 'float16', clbk ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool, length)', function test( t ) { var expected; var clbk;