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/filled-by/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 clbk;
var arr;
var i;

clbk = constantFunction( 0.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = filledarrayBy( 0, 'float16', clbk );
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 clbk;
var arr;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @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 constantFunction = require( '@stdlib/utils/constant-function' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var filledarray = 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 clbk;
var arr;
var i;

clbk = constantFunction( 1.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = filledarray( len, 'float16', clbk );
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 @@ -40,7 +40,7 @@
*
* @returns iterator protocol-compliant object
*/
function next(): any {

Check warning on line 43 in lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
return {
'value': 1.0,
'done': false
Expand All @@ -64,6 +64,7 @@
{
filledarrayBy(); // $ExpectType ArrayOrTypedArray
filledarrayBy( 'float32' ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 'float16' ); // $ExpectType ArrayOrTypedArray

filledarrayBy( 10, clbk ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 10, clbk, {} ); // $ExpectType ArrayOrTypedArray
Expand Down
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/array/filled-by/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 @@ -78,6 +79,9 @@
"float",
"single-precision",
"float32",
"half",
"half-precision",
"float16",
"ieee754",
"integer",
"int32",
Expand Down
148 changes: 148 additions & 0 deletions lib/node_modules/@stdlib/array/filled-by/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
var proxyquire = require( 'proxyquire' );
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 @@ -1183,7 +1184,7 @@

tape( 'the function throws an error if not provided a valid iterable when attempting to create a generic array (non-function iterator symbol property; thisArg)', function test( t ) {
var filledarrayBy;
var values;

Check warning on line 1187 in lib/node_modules/@stdlib/array/filled-by/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

File has too many lines (3568). Maximum allowed is 1000
var i;

filledarrayBy = proxyquire( './../lib/main.js', {
Expand Down Expand Up @@ -1831,6 +1832,20 @@
t.end();
});

tape( 'the function returns a filled array (dtype=float16)', function test( t ) {
var expected;
var arr;

expected = new Float16Array( 0 );
arr = filledarrayBy( 'float16' );

t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
t.strictEqual( arr.length, 0, '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;
Expand Down Expand Up @@ -2185,6 +2200,23 @@
t.end();
});

tape( 'the function returns a filled array (dtype=float16, length)', function test( t ) {
var expected;
var clbk;
var arr;

expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
arr = filledarrayBy( 5, 'float16', clbk );

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, length)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -2495,6 +2527,25 @@
t.end();
});

tape( 'the function returns a filled array (dtype=float16, array)', function test( t ) {
var expected;
var clbk;
var arr;
var out;

expected = new Float16Array( [ 1.0, 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
arr = [ 1.0, 2.0, 3.0 ];
out = filledarrayBy( arr, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled array (dtype=bool, array)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -2826,6 +2877,25 @@
t.end();
});

tape( 'the function returns a filled array (dtype=float16, typed array)', function test( t ) {
var expected;
var clbk;
var arr;
var out;

expected = new Float16Array( [ 1.0, 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
arr = new Float64Array( [ 1.0, 2.0, 3.0 ] );
out = filledarrayBy( arr, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled array (dtype=bool, typed array)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -3158,6 +3228,25 @@
t.end();
});

tape( 'the function returns a filled typed array (dtype=float16, arraybuffer)', function test( t ) {
var expected;
var clbk;
var buf;
var out;

expected = new Float16Array( [ 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
buf = new ArrayBuffer( 4 );
out = filledarrayBy( buf, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled typed array (dtype=bool, arraybuffer)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -3491,6 +3580,25 @@
t.end();
});

tape( 'the function returns a filled typed array (dtype=float16, arraybuffer, byteoffset)', function test( t ) {
var expected;
var clbk;
var buf;
var out;

expected = new Float16Array( [ 1.0, 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
buf = new ArrayBuffer( 8 );
out = filledarrayBy( buf, 2, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -3822,6 +3930,25 @@
t.end();
});

tape( 'the function returns a filled typed array (dtype=float16, arraybuffer, byteoffset, length)', function test( t ) {
var expected;
var clbk;
var buf;
var out;

expected = new Float16Array( [ 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
buf = new ArrayBuffer( 8 );
out = filledarrayBy( buf, 2, 2, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset, length)', function test( t ) {
var expected;
var clbk;
Expand Down Expand Up @@ -4165,6 +4292,27 @@
t.end();
});

tape( 'the function returns a filled array (dtype=float16, iterator)', opts, function test( t ) {
var expected;
var clbk;
var arr;
var out;

expected = new Float16Array( [ 1.0, 1.0, 1.0 ] );

clbk = constantFunction( 1.0 );
arr = iterConstant( 3.0, {
'iter': 3
});
out = filledarrayBy( arr, 'float16', clbk );

t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, expected.length, 'returns expected value' );
t.deepEqual( out, expected, 'returns expected value' );

t.end();
});

tape( 'the function returns a filled array (dtype=bool, iterator)', opts, function test( t ) {
var expected;
var clbk;
Expand Down