diff --git a/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.js index 431d46a2971a..2c7744053f44 100644 --- a/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.js @@ -74,6 +74,28 @@ bench( format( '%s::base:dtype=float32', pkg ), function benchmark( b ) { b.end(); }); +bench( format( '%s::base:dtype=float16', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'float16', [ 0 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = zerosLike( x ); + if ( y.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s::base:dtype=complex128', pkg ), function benchmark( b ) { var x; var y; diff --git a/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.size.float16.js b/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.size.float16.js new file mode 100644 index 000000000000..9bd3d9eed1cb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/zeros-like/benchmark/benchmark.size.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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var zerosLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = zeros( 'float16', [ len ], 'row-major' ); + 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 = zerosLike( x ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + 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::base:dtype=float16,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/zeros-like/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/zeros-like/docs/types/test.ts index e12262d398ae..bd7be14adfd7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/zeros-like/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/zeros-like/docs/types/test.ts @@ -29,6 +29,7 @@ import zerosLike = require( './index' ); zerosLike( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray zerosLike( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray + zerosLike( zeros( 'float16', sh, ord ) ); // $ExpectType float16ndarray zerosLike( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray zerosLike( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray zerosLike( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray diff --git a/lib/node_modules/@stdlib/ndarray/base/zeros-like/test/test.js b/lib/node_modules/@stdlib/ndarray/base/zeros-like/test/test.js index 2c9eee398e5d..e565a05ff778 100644 --- a/lib/node_modules/@stdlib/ndarray/base/zeros-like/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/zeros-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' ); @@ -178,6 +179,50 @@ tape( 'the function returns a zero-filled array (dtype=float32, non-base)', func t.end(); }); +tape( 'the function returns a zero-filled array (dtype=float16, base)', function test( t ) { + var expected; + var arr; + var x; + + expected = new Float16Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + x = zeros( 'float16', [ 2, 2 ], 'row-major' ); + arr = zerosLike( x ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=float16, non-base)', function test( t ) { + var expected; + var arr; + var x; + + expected = new Float16Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + x = array( new Float16Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'float16', + 'order': 'column-major' + }); + arr = zerosLike( x ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a zero-filled array (dtype=int32, base)', function test( t ) { var expected; var arr;