diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/README.md b/lib/node_modules/@stdlib/ndarray/base/full-by/README.md new file mode 100644 index 000000000000..6f95edd4d2c0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/README.md @@ -0,0 +1,161 @@ + + +# fullBy + +> Create an [ndarray][@stdlib/ndarray/base/ctor] filled according to a callback function and having a specified shape and [data type][@stdlib/ndarray/dtypes]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var fullBy = require( '@stdlib/ndarray/base/full-by' ); +``` + +#### fullBy( dtype, shape, order, clbk\[, thisArg] ) + +Returns an [ndarray][@stdlib/ndarray/base/ctor] filled according to a callback function and having a specified shape and [data type][@stdlib/ndarray/dtypes]. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); + +function clbk() { + return 10.0; +} + +var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk ); +// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + +var dt = String( getDType( arr ) ); +// returns 'float64' +``` + +This function accepts the following arguments: + +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. +- **shape**: array shape. +- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). +- **clbk**: callback function. +- **thisArg**: callback function execution context (_optional_). + +The callback function is provided the following arguments: + +- **indices**: current array element indices. + +To set the callback function execution context, provide a `thisArg`. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); + +function clbk( indices ) { + return this.value * ( indices[ 0 ] + indices[ 1 ] ); // eslint-disable-line no-invalid-this +} + +var ctx = { + 'value': 10.0 +}; + +var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk, ctx ); +// returns [ [ 0.0, 10.0 ], [ 10.0, 20.0 ] ] + +var dt = String( getDType( arr ) ); +// returns 'float64' +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var fullBy = require( '@stdlib/ndarray/base/full-by' ); + +// Get a list of data types: +var dt = dtypes( 'integer_and_generic' ); + +// Generate filled arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = fullBy( dt[ i ], [ 2, 2 ], 'row-major', discreteUniform( -100, 100 ) ); + console.log( ndarray2array( arr ) ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.js new file mode 100644 index 000000000000..ef2f00396dbf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.js @@ -0,0 +1,318 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'float64', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10.0; + } +}); + +bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'float32', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10.0; + } +}); + +bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'complex128', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return new Complex128( 10.0, 0.0 ); + } +}); + +bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'complex64', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return new Complex64( 10.0, 0.0 ); + } +}); + +bench( format( '%s:dtype=int32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int32', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return -10; + } +}); + +bench( format( '%s:dtype=uint32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint32', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10; + } +}); + +bench( format( '%s:dtype=int16', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int16', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return -10; + } +}); + +bench( format( '%s:dtype=uint16', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint16', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10; + } +}); + +bench( format( '%s:dtype=int8', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int8', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return -10; + } +}); + +bench( format( '%s:dtype=uint8', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint8', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10; + } +}); + +bench( format( '%s:dtype=uint8c', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint8c', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10; + } +}); + +bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'bool', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return true; + } +}); + +bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'generic', [ 0 ], 'row-major', clbk ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk() { + return 10.0; + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.bool.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.bool.js new file mode 100644 index 000000000000..1098b64f15c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.bool.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return true; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'bool', [ len ], 'row-major', clbk ); + 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:dtype=bool,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex128.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex128.js new file mode 100644 index 000000000000..242a2b8b1d61 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex128.js @@ -0,0 +1,105 @@ +/** +* @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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return new Complex128( 10.0, 0.0 ); +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'complex128', [ len ], 'row-major', clbk ); + 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:dtype=complex128,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex64.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex64.js new file mode 100644 index 000000000000..b60e51e33415 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.complex64.js @@ -0,0 +1,105 @@ +/** +* @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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return new Complex64( 10.0, 0.0 ); +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'complex64', [ len ], 'row-major', clbk ); + 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:dtype=complex64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float32.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float32.js new file mode 100644 index 000000000000..a3dd9e40ec8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float32.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10.0; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'float32', [ len ], 'row-major', clbk ); + 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:dtype=float32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float64.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float64.js new file mode 100644 index 000000000000..a30d501d2667 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.float64.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10.0; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'float64', [ len ], 'row-major', clbk ); + 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:dtype=float64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.generic.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.generic.js new file mode 100644 index 000000000000..e481facf2bc7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.generic.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10.0; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'generic', [ len ], 'row-major', clbk ); + 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:dtype=generic,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int16.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int16.js new file mode 100644 index 000000000000..1b1c93bcdced --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int16.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return -10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int16', [ len ], 'row-major', clbk ); + 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:dtype=int16,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int32.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int32.js new file mode 100644 index 000000000000..7cca62cee5a1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int32.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return -10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int32', [ len ], 'row-major', clbk ); + 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:dtype=int32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int8.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int8.js new file mode 100644 index 000000000000..4411e799b5e2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.int8.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return -10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'int8', [ len ], 'row-major', clbk ); + 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:dtype=int8,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint16.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint16.js new file mode 100644 index 000000000000..209cfad82741 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint16.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint16', [ len ], 'row-major', clbk ); + 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:dtype=uint16,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint32.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint32.js new file mode 100644 index 000000000000..b18116119652 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint32.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint32', [ len ], 'row-major', clbk ); + 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:dtype=uint32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8.js new file mode 100644 index 000000000000..cb55307af75f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint8', [ len ], 'row-major', clbk ); + 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:dtype=uint8,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8c.js b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8c.js new file mode 100644 index 000000000000..064d82d562e4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/benchmark/benchmark.size.uint8c.js @@ -0,0 +1,104 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fullBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @returns {*} fill value +*/ +function clbk() { + return 10; +} + +/** +* 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 arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = fullBy( 'uint8c', [ len ], 'row-major', clbk ); + 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:dtype=uint8c,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/repl.txt new file mode 100644 index 000000000000..49e276e446c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( dtype, shape, order, clbk[, thisArg] ) + Returns an ndarray filled according to a callback function and having a + specified shape and data type. + + The callback function is provided the following arguments: + + - indices: current array element indices. + + Parameters + ---------- + dtype: string|DataType + Underlying data type. + + shape: ArrayLikeObject + Array shape. + + order: string + Specifies whether an array is row-major (C-style) or column-major + (Fortran-style). + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback function execution context. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > function clbk() { return 10.0; }; + > var arr = {{alias}}( 'float64', [ 2, 2 ], 'row-major', clbk ) + [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + > var dt = String( {{alias:@stdlib/ndarray/dtype}}( arr ) ) + 'float64' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/index.d.ts new file mode 100644 index 000000000000..cc053699b354 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/index.d.ts @@ -0,0 +1,403 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Shape, Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray, genericndarray, DataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, BooleanDataType, GenericDataType } from '@stdlib/types/ndarray'; + +/** +* Callback invoked for each ndarray element. +* +* @returns fill value +*/ +type Nullary = ( this: ThisArg ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param indices - current array element indices +* @returns fill value +*/ +type Unary = ( this: ThisArg, indices: Array ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param indices - current array element indices +* @returns fill value +*/ +type Callback = Nullary | Unary; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float64' +*/ +declare function fullBy( dtype: Float64DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): float64ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'float32', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float32' +*/ +declare function fullBy( dtype: Float32DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): float32ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 3.0, 5.0 ); +* } +* +* var arr = fullBy( 'complex128', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ [ 3.0, 5.0 ], [ 3.0, 5.0 ] ], [ [ 3.0, 5.0 ], [ 3.0, 5.0 ] ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'complex128' +*/ +declare function fullBy( dtype: Complex128DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): complex128ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* function clbk() { +* return new Complex64( 3.0, 5.0 ); +* } +* +* var arr = fullBy( 'complex64', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ [ 3.0, 5.0 ], [ 3.0, 5.0 ] ], [ [ 3.0, 5.0 ], [ 3.0, 5.0 ] ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'complex64' +*/ +declare function fullBy( dtype: Complex64DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): complex64ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'int32', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'int32' +*/ +declare function fullBy( dtype: Int32DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): int32ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'int16', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'int16' +*/ +declare function fullBy( dtype: Int16DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): int16ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'int8', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'int8' +*/ +declare function fullBy( dtype: Int8DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): int8ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'uint32', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'uint32' +*/ +declare function fullBy( dtype: Uint32DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): uint32ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'uint16', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'uint16' +*/ +declare function fullBy( dtype: Uint16DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): uint16ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'uint8', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'uint8' +*/ +declare function fullBy( dtype: Uint8DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): uint8ndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10; +* } +* +* var arr = fullBy( 'uint8c', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10, 10 ], [ 10, 10 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'uint8c' +*/ +declare function fullBy( dtype: Uint8cDataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): uint8cndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return true; +* } +* +* var arr = fullBy( 'bool', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ true, true ], [ true, true ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'bool' +*/ +declare function fullBy( dtype: BooleanDataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): boolndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'generic', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'generic' +*/ +declare function fullBy( dtype: GenericDataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): genericndarray; + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'float32', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float32' +*/ +declare function fullBy( dtype: DataType, shape: Shape, order: Order, clbk: Callback, thisArg?: ThisArg ): typedndarray; + + +// EXPORTS // + +export = fullBy; diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/test.ts new file mode 100644 index 000000000000..f855c5641dea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/docs/types/test.ts @@ -0,0 +1,107 @@ +/* +* @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. +*/ + +import fullBy = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + fullBy( 'float64', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectType float64ndarray + fullBy( 'float32', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectType float32ndarray + fullBy( 'complex128', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectType complex128ndarray + fullBy( 'complex64', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectType complex64ndarray + fullBy( 'int32', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType int32ndarray + fullBy( 'int16', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType int16ndarray + fullBy( 'int8', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType int8ndarray + fullBy( 'uint32', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType uint32ndarray + fullBy( 'uint16', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType uint16ndarray + fullBy( 'uint8', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType uint8ndarray + fullBy( 'uint8c', [ 2, 2 ], 'row-major', () => 10 ); // $ExpectType uint8cndarray + fullBy( 'bool', [ 2, 2 ], 'row-major', () => true ); // $ExpectType boolndarray + fullBy( 'generic', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectType genericndarray + + fullBy( 'float64', [ 2, 2 ], 'column-major', () => 10.0 ); // $ExpectType float64ndarray + fullBy( 'float32', [ 2, 2 ], 'column-major', () => 10.0 ); // $ExpectType float32ndarray + fullBy( 'complex128', [ 2, 2 ], 'column-major', () => 10.0 ); // $ExpectType complex128ndarray + fullBy( 'complex64', [ 2, 2 ], 'column-major', () => 10.0 ); // $ExpectType complex64ndarray + fullBy( 'int32', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType int32ndarray + fullBy( 'int16', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType int16ndarray + fullBy( 'int8', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType int8ndarray + fullBy( 'uint32', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType uint32ndarray + fullBy( 'uint16', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType uint16ndarray + fullBy( 'uint8', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType uint8ndarray + fullBy( 'uint8c', [ 2, 2 ], 'column-major', () => 10 ); // $ExpectType uint8cndarray + fullBy( 'bool', [ 2, 2 ], 'column-major', () => true ); // $ExpectType boolndarray + fullBy( 'generic', [ 2, 2 ], 'column-major', () => 10.0 ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is an unrecognized/unsupported data type... +{ + fullBy( '10', [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( 10, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( false, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( true, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( null, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( [], [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( {}, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( ( x: number ): number => x, [ 2, 2 ], 'row-major', () => 10.0 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid shape for the second argument... +{ + fullBy( 'float32', '5', 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', false, 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', true, 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', null, 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', undefined, 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', [ '5' ], 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', {}, 'row-major', () => 10.0 ); // $ExpectError + fullBy( 'float32', ( x: number ): number => x, 'row-major', () => 10.0 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid order for the third argument... +{ + fullBy( 'float32', [ 2, 2 ], '5', () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], false, () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], true, () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], null, () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], undefined, () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], [ '5' ], () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], {}, () => 10.0 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], ( x: number ): number => x, () => 10.0 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a callback function for the fourth argument... +{ + fullBy( 'float32', [ 2, 2 ], 'row-major', '10' ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', 10 ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', false ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', true ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', null ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', [] ); // $ExpectError + fullBy( 'float32', [ 2, 2 ], 'row-major', {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + fullBy( 'float64' ); // $ExpectError + fullBy( 'float64', [ 2, 2 ] ); // $ExpectError + fullBy( 'float64', [ 2, 2 ], 'row-major' ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/full-by/examples/index.js new file mode 100644 index 000000000000..6e800f06730a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var fullBy = require( './../lib' ); + +// Get a list of data types: +var dt = dtypes( 'integer_and_generic' ); + +// Generate filled arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = fullBy( dt[ i ], [ 2, 2 ], 'row-major', discreteUniform( -100, 100 ) ); + console.log( ndarray2array( arr ) ); +} diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/full-by/lib/index.js new file mode 100644 index 000000000000..5adb4fc0df14 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/lib/index.js @@ -0,0 +1,48 @@ +/** +* @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'; + +/** +* Create an ndarray filled according to a callback function and having a specified shape and data type. +* +* @module @stdlib/ndarray/base/full-by +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var fullBy = require( '@stdlib/ndarray/base/full-by' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float64' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/full-by/lib/main.js new file mode 100644 index 000000000000..1cc582db78c8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 empty = require( '@stdlib/ndarray/base/empty' ); +var map = require( '@stdlib/ndarray/base/map' ); + + +// MAIN // + +/** +* Returns an ndarray filled according to a callback function and having a specified shape and data type. +* +* @param {*} dtype - data type +* @param {NonNegativeIntegerArray} shape - array shape +* @param {string} order - array order +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback function execution context +* @throws {TypeError} first argument must be a recognized data type +* @returns {ndarray} ndarray +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* function clbk() { +* return 10.0; +* } +* +* var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'float64' +*/ +function fullBy( dtype, shape, order, clbk, thisArg ) { + var out; + + // Allocate an output array: + out = empty( dtype, shape, order ); + + // Fill the output ndarray according to a callback function: + map( [ out, out ], wrapper ); + + return out; + + /** + * Wraps a callback function so that only indices are passed. + * + * @private + * @param {*} value - current array element + * @param {NonNegativeIntegerArray} indices - current array element indices + * @returns {*} callback return value + */ + function wrapper( value, indices ) { + return clbk.call( thisArg, indices ); + } +} + + +// EXPORTS // + +module.exports = fullBy; diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/package.json b/lib/node_modules/@stdlib/ndarray/base/full-by/package.json new file mode 100644 index 000000000000..d3fe9262d812 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/ndarray/base/full-by", + "version": "0.0.0", + "description": "Create an ndarray filled according to a callback function and having a specified shape and data type.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "data", + "structure", + "ndarray", + "matrix", + "vector", + "fill", + "filled", + "full", + "callback", + "map", + "apply" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/full-by/test/test.js b/lib/node_modules/@stdlib/ndarray/base/full-by/test/test.js new file mode 100644 index 000000000000..5bb3fdbbf0c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/full-by/test/test.js @@ -0,0 +1,947 @@ +/** +* @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 tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Buffer = require( '@stdlib/buffer/ctor' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var fullBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fullBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'empty', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32', + 'GENERIC' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fullBy( value, [ 2, 2 ], 'row-major', clbk ); + }; + } + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=float64, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + + arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=float64, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + + arr = fullBy( 'float64', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=float32, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Float32Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + + arr = fullBy( 'float32', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=float32, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Float32Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + + arr = fullBy( 'float32', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=int32, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Int32Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int32', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=int32, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Int32Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int32', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=int16, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Int16Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int16', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=int16, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Int16Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int16', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=int8, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Int8Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int8', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=int8, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Int8Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'int8', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint32, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint32Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint32', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint32, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint32Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint32', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint16, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint16Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint16', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint16, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint16Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint16', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint8, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint8Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint8', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint8, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint8Array([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint8', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint8c, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint8ClampedArray([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint8c', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8c', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=uint8c, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Uint8ClampedArray([ + 10, + 10, + 10, + 10 + ]); + + arr = fullBy( 'uint8c', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8c', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10; + } +}); + +tape( 'the function returns a filled array (dtype=binary, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Buffer([ + 1, + 1, + 1, + 1 + ]); + + arr = fullBy( 'binary', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'binary', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 1; + } +}); + +tape( 'the function returns a filled array (dtype=binary, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Buffer([ + 1, + 1, + 1, + 1 + ]); + + arr = fullBy( 'binary', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'binary', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 1; + } +}); + +tape( 'the function returns a filled array (dtype=complex128, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Complex128Array([ + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0 + ]); + + arr = fullBy( 'complex128', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return new Complex128( 10.0, 0.0 ); + } +}); + +tape( 'the function returns a filled array (dtype=complex128, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Complex128Array([ + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0 + ]); + + arr = fullBy( 'complex128', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return new Complex128( 10.0, 0.0 ); + } +}); + +tape( 'the function returns a filled array (dtype=complex64, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new Complex64Array([ + 10.0, + 11.0, + 10.0, + 11.0, + 10.0, + 11.0, + 10.0, + 11.0 + ]); + + arr = fullBy( 'complex64', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return new Complex64( 10.0, 11.0 ); + } +}); + +tape( 'the function returns a filled array (dtype=complex64, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new Complex64Array([ + 10.0, + 11.0, + 10.0, + 11.0, + 10.0, + 11.0, + 10.0, + 11.0 + ]); + + arr = fullBy( 'complex64', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return new Complex64( 10.0, 11.0 ); + } +}); + +tape( 'the function returns a filled array (dtype=bool, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = new BooleanArray([ + true, + true, + true, + true + ]); + + arr = fullBy( 'bool', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return true; + } +}); + +tape( 'the function returns a filled array (dtype=bool, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = new BooleanArray([ + true, + true, + true, + true + ]); + + arr = fullBy( 'bool', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return true; + } +}); + +tape( 'the function returns a filled array (dtype=generic, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = [ + 10.0, + 10.0, + 10.0, + 10.0 + ]; + + arr = fullBy( 'generic', [ 2, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function returns a filled array (dtype=generic, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = [ + 10.0, + 10.0, + 10.0, + 10.0 + ]; + + arr = fullBy( 'generic', [ 2, 2 ], 'column-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function supports zero-dimensional arrays', function test( t ) { + var expected; + var arr; + + expected = new Float64Array( [ 10.0 ] ); + + arr = fullBy( 'float64', [], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function supports empty arrays', function test( t ) { + var expected; + var arr; + + expected = new Float64Array( 0 ); + + arr = fullBy( 'float64', [ 2, 0, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); + + function clbk() { + return 10.0; + } +}); + +tape( 'the function invokes the callback with the current array element indices', function test( t ) { + var expected; + var indices; + var arr; + + indices = []; + + arr = fullBy( 'float64', [ 3, 1, 2 ], 'row-major', clbk ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 2, 0, 0 ], + [ 2, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + t.end(); + + function clbk( idx ) { + indices.push( idx ); + return 10.0; + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var arr; + var ctx; + + indices = []; + ctx = { + 'scalar': 10.0 + }; + + arr = fullBy( 'float64', [ 3, 1, 2 ], 'row-major', clbk, ctx ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 2, 0, 0 ], + [ 2, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + t.end(); + + function clbk( idx ) { + indices.push( idx ); + return this.scalar; // eslint-disable-line no-invalid-this + } +});