From 07420c2e3092201a76df5c9cc864ef3c7b7b275f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 25 Sep 2026 23:52:53 +0500 Subject: [PATCH 1/9] feat: add blas/ext/fill --- .../@stdlib/blas/ext/fill/README.md | 152 ++ .../blas/ext/fill/benchmark/benchmark.js | 103 ++ .../@stdlib/blas/ext/fill/docs/repl.txt | 64 + .../blas/ext/fill/docs/types/index.d.ts | 165 ++ .../@stdlib/blas/ext/fill/docs/types/test.ts | 179 +++ .../@stdlib/blas/ext/fill/examples/index.js | 37 + .../@stdlib/blas/ext/fill/lib/base.js | 121 ++ .../blas/ext/fill/lib/broadcast_index.js | 55 + .../@stdlib/blas/ext/fill/lib/index.js | 61 + .../@stdlib/blas/ext/fill/lib/main.js | 229 +++ .../@stdlib/blas/ext/fill/package.json | 64 + .../@stdlib/blas/ext/fill/test/test.js | 1361 +++++++++++++++++ 12 files changed, 2591 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/fill/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/fill/README.md b/lib/node_modules/@stdlib/blas/ext/fill/README.md new file mode 100644 index 000000000000..efde842e3a53 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/README.md @@ -0,0 +1,152 @@ + + +# fill + +> Fill an input [ndarray][@stdlib/ndarray/ctor] with a specified value along an [ndarray][@stdlib/ndarray/ctor] dimension. + +
+ +## Usage + +```javascript +var fill = require( '@stdlib/blas/ext/fill' ); +``` + +#### fill( x, value\[, start\[, end]]\[, options] ) + +Fills an input [ndarray][@stdlib/ndarray/ctor] with a specified value along an [ndarray][@stdlib/ndarray/ctor] dimension. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] + +// Perform operation: +var y = fill( x, 10.0, 1, 4 ); +// returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] + +var bool = ( x === y ); +// returns true +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **value**: fill value. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor]. Must be able to safely cast to the input [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Values having floating-point [data types][@stdlib/ndarray/dtypes] (both real and complex) are allowed to downcast to a lower precision [data type][@stdlib/ndarray/dtypes] of the same kind (e.g., a scalar double-precision floating-point number can be used to fill a `'float32'` input [ndarray][@stdlib/ndarray/ctor]). If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dim`. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, an [ndarray][@stdlib/ndarray/ctor] fill value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. +- **start**: starting index (inclusive) (_optional_). May be either an integer or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes] and following the same broadcasting semantics as an [ndarray][@stdlib/ndarray/ctor] `value` argument. Default: `0`. +- **end**: ending index (exclusive) (_optional_). May be either an integer or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes] and following the same broadcasting semantics as an [ndarray][@stdlib/ndarray/ctor] `value` argument. By default, the ending index is `N`, where `N` is the number of elements along the dimension specified by `options.dim`. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. + +When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var y = fill( x, 10.0, -2 ); +// returns [ 1.0, 2.0, 3.0, 4.0, 10.0, 10.0 ] +``` + +By default, the function performs the operation over elements along the last dimension. To perform the operation over a different dimension, provide a `dim` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); + +var y = fill( x, 0.0, 0, 1, { + 'dim': 0 +}); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] +``` + +
+ + + +
+ +## Notes + +- The input [ndarray][@stdlib/ndarray/ctor] is filled **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fill = require( '@stdlib/blas/ext/fill' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], 0, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +fill( x, 0, 1, 4, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js new file mode 100644 index 000000000000..692ff7dd4f31 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fill = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( [ len ], -50.0, 50.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = fill( x, ( i%2 ) ? 5.0 : -5.0 ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + 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=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt new file mode 100644 index 000000000000..7cf367af1389 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt @@ -0,0 +1,64 @@ + +{{alias}}( x, value[, start[, end]][, options] ) + Fills an input ndarray with a specified value along an ndarray dimension. + + When a `start` and/or `end` index is negative, the respective index is + determined relative to the last indexed element, with out-of-bounds indices + clamped to index bounds. + + The function fills an input ndarray in-place and thus mutates an input + ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + value: ndarray|any + Fill value. May be either a scalar value or an ndarray. Must be able to + safely cast to the input ndarray data type. Values having floating-point + data types (both real and complex) are allowed to downcast to a lower + precision data type of the same kind (e.g., a scalar double-precision + floating-point number can be used to fill a 'float32' input ndarray). If + provided an ndarray, the value must have a shape which is broadcast + compatible with the complement of the shape defined by `options.dim`. + For example, given the input shape `[2, 3, 4]` and `options.dim=0`, an + ndarray fill value must have a shape which is broadcast compatible with + the shape `[3, 4]`. + + start: ndarray|integer (optional) + Starting index (inclusive). May be either an integer or an ndarray + having an integer index or "generic" data type and following the same + broadcasting semantics as an ndarray `value` argument. Default: `0`. + + end: ndarray|integer (optional) + Ending index (exclusive). May be either an integer or an ndarray having + an integer index or "generic" data type and following the same + broadcasting semantics as an ndarray `value` argument. Default: `N` + where `N` is the number of elements along the operation dimension. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform operation. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where `-1` + refers to the last dimension). Default: `-1`. + + Returns + ------- + out: ndarray + Input array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = {{alias}}( x, 10.0, 2 ) + [ 1.0, 2.0, 10.0, 10.0 ] + > var bool = ( x === y ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts new file mode 100644 index 000000000000..cd9364538bb4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts @@ -0,0 +1,165 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Index argument. +*/ +type IndexArgument = typedndarray | number; + +/** +* Fill value argument. +*/ +type FillValue = typedndarray | unknown; + +/** +* Interface defining options. +*/ +interface Options { + /** + * Dimension over which to perform operation. Default: `-1`. + * + * ## Notes + * + * - If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). + */ + dim?: number; +} + +/** +* Interface for filling an ndarray. +*/ +interface Fill { + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * + * @param x - input ndarray + * @param value - fill value + * @param options - function options + * @returns input ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * var y = fill( x, 10.0 ); + * // returns [ 10.0, 10.0, 10.0, 10.0 ] + * + * var bool = ( x === y ); + * // returns true + */ + >( x: T, value: FillValue, options?: Options ): T; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` index is negative, the index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * var y = fill( x, 10.0, 2 ); + * // returns [ 1.0, 2.0, 10.0, 10.0 ] + * + * var bool = ( x === y ); + * // returns true + */ + >( x: T, value: FillValue, start: IndexArgument, options?: Options ): T; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * var y = fill( x, 10.0, 1, 4 ); + * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] + * + * var bool = ( x === y ); + * // returns true + */ + >( x: T, value: FillValue, start: IndexArgument, end: IndexArgument, options?: Options ): T; +} + +/** +* Fills an input ndarray with a specified value along an ndarray dimension. +* +* ## Notes +* +* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). +* - When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. +* +* @param x - input ndarray +* @param value - fill value +* @param start - starting index (inclusive) +* @param end - ending index (exclusive) +* @param options - function options +* @returns input ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var y = fill( x, 10.0, 1, 4 ); +* // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] +* +* var bool = ( x === y ); +* // returns true +*/ +declare const fill: Fill; + + +// EXPORTS // + +export = fill; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts new file mode 100644 index 000000000000..7ddd9ac31c53 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts @@ -0,0 +1,179 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import fill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0 ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, {} ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0 ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, {} ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2 ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2, {} ); // $ExpectType float64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0 ); // $ExpectType float32ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0, {} ); // $ExpectType float32ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10 ); // $ExpectType int32ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10, {} ); // $ExpectType int32ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0 ); // $ExpectType complex128ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0, {} ); // $ExpectType complex128ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0 ); // $ExpectType complex64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0, {} ); // $ExpectType complex64ndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0 ); // $ExpectType genericndarray + fill( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0, {} ); // $ExpectType genericndarray +} + +// The function returns an ndarray when provided ndarray value and index arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill( x, x ); // $ExpectType float64ndarray + fill( x, x, {} ); // $ExpectType float64ndarray + fill( x, x, x ); // $ExpectType float64ndarray + fill( x, x, x, {} ); // $ExpectType float64ndarray + fill( x, x, x, x ); // $ExpectType float64ndarray + fill( x, x, x, x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + fill( '5', 10.0 ); // $ExpectError + fill( 5, 10.0 ); // $ExpectError + fill( true, 10.0 ); // $ExpectError + fill( false, 10.0 ); // $ExpectError + fill( null, 10.0 ); // $ExpectError + fill( void 0, 10.0 ); // $ExpectError + fill( {}, 10.0 ); // $ExpectError + fill( ( x: number ): number => x, 10.0 ); // $ExpectError + + fill( '5', 10.0, {} ); // $ExpectError + fill( 5, 10.0, {} ); // $ExpectError + fill( true, 10.0, {} ); // $ExpectError + fill( false, 10.0, {} ); // $ExpectError + fill( null, 10.0, {} ); // $ExpectError + fill( void 0, 10.0, {} ); // $ExpectError + fill( {}, 10.0, {} ); // $ExpectError + fill( ( x: number ): number => x, 10.0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a start index argument which is not an ndarray or integer... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill( x, 10.0, '5' ); // $ExpectError + fill( x, 10.0, true ); // $ExpectError + fill( x, 10.0, false ); // $ExpectError + fill( x, 10.0, null ); // $ExpectError + fill( x, 10.0, [] ); // $ExpectError + fill( x, 10.0, ( x: number ): number => x ); // $ExpectError + + fill( x, 10.0, '5', {} ); // $ExpectError + fill( x, 10.0, true, {} ); // $ExpectError + fill( x, 10.0, false, {} ); // $ExpectError + fill( x, 10.0, null, {} ); // $ExpectError + fill( x, 10.0, [], {} ); // $ExpectError + fill( x, 10.0, ( x: number ): number => x, {} ); // $ExpectError + + fill( x, 10.0, '5', 2, {} ); // $ExpectError + fill( x, 10.0, true, 2, {} ); // $ExpectError + fill( x, 10.0, false, 2, {} ); // $ExpectError + fill( x, 10.0, null, 2, {} ); // $ExpectError + fill( x, 10.0, [], 2, {} ); // $ExpectError + fill( x, 10.0, ( x: number ): number => x, 2, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an end index argument which is not an ndarray or integer... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill( x, 10.0, 0, '5', {} ); // $ExpectError + fill( x, 10.0, 0, true, {} ); // $ExpectError + fill( x, 10.0, 0, false, {} ); // $ExpectError + fill( x, 10.0, 0, null, {} ); // $ExpectError + fill( x, 10.0, 0, [], {} ); // $ExpectError + fill( x, 10.0, 0, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill( x, 10.0, 0, '5' ); // $ExpectError + fill( x, 10.0, 0, true ); // $ExpectError + fill( x, 10.0, 0, false ); // $ExpectError + fill( x, 10.0, 0, null ); // $ExpectError + fill( x, 10.0, 0, [] ); // $ExpectError + fill( x, 10.0, 0, ( x: number ): number => x ); // $ExpectError + + fill( x, 10.0, 0, 2, '5' ); // $ExpectError + fill( x, 10.0, 0, 2, true ); // $ExpectError + fill( x, 10.0, 0, 2, false ); // $ExpectError + fill( x, 10.0, 0, 2, null ); // $ExpectError + fill( x, 10.0, 0, 2, [] ); // $ExpectError + fill( x, 10.0, 0, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill( x, 10.0, { 'dim': '5' } ); // $ExpectError + fill( x, 10.0, { 'dim': true } ); // $ExpectError + fill( x, 10.0, { 'dim': false } ); // $ExpectError + fill( x, 10.0, { 'dim': null } ); // $ExpectError + fill( x, 10.0, { 'dim': [] } ); // $ExpectError + fill( x, 10.0, { 'dim': {} } ); // $ExpectError + fill( x, 10.0, { 'dim': ( x: number ): number => x } ); // $ExpectError + + fill( x, 10.0, 0, 2, { 'dim': '5' } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': true } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': false } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': null } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': [] } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': {} } ); // $ExpectError + fill( x, 10.0, 0, 2, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fill(); // $ExpectError + fill( x ); // $ExpectError + fill( x, 10.0, 0, 2, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/fill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/fill/examples/index.js new file mode 100644 index 000000000000..3e4a52d5e5ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fill = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], 0, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +fill( x, 0, 1, 4, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/base.js b/lib/node_modules/@stdlib/blas/ext/fill/lib/base.js new file mode 100644 index 000000000000..404271bd0673 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/lib/base.js @@ -0,0 +1,121 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); +var dfill = require( '@stdlib/blas/ext/base/ndarray/dfill' ); +var sfill = require( '@stdlib/blas/ext/base/ndarray/sfill' ); +var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // fill value ndarray +var idtypes1 = dtypes( 'integer_index_and_generic' ); // start/end ndarrays +var odtypes = dtypes( 'all' ); +var table = { + 'types': [ + 'float64', // input/output + 'float32' // input/output + + // FIXME: add specialized support for `cfill` and `zfill` once the corresponding packages are implemented + ], + 'fcns': [ + dfill, + sfill + ], + 'default': gfill +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Fills an input ndarray with a specified value along an ndarray dimension. +* +* @private +* @name fill +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} value - ndarray containing the fill value +* @param {ndarray} start - ndarray containing the starting index (inclusive) +* @param {ndarray} end - ndarray containing the ending index (exclusive) +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} index arguments must be ndarray-like objects +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {Error} must provide valid options +* @returns {ndarray} input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create an ndarray containing the fill value: +* var value = scalar2ndarray( 10.0, { +* 'dtype': 'float64' +* }); +* +* // Create ndarrays containing the starting and ending indices: +* var opts = { +* 'dtype': 'int32' +* }; +* var start = scalar2ndarray( 1, opts ); +* var end = scalar2ndarray( 4, opts ); +* +* // Perform operation: +* var out = fill( x, value, start, end, { +* 'dims': [ 0 ] +* }); +* // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +var fill = factory( table, [ idtypes0, idtypes1, idtypes1 ], odtypes, options ); + + +// EXPORTS // + +module.exports = fill; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js b/lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js new file mode 100644 index 000000000000..1bdbb12ce481 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js @@ -0,0 +1,55 @@ +/** +* @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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var getDefault = require( '@stdlib/ndarray/defaults' ).get; + + +// VARIABLES // + +var DEFAULT_DTYPE = getDefault( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Broadcasts an index argument to match the shape of the non-core dimensions. +* +* @private +* @param {(ndarray|NonNegativeInteger)} idx - index argument +* @param {NonNegativeIntegerArray} shape - shape of the non-core dimensions +* @param {string} order - memory layout order +* @returns {ndarray} ndarray containing index values +*/ +function broadcastIndex( idx, shape, order ) { + if ( isInteger( idx ) ) { + return broadcastScalar( idx, DEFAULT_DTYPE, shape, order ); + } + return maybeBroadcastArray( idx, shape ); +} + + +// EXPORTS // + +module.exports = broadcastIndex; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/fill/lib/index.js new file mode 100644 index 000000000000..d6d1fe1bdad1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/lib/index.js @@ -0,0 +1,61 @@ +/** +* @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'; + +/** +* Fill an input ndarray with a specified value along an ndarray dimension. +* +* @module @stdlib/blas/ext/fill +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var fill = require( '@stdlib/blas/ext/fill' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = fill( x, 10.0, 1, 4 ); +* // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/fill/lib/main.js new file mode 100644 index 000000000000..549659d85019 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/lib/main.js @@ -0,0 +1,229 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isScalarMostlySafeCompatible = require( '@stdlib/ndarray/base/assert/is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length +var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var broadcastIndex = require( './broadcast_index.js' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Fills an input ndarray with a specified value along an ndarray dimension. +* +* ## Notes +* +* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). +* - When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|*)} value - fill value +* @param {(ndarrayLike|integer)} [start] - starting index (inclusive) +* @param {(ndarrayLike|integer)} [end] - ending index (exclusive) +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument cannot be safely cast to the input ndarray data type +* @throws {TypeError} index arguments must be either ndarray-like objects or integers +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {TypeError} must provide valid options +* @returns {ndarray} input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = fill( x, 10.0, 1, 4 ); +* // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +function fill( x, value ) { + var hasOptions; + var hasStart; + var options; + var hasEnd; + var nargs; + var start; + var opts; + var end; + var lsh; + var len; + var ord; + var sh; + var dt; + var d; + var e; + var s; + var v; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Resolve input ndarray meta data: + dt = getDType( x ); + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform the operation over the last dimension + }; + + // Initialize flags indicating whether `start`, `end`, and `options` arguments were provided: + hasOptions = false; + hasStart = false; + hasEnd = false; + + // Case: fill( x, value, start, end, options ) + if ( nargs > 4 ) { + start = arguments[ 2 ]; + if ( !isInteger( start ) && !isndarrayLike( start ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', start ) ); + } + hasStart = true; + end = arguments[ 3 ]; + if ( !isInteger( end ) && !isndarrayLike( end ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be either an ndarray or an integer. Value: `%s`.', end ) ); + } + hasEnd = true; + options = arguments[ 4 ]; + hasOptions = true; + } + // Case: fill( x, value, start, ??? ) + else if ( nargs === 4 ) { + start = arguments[ 2 ]; + if ( !isInteger( start ) && !isndarrayLike( start ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', start ) ); + } + hasStart = true; + + // Case: fill( x, value, start, end ) + if ( isInteger( arguments[ 3 ] ) || isndarrayLike( arguments[ 3 ] ) ) { + end = arguments[ 3 ]; + hasEnd = true; + } + // Case: fill( x, value, start, options ) + else { + options = arguments[ 3 ]; + hasOptions = true; + } + } + // Case: fill( x, value, ??? ) + else if ( nargs === 3 ) { + // Case: fill( x, value, start ) + if ( isInteger( arguments[ 2 ] ) || isndarrayLike( arguments[ 2 ] ) ) { + start = arguments[ 2 ]; + hasStart = true; + } + // Case: fill( x, value, options ) + else { + options = arguments[ 2 ]; + hasOptions = true; + } + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + if ( !isInteger( options.dim ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'dim', options.dim ) ); + } + opts.dims[ 0 ] = options.dim; + } + } + // Resolve the shape of the non-core dimensions and the number of indexed elements... + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + d = normalizeIndex( opts.dims[ 0 ], sh.length-1 ); + if ( d === -1 ) { + throw new RangeError( format( 'invalid option. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', sh.length, opts.dims[ 0 ] ) ); + } + opts.dims[ 0 ] = d; + lsh = nonCoreShape( sh, opts.dims ); + len = sh[ d ]; + + // Case: fill( x, value_ndarray, ... ) + if ( isndarrayLike( value ) ) { + // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the input array data type is floating-point... + if ( !isMostlySafeCast( getDType( value ), dt ) ) { + throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input ndarray data type. Data types: [%s, %s].', getDType( value ), dt ) ); + } + // The fill value must have a shape which is broadcast compatible with the shape of the non-core dimensions... + v = maybeBroadcastArray( value, lsh ); + } + // Case: fill( x, value_scalar, ... ) + else { + // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the input data type is floating-point... + if ( !isScalarMostlySafeCompatible( value, dt ) ) { + throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input ndarray data type. Data type: %s. Value: `%s`.', dt, value ) ); + } + v = broadcastScalar( value, dt, lsh, ord ); + } + // Broadcast the indices to match the shape of the non-core dimensions... + s = broadcastIndex( ( hasStart ) ? start : 0, lsh, ord ); + e = broadcastIndex( ( hasEnd ) ? end : len, lsh, ord ); + + // Perform operation: + return base( x, v, s, e, opts ); +} + + +// EXPORTS // + +module.exports = fill; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/package.json b/lib/node_modules/@stdlib/blas/ext/fill/package.json new file mode 100644 index 000000000000..7c82a15853cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/blas/ext/fill", + "version": "0.0.0", + "description": "Fill an input ndarray with a specified value along an ndarray dimension.", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "fill", + "set", + "assign", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/fill/test/test.js b/lib/node_modules/@stdlib/blas/ext/fill/test/test.js new file mode 100644 index 000000000000..6b2f2e1f6736 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill/test/test.js @@ -0,0 +1,1361 @@ +/** +* @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 isSameArray = require( '@stdlib/assert/is-same-array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var fill = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (start)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (start, end)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0, 0, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (start, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0, 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (start, end, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( value, 10.0, 0, 2, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var i; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( value, 10.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value which cannot be safely cast to the input ndarray data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value which cannot be safely cast to the input ndarray data type (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value ndarray whose data type cannot be safely cast to the input ndarray data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'int32' + }); + + values = [ + scalar2ndarray( 10.0, { + 'dtype': 'float64' + }), + scalar2ndarray( 10.0, { + 'dtype': 'complex128' + }), + scalar2ndarray( 10.0, { + 'dtype': '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() { + fill( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value ndarray whose data type cannot be safely cast to the input ndarray data type (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'int32' + }); + + values = [ + scalar2ndarray( 10.0, { + 'dtype': 'float64' + }), + scalar2ndarray( 10.0, { + 'dtype': 'complex128' + }), + scalar2ndarray( 10.0, { + 'dtype': '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() { + fill( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `start` argument which is not an ndarray-like object or an integer (end)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, value, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided a `start` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `start` argument which is not an ndarray-like object or an integer (end, options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, value, 2, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an `end` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, 0, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value ndarray which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value ndarray which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fill value ndarray which is not broadcast-compatible (dim)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, value, { + 'dim': 0 + }); + }; + } +}); + +tape( 'the function throws an error if provided a `start` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `start` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an `end` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, 0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an `end` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, 0, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + 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() { + fill( x, 10.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (start)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + 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() { + fill( x, 10.0, 0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (start, end)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + 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() { + fill( x, 10.0, 0, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, { + 'dim': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer (start, end)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + 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() { + fill( x, 10.0, 0, 2, { + 'dim': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is out-of-bounds', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + -10, + 20 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, { + 'dim': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is out-of-bounds (start, end)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + -10, + 20 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + fill( x, 10.0, 0, 2, { + 'dim': value + }); + }; + } +}); + +tape( 'the function fills an input ndarray with a specified value (default, row-major)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0 ); + expected = [ 10.0, 10.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an input ndarray with a specified value (default, column-major)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = fill( x, 10.0 ); + expected = [ 10.0, 10.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills an input ndarray with a specified value (default, float64)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0 ); + expected = new Float64Array( [ 10.0, 10.0, 10.0, 10.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged if provided an empty ndarray', function test( t ) { + var actual; + var x; + + x = zeros( [ 0 ], { + 'dtype': 'float64' + }); + + actual = fill( x, 10.0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getData( actual ).length, 0, 'returns expected value' ); + + x = zeros( [ 0, 3 ], { + 'dtype': 'float64' + }); + + actual = fill( x, 10.0, { + 'dim': 0 + }); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getData( actual ).length, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': 0 + }); + expected = [ [ 10.0, 10.0 ], [ 3.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': 1 + }); + expected = [ [ 10.0, 2.0 ], [ 10.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': -2 + }); + expected = [ [ 10.0, 10.0 ], [ 3.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': 0 + }); + expected = [ [ 10.0, 10.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': 1 + }); + expected = [ [ 10.0, 3.0 ], [ 10.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = fill( x, 10.0, 0, 1, { + 'dim': -2 + }); + expected = [ [ 10.0, 10.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a starting index', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 2 ); + expected = [ 1.0, 2.0, 10.0, 10.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'column-major' ); + + actual = fill( x, 10.0, 2 ); + expected = [ 1.0, 2.0, 10.0, 10.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an ending index', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 1, 4 ); + expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'column-major' ); + + actual = fill( x, 10.0, 1, 4 ); + expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing negative indices', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, -2 ); + expected = [ 1.0, 2.0, 3.0, 4.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 0, -2 ); + expected = [ 10.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, -3, -1 ); + expected = [ 1.0, 2.0, 3.0, 10.0, 10.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function clamps out-of-bounds indices', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 10, 3 ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, 0, 100 ); + expected = [ 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, -100, 2 ); + expected = [ 10.0, 10.0, 3.0, 4.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing index arguments as zero-dimensional ndarrays', function test( t ) { + var expected; + var actual; + var opts; + var x; + + opts = { + 'dtype': 'int32' + }; + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, scalar2ndarray( 1, opts ), scalar2ndarray( 4, opts ) ); // eslint-disable-line max-len + expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing index arguments as zero-dimensional ndarrays (broadcasted)', function test( t ) { + var expected; + var actual; + var opts; + var x; + + opts = { + 'dtype': 'int32' + }; + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, scalar2ndarray( 2, opts ), { + 'dim': 1 + }); + expected = [ [ 1.0, 2.0, 10.0, 10.0 ], [ 5.0, 6.0, 10.0, 10.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing index arguments as ndarrays', function test( t ) { + var expected; + var actual; + var start; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + start = new ndarray( 'int32', new Int32Array( [ 0, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, start, 4, { + 'dim': 1 + }); + expected = [ [ 10.0, 10.0, 10.0, 10.0 ], [ 5.0, 6.0, 10.0, 10.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing index arguments as ndarrays containing negative indices', function test( t ) { + var expected; + var actual; + var start; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + start = new ndarray( 'int32', new Int32Array( [ -2, 0 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 10.0, start, { + 'dim': 1 + }); + expected = [ [ 1.0, 2.0, 10.0, 10.0 ], [ 10.0, 10.0, 10.0, 10.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a fill value as a zero-dimensional ndarray', function test( t ) { + var expected; + var actual; + var opts; + var x; + + opts = { + 'dtype': 'generic' + }; + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, scalar2ndarray( 10.0, opts ), 1, 4 ); + expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a fill value as an ndarray (broadcasted)', function test( t ) { + var expected; + var actual; + var value; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); + + value = new ndarray( 'generic', [ 10.0, 20.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, value, { + 'dim': 1 + }); + expected = [ [ 10.0, 10.0, 10.0, 10.0 ], [ 20.0, 20.0, 20.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports filling an input ndarray with non-numeric values', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, 'beep', 1, 3 ); + expected = [ 1.0, 'beep', 'beep', 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + x = new ndarray( 'generic', [ false, false, false, false ], [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = fill( x, true ); + expected = [ true, true, true, true ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); From 04d5aa3626159571ced18ba92d8dd2145b60bc79 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 26 Sep 2026 12:18:02 +0500 Subject: [PATCH 2/9] refactor: apply suggestions from code review --- .../blas/ext/{fill => fill-range}/README.md | 16 +- .../benchmark/benchmark.js | 4 +- .../ext/{fill => fill-range}/docs/repl.txt | 0 .../docs/types/index.d.ts | 14 +- .../blas/ext/fill-range/docs/types/test.ts | 179 +++++++++ .../{fill => fill-range}/examples/index.js | 4 +- .../blas/ext/{fill => fill-range}/lib/base.js | 22 +- .../lib/broadcast_index.js | 0 .../ext/{fill => fill-range}/lib/index.js | 6 +- .../blas/ext/{fill => fill-range}/lib/main.js | 43 ++- .../ext/{fill => fill-range}/package.json | 3 +- .../ext/{fill => fill-range}/test/test.js | 361 ++++++++++++------ .../@stdlib/blas/ext/fill/docs/types/test.ts | 179 --------- 13 files changed, 488 insertions(+), 343 deletions(-) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/README.md (94%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/benchmark/benchmark.js (96%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/docs/types/index.d.ts (95%) create mode 100644 lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/test.ts rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/examples/index.js (93%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/lib/base.js (87%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/lib/broadcast_index.js (100%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/lib/index.js (91%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/lib/main.js (87%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/package.json (95%) rename lib/node_modules/@stdlib/blas/ext/{fill => fill-range}/test/test.js (78%) delete mode 100644 lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/blas/ext/fill/README.md b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md similarity index 94% rename from lib/node_modules/@stdlib/blas/ext/fill/README.md rename to lib/node_modules/@stdlib/blas/ext/fill-range/README.md index efde842e3a53..859768aff5da 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# fill +# fillRange > Fill an input [ndarray][@stdlib/ndarray/ctor] with a specified value along an [ndarray][@stdlib/ndarray/ctor] dimension. @@ -27,10 +27,10 @@ limitations under the License. ## Usage ```javascript -var fill = require( '@stdlib/blas/ext/fill' ); +var fillRange = require( '@stdlib/blas/ext/fill-range' ); ``` -#### fill( x, value\[, start\[, end]]\[, options] ) +#### fillRange( x, value\[, start\[, end]]\[, options] ) Fills an input [ndarray][@stdlib/ndarray/ctor] with a specified value along an [ndarray][@stdlib/ndarray/ctor] dimension. @@ -42,7 +42,7 @@ var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] // Perform operation: -var y = fill( x, 10.0, 1, 4 ); +var y = fillRange( x, 10.0, 1, 4 ); // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] var bool = ( x === y ); @@ -68,7 +68,7 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var y = fill( x, 10.0, -2 ); +var y = fillRange( x, 10.0, -2 ); // returns [ 1.0, 2.0, 3.0, 4.0, 10.0, 10.0 ] ``` @@ -79,7 +79,7 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); -var y = fill( x, 0.0, 0, 1, { +var y = fillRange( x, 0.0, 0, 1, { 'dim': 0 }); // returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] @@ -108,7 +108,7 @@ var y = fill( x, 0.0, 0, 1, { ```javascript var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var fill = require( '@stdlib/blas/ext/fill' ); +var fillRange = require( '@stdlib/blas/ext/fill-range' ); // Generate an ndarray of random numbers: var x = discreteUniform( [ 5, 5 ], 0, 20, { @@ -117,7 +117,7 @@ var x = discreteUniform( [ 5, 5 ], 0, 20, { console.log( ndarray2array( x ) ); // Perform operation: -fill( x, 0, 1, 4, { +fillRange( x, 0, 1, 4, { 'dim': 0 }); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/fill-range/benchmark/benchmark.js similarity index 96% rename from lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/benchmark/benchmark.js index 692ff7dd4f31..a389a4898b5f 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/benchmark/benchmark.js @@ -26,7 +26,7 @@ var pow = require( '@stdlib/math/base/special/pow' ); var uniform = require( '@stdlib/random/uniform' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; -var fill = require( './../lib' ); +var fillRange = require( './../lib' ); // VARIABLES // @@ -61,7 +61,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = fill( x, ( i%2 ) ? 5.0 : -5.0 ); + o = fillRange( x, ( i%2 ) ? 5.0 : -5.0 ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/blas/ext/fill/docs/repl.txt rename to lib/node_modules/@stdlib/blas/ext/fill-range/docs/repl.txt diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts similarity index 95% rename from lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts rename to lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts index cd9364538bb4..2c42f15585e1 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts @@ -49,7 +49,7 @@ interface Options { /** * Interface for filling an ndarray. */ -interface Fill { +interface FillRange { /** * Fills an input ndarray with a specified value along an ndarray dimension. * @@ -67,7 +67,7 @@ interface Fill { * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * - * var y = fill( x, 10.0 ); + * var y = fillRange( x, 10.0 ); * // returns [ 10.0, 10.0, 10.0, 10.0 ] * * var bool = ( x === y ); @@ -94,7 +94,7 @@ interface Fill { * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * - * var y = fill( x, 10.0, 2 ); + * var y = fillRange( x, 10.0, 2 ); * // returns [ 1.0, 2.0, 10.0, 10.0 ] * * var bool = ( x === y ); @@ -122,7 +122,7 @@ interface Fill { * * var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * - * var y = fill( x, 10.0, 1, 4 ); + * var y = fillRange( x, 10.0, 1, 4 ); * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] * * var bool = ( x === y ); @@ -151,15 +151,15 @@ interface Fill { * * var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * -* var y = fill( x, 10.0, 1, 4 ); +* var y = fillRange( x, 10.0, 1, 4 ); * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] * * var bool = ( x === y ); * // returns true */ -declare const fill: Fill; +declare const fillRange: FillRange; // EXPORTS // -export = fill; +export = fillRange; diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/test.ts new file mode 100644 index 000000000000..ce228012b723 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/test.ts @@ -0,0 +1,179 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import fillRange = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0 ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, {} ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0 ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, {} ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2 ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2, {} ); // $ExpectType float64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0 ); // $ExpectType float32ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0, {} ); // $ExpectType float32ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10 ); // $ExpectType int32ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10, {} ); // $ExpectType int32ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0 ); // $ExpectType complex128ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0, {} ); // $ExpectType complex128ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0 ); // $ExpectType complex64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0, {} ); // $ExpectType complex64ndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0 ); // $ExpectType genericndarray + fillRange( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0, {} ); // $ExpectType genericndarray +} + +// The function returns an ndarray when provided ndarray value and index arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange( x, x ); // $ExpectType float64ndarray + fillRange( x, x, {} ); // $ExpectType float64ndarray + fillRange( x, x, x ); // $ExpectType float64ndarray + fillRange( x, x, x, {} ); // $ExpectType float64ndarray + fillRange( x, x, x, x ); // $ExpectType float64ndarray + fillRange( x, x, x, x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + fillRange( '5', 10.0 ); // $ExpectError + fillRange( 5, 10.0 ); // $ExpectError + fillRange( true, 10.0 ); // $ExpectError + fillRange( false, 10.0 ); // $ExpectError + fillRange( null, 10.0 ); // $ExpectError + fillRange( void 0, 10.0 ); // $ExpectError + fillRange( {}, 10.0 ); // $ExpectError + fillRange( ( x: number ): number => x, 10.0 ); // $ExpectError + + fillRange( '5', 10.0, {} ); // $ExpectError + fillRange( 5, 10.0, {} ); // $ExpectError + fillRange( true, 10.0, {} ); // $ExpectError + fillRange( false, 10.0, {} ); // $ExpectError + fillRange( null, 10.0, {} ); // $ExpectError + fillRange( void 0, 10.0, {} ); // $ExpectError + fillRange( {}, 10.0, {} ); // $ExpectError + fillRange( ( x: number ): number => x, 10.0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a start index argument which is not an ndarray or integer... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange( x, 10.0, '5' ); // $ExpectError + fillRange( x, 10.0, true ); // $ExpectError + fillRange( x, 10.0, false ); // $ExpectError + fillRange( x, 10.0, null ); // $ExpectError + fillRange( x, 10.0, [] ); // $ExpectError + fillRange( x, 10.0, ( x: number ): number => x ); // $ExpectError + + fillRange( x, 10.0, '5', {} ); // $ExpectError + fillRange( x, 10.0, true, {} ); // $ExpectError + fillRange( x, 10.0, false, {} ); // $ExpectError + fillRange( x, 10.0, null, {} ); // $ExpectError + fillRange( x, 10.0, [], {} ); // $ExpectError + fillRange( x, 10.0, ( x: number ): number => x, {} ); // $ExpectError + + fillRange( x, 10.0, '5', 2, {} ); // $ExpectError + fillRange( x, 10.0, true, 2, {} ); // $ExpectError + fillRange( x, 10.0, false, 2, {} ); // $ExpectError + fillRange( x, 10.0, null, 2, {} ); // $ExpectError + fillRange( x, 10.0, [], 2, {} ); // $ExpectError + fillRange( x, 10.0, ( x: number ): number => x, 2, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an end index argument which is not an ndarray or integer... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange( x, 10.0, 0, '5', {} ); // $ExpectError + fillRange( x, 10.0, 0, true, {} ); // $ExpectError + fillRange( x, 10.0, 0, false, {} ); // $ExpectError + fillRange( x, 10.0, 0, null, {} ); // $ExpectError + fillRange( x, 10.0, 0, [], {} ); // $ExpectError + fillRange( x, 10.0, 0, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange( x, 10.0, 0, '5' ); // $ExpectError + fillRange( x, 10.0, 0, true ); // $ExpectError + fillRange( x, 10.0, 0, false ); // $ExpectError + fillRange( x, 10.0, 0, null ); // $ExpectError + fillRange( x, 10.0, 0, [] ); // $ExpectError + fillRange( x, 10.0, 0, ( x: number ): number => x ); // $ExpectError + + fillRange( x, 10.0, 0, 2, '5' ); // $ExpectError + fillRange( x, 10.0, 0, 2, true ); // $ExpectError + fillRange( x, 10.0, 0, 2, false ); // $ExpectError + fillRange( x, 10.0, 0, 2, null ); // $ExpectError + fillRange( x, 10.0, 0, 2, [] ); // $ExpectError + fillRange( x, 10.0, 0, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange( x, 10.0, { 'dim': '5' } ); // $ExpectError + fillRange( x, 10.0, { 'dim': true } ); // $ExpectError + fillRange( x, 10.0, { 'dim': false } ); // $ExpectError + fillRange( x, 10.0, { 'dim': null } ); // $ExpectError + fillRange( x, 10.0, { 'dim': [] } ); // $ExpectError + fillRange( x, 10.0, { 'dim': {} } ); // $ExpectError + fillRange( x, 10.0, { 'dim': ( x: number ): number => x } ); // $ExpectError + + fillRange( x, 10.0, 0, 2, { 'dim': '5' } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': true } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': false } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': null } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': [] } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': {} } ); // $ExpectError + fillRange( x, 10.0, 0, 2, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + fillRange(); // $ExpectError + fillRange( x ); // $ExpectError + fillRange( x, 10.0, 0, 2, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/fill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/fill-range/examples/index.js similarity index 93% rename from lib/node_modules/@stdlib/blas/ext/fill/examples/index.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/examples/index.js index 3e4a52d5e5ac..b7b6b85b877b 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/examples/index.js @@ -20,7 +20,7 @@ var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var fill = require( './../lib' ); +var fillRange = require( './../lib' ); // Generate an ndarray of random numbers: var x = discreteUniform( [ 5, 5 ], 0, 20, { @@ -29,7 +29,7 @@ var x = discreteUniform( [ 5, 5 ], 0, 20, { console.log( ndarray2array( x ) ); // Perform operation: -fill( x, 0, 1, 4, { +fillRange( x, 0, 1, 4, { 'dim': 0 }); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/base.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/base.js similarity index 87% rename from lib/node_modules/@stdlib/blas/ext/fill/lib/base.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/lib/base.js index 404271bd0673..2f4e1ed9dbe5 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/base.js @@ -24,6 +24,8 @@ var dtypes = require( '@stdlib/ndarray/dtypes' ); var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); var dfill = require( '@stdlib/blas/ext/base/ndarray/dfill' ); var sfill = require( '@stdlib/blas/ext/base/ndarray/sfill' ); +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); +var zfill = require( '@stdlib/blas/ext/base/ndarray/zfill' ); var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); @@ -34,14 +36,16 @@ var idtypes1 = dtypes( 'integer_index_and_generic' ); // start/end ndarrays var odtypes = dtypes( 'all' ); var table = { 'types': [ - 'float64', // input/output - 'float32' // input/output - - // FIXME: add specialized support for `cfill` and `zfill` once the corresponding packages are implemented + 'float64', // input/output + 'float32', // input/output + 'complex128', // input/output + 'complex64' // input/output ], 'fcns': [ dfill, - sfill + sfill, + zfill, + cfill ], 'default': gfill }; @@ -56,7 +60,7 @@ var options = { * Fills an input ndarray with a specified value along an ndarray dimension. * * @private -* @name fill +* @name fillRange * @type {Function} * @param {ndarray} x - input ndarray * @param {ndarray} value - ndarray containing the fill value @@ -105,7 +109,7 @@ var options = { * var end = scalar2ndarray( 4, opts ); * * // Perform operation: -* var out = fill( x, value, start, end, { +* var out = fillRange( x, value, start, end, { * 'dims': [ 0 ] * }); * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] @@ -113,9 +117,9 @@ var options = { * var bool = ( out === x ); * // returns true */ -var fill = factory( table, [ idtypes0, idtypes1, idtypes1 ], odtypes, options ); +var fillRange = factory( table, [ idtypes0, idtypes1, idtypes1 ], odtypes, options ); // EXPORTS // -module.exports = fill; +module.exports = fillRange; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js similarity index 100% rename from lib/node_modules/@stdlib/blas/ext/fill/lib/broadcast_index.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/index.js similarity index 91% rename from lib/node_modules/@stdlib/blas/ext/fill/lib/index.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/lib/index.js index d6d1fe1bdad1..5d6ff07f168e 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/index.js @@ -21,12 +21,12 @@ /** * Fill an input ndarray with a specified value along an ndarray dimension. * -* @module @stdlib/blas/ext/fill +* @module @stdlib/blas/ext/fill-range * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); -* var fill = require( '@stdlib/blas/ext/fill' ); +* var fillRange = require( '@stdlib/blas/ext/fill-range' ); * * // Create a data buffer: * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); @@ -44,7 +44,7 @@ * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Perform operation: -* var out = fill( x, 10.0, 1, 4 ); +* var out = fillRange( x, 10.0, 1, 4 ); * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] * * var bool = ( out === x ); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/main.js similarity index 87% rename from lib/node_modules/@stdlib/blas/ext/fill/lib/main.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/lib/main.js index 549659d85019..a4d78cd35d0e 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/main.js @@ -26,8 +26,11 @@ var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var isScalarMostlySafeCompatible = require( '@stdlib/ndarray/base/assert/is-scalar-mostly-safe-compatible' ); // eslint-disable-line id-length var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); +var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); +var assign = require( '@stdlib/ndarray/base/assign' ); var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); var getDType = require( '@stdlib/ndarray/dtype' ); @@ -83,13 +86,13 @@ var base = require( './base.js' ); * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Perform operation: -* var out = fill( x, 10.0, 1, 4 ); +* var out = fillRange( x, 10.0, 1, 4 ); * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] * * var bool = ( out === x ); * // returns true */ -function fill( x, value ) { +function fillRange( x, value ) { var hasOptions; var hasStart; var options; @@ -101,6 +104,7 @@ function fill( x, value ) { var lsh; var len; var ord; + var vdt; var sh; var dt; var d; @@ -126,7 +130,7 @@ function fill( x, value ) { hasStart = false; hasEnd = false; - // Case: fill( x, value, start, end, options ) + // Case: fillRange( x, value, start, end, options ) if ( nargs > 4 ) { start = arguments[ 2 ]; if ( !isInteger( start ) && !isndarrayLike( start ) ) { @@ -141,7 +145,7 @@ function fill( x, value ) { options = arguments[ 4 ]; hasOptions = true; } - // Case: fill( x, value, start, ??? ) + // Case: fillRange( x, value, start, ??? ) else if ( nargs === 4 ) { start = arguments[ 2 ]; if ( !isInteger( start ) && !isndarrayLike( start ) ) { @@ -149,25 +153,25 @@ function fill( x, value ) { } hasStart = true; - // Case: fill( x, value, start, end ) + // Case: fillRange( x, value, start, end ) if ( isInteger( arguments[ 3 ] ) || isndarrayLike( arguments[ 3 ] ) ) { end = arguments[ 3 ]; hasEnd = true; } - // Case: fill( x, value, start, options ) + // Case: fillRange( x, value, start, options ) else { options = arguments[ 3 ]; hasOptions = true; } } - // Case: fill( x, value, ??? ) + // Case: fillRange( x, value, ??? ) else if ( nargs === 3 ) { - // Case: fill( x, value, start ) + // Case: fillRange( x, value, start ) if ( isInteger( arguments[ 2 ] ) || isndarrayLike( arguments[ 2 ] ) ) { start = arguments[ 2 ]; hasStart = true; } - // Case: fill( x, value, options ) + // Case: fillRange( x, value, options ) else { options = arguments[ 2 ]; hasOptions = true; @@ -198,16 +202,25 @@ function fill( x, value ) { lsh = nonCoreShape( sh, opts.dims ); len = sh[ d ]; - // Case: fill( x, value_ndarray, ... ) + // Case: fillRange( x, value_ndarray, ... ) if ( isndarrayLike( value ) ) { + vdt = getDType( value ); + // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the input array data type is floating-point... - if ( !isMostlySafeCast( getDType( value ), dt ) ) { - throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input ndarray data type. Data types: [%s, %s].', getDType( value ), dt ) ); + if ( !isMostlySafeCast( vdt, dt ) ) { + throw new TypeError( format( 'invalid argument. Second argument cannot be safely cast to the input ndarray data type. Data types: [%s, %s].', vdt, dt ) ); + } + if ( isEqualDataType( vdt, dt ) ) { + v = value; + } else { + // If we have unequal data types, we need to perform a copy... + v = baseEmpty( dt, getShape( value ), getOrder( value ) ); + assign( [ value, v ] ); } // The fill value must have a shape which is broadcast compatible with the shape of the non-core dimensions... - v = maybeBroadcastArray( value, lsh ); + v = maybeBroadcastArray( v, lsh ); } - // Case: fill( x, value_scalar, ... ) + // Case: fillRange( x, value_scalar, ... ) else { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the input data type is floating-point... if ( !isScalarMostlySafeCompatible( value, dt ) ) { @@ -226,4 +239,4 @@ function fill( x, value ) { // EXPORTS // -module.exports = fill; +module.exports = fillRange; diff --git a/lib/node_modules/@stdlib/blas/ext/fill/package.json b/lib/node_modules/@stdlib/blas/ext/fill-range/package.json similarity index 95% rename from lib/node_modules/@stdlib/blas/ext/fill/package.json rename to lib/node_modules/@stdlib/blas/ext/fill-range/package.json index 7c82a15853cf..ae0cba7eb6a5 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/package.json +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/blas/ext/fill", + "name": "@stdlib/blas/ext/fill-range", "version": "0.0.0", "description": "Fill an input ndarray with a specified value along an ndarray dimension.", "license": "Apache-2.0", @@ -56,6 +56,7 @@ "blas", "extended", "fill", + "range", "set", "assign", "ndarray" diff --git a/lib/node_modules/@stdlib/blas/ext/fill/test/test.js b/lib/node_modules/@stdlib/blas/ext/fill-range/test/test.js similarity index 78% rename from lib/node_modules/@stdlib/blas/ext/fill/test/test.js rename to lib/node_modules/@stdlib/blas/ext/fill-range/test/test.js index 6b2f2e1f6736..d84913be0768 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/test/test.js @@ -23,7 +23,14 @@ var tape = require( 'tape' ); var isSameArray = require( '@stdlib/assert/is-same-array' ); var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); var Int32Array = require( '@stdlib/array/int32' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); @@ -33,14 +40,14 @@ var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var getData = require( '@stdlib/ndarray/data-buffer' ); -var fill = require( './../lib' ); +var fillRange = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof fill, 'function', 'main export is a function' ); + t.strictEqual( typeof fillRange, 'function', 'main export is a function' ); t.end(); }); @@ -67,7 +74,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0 ); + fillRange( value, 10.0 ); }; } }); @@ -95,7 +102,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0, 0 ); + fillRange( value, 10.0, 0 ); }; } }); @@ -123,7 +130,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0, 0, 2 ); + fillRange( value, 10.0, 0, 2 ); }; } }); @@ -151,7 +158,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0, {} ); + fillRange( value, 10.0, {} ); }; } }); @@ -179,7 +186,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0, 0, {} ); + fillRange( value, 10.0, 0, {} ); }; } }); @@ -207,7 +214,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - fill( value, 10.0, 0, 2, {} ); + fillRange( value, 10.0, 0, 2, {} ); }; } }); @@ -228,7 +235,7 @@ tape( 'the function throws an error if provided a first argument which is a zero function badValue( value ) { return function badValue() { - fill( value, 10.0 ); + fillRange( value, 10.0 ); }; } }); @@ -239,80 +246,34 @@ tape( 'the function throws an error if provided a fill value which cannot be saf var i; x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - values = [ - '5', - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - 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() { - fill( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fill value which cannot be safely cast to the input ndarray data type (options)', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ], { - 'dtype': 'float64' + 'dtype': 'int32' }); values = [ '5', + 3.14, true, false, null, void 0, [], {}, - function noop() {} - ]; - 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() { - fill( x, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a fill value ndarray whose data type cannot be safely cast to the input ndarray data type', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - - values = [ + new Complex128( 10.0, 12.0 ), + function noop() {}, scalar2ndarray( 10.0, { 'dtype': 'float64' }), - scalar2ndarray( 10.0, { + scalar2ndarray( new Complex128( 10.0, 12.0 ), { 'dtype': 'complex128' }), + scalar2ndarray( new Complex128( 10.0, 12.0 ), { + 'dtype': 'complex64' + }), scalar2ndarray( 10.0, { 'dtype': 'generic' + }), + scalar2ndarray( true, { + 'dtype': 'bool' }) ]; for ( i = 0; i < values.length; i++ ) { @@ -322,12 +283,12 @@ tape( 'the function throws an error if provided a fill value ndarray whose data function badValue( value ) { return function badValue() { - fill( x, value ); + fillRange( x, value ); }; } }); -tape( 'the function throws an error if provided a fill value ndarray whose data type cannot be safely cast to the input ndarray data type (options)', function test( t ) { +tape( 'the function throws an error if provided a fill value which cannot be safely cast to the input ndarray data type (options)', function test( t ) { var values; var x; var i; @@ -337,14 +298,30 @@ tape( 'the function throws an error if provided a fill value ndarray whose data }); values = [ + '5', + 3.14, + true, + false, + null, + void 0, + [], + {}, + new Complex128( 10.0, 12.0 ), + function noop() {}, scalar2ndarray( 10.0, { 'dtype': 'float64' }), - scalar2ndarray( 10.0, { + scalar2ndarray( new Complex128( 10.0, 12.0 ), { 'dtype': 'complex128' }), + scalar2ndarray( new Complex128( 10.0, 12.0 ), { + 'dtype': 'complex64' + }), scalar2ndarray( 10.0, { 'dtype': 'generic' + }), + scalar2ndarray( true, { + 'dtype': 'bool' }) ]; for ( i = 0; i < values.length; i++ ) { @@ -354,7 +331,7 @@ tape( 'the function throws an error if provided a fill value ndarray whose data function badValue( value ) { return function badValue() { - fill( x, value, {} ); + fillRange( x, value, {} ); }; } }); @@ -387,7 +364,7 @@ tape( 'the function throws an error if provided a `start` argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value, 2 ); + fillRange( x, 10.0, value, 2 ); }; } }); @@ -420,7 +397,7 @@ tape( 'the function throws an error if provided a `start` argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value, {} ); + fillRange( x, 10.0, value, {} ); }; } }); @@ -453,7 +430,7 @@ tape( 'the function throws an error if provided a `start` argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value, 2, {} ); + fillRange( x, 10.0, value, 2, {} ); }; } }); @@ -486,7 +463,7 @@ tape( 'the function throws an error if provided an `end` argument which is not a function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, value, {} ); + fillRange( x, 10.0, 0, value, {} ); }; } }); @@ -514,7 +491,7 @@ tape( 'the function throws an error if provided a fill value ndarray which is no function badValue( value ) { return function badValue() { - fill( x, value ); + fillRange( x, value ); }; } }); @@ -542,7 +519,7 @@ tape( 'the function throws an error if provided a fill value ndarray which is no function badValue( value ) { return function badValue() { - fill( x, value, {} ); + fillRange( x, value, {} ); }; } }); @@ -570,7 +547,7 @@ tape( 'the function throws an error if provided a fill value ndarray which is no function badValue( value ) { return function badValue() { - fill( x, value, { + fillRange( x, value, { 'dim': 0 }); }; @@ -600,7 +577,7 @@ tape( 'the function throws an error if provided a `start` argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value ); + fillRange( x, 10.0, value ); }; } }); @@ -628,7 +605,7 @@ tape( 'the function throws an error if provided a `start` argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value, {} ); + fillRange( x, 10.0, value, {} ); }; } }); @@ -656,7 +633,7 @@ tape( 'the function throws an error if provided an `end` argument which is not b function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, value ); + fillRange( x, 10.0, 0, value ); }; } }); @@ -684,7 +661,7 @@ tape( 'the function throws an error if provided an `end` argument which is not b function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, value, {} ); + fillRange( x, 10.0, 0, value, {} ); }; } }); @@ -716,7 +693,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, value ); + fillRange( x, 10.0, value ); }; } }); @@ -748,7 +725,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, value ); + fillRange( x, 10.0, 0, value ); }; } }); @@ -780,7 +757,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, 2, value ); + fillRange( x, 10.0, 0, 2, value ); }; } }); @@ -812,7 +789,7 @@ tape( 'the function throws an error if provided a `dim` option which is not an i function badValue( value ) { return function badValue() { - fill( x, 10.0, { + fillRange( x, 10.0, { 'dim': value }); }; @@ -846,7 +823,7 @@ tape( 'the function throws an error if provided a `dim` option which is not an i function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, 2, { + fillRange( x, 10.0, 0, 2, { 'dim': value }); }; @@ -873,7 +850,7 @@ tape( 'the function throws an error if provided a `dim` option which is out-of-b function badValue( value ) { return function badValue() { - fill( x, 10.0, { + fillRange( x, 10.0, { 'dim': value }); }; @@ -900,7 +877,7 @@ tape( 'the function throws an error if provided a `dim` option which is out-of-b function badValue( value ) { return function badValue() { - fill( x, 10.0, 0, 2, { + fillRange( x, 10.0, 0, 2, { 'dim': value }); }; @@ -914,7 +891,7 @@ tape( 'the function fills an input ndarray with a specified value (default, row- x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0 ); + actual = fillRange( x, 10.0 ); expected = [ 10.0, 10.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -933,7 +910,7 @@ tape( 'the function fills an input ndarray with a specified value (default, colu x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - actual = fill( x, 10.0 ); + actual = fillRange( x, 10.0 ); expected = [ 10.0, 10.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -954,7 +931,7 @@ tape( 'the function fills an input ndarray with a specified value (default, floa xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0 ); + actual = fillRange( x, 10.0 ); expected = new Float64Array( [ 10.0, 10.0, 10.0, 10.0 ] ); t.strictEqual( actual, x, 'returns expected value' ); @@ -966,6 +943,156 @@ tape( 'the function fills an input ndarray with a specified value (default, floa t.end(); }); +tape( 'the function fills an input ndarray with a specified value (default, complex128)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fillRange( x, new Complex128( 10.0, 12.0 ) ); + expected = new Complex128Array( [ 10.0, 12.0, 10.0, 12.0, 10.0, 12.0, 10.0, 12.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports downcasting a floating-point fill value to an input ndarray data type of the same kind (float32)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fillRange( x, 10.0 ); + expected = new Float32Array( [ 10.0, 10.0, 10.0, 10.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float32', 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports downcasting a floating-point fill value ndarray to an input ndarray data type of the same kind (float32)', function test( t ) { + var expected; + var actual; + var value; + var xbuf; + var x; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + value = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + + actual = fillRange( x, value ); + expected = new Float32Array( [ 10.0, 10.0, 10.0, 10.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float32', 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports downcasting a floating-point fill value to an input ndarray data type of the same kind (complex64)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'complex64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fillRange( x, new Complex128( 10.0, 12.0 ) ); + expected = new Complex64Array( [ 10.0, 12.0, 10.0, 12.0, 10.0, 12.0, 10.0, 12.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex64', 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports downcasting a floating-point fill value ndarray to an input ndarray data type of the same kind (complex64)', function test( t ) { + var expected; + var actual; + var value; + var xbuf; + var x; + + xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'complex64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + value = scalar2ndarray( new Complex128( 10.0, 12.0 ), { + 'dtype': 'complex128' + }); + + actual = fillRange( x, value ); + expected = new Complex64Array( [ 10.0, 12.0, 10.0, 12.0, 10.0, 12.0, 10.0, 12.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex64', 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports promoting a real-valued fill value when an input ndarray has a complex data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = fillRange( x, 10.0 ); + expected = new Complex128Array( [ 10.0, 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 0.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports promoting a real-valued fill value ndarray when an input ndarray has a complex data type', function test( t ) { + var expected; + var actual; + var value; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + value = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + + actual = fillRange( x, value ); + expected = new Complex128Array( [ 10.0, 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 0.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns the input ndarray unchanged if provided an empty ndarray', function test( t ) { var actual; var x; @@ -974,7 +1101,7 @@ tape( 'the function returns the input ndarray unchanged if provided an empty nda 'dtype': 'float64' }); - actual = fill( x, 10.0 ); + actual = fillRange( x, 10.0 ); t.strictEqual( actual, x, 'returns expected value' ); t.strictEqual( getData( actual ).length, 0, 'returns expected value' ); @@ -983,7 +1110,7 @@ tape( 'the function returns the input ndarray unchanged if provided an empty nda 'dtype': 'float64' }); - actual = fill( x, 10.0, { + actual = fillRange( x, 10.0, { 'dim': 0 }); @@ -1000,7 +1127,7 @@ tape( 'the function supports specifying the operation dimension (row-major)', fu x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': 0 }); expected = [ [ 10.0, 10.0 ], [ 3.0, 4.0 ] ]; @@ -1013,7 +1140,7 @@ tape( 'the function supports specifying the operation dimension (row-major)', fu x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': 1 }); expected = [ [ 10.0, 2.0 ], [ 10.0, 4.0 ] ]; @@ -1026,7 +1153,7 @@ tape( 'the function supports specifying the operation dimension (row-major)', fu x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': -2 }); expected = [ [ 10.0, 10.0 ], [ 3.0, 4.0 ] ]; @@ -1047,7 +1174,7 @@ tape( 'the function supports specifying the operation dimension (column-major)', x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': 0 }); expected = [ [ 10.0, 10.0 ], [ 2.0, 4.0 ] ]; @@ -1060,7 +1187,7 @@ tape( 'the function supports specifying the operation dimension (column-major)', x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': 1 }); expected = [ [ 10.0, 3.0 ], [ 10.0, 4.0 ] ]; @@ -1073,7 +1200,7 @@ tape( 'the function supports specifying the operation dimension (column-major)', x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - actual = fill( x, 10.0, 0, 1, { + actual = fillRange( x, 10.0, 0, 1, { 'dim': -2 }); expected = [ [ 10.0, 10.0 ], [ 2.0, 4.0 ] ]; @@ -1094,7 +1221,7 @@ tape( 'the function supports providing a starting index', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 2 ); + actual = fillRange( x, 10.0, 2 ); expected = [ 1.0, 2.0, 10.0, 10.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1105,7 +1232,7 @@ tape( 'the function supports providing a starting index', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'column-major' ); - actual = fill( x, 10.0, 2 ); + actual = fillRange( x, 10.0, 2 ); expected = [ 1.0, 2.0, 10.0, 10.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1124,7 +1251,7 @@ tape( 'the function supports providing an ending index', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 1, 4 ); + actual = fillRange( x, 10.0, 1, 4 ); expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1135,7 +1262,7 @@ tape( 'the function supports providing an ending index', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'column-major' ); - actual = fill( x, 10.0, 1, 4 ); + actual = fillRange( x, 10.0, 1, 4 ); expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1154,7 +1281,7 @@ tape( 'the function supports providing negative indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, -2 ); + actual = fillRange( x, 10.0, -2 ); expected = [ 1.0, 2.0, 3.0, 4.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1162,7 +1289,7 @@ tape( 'the function supports providing negative indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 0, -2 ); + actual = fillRange( x, 10.0, 0, -2 ); expected = [ 10.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1170,7 +1297,7 @@ tape( 'the function supports providing negative indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, -3, -1 ); + actual = fillRange( x, 10.0, -3, -1 ); expected = [ 1.0, 2.0, 3.0, 10.0, 10.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1186,7 +1313,7 @@ tape( 'the function clamps out-of-bounds indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 10, 3 ); + actual = fillRange( x, 10.0, 10, 3 ); expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1194,7 +1321,7 @@ tape( 'the function clamps out-of-bounds indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, 0, 100 ); + actual = fillRange( x, 10.0, 0, 100 ); expected = [ 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1202,7 +1329,7 @@ tape( 'the function clamps out-of-bounds indices', function test( t ) { x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, -100, 2 ); + actual = fillRange( x, 10.0, -100, 2 ); expected = [ 10.0, 10.0, 3.0, 4.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1222,7 +1349,7 @@ tape( 'the function supports providing index arguments as zero-dimensional ndarr }; x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, scalar2ndarray( 1, opts ), scalar2ndarray( 4, opts ) ); // eslint-disable-line max-len + actual = fillRange( x, 10.0, scalar2ndarray( 1, opts ), scalar2ndarray( 4, opts ) ); // eslint-disable-line max-len expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1242,7 +1369,7 @@ tape( 'the function supports providing index arguments as zero-dimensional ndarr }; x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], [ 2, 4 ], [ 4, 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, scalar2ndarray( 2, opts ), { + actual = fillRange( x, 10.0, scalar2ndarray( 2, opts ), { 'dim': 1 }); expected = [ [ 1.0, 2.0, 10.0, 10.0 ], [ 5.0, 6.0, 10.0, 10.0 ] ]; @@ -1263,7 +1390,7 @@ tape( 'the function supports providing index arguments as ndarrays', function te start = new ndarray( 'int32', new Int32Array( [ 0, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, start, 4, { + actual = fillRange( x, 10.0, start, 4, { 'dim': 1 }); expected = [ [ 10.0, 10.0, 10.0, 10.0 ], [ 5.0, 6.0, 10.0, 10.0 ] ]; @@ -1284,7 +1411,7 @@ tape( 'the function supports providing index arguments as ndarrays containing ne start = new ndarray( 'int32', new Int32Array( [ -2, 0 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 10.0, start, { + actual = fillRange( x, 10.0, start, { 'dim': 1 }); expected = [ [ 1.0, 2.0, 10.0, 10.0 ], [ 10.0, 10.0, 10.0, 10.0 ] ]; @@ -1306,7 +1433,7 @@ tape( 'the function supports providing a fill value as a zero-dimensional ndarra }; x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 6 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, scalar2ndarray( 10.0, opts ), 1, 4 ); + actual = fillRange( x, scalar2ndarray( 10.0, opts ), 1, 4 ); expected = [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1325,7 +1452,7 @@ tape( 'the function supports providing a fill value as an ndarray (broadcasted)' value = new ndarray( 'generic', [ 10.0, 20.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, value, { + actual = fillRange( x, value, { 'dim': 1 }); expected = [ [ 10.0, 10.0, 10.0, 10.0 ], [ 20.0, 20.0, 20.0, 20.0 ] ]; @@ -1343,7 +1470,7 @@ tape( 'the function supports filling an input ndarray with non-numeric values', x = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0 ], [ 4 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, 'beep', 1, 3 ); + actual = fillRange( x, 'beep', 1, 3 ); expected = [ 1.0, 'beep', 'beep', 4.0 ]; t.strictEqual( actual, x, 'returns expected value' ); @@ -1351,7 +1478,7 @@ tape( 'the function supports filling an input ndarray with non-numeric values', x = new ndarray( 'generic', [ false, false, false, false ], [ 4 ], [ 1 ], 0, 'row-major' ); - actual = fill( x, true ); + actual = fillRange( x, true ); expected = [ true, true, true, true ]; t.strictEqual( actual, x, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts deleted file mode 100644 index 7ddd9ac31c53..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/fill/docs/types/test.ts +++ /dev/null @@ -1,179 +0,0 @@ -/* -* @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. -*/ - -/* eslint-disable space-in-parens */ - -/// - -import zeros = require( '@stdlib/ndarray/zeros' ); -import fill = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0 ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, {} ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0 ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, {} ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2 ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), 10.0, 0, 2, {} ); // $ExpectType float64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0 ); // $ExpectType float32ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'float32' } ), 10.0, {} ); // $ExpectType float32ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10 ); // $ExpectType int32ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'int32' } ), 10, {} ); // $ExpectType int32ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0 ); // $ExpectType complex128ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), 10.0, {} ); // $ExpectType complex128ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0 ); // $ExpectType complex64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'complex64' } ), 10.0, {} ); // $ExpectType complex64ndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0 ); // $ExpectType genericndarray - fill( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), 10.0, {} ); // $ExpectType genericndarray -} - -// The function returns an ndarray when provided ndarray value and index arguments... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill( x, x ); // $ExpectType float64ndarray - fill( x, x, {} ); // $ExpectType float64ndarray - fill( x, x, x ); // $ExpectType float64ndarray - fill( x, x, x, {} ); // $ExpectType float64ndarray - fill( x, x, x, x ); // $ExpectType float64ndarray - fill( x, x, x, x, {} ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - fill( '5', 10.0 ); // $ExpectError - fill( 5, 10.0 ); // $ExpectError - fill( true, 10.0 ); // $ExpectError - fill( false, 10.0 ); // $ExpectError - fill( null, 10.0 ); // $ExpectError - fill( void 0, 10.0 ); // $ExpectError - fill( {}, 10.0 ); // $ExpectError - fill( ( x: number ): number => x, 10.0 ); // $ExpectError - - fill( '5', 10.0, {} ); // $ExpectError - fill( 5, 10.0, {} ); // $ExpectError - fill( true, 10.0, {} ); // $ExpectError - fill( false, 10.0, {} ); // $ExpectError - fill( null, 10.0, {} ); // $ExpectError - fill( void 0, 10.0, {} ); // $ExpectError - fill( {}, 10.0, {} ); // $ExpectError - fill( ( x: number ): number => x, 10.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a start index argument which is not an ndarray or integer... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill( x, 10.0, '5' ); // $ExpectError - fill( x, 10.0, true ); // $ExpectError - fill( x, 10.0, false ); // $ExpectError - fill( x, 10.0, null ); // $ExpectError - fill( x, 10.0, [] ); // $ExpectError - fill( x, 10.0, ( x: number ): number => x ); // $ExpectError - - fill( x, 10.0, '5', {} ); // $ExpectError - fill( x, 10.0, true, {} ); // $ExpectError - fill( x, 10.0, false, {} ); // $ExpectError - fill( x, 10.0, null, {} ); // $ExpectError - fill( x, 10.0, [], {} ); // $ExpectError - fill( x, 10.0, ( x: number ): number => x, {} ); // $ExpectError - - fill( x, 10.0, '5', 2, {} ); // $ExpectError - fill( x, 10.0, true, 2, {} ); // $ExpectError - fill( x, 10.0, false, 2, {} ); // $ExpectError - fill( x, 10.0, null, 2, {} ); // $ExpectError - fill( x, 10.0, [], 2, {} ); // $ExpectError - fill( x, 10.0, ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an end index argument which is not an ndarray or integer... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill( x, 10.0, 0, '5', {} ); // $ExpectError - fill( x, 10.0, 0, true, {} ); // $ExpectError - fill( x, 10.0, 0, false, {} ); // $ExpectError - fill( x, 10.0, 0, null, {} ); // $ExpectError - fill( x, 10.0, 0, [], {} ); // $ExpectError - fill( x, 10.0, 0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill( x, 10.0, 0, '5' ); // $ExpectError - fill( x, 10.0, 0, true ); // $ExpectError - fill( x, 10.0, 0, false ); // $ExpectError - fill( x, 10.0, 0, null ); // $ExpectError - fill( x, 10.0, 0, [] ); // $ExpectError - fill( x, 10.0, 0, ( x: number ): number => x ); // $ExpectError - - fill( x, 10.0, 0, 2, '5' ); // $ExpectError - fill( x, 10.0, 0, 2, true ); // $ExpectError - fill( x, 10.0, 0, 2, false ); // $ExpectError - fill( x, 10.0, 0, 2, null ); // $ExpectError - fill( x, 10.0, 0, 2, [] ); // $ExpectError - fill( x, 10.0, 0, 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `dim` option... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill( x, 10.0, { 'dim': '5' } ); // $ExpectError - fill( x, 10.0, { 'dim': true } ); // $ExpectError - fill( x, 10.0, { 'dim': false } ); // $ExpectError - fill( x, 10.0, { 'dim': null } ); // $ExpectError - fill( x, 10.0, { 'dim': [] } ); // $ExpectError - fill( x, 10.0, { 'dim': {} } ); // $ExpectError - fill( x, 10.0, { 'dim': ( x: number ): number => x } ); // $ExpectError - - fill( x, 10.0, 0, 2, { 'dim': '5' } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': true } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': false } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': null } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': [] } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': {} } ); // $ExpectError - fill( x, 10.0, 0, 2, { 'dim': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - fill(); // $ExpectError - fill( x ); // $ExpectError - fill( x, 10.0, 0, 2, {}, {} ); // $ExpectError -} From 2c48db819c2b7cfed97a22ebb08d32e14ae6ac75 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 00:57:20 -0700 Subject: [PATCH 3/9] chore: add FIXME Signed-off-by: Athan --- .../@stdlib/blas/ext/fill-range/lib/broadcast_index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js index 1bdbb12ce481..73444af1857a 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js @@ -43,6 +43,7 @@ var DEFAULT_DTYPE = getDefault( 'dtypes.integer_index' ); * @returns {ndarray} ndarray containing index values */ function broadcastIndex( idx, shape, order ) { + // FIXME: this breaks for large integer/array sizes (e.g., casting >4e9 to int32). We also need to update in the future to accommodate 64-bit integer values. if ( isInteger( idx ) ) { return broadcastScalar( idx, DEFAULT_DTYPE, shape, order ); } From acab74d26a81a78431040540d7832287e0c226df Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 00:58:09 -0700 Subject: [PATCH 4/9] docs: update comment Signed-off-by: Athan --- .../@stdlib/blas/ext/fill-range/lib/broadcast_index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js index 73444af1857a..bade251f2423 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/lib/broadcast_index.js @@ -43,7 +43,7 @@ var DEFAULT_DTYPE = getDefault( 'dtypes.integer_index' ); * @returns {ndarray} ndarray containing index values */ function broadcastIndex( idx, shape, order ) { - // FIXME: this breaks for large integer/array sizes (e.g., casting >4e9 to int32). We also need to update in the future to accommodate 64-bit integer values. + // FIXME: this breaks for large integer/array sizes (e.g., casting idx > 2^32 to int32). We also need to update in the future to accommodate 64-bit integer values. if ( isInteger( idx ) ) { return broadcastScalar( idx, DEFAULT_DTYPE, shape, order ); } From 1e8d37d52f6ee2e59ba039862ff208a8b171f7ba Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 01:02:20 -0700 Subject: [PATCH 5/9] docs: update example Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/fill-range/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/README.md b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md index 859768aff5da..09978d6dc7f9 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/README.md +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md @@ -79,10 +79,10 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); -var y = fillRange( x, 0.0, 0, 1, { +var y = fillRange( x, array( [ 0.0, 1.0 ] ), { 'dim': 0 }); -// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 1.0, 1.0, 1.0 ] ] ``` From 8aa3fd5a3de9de54ddf44c06345521163555d76a Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 01:10:00 -0700 Subject: [PATCH 6/9] docs: fix example Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/fill-range/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/README.md b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md index 09978d6dc7f9..5f5ab2beb985 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/README.md +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/README.md @@ -79,10 +79,10 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); -var y = fillRange( x, array( [ 0.0, 1.0 ] ), { +var y = fillRange( x, array( [ 9.0, 10.0, 11.0, 12.0 ] ), { 'dim': 0 }); -// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 1.0, 1.0, 1.0 ] ] +// returns [ [ 9.0, 10.0, 11.0, 12.0 ], [ 9.0, 10.0, 11.0, 12.0 ] ] ``` From 099777f2e0101984cf9dad9e9a62680ebb6b18dc Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 01:29:31 -0700 Subject: [PATCH 7/9] refactor: improve type specificity Signed-off-by: Athan --- .../blas/ext/fill-range/docs/types/index.d.ts | 189 +++++++++++++++++- 1 file changed, 181 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts index 2c42f15585e1..6186ea2da4d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts @@ -20,7 +20,8 @@ /// -import { typedndarray } from '@stdlib/types/ndarray'; +import { typedndarray, complexndarray, genericndarray } from '@stdlib/types/ndarray'; +import { ComplexLike } from '@stdlib/types/complex'; /** * Index argument. @@ -30,7 +31,7 @@ type IndexArgument = typedndarray | number; /** * Fill value argument. */ -type FillValue = typedndarray | unknown; +type FillValue = typedndarray | T; /** * Interface defining options. @@ -50,6 +51,60 @@ interface Options { * Interface for filling an ndarray. */ interface FillRange { + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * + * @param x - input ndarray + * @param value - fill value + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 2, 2 ], { + * 'dtype': 'complex128' + * }); + * + * var y = fillRange( x, 10.0 ); + * // returns [ [ [ 10.0, 0.0 ], [ 10.0, 0.0 ] ], [ [ 10.0, 0.0 ], [ 10.0, 0.0 ] ] ] + * + * var bool = ( x === y ); + * // returns true + */ + ( x: T, value: FillValue, options?: Options ): T; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * + * @param x - input ndarray + * @param value - fill value + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 2, 2 ], { + * 'dtype': 'generic' + * }); + * + * var y = fillRange( x, 10.0 ); + * // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + * + * var bool = ( x === y ); + * // returns true + */ + = genericndarray>( x: V, value: FillValue, options?: Options ): V; + /** * Fills an input ndarray with a specified value along an ndarray dimension. * @@ -73,7 +128,65 @@ interface FillRange { * var bool = ( x === y ); * // returns true */ - >( x: T, value: FillValue, options?: Options ): T; + = typedndarray>( x: U, value: FillValue, options?: Options ): U; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` index is negative, the index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 4 ], { + * 'dtype': 'complex128' + * }); + * + * var y = fillRange( x, 10.0, 2 ); + * // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ [ 10.0, 0.0 ], [ 10.0, 0.0 ] ] + * + * var bool = ( x === y ); + * // returns true + */ + ( x: T, value: FillValue, start: IndexArgument, options?: Options ): T; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` index is negative, the index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 4 ], { + * 'dtype': 'generic' + * }); + * + * var y = fillRange( x, 10.0, 2 ); + * // returns [ 0.0, 0.0, 10.0, 10.0 ] + * + * var bool = ( x === y ); + * // returns true + */ + = genericndarray>( x: V, value: FillValue, start: IndexArgument, options?: Options ): V; /** * Fills an input ndarray with a specified value along an ndarray dimension. @@ -95,12 +208,72 @@ interface FillRange { * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var y = fillRange( x, 10.0, 2 ); - * // returns [ 1.0, 2.0, 10.0, 10.0 ] + * // returns [ 0.0, 0.0, 10.0, 10.0 ] + * + * var bool = ( x === y ); + * // returns true + */ + = typedndarray>( x: U, value: FillValue, start: IndexArgument, options?: Options ): U; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 4 ], { + * 'dtype': 'complex128' + * }); + * + * var y = fillRange( x, 10.0, 1, 4 ); + * // returns [ [ 0.0, 0.0 ], [ 10.0, 0.0 ], [ [ 10.0, 0.0 ], [ 00.0, 0.0 ] ] + * + * var bool = ( x === y ); + * // returns true + */ + ( x: T, value: FillValue, start: IndexArgument, end: IndexArgument, options?: Options ): T; + + /** + * Fills an input ndarray with a specified value along an ndarray dimension. + * + * ## Notes + * + * - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**). + * - When a `start` and/or `end` index is negative, the respective index is determined relative to the last indexed element, with out-of-bounds indices clamped to index bounds. + * + * @param x - input ndarray + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param options - function options + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = zeros( [ 4 ], { + * 'dtype': 'generic' + * }); + * + * var y = fillRange( x, 10.0, 1, 4 ); + * // returns [ 0.0, 10.0, 10.0, 0.0 ] * * var bool = ( x === y ); * // returns true */ - >( x: T, value: FillValue, start: IndexArgument, options?: Options ): T; + = genericndarray>( x: V, value: FillValue, start: IndexArgument, end: IndexArgument, options?: Options ): V; /** * Fills an input ndarray with a specified value along an ndarray dimension. @@ -120,15 +293,15 @@ interface FillRange { * @example * var array = require( '@stdlib/ndarray/array' ); * - * var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var y = fillRange( x, 10.0, 1, 4 ); - * // returns [ 1.0, 10.0, 10.0, 10.0, 5.0, 6.0 ] + * // returns [ 0.0, 10.0, 10.0, 0.0 ] * * var bool = ( x === y ); * // returns true */ - >( x: T, value: FillValue, start: IndexArgument, end: IndexArgument, options?: Options ): T; + = typedndarray>( x: U, value: FillValue, start: IndexArgument, end: IndexArgument, options?: Options ): U; } /** From 3879d561cd9eb64bdced8b42c77fe093d46deac6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 01:34:18 -0700 Subject: [PATCH 8/9] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../blas/ext/fill-range/docs/types/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts index 6186ea2da4d9..69955fd1b1ab 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts @@ -152,7 +152,7 @@ interface FillRange { * }); * * var y = fillRange( x, 10.0, 2 ); - * // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ [ 10.0, 0.0 ], [ 10.0, 0.0 ] ] + * // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 10.0, 0.0 ], [ 10.0, 0.0 ] ] * * var bool = ( x === y ); * // returns true @@ -208,7 +208,7 @@ interface FillRange { * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var y = fillRange( x, 10.0, 2 ); - * // returns [ 0.0, 0.0, 10.0, 10.0 ] + * // returns [ 1.0, 2.0, 10.0, 10.0 ] * * var bool = ( x === y ); * // returns true @@ -237,8 +237,8 @@ interface FillRange { * 'dtype': 'complex128' * }); * - * var y = fillRange( x, 10.0, 1, 4 ); - * // returns [ [ 0.0, 0.0 ], [ 10.0, 0.0 ], [ [ 10.0, 0.0 ], [ 00.0, 0.0 ] ] + * var y = fillRange( x, 10.0, 1, 3 ); + * // returns [ [ 0.0, 0.0 ], [ 10.0, 0.0 ], [ 10.0, 0.0 ], [ 00.0, 0.0 ] ] * * var bool = ( x === y ); * // returns true @@ -267,7 +267,7 @@ interface FillRange { * 'dtype': 'generic' * }); * - * var y = fillRange( x, 10.0, 1, 4 ); + * var y = fillRange( x, 10.0, 1, 3 ); * // returns [ 0.0, 10.0, 10.0, 0.0 ] * * var bool = ( x === y ); @@ -295,7 +295,7 @@ interface FillRange { * * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * - * var y = fillRange( x, 10.0, 1, 4 ); + * var y = fillRange( x, 10.0, 1, 3 ); * // returns [ 0.0, 10.0, 10.0, 0.0 ] * * var bool = ( x === y ); From bd7bdf89339329776f663235f9ffa184df076c67 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 01:53:58 -0700 Subject: [PATCH 9/9] docs: fix example Signed-off-by: Athan --- .../@stdlib/blas/ext/fill-range/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts index 69955fd1b1ab..d398a0139663 100644 --- a/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/fill-range/docs/types/index.d.ts @@ -296,7 +296,7 @@ interface FillRange { * var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); * * var y = fillRange( x, 10.0, 1, 3 ); - * // returns [ 0.0, 10.0, 10.0, 0.0 ] + * // returns [ 1.0, 10.0, 10.0, 4.0 ] * * var bool = ( x === y ); * // returns true