diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/README.md b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/README.md new file mode 100644 index 000000000000..a6048bc62b26 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/README.md @@ -0,0 +1,218 @@ + + +# indexOfTruthy + +> Return the index of the first truthy element along an [ndarray][@stdlib/ndarray/ctor] dimension. + +
+ +## Usage + +```javascript +var indexOfTruthy = require( '@stdlib/blas/ext/index-of-truthy' ); +``` + +#### indexOfTruthy( x\[, options] ) + +Returns the index of the first truthy element along an [ndarray][@stdlib/ndarray/ctor] dimension. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 0.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ); +// returns + +// Perform operation: +var out = indexOfTruthy( x ); +// returns [ 1 ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **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 truthy 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( [ 0.0, 0.0, 0.0, 0.0 ] ); +// returns + +// Perform operation: +var out = indexOfTruthy( x ); +// returns [ -1 ] +``` + +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 = indexOfTruthy( x, { + 'dim': 0 +}); +// returns [ 1, 0 ] +``` + +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 = indexOfTruthy( x, opts ); +// returns [ [ 1, 0 ] ] +``` + +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( [ 0.0, 2.0, 0.0, 4.0 ] ); + +var idx = indexOfTruthy( x, { + 'dtype': 'generic' +}); +// returns + +var dt = dtype( idx ); +// returns 'generic' +``` + +#### indexOfTruthy.assign( x, out\[, options] ) + +Returns the index of the first truthy 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( [ 0.0, 0.0, 3.0, 4.0 ] ); +var y = zeros( [], { + 'dtype': 'int32' +}); + +var out = indexOfTruthy.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. +- **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 indexOfTruthy = require( '@stdlib/blas/ext/index-of-truthy' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 1, { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var idx = indexOfTruthy( x, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..a24e12f96999 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/benchmark/benchmark.assign.js @@ -0,0 +1,109 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var indexOfTruthy = 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 = zeros( [ 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 = indexOfTruthy.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-truthy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/benchmark/benchmark.js new file mode 100644 index 000000000000..4161fc3a5b50 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/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 zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var indexOfTruthy = 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 = zeros( [ 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 = indexOfTruthy( 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-truthy/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/repl.txt new file mode 100644 index 000000000000..1909844390db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/repl.txt @@ -0,0 +1,84 @@ + +{{alias}}( x[, options] ) + Returns the index of the first truthy element along an ndarray dimension. + + If unable to find a truthy 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. + + 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}}( [ 0.0, 2.0, 0.0, 0.0 ] ); + > var y = {{alias}}( x ) + [ 1 ] + + +{{alias}}.assign( x, out[, options] ) + Returns the index of the first truthy element along an ndarray dimension + and assigns results to a provided output ndarray. + + If unable to find a truthy 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. + + 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}}( [ 0.0, 2.0, 0.0, 0.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); + > var y = {{alias}}.assign( x, out ) + [ 1 ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/index.d.ts new file mode 100644 index 000000000000..2e2ba5bc9f63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/index.d.ts @@ -0,0 +1,162 @@ +/* +* @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; + +/** +* 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 `indexOfTruthy`. +*/ +interface IndexOfTruthy { + /** + * Returns the index of the first truthy element along an ndarray dimension. + * + * ## Notes + * + * - If unable to find a truthy 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( [ 0.0, 2.0, 0.0 ] ); + * + * var y = indexOfTruthy( x ); + * // returns [ 1 ] + */ + ( x: InputArray, options?: Options ): OutputArray; + + /** + * Returns the index of the first truthy element along an ndarray dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If unable to find a truthy 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( [ 0.0, 2.0, 0.0 ] ); + * var y = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = indexOfTruthy.assign( x, y ); + * // returns [ 1 ] + * + * var bool = ( out === y ); + * // returns true + */ + assign( x: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Returns the index of the first truthy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a truthy 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( [ 0.0, 2.0, 0.0 ] ); +* +* var y = indexOfTruthy( x ); +* // returns [ 1 ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 2.0, 0.0 ] ); +* var y = zeros( [], { +* 'dtype': 'int32' +* } ); +* +* var out = indexOfTruthy.assign( x, y ); +* // returns [ 1 ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const indexOfTruthy: IndexOfTruthy; + + +// EXPORTS // + +export = indexOfTruthy; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/test.ts new file mode 100644 index 000000000000..25e471e6471f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/docs/types/test.ts @@ -0,0 +1,236 @@ +/* +* @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 indexOfTruthy = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOfTruthy( x ); // $ExpectType OutputArray + indexOfTruthy( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + indexOfTruthy( '5' ); // $ExpectError + indexOfTruthy( 5 ); // $ExpectError + indexOfTruthy( true ); // $ExpectError + indexOfTruthy( false ); // $ExpectError + indexOfTruthy( null ); // $ExpectError + indexOfTruthy( void 0 ); // $ExpectError + indexOfTruthy( {} ); // $ExpectError + indexOfTruthy( ( x: number ): number => x ); // $ExpectError + + indexOfTruthy( '5', {} ); // $ExpectError + indexOfTruthy( 5, {} ); // $ExpectError + indexOfTruthy( true, {} ); // $ExpectError + indexOfTruthy( false, {} ); // $ExpectError + indexOfTruthy( null, {} ); // $ExpectError + indexOfTruthy( void 0, {} ); // $ExpectError + indexOfTruthy( {}, {} ); // $ExpectError + indexOfTruthy( ( 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' + }); + + indexOfTruthy( x, '5' ); // $ExpectError + indexOfTruthy( x, true ); // $ExpectError + indexOfTruthy( x, false ); // $ExpectError + indexOfTruthy( x, null ); // $ExpectError + indexOfTruthy( x, [] ); // $ExpectError + indexOfTruthy( x, ( 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' + }); + + indexOfTruthy( x, { 'dtype': '5' } ); // $ExpectError + indexOfTruthy( x, { 'dtype': 5 } ); // $ExpectError + indexOfTruthy( x, { 'dtype': true } ); // $ExpectError + indexOfTruthy( x, { 'dtype': false } ); // $ExpectError + indexOfTruthy( x, { 'dtype': null } ); // $ExpectError + indexOfTruthy( x, { 'dtype': [] } ); // $ExpectError + indexOfTruthy( x, { 'dtype': {} } ); // $ExpectError + indexOfTruthy( x, { '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' + }); + + indexOfTruthy( x, { 'dim': '5' } ); // $ExpectError + indexOfTruthy( x, { 'dim': true } ); // $ExpectError + indexOfTruthy( x, { 'dim': false } ); // $ExpectError + indexOfTruthy( x, { 'dim': null } ); // $ExpectError + indexOfTruthy( x, { 'dim': [] } ); // $ExpectError + indexOfTruthy( x, { 'dim': {} } ); // $ExpectError + indexOfTruthy( x, { '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' + }); + + indexOfTruthy( x, { 'keepdims': '5' } ); // $ExpectError + indexOfTruthy( x, { 'keepdims': 5 } ); // $ExpectError + indexOfTruthy( x, { 'keepdims': null } ); // $ExpectError + indexOfTruthy( x, { 'keepdims': {} } ); // $ExpectError + indexOfTruthy( x, { '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' + }); + + indexOfTruthy(); // $ExpectError + indexOfTruthy( x, {}, {} ); // $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' + }); + + indexOfTruthy.assign( x, y ); // $ExpectType int32ndarray + indexOfTruthy.assign( x, 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' + }); + + indexOfTruthy.assign( '5', y ); // $ExpectError + indexOfTruthy.assign( 5, y ); // $ExpectError + indexOfTruthy.assign( true, y ); // $ExpectError + indexOfTruthy.assign( false, y ); // $ExpectError + indexOfTruthy.assign( null, y ); // $ExpectError + indexOfTruthy.assign( void 0, y ); // $ExpectError + indexOfTruthy.assign( {}, y ); // $ExpectError + indexOfTruthy.assign( ( x: number ): number => x, y ); // $ExpectError + + indexOfTruthy.assign( '5', y, {} ); // $ExpectError + indexOfTruthy.assign( 5, y, {} ); // $ExpectError + indexOfTruthy.assign( true, y, {} ); // $ExpectError + indexOfTruthy.assign( false, y, {} ); // $ExpectError + indexOfTruthy.assign( null, y, {} ); // $ExpectError + indexOfTruthy.assign( void 0, y, {} ); // $ExpectError + indexOfTruthy.assign( {}, y, {} ); // $ExpectError + indexOfTruthy.assign( ( 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' + }); + + indexOfTruthy.assign( x, '5' ); // $ExpectError + indexOfTruthy.assign( x, 5 ); // $ExpectError + indexOfTruthy.assign( x, true ); // $ExpectError + indexOfTruthy.assign( x, false ); // $ExpectError + indexOfTruthy.assign( x, null ); // $ExpectError + indexOfTruthy.assign( x, void 0 ); // $ExpectError + indexOfTruthy.assign( x, ( x: number ): number => x ); // $ExpectError + + indexOfTruthy.assign( x, '5', {} ); // $ExpectError + indexOfTruthy.assign( x, 5, {} ); // $ExpectError + indexOfTruthy.assign( x, true, {} ); // $ExpectError + indexOfTruthy.assign( x, false, {} ); // $ExpectError + indexOfTruthy.assign( x, null, {} ); // $ExpectError + indexOfTruthy.assign( x, void 0, {} ); // $ExpectError + indexOfTruthy.assign( x, ( 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' + }); + + indexOfTruthy.assign( x, y, '5' ); // $ExpectError + indexOfTruthy.assign( x, y, true ); // $ExpectError + indexOfTruthy.assign( x, y, false ); // $ExpectError + indexOfTruthy.assign( x, y, null ); // $ExpectError + indexOfTruthy.assign( x, y, [] ); // $ExpectError + indexOfTruthy.assign( x, 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' + }); + + indexOfTruthy.assign( x, y, { 'dim': '5' } ); // $ExpectError + indexOfTruthy.assign( x, y, { 'dim': true } ); // $ExpectError + indexOfTruthy.assign( x, y, { 'dim': false } ); // $ExpectError + indexOfTruthy.assign( x, y, { 'dim': null } ); // $ExpectError + indexOfTruthy.assign( x, y, { 'dim': [] } ); // $ExpectError + indexOfTruthy.assign( x, y, { 'dim': {} } ); // $ExpectError + indexOfTruthy.assign( x, 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' + }); + + indexOfTruthy.assign(); // $ExpectError + indexOfTruthy.assign( x ); // $ExpectError + indexOfTruthy.assign( x, y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/examples/index.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/examples/index.js new file mode 100644 index 000000000000..9b9909b536de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/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 indexOfTruthy = 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 = indexOfTruthy( x, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/assign.js new file mode 100644 index 000000000000..b7356734f61d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/assign.js @@ -0,0 +1,118 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ).assign; + + +// MAIN // + +/** +* Returns the index of the first truthy element along an ndarray dimension and assigns the results to a provided output ndarray. +* +* ## Notes +* +* - If unable to find a truthy 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} out - output ndarray +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument 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( [ 0.0, 2.0, 0.0, 4.0, 0.0, 6.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 [ 1, 0 ] +* +* var bool = ( out === y ); +* // returns true +*/ +function assign( x, out, options ) { + var opts; + var sh; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', out ) ); + } + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension + }; + if ( arguments.length > 2 ) { + 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; + } + } + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + return base( x, out, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/base.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/base.js new file mode 100644 index 000000000000..d5851755f31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/base.js @@ -0,0 +1,111 @@ +/** +* @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 gindexOfTruthy = require( '@stdlib/blas/ext/base/ndarray/gindex-of-truthy' ); +var dindexOfTruthy = require( '@stdlib/blas/ext/base/ndarray/dindex-of-truthy' ); +var sindexOfTruthy = require( '@stdlib/blas/ext/base/ndarray/sindex-of-truthy' ); +var zindexOfTruthy = require( '@stdlib/blas/ext/base/ndarray/zindex-of-truthy' ); +var cindexOfTruthy = require( '@stdlib/blas/ext/base/ndarray/cindex-of-truthy' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'all' ); // input 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': [ + dindexOfTruthy, + sindexOfTruthy, + zindexOfTruthy, + cindexOfTruthy + ], + 'default': gindexOfTruthy +}; + + +// MAIN // + +/** +* Returns the index of the first truthy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a truthy element along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* - The function explicitly treats `NaN` values as falsy. +* +* @private +* @name indexOfTruthy +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @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} 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 ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 0.0, 3.0, 0.0, 4.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = indexOfTruthy( x ); +* // returns [ 2 ] +*/ +var indexOfTruthy = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = indexOfTruthy; + +// exports: { "assign": "indexOfTruthy.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/index.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/index.js new file mode 100644 index 000000000000..f6f8f2d3375d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/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 truthy element along an ndarray dimension. +* +* @module @stdlib/blas/ext/index-of-truthy +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var indexOfTruthy = require( '@stdlib/blas/ext/index-of-truthy' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 2.0, 0.0, 4.0, 0.0, 6.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 = indexOfTruthy( x ); +* // returns [ 1, 0 ] +*/ + +// 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-truthy/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/main.js new file mode 100644 index 000000000000..a9c6d78a1293 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/lib/main.js @@ -0,0 +1,113 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the index of the first truthy element along an ndarray dimension. +* +* ## Notes +* +* - If unable to find a truthy 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 {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} 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( [ 0.0, 2.0, 0.0, 4.0, 0.0, 6.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 = indexOfTruthy( x ); +* // returns [ 1, 0 ] +*/ +function indexOfTruthy( x, options ) { + var opts; + var sh; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Initialize an options object: + opts = { + 'dims': [ -1 ], // default behavior is to perform a reduction over the last dimension + 'keepdims': false + }; + if ( arguments.length > 1 ) { + 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; + } + } + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + return base( x, opts ); +} + + +// EXPORTS // + +module.exports = indexOfTruthy; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/package.json b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/package.json new file mode 100644 index 000000000000..ba5edb080dee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/blas/ext/index-of-truthy", + "version": "0.0.0", + "description": "Return the index of the first truthy 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", + "blas", + "find", + "index", + "search", + "truthy", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.assign.js new file mode 100644 index 000000000000..779ec54c9079 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.assign.js @@ -0,0 +1,469 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var indexOfTruthy = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfTruthy, '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() { + indexOfTruthy( value, 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() { + indexOfTruthy( value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + '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() { + indexOfTruthy( 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() { + indexOfTruthy( 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() { + indexOfTruthy( x, 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() { + indexOfTruthy( x ); + } + + function badValue2() { + indexOfTruthy(); + } +}); + +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() { + indexOfTruthy( x, 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() { + indexOfTruthy( x, y, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first truthy 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 = indexOfTruthy( x, y ); + expected = [ 1, -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 = indexOfTruthy( x, y, {} ); + expected = [ 1, -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 returns the index of the first truthy 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 = indexOfTruthy( x, y ); + expected = [ -1, 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 = indexOfTruthy( x, y, {} ); + expected = [ -1, 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 (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 = indexOfTruthy( x, y, { + 'dim': 0 + }); + expected = [ -1, 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 = indexOfTruthy( x, y, { + 'dim': 1 + }); + expected = [ 1, -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 (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 = indexOfTruthy( x, y, { + 'dim': 0 + }); + expected = [ 1, -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 = indexOfTruthy( x, y, { + 'dim': 1 + }); + expected = [ -1, 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(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.js new file mode 100644 index 000000000000..aa61dc7ab117 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/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 indexOfTruthy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfTruthy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( indexOfTruthy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.main.js new file mode 100644 index 000000000000..714b16f81af0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of-truthy/test/test.main.js @@ -0,0 +1,455 @@ +/** +* @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 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 indexOfTruthy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOfTruthy, '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() { + indexOfTruthy( value ); + }; + } +}); + +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() { + indexOfTruthy( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var i; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOfTruthy( 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', + 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() { + indexOfTruthy( x, 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() { + indexOfTruthy( 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() { + indexOfTruthy( x, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first truthy 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 = indexOfTruthy( x ); + expected = [ 1, -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 = indexOfTruthy( x, {} ); + expected = [ 1, -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 returns the index of the first truthy 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 = indexOfTruthy( x ); + expected = [ -1, 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 = indexOfTruthy( x, {} ); + expected = [ -1, 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 ignores falsy elements (e.g., `0`, `NaN`)', 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 = indexOfTruthy( x ); + expected = [ 1, -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' ); + + x = new ndarray( 'float64', new Float64Array( [ NaN, 2.0, 0.0, NaN ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOfTruthy( x ); + expected = [ 1, -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 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 = indexOfTruthy( x, { + 'dim': 0 + }); + expected = [ -1, 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 = indexOfTruthy( x, { + 'dim': 1 + }); + expected = [ 1, -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 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 = indexOfTruthy( x, { + 'dim': 0 + }); + expected = [ 1, -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 = indexOfTruthy( x, { + 'dim': 1 + }); + expected = [ -1, 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 `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 = indexOfTruthy( x, { + 'keepdims': true + }); + expected = [ [ 1 ], [ 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 `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 = indexOfTruthy( x, { + 'keepdims': true + }); + expected = [ [ -1 ], [ 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 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 = indexOfTruthy( x, { + 'dtype': 'int32' + }); + expected = [ 1, -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' ); + + xbuf = [ 0.0, 2.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOfTruthy( x, { + 'dtype': 'int32' + }); + expected = [ -1, 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(); +});