diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/README.md b/lib/node_modules/@stdlib/ndarray/fill-slice-by/README.md new file mode 100644 index 000000000000..7c1d0b00d4a4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/README.md @@ -0,0 +1,293 @@ + + +# fillSliceBy + +> Fill an input [ndarray][@stdlib/ndarray/ctor] view according to a callback function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var fillSliceBy = require( '@stdlib/ndarray/fill-slice-by' ); +``` + +#### fillSliceBy( x, ...s\[, options], fcn\[, thisArg] ) + +Fills an input [ndarray][@stdlib/ndarray/ctor] view according to a callback function. + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var Slice = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function fcn( value ) { + return value + 10.0; +} + +var x = zeros( [ 3, 4 ], { + 'dtype': 'float64' +}); + +// Define the slice region: +var s0 = new Slice( 1, 3 ); +var s1 = new Slice( 2, 4 ); +var s = new MultiSlice( s0, s1 ); + +var y = fillSliceBy( x, s, fcn ); +// returns + +var bool = ( y === x ); +// returns true + +var arr = ndarray2array( y ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0 ], [ 0.0, 0.0, 10.0, 10.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: array-like object containing an input [ndarray][@stdlib/ndarray/ctor]. +- **s**: a [`MultiSlice`][@stdlib/slice/multi] instance, an array of slice arguments, or slice arguments as separate arguments. +- **options**: function options. +- **fcn**: callback function. +- **thisArg**: callback function execution context (_optional_). + +The function supports three (mutually exclusive) means for providing slice arguments: + +1. providing a single [`MultiSlice`][@stdlib/slice/multi] instance. +2. providing a single array of slice arguments. +3. providing slice arguments as separate arguments. + +The following example demonstrates each invocation style achieving equivalent results. + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var Slice = require( '@stdlib/slice/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function clbk() { + return 5.0; +} + +var opts = { + 'dtype': 'float64' +}; + +// 1. Using a MultiSlice: +var x = zeros( [ 3, 4 ], opts ); + +var s0 = new Slice( 1, 3 ); +var s1 = new Slice( 2, 4 ); +var s = new MultiSlice( s0, s1 ); + +var out = fillSliceBy( x, s, clbk ); +// returns + +var arr = ndarray2array( out ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 5.0, 5.0 ], [ 0.0, 0.0, 5.0, 5.0 ] ] + +// 2. Using an array of slice arguments: +x = zeros( [ 3, 4 ], opts ); + +s0 = new Slice( 1, 3 ); +s1 = new Slice( 2, 4 ); +s = new MultiSlice( s0, s1 ); + +out = fillSliceBy( x, [ s0, s1 ], clbk ); +// returns + +arr = ndarray2array( out ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 5.0, 5.0 ], [ 0.0, 0.0, 5.0, 5.0 ] ] + +// 3. Providing separate arguments: +x = zeros( [ 3, 4 ], opts ); + +s0 = new Slice( 1, 3 ); +s1 = new Slice( 2, 4 ); +s = new MultiSlice( s0, s1 ); + +out = fillSliceBy( x, s0, s1, clbk ); +// returns + +arr = ndarray2array( out ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 5.0, 5.0 ], [ 0.0, 0.0, 5.0, 5.0 ] ] +``` + +The function supports the following options: + +- **strict**: boolean indicating whether to enforce strict bounds checking. + +By default, the function throws an error when provided a slice which exceeds array bounds. To ignore slice indices exceeding array bounds, set the `strict` option to `false`. + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var Slice = require( '@stdlib/slice/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function clbk() { + return 5.0; +} + +var x = zeros( [ 3, 4 ], { + 'dtype': 'float64' +}); + +// Define the fill region: +var s0 = new Slice( 1, null, 1 ); +var s1 = new Slice( 10, 20, 1 ); +var s = new MultiSlice( s0, s1 ); + +var opts = { + 'strict': false +}; + +// Fill the region with a scalar value: +var y = fillSliceBy( x, s, opts, clbk ); +// returns + +var arr = ndarray2array( x ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0 ] ] +``` + +To set the callback function execution context, provide a `thisArg`. + + + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var Slice = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function fcn( value ) { + return value + this.factor; +} + +var x = zeros( [ 3, 4 ], { + 'dtype': 'float64' +}); + +var ctx = { + 'factor': 10.0 +}; + +// Define the slice region: +var s0 = new Slice( 1, 3 ); +var s1 = new Slice( 2, 4 ); +var s = new MultiSlice( s0, s1 ); + +var y = fillSliceBy( x, s, fcn, ctx ); +// returns + +var arr = ndarray2array( y ); +// returns [ [ 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0 ], [ 0.0, 0.0, 10.0, 10.0 ] ] +``` + +The callback function is provided the following arguments: + +- **value**: current array element. +- **indices**: current array element indices. +- **arr**: the input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- An input [ndarray][@stdlib/ndarray/ctor] **must** be writable. If provided a **read-only** [ndarray][@stdlib/ndarray/ctor], the function throws an error. +- A **slice argument** must be either a [`Slice`][@stdlib/slice/ctor], an integer, `null`, or `undefined`. +- The function **mutates** the input [ndarray][@stdlib/ndarray/ctor]. +- The function assumes that each element in the underlying input [ndarray][@stdlib/ndarray/ctor] data buffer has one, and only one, corresponding element in input [ndarray][@stdlib/ndarray/ctor] view (i.e., a provided [ndarray][@stdlib/ndarray/ctor] is not a broadcasted [ndarray][@stdlib/ndarray/ctor] view). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var Slice = require( '@stdlib/slice/ctor' ); +var fillSliceBy = require( '@stdlib/ndarray/fill-slice-by' ); + +// Create a zero-filled ndarray: +var x = zeros( [ 2, 3, 4 ], { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Specify the slice region: +var s0 = new Slice( 1, 2 ); +var s1 = new Slice( null, null ); +var s2 = new Slice( 2, 4 ); +var s = new MultiSlice( s0, s1, s2 ); + +// Fill the slice: +fillSliceBy( x, s, discreteUniform( -100, 100 ) ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.1d.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.1d.js new file mode 100644 index 000000000000..b1882ceafedf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.1d.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var pkg = require( './../package.json' ).name; +var fillSliceBy = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var orders = [ 'row-major', 'column-major' ]; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {*} value - input value +* @returns {*} input value +*/ +function fcn( value ) { + return value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, order ) { + var xbuf; + var x; + + x = zeros( shape, { + 'dtype': xtype, + 'order': order + }); + xbuf = getData( x ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var s; + var i; + + s = new MultiSlice( null ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + fillSliceBy( x, s, fcn ); + if ( isnan( xbuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( xbuf[ 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 ord; + var sh; + var t1; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < orders.length; k++ ) { + ord = orders[ k ]; + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',xtype='+t1, f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.2d.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.2d.js new file mode 100644 index 000000000000..42f381dba42f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/benchmark/benchmark.2d.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var pkg = require( './../package.json' ).name; +var fillSliceBy = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var orders = [ 'row-major', 'column-major' ]; + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {*} value - input value +* @returns {*} input value +*/ +function fcn( value ) { + return value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, order ) { + var xbuf; + var x; + + x = zeros( shape, { + 'dtype': xtype, + 'order': order + }); + xbuf = getData( x ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var s; + var i; + + s = new MultiSlice( null, null ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + fillSliceBy( x, s, fcn ); + if ( isnan( xbuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( xbuf[ 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 ord; + var sh; + var t1; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < orders.length; k++ ) { + ord = orders[ k ]; + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',xtype='+t1, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',xtype='+t1, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',xtype='+t1, f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/repl.txt new file mode 100644 index 000000000000..8ede17fb2997 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/repl.txt @@ -0,0 +1,73 @@ + +{{alias}}( x, ...s[, options], fcn[, thisArg] ) + Fills an input ndarray view according to a callback function. + + The function *mutates* the input ndarray. + + The function supports three (mutually exclusive) means of providing slice + arguments: + + 1. Providing a single MultiSlice object. + 2. Providing a single array containing slice arguments. + 3. Providing slice arguments as separate arguments. + + An individual slice argument must be either a Slice, an integer, null, or + undefined. + + If providing a MultiSlice object or an array of slice arguments, no other + slice arguments should be provided. + + Mixing function invocation styles (e.g., providing multiple MultiSlice + objects or providing an array of slice arguments followed by additional + slice arguments) is not supported. + + The callback function is provided the following arguments: + + - value: current array element. + - indices: current array element indices. + - arr: the input ndarray. + + Parameters + ---------- + x: ndarrayLike + Input ndarray. + + s: ...MultiSlice|Slice|null|undefined|integer|ArrayLike + Slice arguments. + + options: Object (optional) + Options. + + options.strict: boolean (optional) + Boolean indicating whether to enforce strict bounds checking. Default: + true. + + fcn: Function + Callback function. + + thisArg: any (optional) + Callback function execution context. + + Returns + ------- + out: ndarrayLike + Input ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ], { 'dtype': 'float64' } ); + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + > var s0 = new {{alias:@stdlib/slice/ctor}}( 0, 1 ); + > var s1 = new {{alias:@stdlib/slice/ctor}}( null, null ); + > var s = new {{alias:@stdlib/slice/multi}}( s0, s1 ); + > function f() { return 10.0; }; + > var out = {{alias}}( x, s, f ); + > var bool = ( out === x ) + true + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ [ 10.0, 10.0 ], [ 0.0, 0.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/index.d.ts new file mode 100644 index 000000000000..5bd3b71572a8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/index.d.ts @@ -0,0 +1,574 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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, complexndarray, genericndarray } from '@stdlib/types/ndarray'; +import { MultiSlice, Slice } from '@stdlib/types/slice'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Boolean indicating whether to enforce strict bounds checking (default: true). + */ + strict?: boolean; +} + +/** +* Slice argument. +*/ +type SliceArgument = Slice | number | null | undefined; + +/** +* Callback invoked for each ndarray element. +* +* @returns fill value +*/ +type Nullary = ( this: ThisArg ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @returns fill value +*/ +type Unary = ( this: ThisArg, value: T ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @returns fill value +*/ +type Binary = ( this: ThisArg, value: T, indices: Array ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns fill value +*/ +type Ternary = ( this: ThisArg, value: T, indices: Array, arr: V ) => U; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns fill value +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 5.0, 0.0 ); +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'complex128' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 5.0, 0.0 ); +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'complex128' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +*/ +declare function fillSliceBy( x: V, s: MultiSlice | ArrayLike, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param options - function options +* @param options.strict - boolean indicating whether to enforce strict bounds checking +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 5.0, 0.0 ); +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'complex128' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, {}, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 5.0, 0.0 ); +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'complex128' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], {}, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +*/ +declare function fillSliceBy( x: V, s: MultiSlice | ArrayLike, options: Options, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param args - slice, option, callback and callback execution context arguments +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* function clbk() { +* return new Complex128( 5.0, 0.0 ); +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'complex128' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* +* var y = fillSliceBy( x, s0, s1, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +*/ +declare function fillSliceBy( x: V, ...args: Array | ThisParameterType>> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = genericndarray, ThisArg = unknown>( x: V, s: MultiSlice | ArrayLike, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param options - function options +* @param options.strict - boolean indicating whether to enforce strict bounds checking +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, {}, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], {}, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = genericndarray, ThisArg = unknown>( x: V, s: MultiSlice | ArrayLike, options: Options, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param args - slice, option, callback and callback execution context arguments +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* +* var y = fillSliceBy( x, s0, s1, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = genericndarray, ThisArg = unknown>( x: V, ...args: Array | ThisParameterType>> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'float64' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'float64' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = typedndarray, ThisArg = unknown>( x: V, s: MultiSlice | ArrayLike, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param s - slice argument +* @param options - function options +* @param options.strict - boolean indicating whether to enforce strict bounds checking +* @param clbk - callback function +* @param thisArg - callback function execution context +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, {}, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, [ s0, s1 ], {}, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = typedndarray, ThisArg = unknown>( x: V, s: MultiSlice | ArrayLike, options: Options, clbk: Callback, thisArg?: ThisParameterType> ): V; + +/** +* Fills an input ndarray view according to a callback function. +* +* @param x - input ndarray +* @param args - slice, option, callback and callback execution context arguments +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'generic' +* }); +* +* // Specify the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* +* var y = fillSliceBy( x, s0, s1, clbk ); +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ +declare function fillSliceBy = typedndarray, ThisArg = unknown>( x: V, ...args: Array | ThisParameterType>> ): V; + + +// EXPORTS // + +export = fillSliceBy; diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/test.ts new file mode 100644 index 000000000000..7ea911e27099 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/docs/types/test.ts @@ -0,0 +1,224 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/// + +import { ComplexLike } from '@stdlib/types/complex'; +import zeros = require( '@stdlib/ndarray/zeros' ); +import Complex128 = require( '@stdlib/complex/float64/ctor' ); +import MultiSlice = require( '@stdlib/slice/multi' ); +import fillSliceBy = require( './index' ); + +/** +* Real-valued callback function. +* +* @returns fill value +*/ +function fcn1(): number { + return 10.0; +} + +/** +* Complex-valued callback function. +* +* @returns fill value +*/ +function fcn2(): ComplexLike { + return new Complex128( 10.0, 10.0 ); +} + + +// TESTS // + +// The function returns an ndarray... +{ + const s = new MultiSlice( null, null ); + + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), s, fcn1 ); // $ExpectType float64ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), s, fcn2 ); // $ExpectType complex128ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), s, fcn1 ); // $ExpectType genericndarray + + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), s, {}, fcn1 ); // $ExpectType float64ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), s, {}, fcn2 ); // $ExpectType complex128ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), s, {}, fcn1 ); // $ExpectType genericndarray + + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), s, fcn1, {} ); // $ExpectType float64ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), s, fcn2, {} ); // $ExpectType complex128ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), s, fcn1, {} ); // $ExpectType genericndarray + + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'float64' } ), s, {}, fcn1, {} ); // $ExpectType float64ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), s, {}, fcn2, {} ); // $ExpectType complex128ndarray + fillSliceBy( zeros( [ 2, 2 ], { 'dtype': 'generic' } ), s, {}, fcn1, {} ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray-like object... +{ + const s = new MultiSlice( null, null ); + + fillSliceBy( '5', s, fcn1 ); // $ExpectError + fillSliceBy( 5, s, fcn1 ); // $ExpectError + fillSliceBy( true, s, fcn1 ); // $ExpectError + fillSliceBy( false, s, fcn1 ); // $ExpectError + fillSliceBy( null, s, fcn1 ); // $ExpectError + fillSliceBy( undefined, s, fcn1 ); // $ExpectError + fillSliceBy( {}, s, fcn1 ); // $ExpectError + fillSliceBy( [ 1 ], s, fcn1 ); // $ExpectError + fillSliceBy( ( x: number ): number => x, s, fcn1 ); // $ExpectError + + fillSliceBy( '5', s, {}, fcn1 ); // $ExpectError + fillSliceBy( 5, s, {}, fcn1 ); // $ExpectError + fillSliceBy( true, s, {}, fcn1 ); // $ExpectError + fillSliceBy( false, s, {}, fcn1 ); // $ExpectError + fillSliceBy( null, s, {}, fcn1 ); // $ExpectError + fillSliceBy( undefined, s, {}, fcn1 ); // $ExpectError + fillSliceBy( {}, s, {}, fcn1 ); // $ExpectError + fillSliceBy( [ 1 ], s, {}, fcn1 ); // $ExpectError + fillSliceBy( ( x: number ): number => x, s, {}, fcn1 ); // $ExpectError + + fillSliceBy( '5', s, fcn1, {} ); // $ExpectError + fillSliceBy( 5, s, fcn1, {} ); // $ExpectError + fillSliceBy( true, s, fcn1, {} ); // $ExpectError + fillSliceBy( false, s, fcn1, {} ); // $ExpectError + fillSliceBy( null, s, fcn1, {} ); // $ExpectError + fillSliceBy( undefined, s, fcn1, {} ); // $ExpectError + fillSliceBy( {}, s, fcn1, {} ); // $ExpectError + fillSliceBy( [ 1 ], s, fcn1, {} ); // $ExpectError + fillSliceBy( ( x: number ): number => x, s, fcn1, {} ); // $ExpectError + + fillSliceBy( '5', s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( 5, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( true, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( false, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( null, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( undefined, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( {}, s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( [ 1 ], s, {}, fcn1, {} ); // $ExpectError + fillSliceBy( ( x: number ): number => x, s, {}, fcn1, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid slice argument... +{ + const x = zeros( [ 2, 2 ] ); + + fillSliceBy( x, '5', fcn1 ); // $ExpectError + fillSliceBy( x, false, fcn1 ); // $ExpectError + fillSliceBy( x, true, fcn1 ); // $ExpectError + fillSliceBy( x, [ '5' ], fcn1 ); // $ExpectError + fillSliceBy( x, ( x: number ): number => x, fcn1 ); // $ExpectError + + fillSliceBy( x, '5', {}, fcn1 ); // $ExpectError + fillSliceBy( x, false, {}, fcn1 ); // $ExpectError + fillSliceBy( x, true, {}, fcn1 ); // $ExpectError + fillSliceBy( x, [ '5' ], {}, fcn1 ); // $ExpectError + fillSliceBy( x, ( x: number ): number => x, {}, fcn1 ); // $ExpectError + + fillSliceBy( x, '5', fcn1, {} ); // $ExpectError + fillSliceBy( x, false, fcn1, {} ); // $ExpectError + fillSliceBy( x, true, fcn1, {} ); // $ExpectError + fillSliceBy( x, [ '5' ], fcn1, {} ); // $ExpectError + fillSliceBy( x, ( x: number ): number => x, fcn1, {} ); // $ExpectError + + fillSliceBy( x, '5', {}, fcn1, {} ); // $ExpectError + fillSliceBy( x, false, {}, fcn1, {} ); // $ExpectError + fillSliceBy( x, true, {}, fcn1, {} ); // $ExpectError + fillSliceBy( x, [ '5' ], {}, fcn1, {} ); // $ExpectError + fillSliceBy( x, ( x: number ): number => x, {}, fcn1, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ] ); + const s = new MultiSlice( null, null ); + + fillSliceBy( x, s, '5', fcn1 ); // $ExpectError + fillSliceBy( x, s, 5, fcn1 ); // $ExpectError + fillSliceBy( x, s, null, fcn1 ); // $ExpectError + fillSliceBy( x, s, true, fcn1 ); // $ExpectError + fillSliceBy( x, s, false, fcn1 ); // $ExpectError + fillSliceBy( x, s, [ '5' ], fcn1 ); // $ExpectError + fillSliceBy( x, s, ( x: number ): number => x, fcn1 ); // $ExpectError + + fillSliceBy( x, s, '5', fcn1, {} ); // $ExpectError + fillSliceBy( x, s, 5, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, null, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, true, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, false, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, [ '5' ], fcn1, {} ); // $ExpectError + fillSliceBy( x, s, ( x: number ): number => x, fcn1, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `strict` option which is not a boolean... +{ + const x = zeros( [ 2, 2 ] ); + const s = new MultiSlice( null, null ); + + fillSliceBy( x, s, { 'strict': '5' }, fcn1 ); // $ExpectError + fillSliceBy( x, s, { 'strict': 5 }, fcn1 ); // $ExpectError + fillSliceBy( x, s, { 'strict': null }, fcn1 ); // $ExpectError + fillSliceBy( x, s, { 'strict': [ '5' ] }, fcn1 ); // $ExpectError + fillSliceBy( x, s, { 'strict': {} }, fcn1 ); // $ExpectError + fillSliceBy( x, s, { 'strict': ( x: number ): number => x }, fcn1 ); // $ExpectError + + fillSliceBy( x, s, { 'strict': '5' }, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, { 'strict': 5 }, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, { 'strict': null }, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, { 'strict': [ '5' ] }, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, { 'strict': {} }, fcn1, {} ); // $ExpectError + fillSliceBy( x, s, { 'strict': ( x: number ): number => x }, fcn1, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback argument which is not a function... +{ + const x = zeros( [ 2, 2 ] ); + const s = new MultiSlice( null, null ); + + fillSliceBy( x, s, '5' ); // $ExpectError + fillSliceBy( x, s, 5 ); // $ExpectError + fillSliceBy( x, s, true ); // $ExpectError + fillSliceBy( x, s, false ); // $ExpectError + fillSliceBy( x, s, null ); // $ExpectError + fillSliceBy( x, s, undefined ); // $ExpectError + fillSliceBy( x, s, {} ); // $ExpectError + fillSliceBy( x, s, [ 1 ] ); // $ExpectError + + fillSliceBy( x, s, {}, '5' ); // $ExpectError + fillSliceBy( x, s, {}, 5 ); // $ExpectError + fillSliceBy( x, s, {}, true ); // $ExpectError + fillSliceBy( x, s, {}, false ); // $ExpectError + fillSliceBy( x, s, {}, null ); // $ExpectError + fillSliceBy( x, s, {}, undefined ); // $ExpectError + fillSliceBy( x, s, {}, {} ); // $ExpectError + fillSliceBy( x, s, {}, [ 1 ] ); // $ExpectError + + fillSliceBy( x, s, {}, '5', {} ); // $ExpectError + fillSliceBy( x, s, {}, 5, {} ); // $ExpectError + fillSliceBy( x, s, {}, true, {} ); // $ExpectError + fillSliceBy( x, s, {}, false, {} ); // $ExpectError + fillSliceBy( x, s, {}, {} ); // $ExpectError + fillSliceBy( x, s, {}, undefined, {} ); // $ExpectError + fillSliceBy( x, s, {}, {}, {} ); // $ExpectError + fillSliceBy( x, s, {}, [ 1 ], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + const s = new MultiSlice( null, null ); + + fillSliceBy(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/examples/index.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/examples/index.js new file mode 100644 index 000000000000..805b41556717 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var Slice = require( '@stdlib/slice/ctor' ); +var fillSliceBy = require( './../lib' ); + +// Create a zero-filled ndarray: +var x = zeros( [ 2, 3, 4 ], { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Specify the slice region: +var s0 = new Slice( 1, 2 ); +var s1 = new Slice( null, null ); +var s2 = new Slice( 2, 4 ); +var s = new MultiSlice( s0, s1, s2 ); + +// Fill the slice: +fillSliceBy( x, s, discreteUniform( -100, 100 ) ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/index.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/index.js new file mode 100644 index 000000000000..138d8f5d2190 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/index.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 view according to a callback function. +* +* @module @stdlib/ndarray/fill-slice-by +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var fillSliceBy = require( '@stdlib/ndarray/fill-slice-by' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'float64' +* }); +* +* // Define the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5, 5 ], [ 0, 0, 5, 5 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/main.js new file mode 100644 index 000000000000..f92008264819 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/lib/main.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isFunction = require( '@stdlib/assert/is-function' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isMultiSlice = require( '@stdlib/assert/is-multi-slice' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var args2multislice = require( '@stdlib/slice/base/args2multislice' ); +var slice = require( '@stdlib/ndarray/base/slice' ); +var base = require( '@stdlib/ndarray/base/fill-by' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Fills an input ndarray view according to a callback function. +* +* @param {ndarray} x - input ndarray +* @param {...*} s - slice arguments +* @param {Options} [options] - options +* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @throws {TypeError} callback argument must be a function +* @throws {Error} too many arguments +* @throws {Error} cannot write to a read-only ndarray +* @returns {ndarray} input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var Slice = require( '@stdlib/slice/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function clbk() { +* return 5.0; +* } +* +* var x = zeros( [ 3, 4 ], { +* 'dtype': 'float64' +* }); +* +* // Define the fill region: +* var s0 = new Slice( 1, 3 ); +* var s1 = new Slice( 2, 4 ); +* var s = new MultiSlice( s0, s1 ); +* +* var y = fillSliceBy( x, s, clbk ); +* // returns +* +* var bool = ( y === x ); +* // returns true +* +* var arr = ndarray2array( x ); +* // returns [ [ 0, 0, 0, 0 ], [ 0, 0, 5.0, 5.0 ], [ 0, 0, 5.0, 5.0 ] ] +*/ +function fillSliceBy() { + var options; + var flgOpts; + var flgCtx; + var nargs; + var sArgs; + var opts; + var ctx; + var cb; + var ns; + var S; + var s; + var i; + var x; + + opts = { + 'strict': true + }; + flgOpts = false; + flgCtx = false; + nargs = arguments.length; + x = arguments[ 0 ]; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( isReadOnly( x ) ) { + throw new Error( 'invalid argument. Cannot write to a read-only array.' ); + } + + // Resolve function arguments: + if ( isFunction( arguments[ nargs - 1 ] ) ) { // Case: fillSliceBy( x, ???, ???, clbk ) + cb = arguments[ nargs - 1 ]; + if ( isPlainObject( arguments[ nargs - 2 ] ) ) { // Case: fillSliceBy( x, ???, options, clbk ) + flgOpts = true; + options = arguments[ nargs - 2 ]; + if ( nargs > 3 ) { + s = arguments[ nargs - 3 ]; + } + } else if ( nargs > 2 ) { // Case: fillSliceBy( x, s, clbk ) + s = arguments[ nargs - 2 ]; + } + } else if ( isFunction( arguments[ nargs - 2 ] ) ) { // Case: fillSliceBy( x, ???, ???, clbk, thisArg ) + cb = arguments[ nargs -2 ]; + ctx = arguments[ nargs - 1 ]; + flgCtx = true; + if ( isPlainObject( arguments[ nargs - 3 ] ) ) { // Case: fillSliceBy( x, ???, options, clbk, thisArg ) + flgOpts = true; + options = arguments[ nargs - 3 ]; + s = arguments[ nargs - 4 ]; + } else { // Case: fillSliceBy( x, s, clbk, thisArg ) + s = arguments[ nargs - 3 ]; + } + } else { + throw new TypeError( 'invalid argument. Callback argument must be a function' ); + } + + // Resolve function options: + if ( flgOpts ) { + if ( hasOwnProp( options, 'strict' ) ) { + if ( !isBoolean( options.strict ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + } + opts.strict = options.strict; + } + } + + // Resolve slice: + if ( isMultiSlice( s ) ) { + S = s; + if ( nargs > 5 ) { + throw new Error( 'invalid invocation. Too many arguments.' ); + } + } else { + if ( isArrayLikeObject( s ) ) { + sArgs = s; + if ( nargs > 5 ) { + throw new Error( 'invalid invocation. Too many arguments.' ); + } + } else { + sArgs = []; + ns = 0; + if ( flgCtx && flgOpts ) { + ns = nargs - 3; + } else if ( flgCtx && !flgOpts ) { + ns = nargs - 2; + } else if ( !flgCtx && flgOpts ) { + ns = nargs - 2; + } else { + ns = nargs - 1; + } + for ( i = 1; i < ns; i++ ) { + sArgs.push( arguments[ i ] ); + } + } + try { + S = args2multislice( sArgs ); + } catch ( err ) { // eslint-disable-line no-unused-vars + // Search for the first offending value... + for ( i = 0; i < sArgs.length; i++ ) { + try { + new MultiSlice( sArgs[ i ] ); // eslint-disable-line no-new + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. Slice arguments must be either a Slice, integer, null, or undefined. Value: `%s`.', String( sArgs[ i ] ) ) ); + } + } + } + } + base( slice( x, S, opts.strict, true ), cb, ctx ); + return x; +} + + +// EXPORTS // + +module.exports = fillSliceBy; diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/package.json b/lib/node_modules/@stdlib/ndarray/fill-slice-by/package.json new file mode 100644 index 000000000000..7a7f28788154 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/fill-slice-by", + "version": "0.0.0", + "description": "Fill an input ndarray view according to a callback function.", + "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", + "strided", + "array", + "ndarray", + "fill", + "slice", + "view", + "transform", + "set", + "setitem" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/fill-slice-by/test/test.js b/lib/node_modules/@stdlib/ndarray/fill-slice-by/test/test.js new file mode 100644 index 000000000000..4883c3261ec6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fill-slice-by/test/test.js @@ -0,0 +1,2396 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var ndzeros = require( '@stdlib/ndarray/zeros' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Slice = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var fillSliceBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fillSliceBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (multislice)', function test( t ) { + var values; + var s; + var i; + + s = new MultiSlice( null ); + 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() { + fillSliceBy( value, s, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', 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() { + fillSliceBy( value, [], fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', 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() { + fillSliceBy( value, null, null, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a first argument which is a read-only ndarray (multislice)', function test( t ) { + var x; + var s; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64', + 'readonly': true + }); + s = new MultiSlice( null ); + + t.throws( badValue( x ), Error, 'throws an error' ); + t.end(); + + function badValue( value ) { + return function badValue() { + fillSliceBy( value, s, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a first argument which is a read-only ndarray (array)', function test( t ) { + var x; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64', + 'readonly': true + }); + + t.throws( badValue( x ), Error, 'throws an error' ); + t.end(); + + function badValue( value ) { + return function badValue() { + fillSliceBy( value, [], fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a first argument which is a read-only ndarray (slice arguments)', function test( t ) { + var x; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64', + 'readonly': true + }); + + t.throws( badValue( x ), Error, 'throws an error' ); + t.end(); + + function badValue( value ) { + return function badValue() { + fillSliceBy( value, null, null, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (multislice)', function test( t ) { + var values; + var x; + var s; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + s = new MultiSlice( null ); + + 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() { + fillSliceBy( x, s, value, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { + var values; + var x; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + + 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() { + fillSliceBy( x, [], value, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (slice arguments)', function test( t ) { + var values; + var x; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + + 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() { + fillSliceBy( x, null, null, value, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (multislice)', function test( t ) { + var values; + var x; + var s; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + s = new MultiSlice( null ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, s, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (array)', function test( t ) { + var values; + var x; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, [], value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (slice arguments)', function test( t ) { + var values; + var x; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, null, null, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (multislice, options)', function test( t ) { + var values; + var x; + var s; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + s = new MultiSlice( null ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, s, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (array, options)', function test( t ) { + var values; + var x; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, [], {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback which is not a function (slice arguments, options)', function test( t ) { + var values; + var x; + var i; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + 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() { + fillSliceBy( x, null, null, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `strict` option which is not a boolean (multislice)', function test( t ) { + var values; + var opts; + var x; + var s; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + s = new MultiSlice( null ); + + 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() { + opts = { + 'strict': value + }; + fillSliceBy( x, s, opts, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { + var values; + var opts; + var x; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + + 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() { + opts = { + 'strict': value + }; + fillSliceBy( x, [], opts, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided a `strict` option which is not a boolean (slice arguments)', function test( t ) { + var values; + var opts; + var x; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + [], + function noop() {} + ]; + x = ndzeros( [ 2 ], { + 'dtype': 'float64' + }); + + 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() { + opts = { + 'strict': value + }; + fillSliceBy( x, null, null, opts, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided an invalid slice argument', function test( t ) { + var values; + var x; + var s; + var i; + + values = [ + '5', + NaN, + function noop() {} + ]; + x = ndzeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + s = null; + + 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() { + fillSliceBy( x, s, value, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if provided an invalid slice argument (options)', function test( t ) { + var values; + var x; + var s; + var i; + + values = [ + '5', + NaN, + function noop() {} + ]; + x = ndzeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + s = null; + + 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() { + fillSliceBy( x, s, value, {}, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (multislice)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + new MultiSlice( null ), + new MultiSlice( null, null, null ), + new MultiSlice( null, null, null, null ) + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (arrays)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + [ null ], + [ null, null, null ], + [ null, null, null, null ] + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (slice arguments)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + [ null ], + [ null, null, null ], + [ null, null, null, null ] + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + if ( s.length === 1 ) { + return fillSliceBy( x, s[ 0 ], fcn ); + } + if ( s.length === 2 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], fcn ); + } + if ( s.length === 3 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], s[ 2 ], fcn ); + } + if ( s.length === 4 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], s[ 2 ], s[ 3 ], fcn ); + } + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (multislice, options)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + new MultiSlice( null ), + new MultiSlice( null, null, null ), + new MultiSlice( null, null, null, null ) + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, {}, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (arrays, options)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + [ null ], + [ null, null, null ], + [ null, null, null, null ] + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, {}, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'the function throws an error if the number of slice dimensions does not match the number of input array dimensions (slice arguments, options)', function test( t ) { + var slices; + var x; + var i; + + x = ndzeros( [ 2, 2 ] ); + + slices = [ + [ null ], + [ null, null, null ], + [ null, null, null, null ] + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + if ( s.length === 1 ) { + return fillSliceBy( x, s[ 0 ], {}, fcn ); + } + if ( s.length === 2 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], {}, fcn ); + } + if ( s.length === 3 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], s[ 2 ], {}, fcn ); + } + if ( s.length === 4 ) { + return fillSliceBy( x, s[ 0 ], s[ 1 ], s[ 2 ], s[ 3 ], {}, fcn ); + } + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'by default, the function throws an error when a slice exceeds output array bounds', function test( t ) { + var slices; + var x; + var s; + var i; + + x = ndzeros( [ 2, 2 ] ); + + s = new Slice( 10, 20, 1 ); + slices = [ + new MultiSlice( 10, 0 ), + new MultiSlice( null, s ), + new MultiSlice( s, null ), + new MultiSlice( s, s ) + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { + var slices; + var opts; + var x; + var s; + var i; + + x = ndzeros( [ 2, 2 ] ); + opts = { + 'strict': true + }; + s = new Slice( 10, 20, 1 ); + slices = [ + new MultiSlice( 10, 0 ), + new MultiSlice( null, s ), + new MultiSlice( s, null ), + new MultiSlice( s, s ) + ]; + for ( i = 0; i < slices.length; i++ ) { + t.throws( badValues( slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); + } + t.end(); + + function badValues( s ) { + return function badValues() { + fillSliceBy( x, s, opts, fcn ); + }; + } + + function fcn() { + return 10.0; + } +}); + +tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { + var actual; + var slices; + var opts; + var x; + var s; + var i; + + x = ndzeros( [ 2, 2 ] ); + opts = { + 'strict': false + }; + s = new Slice( 10, 20, 1 ); + slices = [ + new MultiSlice( 10, 0 ), + new MultiSlice( null, s ), + new MultiSlice( s, null ), + new MultiSlice( s, s ) + ]; + for ( i = 0; i < slices.length; i++ ) { + actual = fillSliceBy( x, slices[ i ], opts, fcn ); + t.strictEqual( x, actual, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( x ), new Float64Array( 4 ) ), true, 'returns expected value' ); + } + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (multislice)', function test( t ) { + var actual; + var x; + var s; + + x = scalar2ndarray( 3.14 ); + s = new MultiSlice(); + + actual = fillSliceBy( x, s, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (array)', function test( t ) { + var actual; + var x; + var s; + + x = scalar2ndarray( 3.14 ); + s = []; + + actual = fillSliceBy( x, s, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (slice arguments)', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 3.14 ); + + actual = fillSliceBy( x, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (multislice, options)', function test( t ) { + var actual; + var x; + var s; + + x = scalar2ndarray( 3.14 ); + s = new MultiSlice(); + + actual = fillSliceBy( x, s, {}, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (array)', function test( t ) { + var actual; + var x; + var s; + + x = scalar2ndarray( 3.14 ); + s = []; + + actual = fillSliceBy( x, s, {}, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function supports filling a zero-dimensional ndarray (slice arguments)', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 3.14 ); + + actual = fillSliceBy( x, {}, fcn ); + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( actual.get(), 10.0, 'returns expected value' ); + + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, multislice)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + fillSliceBy( x, s, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, array)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, [ s0, s1, s2 ], fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, slice arguments)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, multislice, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s, opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, array, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, [ s0, s1, s2 ], opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, slice arguments, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, multislice)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + fillSliceBy( x, s, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, array)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, slice arguments)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, multislice, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, array, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (row-major, contiguous, accessors, slice arguments, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, multislice)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + fillSliceBy( x, s, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, array)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, [ s0, s1, s2 ], fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, slice arguments)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, multislice, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s, opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, array, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, [ s0, s1, s2 ], opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, slice arguments, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return 10.0; + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, multislice)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + fillSliceBy( x, s, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, array)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, slice arguments)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + + fillSliceBy( x, s0, s1, s2, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, multislice, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var s; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, array, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function fills an input ndarray view with a specified value (column-major, contiguous, accessors, slice arguments, options)', function test( t ) { + var expected; + var opts; + var ord; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + opts = { + 'strict': false + }; + + fillSliceBy( x, s0, s1, s2, opts, fcn ); + + expected = new Complex128Array([ + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0, + -10.0, + -20.0, + -10.0, + -20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( getData( x ), expected ), true, 'returns expected value' ); + t.end(); + + function fcn() { + return new Complex128( -10.0, -20.0 ); + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var ord; + var buf; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + var s; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + ctx = { + 'scalar': 10.0 + }; + fillSliceBy( x, s, fcn, ctx ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 5.0, + 6.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + expected = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function fcn( value, idx, array ) { + values.push( value ); + indices.push( idx ); + arrays.push( array ); + return this.scalar; // eslint-disable-line no-invalid-this + } +}); + +tape( 'the function supports providing an execution context(options)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var opts; + var ctx; + var ord; + var buf; + var sh; + var st; + var dt; + var s0; + var s1; + var s2; + var o; + var x; + var s; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + s0 = new Slice( 0, 2 ); + s1 = new Slice( null, null ); + s2 = new Slice( null, null ); + s = new MultiSlice( s0, s1, s2 ); + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + ctx = { + 'scalar': 10.0 + }; + opts = { + 'strict': false + }; + fillSliceBy( x, s, opts, fcn, ctx ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 5.0, + 6.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + expected = [ + 1.0, + 2.0, + 3.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + t.end(); + + function fcn( value, idx, array ) { + values.push( value ); + indices.push( idx ); + arrays.push( array ); + return this.scalar; // eslint-disable-line no-invalid-this + } +});