Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/node_modules/@stdlib/array/empty-like/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ 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 x;
var i;

x = empty( 0, 'float16' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = emptyLike( x );
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, 'bool' ), function benchmark( b ) {
var arr;
var x;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 emptyLike = 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 = emptyLike( x );
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();
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* var arr = emptyLike( x );
* // returns [ 0.0, 0.0 ]
*/
declare function emptyLike( x: Array<any> ): Array<number>;

Check warning on line 45 in lib/node_modules/@stdlib/array/empty-like/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates an uninitialized array having the same length and data type as a provided input array.
Expand All @@ -63,6 +63,15 @@
*
* var arr = emptyLike( x );
* // returns <Float64Array>
*
* @example
* var zeros = require( '@stdlib/array/zeros' );
*
* var x = zeros( 2, 'float16' );
* // returns <Float16Array>[ 0.0, 0.0 ]
*
* var arr = emptyLike( x );
* // returns <Float16Array>
*/
declare function emptyLike<T extends TypedArray | ComplexTypedArray | BooleanTypedArray>( x: T ): T;

Expand Down
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/array/empty-like/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Complex128Array = require( '@stdlib/array/complex128' );
import Complex64Array = require( '@stdlib/array/complex64' );
import Float16Array = require( '@stdlib/array/float16' );
import BooleanArray = require( '@stdlib/array/bool' );
import emptyLike = require( './index' );

Expand All @@ -29,6 +30,7 @@ import emptyLike = require( './index' );
emptyLike( [ 0, 0 ] ); // $ExpectType number[]
emptyLike( new Float64Array( [ 0, 0 ] ) ); // $ExpectType Float64Array
emptyLike( new Float32Array( [ 0, 0 ] ) ); // $ExpectType Float32Array
emptyLike( new Float16Array( [ 0, 0 ] ) ); // $ExpectType Float16Array
emptyLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array
emptyLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array
emptyLike( new Complex64Array( [ 0, 0 ] ) ); // $ExpectType Complex64Array
Expand All @@ -45,6 +47,7 @@ import emptyLike = require( './index' );

emptyLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array
emptyLike( [ 0, 0 ], 'float32' ); // $ExpectType Float32Array
emptyLike( [ 0, 0 ], 'float16' ); // $ExpectType Float16ArrayFallback
emptyLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array
emptyLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array
emptyLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array
Expand Down
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/array/empty-like/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"matrix",
"float64array",
"float32array",
"float16array",
"int32array",
"uint32array",
"int16array",
Expand All @@ -85,6 +86,9 @@
"float",
"single-precision",
"float32",
"half",
"half-precision",
"float16",
"ieee754",
"integer",
"int32",
Expand Down
27 changes: 27 additions & 0 deletions lib/node_modules/@stdlib/array/empty-like/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -190,6 +191,32 @@ tape( 'the function returns an empty array (dtype=float32)', function test( t )
t.end();
});

tape( 'the function returns an empty array (float16)', function test( t ) {
var arr;
var x;

x = new Float16Array( 5 );

arr = emptyLike( x );
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
t.strictEqual( arr.length, x.length, 'returns expected value' );

t.end();
});

tape( 'the function returns an empty array (dtype=float16)', function test( t ) {
var arr;
var x;

x = new Float64Array( 5 );

arr = emptyLike( x, 'float16' );
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
t.strictEqual( arr.length, x.length, 'returns expected value' );

t.end();
});

tape( 'the function returns an empty array (bool)', function test( t ) {
var arr;
var x;
Expand Down