Skip to content
Open
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 @@ -26,14 +26,14 @@
/**
* Array or typed array.
*/
type ArrayOrTypedArray = Array<any> | RealOrComplexTypedArray | BooleanArray;

Check warning on line 29 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Nullary callback function.
*
* @returns fill value
*/
type Nullary = () => any;

Check warning on line 36 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Unary callback function.
Expand All @@ -41,7 +41,7 @@
* @param i - current array index
* @returns fill value
*/
type Unary = ( i: number ) => any;

Check warning on line 44 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Callback function.
Expand Down Expand Up @@ -81,7 +81,7 @@
* var arr = filledarrayBy( 5, constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( length: number, clbk: Callback, thisArg?: any ): ArrayOrTypedArray;

Check warning on line 84 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates a filled array according to a provided callback function and having a specified `length`.
Expand All @@ -97,8 +97,14 @@
*
* var arr = filledarrayBy( 5, 'float64', constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0, 1.0, 1.0 ]
*
* @example
* var constantFunction = require( '@stdlib/utils/constant-function' );
*
* var arr = filledarrayBy( 5, 'float16', constantFunction( 1.0 ) );
* // returns <Float16Array>[ 1.0, 1.0, 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( length: number, dtype: DataType, clbk: Callback, thisArg?: any ): ArrayOrTypedArray;

Check warning on line 107 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates a filled array from another `array` according to a provided callback function.
Expand All @@ -114,7 +120,7 @@
* var arr = filledarrayBy( [ 5.0, -3.0, 2.0 ], constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( array: Collection, clbk: Callback, thisArg?: any ): ArrayOrTypedArray; // eslint-disable-line @typescript-eslint/unified-signatures

Check warning on line 123 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates a filled array from another `array` according to a provided callback function.
Expand All @@ -131,7 +137,7 @@
* var arr = filledarrayBy( [ 5.0, -3.0, 2.0 ], 'float64', constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( array: Collection, dtype: DataType, clbk: Callback, thisArg?: any ): ArrayOrTypedArray; // eslint-disable-line @typescript-eslint/unified-signatures

Check warning on line 140 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates a filled array from an iterable according to a callback function.
Expand All @@ -151,7 +157,7 @@
* var arr = filledarrayBy( it, constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( iterable: IterableIterator, clbk: Callback, thisArg?: any ): ArrayOrTypedArray; // eslint-disable-line @typescript-eslint/unified-signatures

Check warning on line 160 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Creates a filled array from an iterable according to a callback function.
Expand All @@ -172,7 +178,7 @@
* var arr = filledarrayBy( it, 'float64', constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
*/
declare function filledarrayBy( iterable: IterableIterator, dtype: DataType, clbk: Callback, thisArg?: any ): ArrayOrTypedArray; // eslint-disable-line @typescript-eslint/unified-signatures

Check warning on line 181 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Returns a filled typed array view of an `ArrayBuffer` according to a provided callback function.
Expand All @@ -196,7 +202,7 @@
* var arr = filledarrayBy( buf, 8, 2, constantFunction( 1.0 ) );
* // returns <Float64Array>[ 1.0, 1.0 ]
*/
declare function filledarrayBy( buffer: ArrayBuffer, byteOffset: number, length: number, clbk: Callback, thisArg?: any ): RealOrComplexTypedArray | BooleanArray;

Check warning on line 205 in lib/node_modules/@stdlib/array/filled-by/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Returns a filled typed array view of an `ArrayBuffer` according to a provided callback function.
Expand Down
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/array/filled-by/docs/types/test.ts
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,12 +64,15 @@
{
filledarrayBy(); // $ExpectType ArrayOrTypedArray
filledarrayBy( 'float32' ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 'float16' ); // $ExpectType ArrayOrTypedArray

filledarrayBy( 10, clbk ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 10, clbk, {} ); // $ExpectType ArrayOrTypedArray

filledarrayBy( 10, 'int32', clbk ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 10, 'int32', clbk, {} ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 10, 'float16', clbk ); // $ExpectType ArrayOrTypedArray
filledarrayBy( 10, 'float16', clbk, {} ); // $ExpectType ArrayOrTypedArray

const x = new Float64Array( 10 );
filledarrayBy( x, 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
32 changes: 32 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 (3482). 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