diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/README.md b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/README.md new file mode 100644 index 000000000000..fef81638e48d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/README.md @@ -0,0 +1,234 @@ + + +# indexOfFalsy + +> Return the index of the first falsy element along an [ndarray][@stdlib/ndarray/ctor] dimension. + +
+ +## Usage + +```javascript +var indexOfFalsy = require( '@stdlib/blas/ext/index-of-falsy' ); +``` + +#### indexOfFalsy( x\[, fromIndex]\[, options] ) + +Returns the index of the first falsy element along an [ndarray][@stdlib/ndarray/ctor] dimension. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +// returns + +// Perform operation: +var out = indexOfFalsy( x ); +// returns [ 2 ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer index or generic [data type][@stdlib/ndarray/dtypes]. +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +If the function is unable to find a falsy element along an [ndarray][@stdlib/ndarray/ctor] dimension, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +// returns + +// Perform operation: +var out = indexOfFalsy( x ); +// returns [ -1 ] +``` + +By default, the function begins searching from the first element along the reduction dimension. To begin searching from a different index, provide a `fromIndex` argument. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +// returns + +// Perform operation: +var out = indexOfFalsy( x, 3 ); +// returns [ 4 ] +``` + +By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 0.0, 2.0 ], [ 3.0, 0.0 ] ] ); + +var out = indexOfFalsy( x, { + 'dim': 0 +}); +// returns [ 0, 1 ] +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 0.0, 2.0 ], [ 3.0, 0.0 ] ] ); + +var opts = { + 'dim': 0, + 'keepdims': true +}; + +var out = indexOfFalsy( x, opts ); +// returns [ [ 0, 1 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var dtype = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 3.0, 0.0, 2.0 ] ); + +var idx = indexOfFalsy( x, { + 'dtype': 'generic' +}); +// returns + +var dt = dtype( idx ); +// returns 'generic' +``` + +#### indexOfFalsy.assign( x\[, fromIndex], out\[, options] ) + +Returns the index of the first falsy element along an [ndarray][@stdlib/ndarray/ctor] dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ 1.0, 3.0, 0.0, 2.0 ] ); +var y = zeros( [], { + 'dtype': 'int32' +}); + +var out = indexOfFalsy.assign( x, y ); +// returns [ 2 ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. + +
+ + + +
+ +## Notes + +- The function explicitly treats `NaN` values as falsy. +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var indexOfFalsy = require( '@stdlib/blas/ext/index-of-falsy' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 1, { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var idx = indexOfFalsy( x, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..85526ebc1f34 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.assign.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ones = require( '@stdlib/ndarray/ones' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var indexOfFalsy = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = ones( [ len ], options ); + out = zeros( [], { + 'dtype': 'int32' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = indexOfFalsy.assign( x, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.js new file mode 100644 index 000000000000..267919dca986 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ones = require( '@stdlib/ndarray/ones' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var indexOfFalsy = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = ones( [ len ], options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = indexOfFalsy( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/repl.txt new file mode 100644 index 000000000000..573d4dd4cfd0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/repl.txt @@ -0,0 +1,106 @@ + +{{alias}}( x[, fromIndex][, options] ) + Returns the index of the first falsy element along an ndarray dimension. + + If unable to find a falsy element along an ndarray dimension, the + corresponding element in the returned ndarray is `-1`. + + The function explicitly treats `NaN` values as falsy. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + fromIndex: ndarray|integer (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the non- + reduced dimensions of the input ndarray. For example, given the input + shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a + shape which is broadcast-compatible with the shape `[3, 4]`. If provided + a negative integer, the index at which to begin searching along a + dimension is determined by counting backward from the last element + (where -1 refers to the last element). Default: 0. + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output array data type. Must be an integer index or "generic" data type. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 3.0, 0.0, 2.0 ] ); + > var y = {{alias}}( x ) + [ 2 ] + + +{{alias}}.assign( x[, fromIndex], out[, options] ) + Returns the index of the first falsy element along an ndarray dimension + and assigns results to a provided output ndarray. + + If unable to find a falsy element along an ndarray dimension, the + corresponding element in the returned ndarray is `-1`. + + The function explicitly treats `NaN` values as falsy. + + Parameters + ---------- + x: ndarray + Input array. Must have at least one dimension. + + fromIndex: ndarray|integer (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the non- + reduced dimensions of the input ndarray. For example, given the input + shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a + shape which is broadcast-compatible with the shape `[3, 4]`. If provided + a negative integer, the index at which to begin searching along a + dimension is determined by counting backward from the last element + (where -1 refers to the last element). Default: 0. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 3.0, 0.0, 2.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); + > var y = {{alias}}.assign( x, out ) + [ 2 ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/index.d.ts new file mode 100644 index 000000000000..b451171bc4ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/index.d.ts @@ -0,0 +1,222 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* From index. +*/ +type FromIndex = typedndarray | number; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * Dimension over which to perform operation. Default: `-1`. + * + * ## Notes + * + * - If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). + */ + dim?: number; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + + +/** +* Interface describing `indexOfFalsy`. +*/ +interface IndexOfFalsy { + /** + * Returns the index of the first falsy element along an ndarray dimension. + * + * ## Notes + * + * - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * - The function explicitly treats `NaN` values as falsy. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 3.0, 0.0, 2.0 ] ); + * + * var y = indexOfFalsy( x ); + * // returns [ 2 ] + */ + ( x: InputArray, options?: Options ): OutputArray; + + /** + * Returns the index of the first falsy element along an ndarray dimension. + * + * ## Notes + * + * - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * - The function explicitly treats `NaN` values as falsy. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); + * + * var y = indexOfFalsy( x, 3 ); + * // returns [ 4 ] + */ + ( x: InputArray, fromIndex: FromIndex, options?: Options ): OutputArray; + + /** + * Returns the index of the first falsy element along an ndarray dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * - The function explicitly treats `NaN` values as falsy. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 3.0, 0.0, 2.0 ] ); + * var y = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = indexOfFalsy.assign( x, y ); + * // returns [ 2 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign( x: InputArray, out: U, options?: BaseOptions ): U; + + /** + * Returns the index of the first falsy element along an ndarray dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * - The function explicitly treats `NaN` values as falsy. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); + * var y = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = indexOfFalsy.assign( x, 3, y ); + * // returns [ 4 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign( x: InputArray, fromIndex: FromIndex, out: U, options?: BaseOptions ): U; +} + +/** +* Returns the index of the first falsy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* - The function explicitly treats `NaN` values as falsy. +* +* @param x - input ndarray +* @param fromIndex - index from which to begin searching +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 3.0, 0.0, 2.0 ] ); +* +* var y = indexOfFalsy( x, 0 ); +* // returns [ 2 ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +* var y = zeros( [], { +* 'dtype': 'int32' +* } ); +* +* var out = indexOfFalsy.assign( x, 3, y ); +* // returns [ 4 ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const indexOfFalsy: IndexOfFalsy; + + +// EXPORTS // + +export = indexOfFalsy; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/test.ts new file mode 100644 index 000000000000..e836747e1f06 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/docs/types/test.ts @@ -0,0 +1,381 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import indexOfFalsy = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x ); // $ExpectType OutputArray + indexOfFalsy( x, 1 ); // $ExpectType OutputArray + indexOfFalsy( x, {} ); // $ExpectType OutputArray + indexOfFalsy( x, 1, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + indexOfFalsy( '5' ); // $ExpectError + indexOfFalsy( 5 ); // $ExpectError + indexOfFalsy( true ); // $ExpectError + indexOfFalsy( false ); // $ExpectError + indexOfFalsy( null ); // $ExpectError + indexOfFalsy( void 0 ); // $ExpectError + indexOfFalsy( {} ); // $ExpectError + indexOfFalsy( ( x: number ): number => x ); // $ExpectError + + indexOfFalsy( '5', 0 ); // $ExpectError + indexOfFalsy( 5, 0 ); // $ExpectError + indexOfFalsy( true, 0 ); // $ExpectError + indexOfFalsy( false, 0 ); // $ExpectError + indexOfFalsy( null, 0 ); // $ExpectError + indexOfFalsy( void 0, 0 ); // $ExpectError + indexOfFalsy( {}, 0 ); // $ExpectError + indexOfFalsy( ( x: number ): number => x, 0 ); // $ExpectError + + indexOfFalsy( '5', {} ); // $ExpectError + indexOfFalsy( 5, {} ); // $ExpectError + indexOfFalsy( true, {} ); // $ExpectError + indexOfFalsy( false, {} ); // $ExpectError + indexOfFalsy( null, {} ); // $ExpectError + indexOfFalsy( void 0, {} ); // $ExpectError + indexOfFalsy( {}, {} ); // $ExpectError + indexOfFalsy( ( x: number ): number => x, {} ); // $ExpectError + + indexOfFalsy( '5', 0, {} ); // $ExpectError + indexOfFalsy( 5, 0, {} ); // $ExpectError + indexOfFalsy( true, 0, {} ); // $ExpectError + indexOfFalsy( false, 0, {} ); // $ExpectError + indexOfFalsy( null, 0, {} ); // $ExpectError + indexOfFalsy( void 0, 0, {} ); // $ExpectError + indexOfFalsy( {}, 0, {} ); // $ExpectError + indexOfFalsy( ( x: number ): number => x, 0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a from index argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x, '5' ); // $ExpectError + indexOfFalsy( x, true ); // $ExpectError + indexOfFalsy( x, false ); // $ExpectError + indexOfFalsy( x, [] ); // $ExpectError + indexOfFalsy( x, ( x: number ): number => x ); // $ExpectError + + indexOfFalsy( x, '5', {} ); // $ExpectError + indexOfFalsy( x, true, {} ); // $ExpectError + indexOfFalsy( x, false, {} ); // $ExpectError + indexOfFalsy( x, [], {} ); // $ExpectError + indexOfFalsy( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x, '5' ); // $ExpectError + indexOfFalsy( x, true ); // $ExpectError + indexOfFalsy( x, false ); // $ExpectError + indexOfFalsy( x, [] ); // $ExpectError + indexOfFalsy( x, ( x: number ): number => x ); // $ExpectError + + indexOfFalsy( x, 0, '5' ); // $ExpectError + indexOfFalsy( x, 0, true ); // $ExpectError + indexOfFalsy( x, 0, false ); // $ExpectError + indexOfFalsy( x, 0, null ); // $ExpectError + indexOfFalsy( x, 0, [] ); // $ExpectError + indexOfFalsy( x, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x, { 'dtype': '5' } ); // $ExpectError + indexOfFalsy( x, { 'dtype': 5 } ); // $ExpectError + indexOfFalsy( x, { 'dtype': true } ); // $ExpectError + indexOfFalsy( x, { 'dtype': false } ); // $ExpectError + indexOfFalsy( x, { 'dtype': null } ); // $ExpectError + indexOfFalsy( x, { 'dtype': [] } ); // $ExpectError + indexOfFalsy( x, { 'dtype': {} } ); // $ExpectError + indexOfFalsy( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError + + indexOfFalsy( x, 0, { 'dtype': '5' } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': 5 } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': true } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': false } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': null } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': [] } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': {} } ); // $ExpectError + indexOfFalsy( x, 0, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x, { 'dim': '5' } ); // $ExpectError + indexOfFalsy( x, { 'dim': true } ); // $ExpectError + indexOfFalsy( x, { 'dim': false } ); // $ExpectError + indexOfFalsy( x, { 'dim': null } ); // $ExpectError + indexOfFalsy( x, { 'dim': [] } ); // $ExpectError + indexOfFalsy( x, { 'dim': {} } ); // $ExpectError + indexOfFalsy( x, { 'dim': ( x: number ): number => x } ); // $ExpectError + + indexOfFalsy( x, 0, { 'dim': '5' } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': true } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': false } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': null } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': [] } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': {} } ); // $ExpectError + indexOfFalsy( x, 0, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy( x, { 'keepdims': '5' } ); // $ExpectError + indexOfFalsy( x, { 'keepdims': 5 } ); // $ExpectError + indexOfFalsy( x, { 'keepdims': null } ); // $ExpectError + indexOfFalsy( x, { 'keepdims': {} } ); // $ExpectError + indexOfFalsy( x, { 'keepdims': ( x: number ): number => x } ); // $ExpectError + + indexOfFalsy( x, 0, { 'keepdims': '5' } ); // $ExpectError + indexOfFalsy( x, 0, { 'keepdims': 5 } ); // $ExpectError + indexOfFalsy( x, 0, { 'keepdims': null } ); // $ExpectError + indexOfFalsy( x, 0, { 'keepdims': {} } ); // $ExpectError + indexOfFalsy( x, 0, { 'keepdims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy(); // $ExpectError + indexOfFalsy( x, 0, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign( x, y ); // $ExpectType int32ndarray + indexOfFalsy.assign( x, y, {} ); // $ExpectType int32ndarray + indexOfFalsy.assign( x, 1, y ); // $ExpectType int32ndarray + indexOfFalsy.assign( x, 1, y, {} ); // $ExpectType int32ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign( '5', y ); // $ExpectError + indexOfFalsy.assign( 5, y ); // $ExpectError + indexOfFalsy.assign( true, y ); // $ExpectError + indexOfFalsy.assign( false, y ); // $ExpectError + indexOfFalsy.assign( null, y ); // $ExpectError + indexOfFalsy.assign( void 0, y ); // $ExpectError + indexOfFalsy.assign( {}, y ); // $ExpectError + indexOfFalsy.assign( ( x: number ): number => x, y ); // $ExpectError + + indexOfFalsy.assign( '5', 0, y ); // $ExpectError + indexOfFalsy.assign( 5, 0, y ); // $ExpectError + indexOfFalsy.assign( true, 0, y ); // $ExpectError + indexOfFalsy.assign( false, 0, y ); // $ExpectError + indexOfFalsy.assign( null, 0, y ); // $ExpectError + indexOfFalsy.assign( void 0, 0, y ); // $ExpectError + indexOfFalsy.assign( {}, 0, y ); // $ExpectError + indexOfFalsy.assign( ( x: number ): number => x, 0, y ); // $ExpectError + + indexOfFalsy.assign( '5', y, {} ); // $ExpectError + indexOfFalsy.assign( 5, y, {} ); // $ExpectError + indexOfFalsy.assign( true, y, {} ); // $ExpectError + indexOfFalsy.assign( false, y, {} ); // $ExpectError + indexOfFalsy.assign( null, y, {} ); // $ExpectError + indexOfFalsy.assign( void 0, y, {} ); // $ExpectError + indexOfFalsy.assign( {}, y, {} ); // $ExpectError + indexOfFalsy.assign( ( x: number ): number => x, y, {} ); // $ExpectError + + indexOfFalsy.assign( '5', 0, y, {} ); // $ExpectError + indexOfFalsy.assign( 5, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( true, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( false, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( null, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( void 0, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( {}, 0, y, {} ); // $ExpectError + indexOfFalsy.assign( ( x: number ): number => x, 0, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a from index argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign( x, '5', y ); // $ExpectError + indexOfFalsy.assign( x, true, y ); // $ExpectError + indexOfFalsy.assign( x, false, y ); // $ExpectError + indexOfFalsy.assign( x, null, y ); // $ExpectError + indexOfFalsy.assign( x, void 0, y ); // $ExpectError + indexOfFalsy.assign( x, {}, y ); // $ExpectError + indexOfFalsy.assign( x, ( x: number ): number => x, y ); // $ExpectError + + indexOfFalsy.assign( x, '5', y, {} ); // $ExpectError + indexOfFalsy.assign( x, true, y, {} ); // $ExpectError + indexOfFalsy.assign( x, false, y, {} ); // $ExpectError + indexOfFalsy.assign( x, null, y, {} ); // $ExpectError + indexOfFalsy.assign( x, void 0, y, {} ); // $ExpectError + indexOfFalsy.assign( x, {}, y, {} ); // $ExpectError + indexOfFalsy.assign( x, ( x: number ): number => x, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfFalsy.assign( x, '5' ); // $ExpectError + indexOfFalsy.assign( x, 5 ); // $ExpectError + indexOfFalsy.assign( x, true ); // $ExpectError + indexOfFalsy.assign( x, false ); // $ExpectError + indexOfFalsy.assign( x, null ); // $ExpectError + indexOfFalsy.assign( x, void 0 ); // $ExpectError + indexOfFalsy.assign( x, ( x: number ): number => x ); // $ExpectError + + indexOfFalsy.assign( x, '5', {} ); // $ExpectError + indexOfFalsy.assign( x, 5, {} ); // $ExpectError + indexOfFalsy.assign( x, true, {} ); // $ExpectError + indexOfFalsy.assign( x, false, {} ); // $ExpectError + indexOfFalsy.assign( x, null, {} ); // $ExpectError + indexOfFalsy.assign( x, void 0, {} ); // $ExpectError + indexOfFalsy.assign( x, ( x: number ): number => x, {} ); // $ExpectError + + indexOfFalsy.assign( x, 1, '5' ); // $ExpectError + indexOfFalsy.assign( x, 1, 5 ); // $ExpectError + indexOfFalsy.assign( x, 1, true ); // $ExpectError + indexOfFalsy.assign( x, 1, false ); // $ExpectError + indexOfFalsy.assign( x, 1, null ); // $ExpectError + indexOfFalsy.assign( x, 1, void 0 ); // $ExpectError + indexOfFalsy.assign( x, 1, ( x: number ): number => x ); // $ExpectError + + indexOfFalsy.assign( x, 1, '5', {} ); // $ExpectError + indexOfFalsy.assign( x, 1, 5, {} ); // $ExpectError + indexOfFalsy.assign( x, 1, true, {} ); // $ExpectError + indexOfFalsy.assign( x, 1, false, {} ); // $ExpectError + indexOfFalsy.assign( x, 1, null, {} ); // $ExpectError + indexOfFalsy.assign( x, 1, void 0, {} ); // $ExpectError + indexOfFalsy.assign( x, 1, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign( x, y, '5' ); // $ExpectError + indexOfFalsy.assign( x, y, true ); // $ExpectError + indexOfFalsy.assign( x, y, false ); // $ExpectError + indexOfFalsy.assign( x, y, null ); // $ExpectError + indexOfFalsy.assign( x, y, [] ); // $ExpectError + indexOfFalsy.assign( x, y, ( x: number ): number => x ); // $ExpectError + + indexOfFalsy.assign( x, 1, y, '5' ); // $ExpectError + indexOfFalsy.assign( x, 1, y, true ); // $ExpectError + indexOfFalsy.assign( x, 1, y, false ); // $ExpectError + indexOfFalsy.assign( x, 1, y, null ); // $ExpectError + indexOfFalsy.assign( x, 1, y, [] ); // $ExpectError + indexOfFalsy.assign( x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign( x, y, { 'dim': '5' } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': true } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': false } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': null } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': [] } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': {} } ); // $ExpectError + indexOfFalsy.assign( x, y, { 'dim': ( x: number ): number => x } ); // $ExpectError + + indexOfFalsy.assign( x, 1, y, { 'dim': '5' } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': true } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': false } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': null } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': [] } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': {} } ); // $ExpectError + indexOfFalsy.assign( x, 1, y, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOfFalsy.assign(); // $ExpectError + indexOfFalsy.assign( x ); // $ExpectError + indexOfFalsy.assign( x, 1, y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/examples/index.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/examples/index.js new file mode 100644 index 000000000000..70256abdfc6f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var indexOfFalsy = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 1, { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var idx = indexOfFalsy( x, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/assign.js new file mode 100644 index 000000000000..68fb49ddecf2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/assign.js @@ -0,0 +1,218 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ).assign; + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the index of the first falsy element along an ndarray dimension and assigns the results to a provided output ndarray. +* +* ## Notes +* +* - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* - The function explicitly treats `NaN` values as falsy. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=0] - index from which to begin searching +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @throws {TypeError} function must be provided at least two arguments +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or an integer +* @throws {TypeError} output argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 2, 3 ]; +* +* // Define the array strides: +* var strides = [ 3, 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create an output ndarray: +* var y = zeros( [ 2 ], { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = assign( x, y ); +* // returns [ 2, 1 ] +* +* var bool = ( out === y ); +* // returns true +*/ +function assign( x, fromIndex, out ) { + var hasOptions; + var options; + var nargs; + var opts; + var fidx; + var iflg; + var ord; + var sh; + var o; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension + }; + + // Initialize the `fromIndex` to the first element along a dimension: + fidx = 0; + + // Initialize a flag indicating whether the `fromIndex` argument is a scalar: + iflg = true; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: assign( x, out ) + if ( nargs <= 2 ) { + o = fromIndex; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', o ) ); + } + } + // Case: assign( x, ???, ??? ) + else if ( nargs === 3 ) { + // Case: assign( x, from_index, out ) + if ( isndarrayLike( out ) ) { + o = out; + + // Case: assign( x, from_index_scalar, out ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: assign( x, from_index_ndarray, out ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: assign( x, ???, out ) + else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + } + // Case: assign( x, out, options ) + else { + o = fromIndex; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', o ) ); + } + options = out; + hasOptions = true; + } + } + // Case: assign( x, from_index, out, options ) + else { // nargs > 3 + // Case: assign( x, from_index_scalar, out, options ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: assign( x, from_index_ndarray, out, options ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: assign( x, ???, out, options ) + else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + o = out; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', o ) ); + } + options = arguments[ 3 ]; + hasOptions = true; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the `fromIndex` to match the shape of the non-reduced dimensions... + if ( iflg ) { + fidx = broadcastScalar( fidx, DEFAULT_DTYPE, sh, ord ); + } else { + fidx = maybeBroadcastArray( fidx, sh ); + } + return base( x, fidx, o, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/base.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/base.js new file mode 100644 index 000000000000..940aa0d38ce8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/base.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gindexOfFalsy = require( '@stdlib/blas/ext/base/ndarray/gindex-of-falsy' ); +var dindexOfFalsy = require( '@stdlib/blas/ext/base/ndarray/dindex-of-falsy' ); +var sindexOfFalsy = require( '@stdlib/blas/ext/base/ndarray/sindex-of-falsy' ); +var zindexOfFalsy = require( '@stdlib/blas/ext/base/ndarray/zindex-of-falsy' ); +var cindexOfFalsy = require( '@stdlib/blas/ext/base/ndarray/cindex-of-falsy' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'integer_index_and_generic' ); // from index ndarray +var odtypes = dtypes( 'integer_index_and_generic' ); +var policies = { + 'output': 'integer_index_and_generic', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', + 'float32', + 'complex128', + 'complex64' + ], + 'fcns': [ + dindexOfFalsy, + sindexOfFalsy, + zindexOfFalsy, + cindexOfFalsy + ], + 'default': gindexOfFalsy +}; + + +// MAIN // + +/** +* Returns the index of the first falsy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* - The function explicitly treats `NaN` values as falsy. +* +* @private +* @name indexOfFalsy +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} fromIndex - indices from which to begin searching +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create a from index ndarray: +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = indexOfFalsy( x, fromIndex ); +* // returns [ 2 ] +*/ +var indexOfFalsy = factory( table, [ idtypes0, idtypes1 ], odtypes, policies ); + + +// EXPORTS // + +module.exports = indexOfFalsy; + +// exports: { "assign": "indexOfFalsy.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/index.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/index.js new file mode 100644 index 000000000000..76bad093c150 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/index.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the index of the first falsy element along an ndarray dimension. +* +* @module @stdlib/blas/ext/index-of-falsy +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var indexOfFalsy = require( '@stdlib/blas/ext/index-of-falsy' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = indexOfFalsy( x ); +* // returns [ 2, 1 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/main.js new file mode 100644 index 000000000000..781705955aa7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/lib/main.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ); + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the index of the first falsy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a falsy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* - The function explicitly treats `NaN` values as falsy. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=0] - index from which to begin searching +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or an integer +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = indexOfFalsy( x ); +* // returns [ 2, 1 ] +*/ +function indexOfFalsy( x, fromIndex ) { + var hasOptions; + var options; + var nargs; + var opts; + var fidx; + var iflg; + var ord; + var sh; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ], // default behavior is to perform a reduction over the last dimension + 'keepdims': false + }; + + // Initialize the `fromIndex` to the first element along a dimension: + fidx = 0; + + // Initialize a flag indicating whether the `fromIndex` argument is a scalar: + iflg = true; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: indexOfFalsy( x, ??? ) + if ( nargs === 2 ) { + // Case: indexOfFalsy( x, from_index_scalar ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: indexOfFalsy( x, from_index_ndarray ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: indexOfFalsy( x, options ) + else { + options = fromIndex; + hasOptions = true; + } + } + // Case: indexOfFalsy( x, from_index, options ) + else if ( nargs > 2 ) { + // Case: indexOfFalsy( x, from_index_scalar, options ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: indexOfFalsy( x, from_index_ndarray, options ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: indexOfFalsy( x, ???, options ) + else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + options = arguments[ 2 ]; + hasOptions = true; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + } + if ( hasOwnProp( options, 'dtype' ) ) { + opts.dtype = options.dtype; + } + } + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the `fromIndex` to match the shape of the non-reduced dimensions... + if ( iflg ) { + fidx = broadcastScalar( fidx, DEFAULT_DTYPE, sh, ord ); + } else { + fidx = maybeBroadcastArray( fidx, sh ); + } + return base( x, fidx, opts ); +} + + +// EXPORTS // + +module.exports = indexOfFalsy; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/package.json b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/package.json new file mode 100644 index 000000000000..363c1556ba9d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/index-of-falsy", + "version": "0.0.0", + "description": "Return the index of the first falsy element along an ndarray dimension.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "find", + "index", + "search", + "falsy", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.assign.js new file mode 100644 index 000000000000..efb7ebf71904 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.assign.js @@ -0,0 +1,1433 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var indexOfFalsy = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfFalsy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, 0, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + 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() { + indexOfFalsy( value, scalar2ndarray( 0, opts ), y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, 0, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + 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() { + indexOfFalsy( value, scalar2ndarray( 0, opts ), y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, scalar2ndarray( 0, opts ), y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fromIndex argument which is not an ndarray-like object, an integer, or an object', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + values = [ + '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() { + indexOfFalsy( x, value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a fromIndex argument which is not an ndarray-like object, an integer, or an object (options)', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + values = [ + '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() { + indexOfFalsy( x, value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (fromIndex)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (fromIndex, options)', function test( t ) { + var values; + var i; + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, 2, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + indexOfFalsy( x ); + } + + function badValue2() { + indexOfFalsy(); + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, 0, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + 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() { + indexOfFalsy( x, scalar2ndarray( 0, opts ), y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, y, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first falsy element in an ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, y ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, y, {} ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, 0, y ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first falsy element in an ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, y ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, y, {} ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 0, y ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, y, { + 'dim': 0 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, 0, y, { + 'dim': 0 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, y, { + 'dim': 1 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = indexOfFalsy( x, 0, y, { + 'dim': 1 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, y, { + 'dim': 0 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 0, y, { + 'dim': 0 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, y, { + 'dim': 1 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 0, y, { + 'dim': 1 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOfFalsy( x, 2, y ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 2, y ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, float64)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = new Float64Array( [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'int32' + }); + + actual = indexOfFalsy( x, 2, y ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = new Float64Array( [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'int32', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 2, y ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOfFalsy( x, 2, y, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 2, y, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = indexOfFalsy( x, fromIdx, y ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, fromIdx, y ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = indexOfFalsy( x, fromIdx, y, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, fromIdx, y, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, + * 0.0, 2.0, + * 0.0, 6.0, + * 0.0, 2.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOfFalsy( x, 2, y, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 6.0, + * 2.0, 0.0, + * 0.0, 2.0, + * 2.0, 0.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, 2, y, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 2.0, + * 0.0, 2.0, + * 0.0, 6.0, + * 0.0, 2.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + actual = indexOfFalsy( x, fromIdx, y, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + /* + * [ + * 0.0, 6.0, + * 2.0, 0.0, + * 0.0, 2.0, + * 2.0, 0.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOfFalsy( x, fromIdx, y, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 0.0, 0.0, + * 1.0, 0.0, + * 0.0, 0.0, + * 1.0, 1.0, + * 0.0, 1.0 + * ] + */ + xbuf = [ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 3 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + actual = indexOfFalsy( x, fromIdx, y, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.js new file mode 100644 index 000000000000..6eaf2dc5f171 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var indexOfFalsy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfFalsy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( indexOfFalsy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.main.js new file mode 100644 index 000000000000..d0865b5133ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-falsy/test/test.main.js @@ -0,0 +1,1200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var indexOfFalsy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfFalsy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar)', 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() { + indexOfFalsy( value, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray)', 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() { + indexOfFalsy( value, scalar2ndarray( 0, { + 'dtype': 'generic' + })); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, scalar2ndarray( 0, { + 'dtype': 'generic' + }), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var i; + + opts = { + 'dtype': 'generic' + }; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( value, scalar2ndarray( 0, opts ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object, an integer, or an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '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() { + indexOfFalsy( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + indexOfFalsy( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, 0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + 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() { + indexOfFalsy( x, scalar2ndarray( 0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'bool', + 'float64', + 'float32', + 'boop' + ]; + 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() { + indexOfFalsy( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfFalsy( x, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first falsy element in an ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, {} ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0 ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first falsy element in an ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, {} ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0 ); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `NaN` values as falsy', function test( t ) { + var expected; + var actual; + var x; + + x = new ndarray( 'generic', [ NaN, 2.0, 0.0, NaN ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + x = new ndarray( 'float64', new Float64Array( [ NaN, 2.0, 0.0, NaN ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x ); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, { + 'dim': 0 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'dim': 0 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, { + 'dim': 1 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'dim': 1 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, { + 'dim': 0 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'dim': 0 + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, { + 'dim': 1 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'dim': 1 + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, { + 'keepdims': true + }); + expected = [ [ 0 ], [ 0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'keepdims': true + }); + expected = [ [ 0 ], [ 0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, { + 'keepdims': true + }); + expected = [ [ 0 ], [ -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOfFalsy( x, 0, { + 'keepdims': true + }); + expected = [ [ 0 ], [ -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, { + 'dtype': 'int32' + }); + expected = [ 0, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, 0, { + 'dtype': 'int32' + }); + expected = [ 0, 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, 2 ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, 2 ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, float64)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = new Float64Array( [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, 2 ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = new Float64Array( [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, 2 ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, 2, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, 2, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = indexOfFalsy( x, fromIdx ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, fromIdx ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, 0.0, 2.0, 0.0, + * 6.0, 0.0, 2.0, 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = indexOfFalsy( x, fromIdx, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 0.0, 0.0, 0.0, 0.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, fromIdx, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, + * 0.0, 2.0, + * 0.0, 6.0, + * 0.0, 2.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfFalsy( x, 2, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 6.0, + * 2.0, 0.0, + * 0.0, 2.0, + * 2.0, 0.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, 2, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 2.0, + * 0.0, 2.0, + * 0.0, 6.0, + * 0.0, 2.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + actual = indexOfFalsy( x, fromIdx, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * 0.0, 6.0, + * 2.0, 0.0, + * 0.0, 2.0, + * 2.0, 0.0, + * 0.0, 2.0 + * ] + */ + xbuf = [ 0.0, 2.0, 0.0, 2.0, 0.0, 6.0, 0.0, 2.0, 0.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + + actual = indexOfFalsy( x, fromIdx, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + /* + * [ + * 0.0, 0.0, + * 1.0, 0.0, + * 0.0, 0.0, + * 1.0, 1.0, + * 0.0, 1.0 + * ] + */ + xbuf = [ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 3 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + actual = indexOfFalsy( x, fromIdx, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +});