From dcd7fa079e0cf5d56943fbe0dfd1b00af0bec993 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 10 Aug 2026 13:33:46 +0530 Subject: [PATCH 1/2] feat: add float16 dtype support to array/ones --- 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: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - 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 --- --- lib/node_modules/@stdlib/array/ones/README.md | 1 + .../@stdlib/array/ones/benchmark/benchmark.js | 18 ++++ .../benchmark/benchmark.length.float16.js | 94 +++++++++++++++++++ .../@stdlib/array/ones/docs/repl.txt | 1 + .../@stdlib/array/ones/docs/types/index.d.ts | 1 + .../@stdlib/array/ones/docs/types/test.ts | 1 + .../@stdlib/array/ones/package.json | 4 + .../@stdlib/array/ones/test/test.js | 15 +++ 8 files changed, 135 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/ones/benchmark/benchmark.length.float16.js diff --git a/lib/node_modules/@stdlib/array/ones/README.md b/lib/node_modules/@stdlib/array/ones/README.md index a3fbe0aeadb9..4db2860978d3 100644 --- a/lib/node_modules/@stdlib/array/ones/README.md +++ b/lib/node_modules/@stdlib/array/ones/README.md @@ -53,6 +53,7 @@ The function recognizes the following data types: - `float64`: double-precision floating-point numbers (IEEE 754) - `float32`: single-precision floating-point numbers (IEEE 754) +- `float16`: half-precision floating-point numbers (IEEE 754) - `complex128`: double-precision complex floating-point numbers - `complex64`: single-precision complex floating-point numbers - `int32`: 32-bit two's complement signed integers diff --git a/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.js index 8c243f52eb5d..36b3b4c628c4 100644 --- a/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.js @@ -84,6 +84,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 = ones( 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=%s', pkg, 'complex128' ), function benchmark( b ) { var arr; var i; diff --git a/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/ones/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..d13a72ef0966 --- /dev/null +++ b/lib/node_modules/@stdlib/array/ones/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 ones = 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 = ones( 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, 'float16', len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/ones/docs/repl.txt b/lib/node_modules/@stdlib/array/ones/docs/repl.txt index fea655d7afb2..fa198de64bb8 100644 --- a/lib/node_modules/@stdlib/array/ones/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/ones/docs/repl.txt @@ -6,6 +6,7 @@ - float64: double-precision floating-point numbers (IEEE 754). - float32: single-precision floating-point numbers (IEEE 754). + - float16: half-precision floating-point numbers (IEEE 754). - complex128: double-precision complex floating-point numbers. - complex64: single-precision complex floating-point numbers. - int32: 32-bit two's complement signed integers. diff --git a/lib/node_modules/@stdlib/array/ones/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/ones/docs/types/index.d.ts index e9da827f9cf2..cba0c6998c84 100644 --- a/lib/node_modules/@stdlib/array/ones/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/ones/docs/types/index.d.ts @@ -29,6 +29,7 @@ import { NumericAndGenericDataTypeMap } from '@stdlib/types/array'; * * - `float64`: double-precision floating-point numbers (IEEE 754) * - `float32`: single-precision floating-point numbers (IEEE 754) +* - `float16`: half-precision floating-point numbers (IEEE 754) * - `complex128`: double-precision complex floating-point numbers * - `complex64`: single-precision complex floating-point numbers * - `int32`: 32-bit two's complement signed integers diff --git a/lib/node_modules/@stdlib/array/ones/docs/types/test.ts b/lib/node_modules/@stdlib/array/ones/docs/types/test.ts index ce2d2e1fa4a5..2e1c735805f4 100644 --- a/lib/node_modules/@stdlib/array/ones/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/ones/docs/types/test.ts @@ -26,6 +26,7 @@ import ones = require( './index' ); ones( 10 ); // $ExpectType Float64Array ones( 10, 'float64' ); // $ExpectType Float64Array ones( 10, 'float32' ); // $ExpectType Float32Array + ones( 10, 'float16' ); // $ExpectType Float16ArrayFallback ones( 10, 'complex128' ); // $ExpectType Complex128Array ones( 10, 'complex64' ); // $ExpectType Complex64Array ones( 10, 'int32' ); // $ExpectType Int32Array diff --git a/lib/node_modules/@stdlib/array/ones/package.json b/lib/node_modules/@stdlib/array/ones/package.json index f4dba5a3064c..661ac2e32ec7 100644 --- a/lib/node_modules/@stdlib/array/ones/package.json +++ b/lib/node_modules/@stdlib/array/ones/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/ones/test/test.js b/lib/node_modules/@stdlib/array/ones/test/test.js index b2f1b243202b..24397d55188c 100644 --- a/lib/node_modules/@stdlib/array/ones/test/test.js +++ b/lib/node_modules/@stdlib/array/ones/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' ); @@ -183,6 +184,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 = ones( 5, '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=complex128)', function test( t ) { var expected; var arr; From e013ca162484d08411b175ceec635cbe45f2c064 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 10 Aug 2026 13:44:39 +0530 Subject: [PATCH 2/2] fix: specify 'numeric' dtype in examples for clarity --- 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: passed - 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- lib/node_modules/@stdlib/array/ones/README.md | 2 +- lib/node_modules/@stdlib/array/ones/examples/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/ones/README.md b/lib/node_modules/@stdlib/array/ones/README.md index 4db2860978d3..c264a28d2686 100644 --- a/lib/node_modules/@stdlib/array/ones/README.md +++ b/lib/node_modules/@stdlib/array/ones/README.md @@ -101,7 +101,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var ones = require( '@stdlib/array/ones' ); // Get a list of array data types: -var dt = dtypes(); +var dt = dtypes( 'numeric' ); // Generate filled arrays... var arr; diff --git a/lib/node_modules/@stdlib/array/ones/examples/index.js b/lib/node_modules/@stdlib/array/ones/examples/index.js index 4089b596f20c..0d09857c639c 100644 --- a/lib/node_modules/@stdlib/array/ones/examples/index.js +++ b/lib/node_modules/@stdlib/array/ones/examples/index.js @@ -22,7 +22,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var ones = require( './../lib' ); // Get a list of array data types: -var dt = dtypes(); +var dt = dtypes( 'numeric' ); // Generate filled arrays... var arr;