diff --git a/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.js index daf959229646..1df088848860 100644 --- a/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/full-like/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 arr; + var x; + var i; + + x = empty( 0, 'float16' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullLike( x, 1.0 ); + 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 x; diff --git a/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..b1cc573855bf --- /dev/null +++ b/lib/node_modules/@stdlib/array/full-like/benchmark/benchmark.length.float16.js @@ -0,0 +1,96 @@ +/** +* @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 empty = require( '@stdlib/array/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = empty( len, 'float16' ); + 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 = fullLike( x, 1.0 ); + 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-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/full-like/docs/types/index.d.ts index f9d2f1173c25..410b104084aa 100644 --- a/lib/node_modules/@stdlib/array/full-like/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/full-like/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { Complex128Array, Complex64Array, BooleanArray, AnyArray, DataType } from '@stdlib/types/array'; +import { Complex128Array, Complex64Array, Float16Array, BooleanArray, AnyArray, DataType } from '@stdlib/types/array'; import { ComplexLike } from '@stdlib/types/complex'; /** @@ -61,6 +61,25 @@ declare function fullLike( x: AnyArray, value: number, dtype: 'float64' ): Float */ declare function fullLike( x: AnyArray, value: number, dtype: 'float32' ): Float32Array; +/** +* Creates a filled array having the same length as a provided input array. +* +* @param x - input array from which to derive the output array length +* @param value - fill value +* @param dtype - data type +* @returns filled array +* +* @example +* var zeros = require( '@stdlib/array/zeros' ); +* +* var x = zeros( 2, 'float64' ); +* // returns [ 0.0, 0.0 ] +* +* var y = fullLike( x, 1.0, 'float16' ); +* // returns [ 1.0, 1.0 ] +*/ +declare function fullLike( x: AnyArray, value: number, dtype: 'float16' ): Float16Array; + /** * Creates a filled array having the same length as a provided input array. * @@ -316,6 +335,25 @@ declare function fullLike( x: Float64Array, value: number, dtype?: DataType ): F */ declare function fullLike( x: Float32Array, value: number, dtype?: DataType ): Float32Array; +/** +* Creates a filled array having the same length and data type as a provided input array. +* +* @param x - input array from which to derive the output array length +* @param value - fill value +* @param dtype - data type +* @returns filled array +* +* @example +* var zeros = require( '@stdlib/array/zeros' ); +* +* var x = zeros( 2, 'float16' ); +* // returns [ 0.0, 0.0 ] +* +* var y = fullLike( x, 1.0 ); +* // returns [ 1.0, 1.0 ] +*/ +declare function fullLike( x: Float16Array, value: number, dtype?: DataType ): Float16Array; + /** * Creates a filled array having the same length and data type as a provided input array. * diff --git a/lib/node_modules/@stdlib/array/full-like/docs/types/test.ts b/lib/node_modules/@stdlib/array/full-like/docs/types/test.ts index 785e1ea27096..58e90076ce0a 100644 --- a/lib/node_modules/@stdlib/array/full-like/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/full-like/docs/types/test.ts @@ -19,6 +19,7 @@ import BooleanArray = require( '@stdlib/array/bool' ); import Complex128Array = require( '@stdlib/array/complex128' ); import Complex64Array = require( '@stdlib/array/complex64' ); +import Float16Array = require( '@stdlib/array/float16' ); import Complex128 = require( '@stdlib/complex/float64/ctor' ); import Complex64 = require( '@stdlib/complex/float32/ctor' ); import fullLike = require( './index' ); @@ -31,6 +32,7 @@ import fullLike = require( './index' ); fullLike( [ 0, 0 ], 1 ); // $ExpectType any[] fullLike( new Float64Array( [ 0, 0 ] ), 1 ); // $ExpectType Float64Array fullLike( new Float32Array( [ 0, 0 ] ), 1 ); // $ExpectType Float32Array + fullLike( new Float16Array( [ 0, 0 ] ), 1 ); // $ExpectType Float16ArrayFallback fullLike( new Complex128Array( [ 0, 0 ] ), 1 ); // $ExpectType Complex128Array fullLike( new Complex128Array( [ 0, 0 ] ), new Complex128( 1.0, 1.0 ) ); // $ExpectType Complex128Array fullLike( new Complex64Array( [ 0, 0 ] ), 1 ); // $ExpectType Complex64Array @@ -46,6 +48,7 @@ import fullLike = require( './index' ); fullLike( [ 0, 0 ], 1, 'float64' ); // $ExpectType Float64Array fullLike( [ 0, 0 ], 1, 'float32' ); // $ExpectType Float32Array + fullLike( [ 0, 0 ], 1, 'float16' ); // $ExpectType Float16ArrayFallback fullLike( [ 0, 0 ], 1, 'complex128' ); // $ExpectType Complex128Array fullLike( [ 0, 0 ], new Complex128( 1.0, 1.0 ), 'complex128' ); // $ExpectType Complex128Array fullLike( [ 0, 0 ], 1, 'complex64' ); // $ExpectType Complex64Array diff --git a/lib/node_modules/@stdlib/array/full-like/package.json b/lib/node_modules/@stdlib/array/full-like/package.json index 9e007de773d7..b14c9b0fb223 100644 --- a/lib/node_modules/@stdlib/array/full-like/package.json +++ b/lib/node_modules/@stdlib/array/full-like/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-like/test/test.js b/lib/node_modules/@stdlib/array/full-like/test/test.js index 45e84fe10c80..a7cf84682fe9 100644 --- a/lib/node_modules/@stdlib/array/full-like/test/test.js +++ b/lib/node_modules/@stdlib/array/full-like/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' ); @@ -207,6 +208,38 @@ tape( 'the function returns a filled array (dtype=float32)', function test( t ) t.end(); }); +tape( 'the function returns a filled array (float16)', function test( t ) { + var expected; + var arr; + var x; + + x = new Float16Array( 5 ); + expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr = fullLike( x, 1.0 ); + 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=float16)', function test( t ) { + var expected; + var arr; + var x; + + x = new Float64Array( 5 ); + expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr = fullLike( x, 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 (bool)', function test( t ) { var expected; var arr;