From 9e3c1866729ca82bd702cf494ae7203012d46ff2 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 11 Aug 2026 00:48:51 +0530 Subject: [PATCH] feat: add float16 dtype support to array/full --- 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 --- --- .../@stdlib/array/full/benchmark/benchmark.js | 18 ++++ .../benchmark/benchmark.length.float16.js | 94 +++++++++++++++++++ .../@stdlib/array/full/docs/types/test.ts | 1 + .../@stdlib/array/full/package.json | 4 + .../@stdlib/array/full/test/test.js | 15 +++ 5 files changed, 132 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/full/benchmark/benchmark.length.float16.js diff --git a/lib/node_modules/@stdlib/array/full/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/full/benchmark/benchmark.js index bf270515c272..0ecbc817dab9 100644 --- a/lib/node_modules/@stdlib/array/full/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/full/benchmark/benchmark.js @@ -86,6 +86,24 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = full( 0, 1.0, 'float16' ); + 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 arr; var i; diff --git a/lib/node_modules/@stdlib/array/full/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/full/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..234deb577b19 --- /dev/null +++ b/lib/node_modules/@stdlib/array/full/benchmark/benchmark.length.float16.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var full = 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 = full( len, 1.0, '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=float16,len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/full/docs/types/test.ts b/lib/node_modules/@stdlib/array/full/docs/types/test.ts index 118d4985e040..b42e4ee8b4b9 100644 --- a/lib/node_modules/@stdlib/array/full/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/full/docs/types/test.ts @@ -29,6 +29,7 @@ import full = require( './index' ); full( 10, 1 ); // $ExpectType Float64Array full( 10, 1, 'float64' ); // $ExpectType Float64Array full( 10, 1, 'float32' ); // $ExpectType Float32Array + full( 10, 1, 'float16' ); // $ExpectType Float16ArrayFallback full( 10, z, 'complex128' ); // $ExpectType Complex128Array full( 10, z, 'complex64' ); // $ExpectType Complex64Array full( 10, true, 'bool' ); // $ExpectType BooleanArray diff --git a/lib/node_modules/@stdlib/array/full/package.json b/lib/node_modules/@stdlib/array/full/package.json index cf66f47daed7..c119debf7fea 100644 --- a/lib/node_modules/@stdlib/array/full/package.json +++ b/lib/node_modules/@stdlib/array/full/package.json @@ -63,6 +63,7 @@ "matrix", "float64array", "float32array", + "float16array", "int32array", "uint32array", "int16array", @@ -84,6 +85,9 @@ "float", "single-precision", "float32", + "half", + "half-precision", + "float16", "ieee754", "integer", "int32", diff --git a/lib/node_modules/@stdlib/array/full/test/test.js b/lib/node_modules/@stdlib/array/full/test/test.js index 2cd97032627d..4de8859b62b1 100644 --- a/lib/node_modules/@stdlib/array/full/test/test.js +++ b/lib/node_modules/@stdlib/array/full/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' ); @@ -187,6 +188,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( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr = full( 5, 1.0, 'float16' ); + 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)', function test( t ) { var expected; var arr;