diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/README.md b/lib/node_modules/@stdlib/blas/ext/find-last-index/README.md index f2f2c916d419..89ce0b55a551 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/README.md +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/README.md @@ -30,7 +30,7 @@ limitations under the License. var findLastIndex = require( '@stdlib/blas/ext/find-last-index' ); ``` -#### findLastIndex( x\[, options], clbk\[, thisArg] ) +#### findLastIndex( x\[, fromIndex]\[, options], clbk\[, thisArg] ) Returns the index of the last element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function. @@ -56,6 +56,7 @@ var idx = out.get(); 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: `-1`. - **options**: function options (_optional_). - **clbk**: callback function. - **thisArg**: callback execution context (_optional_). @@ -120,6 +121,27 @@ var idx = out.get(); // returns -1 ``` +By default, the function begins searching from the last element along the operation dimension. To begin searching from a different index, provide a `fromIndex` argument. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +function isEven( v ) { + return v % 2.0 === 0.0; +} + +// Create an input ndarray: +var x = array( [ 2.0, 1.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Perform operation: +var out = findLastIndex( x, 2, isEven ); +// returns + +var idx = out.get(); +// returns 0 +``` + 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 @@ -190,7 +212,7 @@ var dt = dtype( idx ); // returns 'generic' ``` -#### findLastIndex.assign( x, out\[, options], clbk\[, thisArg] ) +#### findLastIndex.assign( x\[, fromIndex], out\[, options], clbk\[, thisArg] ) Returns the index of the last element along an [ndarray][@stdlib/ndarray/ctor] dimension which passes a test implemented by a predicate function and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. @@ -220,6 +242,7 @@ var bool = ( out === y ); 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: `-1`. - **out**: output [ndarray][@stdlib/ndarray/ctor]. - **options**: function options (_optional_). - **clbk**: callback function. diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/repl.txt index 3176847acfb7..7d2be352f9d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x[, options], clbk[, thisArg] ) +{{alias}}( x[, fromIndex][, options], clbk[, thisArg] ) Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function. @@ -20,6 +20,17 @@ x: ndarray Input array. Must at least have 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: -1. + options: Object (optional) Function options. @@ -56,7 +67,7 @@ 3 -{{alias}}.assign( x, out[, options], clbk[, thisArg] ) +{{alias}}.assign( x[, fromIndex], out[, options], clbk[, thisArg] ) Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. @@ -78,6 +89,17 @@ x: ndarray Input array. Must at least have 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: -1. + out: ndarray Output array. diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/index.d.ts index 2a1083379ccf..3a4fbf2fbb0e 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/index.d.ts @@ -27,6 +27,11 @@ import { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdli */ type InputArray = typedndarray; +/** +* From index. +*/ +type FromIndex = typedndarray | number; + /** * Output array. */ @@ -138,6 +143,36 @@ interface FindLastIndex { */ = InputArray, ThisArg = unknown>( x: U, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; + /** + * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); + * + * var y = findLastIndex( x, 2, clbk ); + * // returns + * + * var v = y.get(); + * // returns 1 + */ + = InputArray, ThisArg = unknown>( x: U, fromIndex: FromIndex, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; + /** * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function. * @@ -166,7 +201,38 @@ interface FindLastIndex { * var v = y.get(); * // returns 1 */ - = InputArray, ThisArg = unknown>( x: U, options: Options, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; + = InputArray, ThisArg = unknown>( x: U, options: Options, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; // eslint-disable-line @typescript-eslint/unified-signatures + + /** + * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param options - function options + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); + * + * var y = findLastIndex( x, 2, {}, clbk ); + * // returns + * + * var v = y.get(); + * // returns 1 + */ + = InputArray, ThisArg = unknown>( x: U, fromIndex: FromIndex, options: Options, clbk: Predicate, thisArg?: ThisParameterType> ): OutputArray; /** * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. @@ -203,6 +269,42 @@ interface FindLastIndex { */ assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Predicate, thisArg?: ThisParameterType> ): V; + /** + * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param out - output ndarray + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = findLastIndex.assign( x, 2, y, clbk ); + * // returns + * + * var v = out.get(); + * // returns 1 + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, fromIndex: FromIndex, out: V, clbk: Predicate, thisArg?: ThisParameterType> ): V; + /** * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. * @@ -238,6 +340,43 @@ interface FindLastIndex { * // returns true */ assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Predicate, thisArg?: ThisParameterType> ): V; + + /** + * Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray. + * + * ## Notes + * + * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. + * + * @param x - input ndarray + * @param fromIndex - index from which to begin searching + * @param out - output ndarray + * @param options - function options + * @param clbk - predicate function + * @param thisArg - predicate function execution context + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * function clbk( value ) { + * return value % 2.0 === 0.0; + * } + * + * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = findLastIndex.assign( x, 2, y, {}, clbk ); + * // returns + * + * var v = out.get(); + * // returns 1 + * + * var bool = ( out === y ); + * // returns true + */ + assign = InputArray, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, fromIndex: FromIndex, out: V, options: BaseOptions, clbk: Predicate, thisArg?: ThisParameterType> ): V; } /** @@ -248,6 +387,7 @@ interface FindLastIndex { * - If no element along an ndarray dimension passes a test implemented by the predicate function, the corresponding element in the returned ndarray is `-1`. * * @param x - input ndarray +* @param fromIndex - index from which to begin searching * @param options - function options * @param clbk - predicate function * @param thisArg - predicate function execution context diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/test.ts index 1aa459021b48..b93d11bea3c1 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/test.ts @@ -45,8 +45,14 @@ function clbk( value: any ): boolean { findLastIndex( x, clbk ); // $ExpectType OutputArray findLastIndex( x, clbk, {} ); // $ExpectType OutputArray + findLastIndex( x, 1, clbk ); // $ExpectType OutputArray + findLastIndex( x, 1, clbk, {} ); // $ExpectType OutputArray + findLastIndex( x, {}, clbk ); // $ExpectType OutputArray findLastIndex( x, {}, clbk, {} ); // $ExpectType OutputArray + + findLastIndex( x, 1, {}, clbk ); // $ExpectType OutputArray + findLastIndex( x, 1, {}, clbk, {} ); // $ExpectType OutputArray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... @@ -86,6 +92,73 @@ function clbk( value: any ): boolean { findLastIndex( void 0, {}, clbk, {} ); // $ExpectError findLastIndex( {}, {}, clbk, {} ); // $ExpectError findLastIndex( ( x: number ): number => x, {}, clbk, {} ); // $ExpectError + + findLastIndex( '5', 1, clbk ); // $ExpectError + findLastIndex( 5, 1, clbk ); // $ExpectError + findLastIndex( true, 1, clbk ); // $ExpectError + findLastIndex( false, 1, clbk ); // $ExpectError + findLastIndex( null, 1, clbk ); // $ExpectError + findLastIndex( void 0, 1, clbk ); // $ExpectError + findLastIndex( {}, 1, clbk ); // $ExpectError + findLastIndex( ( x: number ): number => x, 1, clbk ); // $ExpectError + + findLastIndex( '5', 1, clbk, {} ); // $ExpectError + findLastIndex( 5, 1, clbk, {} ); // $ExpectError + findLastIndex( true, 1, clbk, {} ); // $ExpectError + findLastIndex( false, 1, clbk, {} ); // $ExpectError + findLastIndex( null, 1, clbk, {} ); // $ExpectError + findLastIndex( void 0, 1, clbk, {} ); // $ExpectError + findLastIndex( {}, 1, clbk, {} ); // $ExpectError + findLastIndex( ( x: number ): number => x, 1, clbk, {} ); // $ExpectError + + findLastIndex( '5', 1, {}, clbk ); // $ExpectError + findLastIndex( 5, 1, {}, clbk ); // $ExpectError + findLastIndex( true, 1, {}, clbk ); // $ExpectError + findLastIndex( false, 1, {}, clbk ); // $ExpectError + findLastIndex( null, 1, {}, clbk ); // $ExpectError + findLastIndex( void 0, 1, {}, clbk ); // $ExpectError + findLastIndex( {}, 1, {}, clbk ); // $ExpectError + findLastIndex( ( x: number ): number => x, 1, {}, clbk ); // $ExpectError + + findLastIndex( '5', 1, {}, clbk, {} ); // $ExpectError + findLastIndex( 5, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( true, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( false, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( null, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( void 0, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( {}, 1, {}, clbk, {} ); // $ExpectError + findLastIndex( ( x: number ): number => x, 1, {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `fromIndex` argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + findLastIndex( x, '5', clbk ); // $ExpectError + findLastIndex( x, true, clbk ); // $ExpectError + findLastIndex( x, false, clbk ); // $ExpectError + findLastIndex( x, null, clbk ); // $ExpectError + findLastIndex( x, [], clbk ); // $ExpectError + + findLastIndex( x, '5', clbk, {} ); // $ExpectError + findLastIndex( x, true, clbk, {} ); // $ExpectError + findLastIndex( x, false, clbk, {} ); // $ExpectError + findLastIndex( x, null, clbk, {} ); // $ExpectError + findLastIndex( x, [], clbk, {} ); // $ExpectError + + findLastIndex( x, '5', {}, clbk ); // $ExpectError + findLastIndex( x, true, {}, clbk ); // $ExpectError + findLastIndex( x, false, {}, clbk ); // $ExpectError + findLastIndex( x, null, {}, clbk ); // $ExpectError + findLastIndex( x, [], {}, clbk ); // $ExpectError + + findLastIndex( x, '5', {}, clbk, {} ); // $ExpectError + findLastIndex( x, true, {}, clbk, {} ); // $ExpectError + findLastIndex( x, false, {}, clbk, {} ); // $ExpectError + findLastIndex( x, null, {}, clbk, {} ); // $ExpectError + findLastIndex( x, [], {}, clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided an options argument which is not an object... @@ -105,6 +178,18 @@ function clbk( value: any ): boolean { findLastIndex( x, false, clbk, {} ); // $ExpectError findLastIndex( x, null, clbk, {} ); // $ExpectError findLastIndex( x, [], clbk, {} ); // $ExpectError + + findLastIndex( x, 1, '5', clbk ); // $ExpectError + findLastIndex( x, 1, true, clbk ); // $ExpectError + findLastIndex( x, 1, false, clbk ); // $ExpectError + findLastIndex( x, 1, null, clbk ); // $ExpectError + findLastIndex( x, 1, [], clbk ); // $ExpectError + + findLastIndex( x, 1, '5', clbk, {} ); // $ExpectError + findLastIndex( x, 1, true, clbk, {} ); // $ExpectError + findLastIndex( x, 1, false, clbk, {} ); // $ExpectError + findLastIndex( x, 1, null, clbk, {} ); // $ExpectError + findLastIndex( x, 1, [], clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided a callback argument which is not a function... @@ -130,6 +215,24 @@ function clbk( value: any ): boolean { findLastIndex( x, {}, false, {} ); // $ExpectError findLastIndex( x, {}, null, {} ); // $ExpectError findLastIndex( x, {}, [], {} ); // $ExpectError + + findLastIndex( x, 1, '5' ); // $ExpectError + findLastIndex( x, 1, true ); // $ExpectError + findLastIndex( x, 1, false ); // $ExpectError + findLastIndex( x, 1, null ); // $ExpectError + findLastIndex( x, 1, [] ); // $ExpectError + + findLastIndex( x, 1, '5', {} ); // $ExpectError + findLastIndex( x, 1, true, {} ); // $ExpectError + findLastIndex( x, 1, false, {} ); // $ExpectError + findLastIndex( x, 1, null, {} ); // $ExpectError + findLastIndex( x, 1, [], {} ); // $ExpectError + + findLastIndex( x, 1, {}, '5', {} ); // $ExpectError + findLastIndex( x, 1, {}, true, {} ); // $ExpectError + findLastIndex( x, 1, {}, false, {} ); // $ExpectError + findLastIndex( x, 1, {}, null, {} ); // $ExpectError + findLastIndex( x, 1, {}, [], {} ); // $ExpectError } // The compiler throws an error if the function is provided an invalid `dtype` option... @@ -155,6 +258,24 @@ function clbk( value: any ): boolean { findLastIndex( x, { 'dtype': [] }, clbk, {} ); // $ExpectError findLastIndex( x, { 'dtype': {} }, clbk, {} ); // $ExpectError findLastIndex( x, { 'dtype': ( x: number ): number => x }, clbk, {} ); // $ExpectError + + findLastIndex( x, 1, { 'dtype': '5' }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': 5 }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': true }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': false }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': null }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': [] }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': {} }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dtype': ( x: number ): number => x }, clbk ); // $ExpectError + + findLastIndex( x, 1, { 'dtype': '5' }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': 5 }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': true }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': false }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': null }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': [] }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': {} }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dtype': ( x: number ): number => x }, clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided an invalid `keepdims` option... @@ -176,6 +297,20 @@ function clbk( value: any ): boolean { findLastIndex( x, { 'keepdims': [] }, clbk, {} ); // $ExpectError findLastIndex( x, { 'keepdims': {} }, clbk, {} ); // $ExpectError findLastIndex( x, { 'keepdims': ( x: number ): number => x }, clbk, {} ); // $ExpectError + + findLastIndex( x, 1, { 'keepdims': '5' }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': 5 }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': null }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': [] }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': {} }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': ( x: number ): number => x }, clbk ); // $ExpectError + + findLastIndex( x, 1, { 'keepdims': '5' }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': 5 }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': null }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': [] }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': {} }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'keepdims': ( x: number ): number => x }, clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided an invalid `dim` option... @@ -197,6 +332,20 @@ function clbk( value: any ): boolean { findLastIndex( x, { 'dim': null }, clbk, {} ); // $ExpectError findLastIndex( x, { 'dim': {} }, clbk, {} ); // $ExpectError findLastIndex( x, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError + + findLastIndex( x, 1, { 'dim': '5' }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dim': true }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dim': false }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dim': null }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dim': {} }, clbk ); // $ExpectError + findLastIndex( x, 1, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findLastIndex( x, 1, { 'dim': '5' }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dim': true }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dim': false }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dim': null }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dim': {} }, clbk, {} ); // $ExpectError + findLastIndex( x, 1, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -207,7 +356,7 @@ function clbk( value: any ): boolean { findLastIndex(); // $ExpectError findLastIndex( x ); - findLastIndex( x, {}, clbk, {}, {} ); // $ExpectError + findLastIndex( x, 1, {}, clbk, {}, {} ); // $ExpectError } // Attached to the function is an `assign` method which returns an ndarray... @@ -224,6 +373,11 @@ function clbk( value: any ): boolean { findLastIndex.assign( x, y, clbk, {} ); // $ExpectType int32ndarray findLastIndex.assign( x, y, {}, clbk, {} ); // $ExpectType int32ndarray + + findLastIndex.assign( x, 1, y, clbk ); // $ExpectType int32ndarray + findLastIndex.assign( x, 1, y, clbk, {} ); // $ExpectType int32ndarray + findLastIndex.assign( x, 1, y, {}, clbk ); // $ExpectType int32ndarray + findLastIndex.assign( x, 1, y, {}, clbk, {} ); // $ExpectType int32ndarray } // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... @@ -267,6 +421,42 @@ function clbk( value: any ): boolean { findLastIndex.assign( void 0, y, {}, clbk, {} ); // $ExpectError findLastIndex.assign( {}, y, {}, clbk, {} ); // $ExpectError findLastIndex.assign( ( x: number ): number => x, y, {}, clbk, {} ); // $ExpectError + + findLastIndex.assign( '5', 1, y, clbk ); // $ExpectError + findLastIndex.assign( 5, 1, y, clbk ); // $ExpectError + findLastIndex.assign( true, 1, y, clbk ); // $ExpectError + findLastIndex.assign( false, 1, y, clbk ); // $ExpectError + findLastIndex.assign( null, 1, y, clbk ); // $ExpectError + findLastIndex.assign( void 0, 1, y, clbk ); // $ExpectError + findLastIndex.assign( {}, 1, y, clbk ); // $ExpectError + findLastIndex.assign( ( x: number ): number => x, 1, y, clbk ); // $ExpectError + + findLastIndex.assign( '5', 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( 5, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( true, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( false, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( null, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( void 0, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( {}, 1, y, {}, clbk ); // $ExpectError + findLastIndex.assign( ( x: number ): number => x, 1, y, {}, clbk ); // $ExpectError + + findLastIndex.assign( '5', 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( 5, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( true, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( false, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( null, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( void 0, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( {}, 1, y, clbk, {} ); // $ExpectError + findLastIndex.assign( ( x: number ): number => x, 1, y, clbk, {} ); // $ExpectError + + findLastIndex.assign( '5', 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( 5, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( true, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( false, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( null, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( void 0, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( {}, 1, y, {}, clbk, {} ); // $ExpectError + findLastIndex.assign( ( x: number ): number => x, 1, y, {}, clbk, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... @@ -328,6 +518,18 @@ function clbk( value: any ): boolean { findLastIndex.assign( x, y, false, clbk, {} ); // $ExpectError findLastIndex.assign( x, y, null, clbk, {} ); // $ExpectError findLastIndex.assign( x, y, [], clbk, {} ); // $ExpectError + + findLastIndex.assign( x, 1, y, '5', clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, true, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, false, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, null, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, [], clbk ); // $ExpectError + + findLastIndex.assign( x, 1, y, '5', clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, true, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, false, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, null, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, [], clbk, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a callback argument which is not a function... @@ -362,6 +564,30 @@ function clbk( value: any ): boolean { findLastIndex.assign( x, y, {}, false, {} ); // $ExpectError findLastIndex.assign( x, y, {}, null, {} ); // $ExpectError findLastIndex.assign( x, y, {}, [], {} ); // $ExpectError + + findLastIndex.assign( x, 1, y, '5' ); // $ExpectError + findLastIndex.assign( x, 1, y, true ); // $ExpectError + findLastIndex.assign( x, 1, y, false ); // $ExpectError + findLastIndex.assign( x, 1, y, null ); // $ExpectError + findLastIndex.assign( x, 1, y, [] ); // $ExpectError + + findLastIndex.assign( x, 1, y, '5', {} ); // $ExpectError + findLastIndex.assign( x, 1, y, true, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, false, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, null, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, [], {} ); // $ExpectError + + findLastIndex.assign( x, 1, y, {}, '5' ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, true ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, false ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, null ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, [] ); // $ExpectError + + findLastIndex.assign( x, 1, y, {}, '5', {} ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, true, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, false, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, null, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, [], {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an invalid `dim` option... @@ -386,6 +612,20 @@ function clbk( value: any ): boolean { findLastIndex.assign( x, y, { 'dim': null }, clbk, {} ); // $ExpectError findLastIndex.assign( x, y, { 'dim': {} }, clbk, {} ); // $ExpectError findLastIndex.assign( x, y, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError + + findLastIndex.assign( x, 1, y, { 'dim': '5' }, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': true }, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': false }, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': null }, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': {} }, clbk ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': ( x: number ): number => x }, clbk ); // $ExpectError + + findLastIndex.assign( x, 1, y, { 'dim': '5' }, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': true }, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': false }, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': null }, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': {} }, clbk, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, { 'dim': ( x: number ): number => x }, clbk, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... @@ -400,5 +640,5 @@ function clbk( value: any ): boolean { findLastIndex.assign(); // $ExpectError findLastIndex.assign( x ); // $ExpectError findLastIndex.assign( x, y ); // $ExpectError - findLastIndex.assign( x, y, {}, clbk, {}, {} ); // $ExpectError + findLastIndex.assign( x, 1, y, {}, clbk, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/assign.js index 6f14b8d55266..d7a326db1397 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/assign.js @@ -23,18 +23,31 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); 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 ndims = require( '@stdlib/ndarray/ndims' ); 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 last element along an ndarray dimension which passes a test implemented by a predicate function and assigns the results to a provided output ndarray. * * @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=-1] - 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 @@ -42,7 +55,8 @@ var base = require( './base.js' ).assign; * @param {*} [thisArg] - callback execution context * @throws {TypeError} function must be provided at least three arguments * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} `fromIndex` argument must be either an ndarray-like object or an integer +* @throws {TypeError} output argument must be an ndarray-like object * @throws {TypeError} callback argument must be a function * @throws {TypeError} options argument must be an object * @throws {RangeError} dimension index must not exceed input ndarray bounds @@ -89,62 +103,167 @@ var base = require( './base.js' ).assign; * var arr = ndarray2array( out ); * // returns [ 1, 2 ] */ -function assign( x, out ) { +function assign( x, fromIndex, out ) { var hasOptions; var options; var nargs; + var isnd; var opts; + var fidx; + var iflg; + var ord; var ctx; + var sh; var cb; + var o; nargs = arguments.length; 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 ) ); - } + // 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 last element along a dimension: + fidx = -1; + + // 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, clbk ) if ( nargs <= 3 ) { - cb = arguments[ 2 ]; + o = fromIndex; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', o ) ); + } + cb = out; if ( !isFunction( cb ) ) { throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) ); } } - // Case: assign( x, out, ???, ??? ) + // Case: assign( x, ???, ???, ??? ) else if ( nargs === 4 ) { + isnd = isndarrayLike( fromIndex ); + // Case: assign( x, out, clbk, thisArg ) - if ( isFunction( arguments[ 2 ] ) ) { - cb = arguments[ 2 ]; + if ( isnd && isFunction( out ) ) { + o = fromIndex; + cb = out; ctx = arguments[ 3 ]; } // Case: assign( x, out, options, clbk ) + else if ( isnd && isPlainObject( out ) ) { + o = fromIndex; + options = out; + hasOptions = true; + cb = arguments[ 3 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: assign( x, from_index, out, clbk ) else { - options = arguments[ 2 ]; + if ( isnd ) { + fidx = fromIndex; + iflg = false; + } else if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } 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 ) ); + } cb = arguments[ 3 ]; if ( !isFunction( cb ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); } + } + } + // Case: assign( x, ???, ???, ???, ??? ) + else if ( nargs === 5 ) { + isnd = isndarrayLike( fromIndex ); + + // Case: assign( x, out, options, clbk, thisArg ) + if ( isnd && isPlainObject( out ) ) { + o = fromIndex; + options = out; hasOptions = true; + cb = arguments[ 3 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 4 ]; + } + // Case: assign( x, from_index, out, clbk, thisArg ) + else if ( isFunction( arguments[ 3 ] ) ) { + if ( isnd ) { + fidx = fromIndex; + iflg = false; + } else if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } 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 ) ); + } + cb = arguments[ 3 ]; + ctx = arguments[ 4 ]; + } + // Case: assign( x, from_index, out, options, clbk ) + else { + if ( isnd ) { + fidx = fromIndex; + iflg = false; + } else if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } 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; + cb = arguments[ 4 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', cb ) ); + } } } - // Case: assign( x, out, options, clbk, thisArg ) + // Case: assign( x, from_index, out, options, clbk, thisArg ) else { - options = arguments[ 2 ]; - cb = arguments[ 3 ]; - ctx = arguments[ 4 ]; - if ( !isFunction( cb ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } 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; + cb = arguments[ 4 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 5 ]; } if ( hasOptions ) { if ( !isPlainObject( options ) ) { @@ -158,7 +277,17 @@ function assign( x, out ) { if ( ndims( x ) < 1 ) { throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); } - return base( x, out, opts, cb, ctx ); + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + 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, cb, ctx ); } diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/base.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/base.js index 3973f6e9d7cf..c78d0b851500 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/base.js @@ -27,7 +27,8 @@ var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by- // VARIABLES // -var idtypes = dtypes( 'all' ); +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', @@ -47,12 +48,14 @@ var table = { * @name findLastIndex * @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 * @param {Function} clbk - callback function * @param {*} [thisArg] - callback execution context * @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 indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions @@ -60,6 +63,7 @@ var table = { * @returns {ndarray} output ndarray * * @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * function isEven( v ) { @@ -81,14 +85,19 @@ var table = { * // Create an input ndarray: * var x = new ndarray( 'generic', xbuf, sh, sx, ox, 'row-major' ); * +* // Create a from index ndarray: +* var fromIndex = scalar2ndarray( -1, { +* 'dtype': 'int32' +* }); +* * // Perform operation: -* var out = findLastIndex( x, isEven ); +* var out = findLastIndex( x, fromIndex, isEven ); * // returns * * var idx = out.get(); * // returns 5 */ -var findLastIndex = factory( table, [ idtypes ], odtypes, policies ); +var findLastIndex = factory( table, [ idtypes0, idtypes1 ], odtypes, policies ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/index.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/index.js index 61e5539ed4ba..01d6367a3657 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/index.js @@ -53,6 +53,37 @@ * * var arr = ndarray2array( out ); * // returns [ 1, 2 ] +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var findLastIndex = require( '@stdlib/blas/ext/find-last-index' ); +* +* function isEven( v ) { +* return v % 2.0 === 0.0; +* } +* +* // Create a data buffer: +* var xbuf = [ 1.0, 2.0, -3.0, 4.0, -5.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( 'generic', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = findLastIndex( x, 1, isEven ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ 1, 0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/main.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/main.js index 64dc8656c433..ad0a8379a954 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/lib/main.js @@ -23,18 +23,31 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); 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 ndims = require( '@stdlib/ndarray/ndims' ); 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 last element along an ndarray dimension which passes a test implemented by a predicate function. * * @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=-1] - 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 @@ -44,6 +57,7 @@ var base = require( './base.js' ); * @throws {TypeError} first argument must be an ndarray-like object * @throws {TypeError} callback argument must be a function * @throws {TypeError} options argument must be an object +* @throws {TypeError} `fromIndex` argument must be either an ndarray-like object or an integer * @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 @@ -84,19 +98,32 @@ function findLastIndex( x ) { var options; var nargs; var opts; + var fidx; + var iflg; + var ord; var ctx; + var sh; var cb; 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 last element along a dimension: + fidx = -1; + + // 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; @@ -114,6 +141,23 @@ function findLastIndex( x ) { cb = arguments[ 1 ]; ctx = arguments[ 2 ]; } + // Case: findLastIndex( x, from_index_scalar, clbk ) + else if ( isInteger( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + cb = arguments[ 2 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) ); + } + } + // Case: findLastIndex( x, from_index_ndarray, clbk ) + else if ( isndarrayLike( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + iflg = false; + cb = arguments[ 2 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) ); + } + } // Case: findLastIndex( x, options, clbk ) else { options = arguments[ 1 ]; @@ -124,13 +168,62 @@ function findLastIndex( x ) { hasOptions = true; } } - // Case: findLastIndex( x, options, clbk, thisArg ) + // Case: findLastIndex( x, ???, ???, ??? ) + else if ( nargs === 4 ) { + // Case: findLastIndex( x, from_index, clbk, thisArg ) or findLastIndex( x, options, clbk, thisArg ) + if ( isFunction( arguments[ 2 ] ) ) { + cb = arguments[ 2 ]; + ctx = arguments[ 3 ]; + if ( isInteger( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + } else if ( isndarrayLike( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + iflg = false; + } else { + options = arguments[ 1 ]; + hasOptions = true; + } + } + // Case: findLastIndex( x, from_index, options, clbk ) + else if ( isFunction( arguments[ 3 ] ) ) { + cb = arguments[ 3 ]; + if ( isInteger( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + } else if ( isndarrayLike( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + iflg = false; + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', arguments[ 1 ] ) ); + } + options = arguments[ 2 ]; + hasOptions = true; + } + // Case: findLastIndex( x, options, clbk, thisArg ) + else { + options = arguments[ 1 ]; + cb = arguments[ 2 ]; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) ); + } + ctx = arguments[ 3 ]; + hasOptions = true; + } + } + // Case: findLastIndex( x, from_index, options, clbk, thisArg ) else { - options = arguments[ 1 ]; - cb = arguments[ 2 ]; - ctx = arguments[ 3 ]; + if ( isInteger( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + } else if ( isndarrayLike( arguments[ 1 ] ) ) { + fidx = arguments[ 1 ]; + iflg = false; + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', arguments[ 1 ] ) ); + } + options = arguments[ 2 ]; + cb = arguments[ 3 ]; + ctx = arguments[ 4 ]; if ( !isFunction( cb ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) ); + throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) ); } hasOptions = true; } @@ -152,7 +245,17 @@ function findLastIndex( x ) { if ( ndims( x ) < 1 ) { throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); } - return base( x, opts, cb, ctx ); + // Resolve the list of non-reduced dimensions: + sh = getShape( x ); + 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, cb, ctx ); } diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.assign.js index bdf957c98d37..322d17262212 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.assign.js @@ -27,6 +27,7 @@ var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var getOrder = require( '@stdlib/ndarray/order' ); var findLastIndex = require( './../lib' ).assign; @@ -555,6 +556,74 @@ tape( 'the function throws an error if provided an options argument which is not } }); +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 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() { + findLastIndex( x, value, y, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = zeros( [ 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() { + findLastIndex( x, value, y, {}, clbk ); + }; + } +}); + tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { var x; var y; @@ -673,7 +742,7 @@ tape( 'the function returns the index of the last element which passes a test (r var x; var y; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 2.0, 4.0, 6.0, -5.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); y = zeros( [ 2 ], { 'dtype': 'generic', @@ -681,7 +750,7 @@ tape( 'the function returns the index of the last element which passes a test (r }); actual = findLastIndex( x, y, clbk ); - expected = [ 1, 1 ]; + expected = [ 1, 0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -804,7 +873,7 @@ tape( 'the function supports specifying an operation dimension (column-major)', 'order': 'column-major' }); opts = { - 'dims': 1 + 'dim': 1 }; actual = findLastIndex( x, y, opts, clbk ); @@ -820,6 +889,224 @@ tape( 'the function supports specifying an operation dimension (column-major)', t.end(); }); +tape( 'the function supports specifying a starting search index (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = findLastIndex( x, 1, y, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 2.0, -3.0, 1.0, -5.0, 4.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = findLastIndex( x, 1, y, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = findLastIndex( x, 1, y, {}, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + actual = findLastIndex( x, fromIdx, y, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + actual = findLastIndex( x, fromIdx, y, {}, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, 1, y, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, fromIdx, y, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 a starting search index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var opts; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + fromIdx = new ndarray( 'generic', [ 1, 0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, fromIdx, y, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, '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 an execution context', function test( t ) { var expected; var indices; @@ -863,8 +1150,8 @@ tape( 'the function supports providing an execution context', function test( t ) t.deepEqual( values, expected, 'returns expected value' ); expected = [ - [ 0, 0 ], - [ 1, 0 ] + [ 0, 1 ], + [ 1, 1 ] ]; t.deepEqual( indices, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.main.js index 0f4a986dc053..7e906e9bf3a7 100644 --- a/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/find-last-index/test/test.main.js @@ -27,6 +27,7 @@ var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var getOrder = require( '@stdlib/ndarray/order' ); var findLastIndex = require( './../lib' ); @@ -165,6 +166,118 @@ tape( 'the function throws an error if provided a first argument which is not an } }); +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex)', 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() { + findLastIndex( value, 0, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex, thisArg)', 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() { + findLastIndex( value, 0, clbk, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex, 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() { + findLastIndex( value, 0, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex, options, thisArg)', 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() { + findLastIndex( value, 0, {}, clbk, {} ); + }; + } +}); + tape( 'the function throws an error if provided a zero-dimensional input ndarray-like object', function test( t ) { var values; var i; @@ -360,6 +473,66 @@ tape( 'the function throws an error if provided an options argument which is not } }); +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or 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, + [], + 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() { + findLastIndex( x, value, {}, clbk ); + }; + } +}); + +tape( 'the function throws an error if provided a `fromIndex` argument which is not an ndarray-like object or an integer (thisArg)', 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() { + findLastIndex( x, value, {}, clbk, {} ); + }; + } +}); + tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { var x; @@ -520,11 +693,11 @@ tape( 'the function returns the index of the last element which passes a test (r var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 2.0, 4.0, 6.0, -5.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = findLastIndex( x, clbk ); - expected = [ 1, 1 ]; + expected = [ 1, 0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -686,6 +859,176 @@ tape( 'the function supports specifying the output array data type', function te t.end(); }); +tape( 'the function supports specifying a starting search index (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + actual = findLastIndex( x, 1, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 2.0, -3.0, 1.0, -5.0, 4.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + + actual = findLastIndex( x, 1, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + actual = findLastIndex( x, 1, {}, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + actual = findLastIndex( x, fromIdx, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + xbuf = [ 2.0, 1.0, 4.0, -3.0, -5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + actual = findLastIndex( x, fromIdx, {}, clbk ); + expected = [ 0, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, 1, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 1, { + 'dtype': 'int32' + }); + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, fromIdx, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a starting search index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var opts; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 4.0, -3.0, 6.0, -5.0 ]; + x = new ndarray( 'generic', xbuf, [ 3, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = new ndarray( 'generic', [ 1, 0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + opts = { + 'dim': 0 + }; + actual = findLastIndex( x, fromIdx, opts, clbk ); + expected = [ 1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports providing an execution context', function test( t ) { var expected; var indices; @@ -723,8 +1066,8 @@ tape( 'the function supports providing an execution context', function test( t ) t.deepEqual( values, expected, 'returns expected value' ); expected = [ - [ 0, 0 ], - [ 1, 0 ] + [ 0, 1 ], + [ 1, 1 ] ]; t.deepEqual( indices, expected, 'returns expected value' );