From c9d34ee4b89c667cb3c324c46e6b6dc0cb5fdacb Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 5 Jul 2025 19:12:53 +0000 Subject: [PATCH 01/14] feat: add blas/ext/index-of --- .../@stdlib/blas/ext/index-of/README.md | 262 +++++++++ .../index-of/benchmark/benchmark.assign.js | 113 ++++ .../blas/ext/index-of/benchmark/benchmark.js | 105 ++++ .../@stdlib/blas/ext/index-of/docs/repl.txt | 126 +++++ .../blas/ext/index-of/docs/types/index.d.ts | 226 ++++++++ .../blas/ext/index-of/docs/types/test.ts | 531 ++++++++++++++++++ .../blas/ext/index-of/examples/index.js | 41 ++ .../@stdlib/blas/ext/index-of/lib/assign.js | 228 ++++++++ .../@stdlib/blas/ext/index-of/lib/base.js | 109 ++++ .../@stdlib/blas/ext/index-of/lib/index.js | 71 +++ .../@stdlib/blas/ext/index-of/lib/main.js | 204 +++++++ .../blas/ext/index-of/lib/non_core_shape.js | 50 ++ .../@stdlib/blas/ext/index-of/package.json | 67 +++ .../@stdlib/blas/ext/index-of/test/test.js | 39 ++ 14 files changed, 2172 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/README.md b/lib/node_modules/@stdlib/blas/ext/index-of/README.md new file mode 100644 index 000000000000..18f908653c8e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/README.md @@ -0,0 +1,262 @@ + + +# indexOf + +> Return the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var indexOf = require( '@stdlib/blas/ext/index-of' ); +``` + +#### indexOf( x, searchElement\[, fromIndex]\[, options] ) + +Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Find index: +var out = indexOf( x, 2.0 ); +// returns + +var idx = out.get(); +// returns 1 +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], the search element [ndarray][@stdlib/ndarray/ctor] must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a numeric 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a "integer_index" [data type][@stdlib/ndarray/dtypes]. +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **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 search element, the function returns `-1`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +// returns + +// Find index: +var out = indexOf( x, 10.0 ); +// returns + +var idx = out.get(); +// returns -1 +``` + +By default, the function uses `0` as the index from which to begin searching. To begin searching from a different index, provide the `fromIndex` argument. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0, 2.0, 6.0 ] ); +// returns + +// Find index: +var out = indexOf( x, 2.0, 2 ); +// returns + +var idx = out.get(); +// returns 4 +``` + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); + +var out = indexOf( x, -3.0, { + 'dims': [ 0 ] +}); +// returns + +var idx = ndarray2array( out ); +// returns [ 1, -1 ] +``` + +By default, the function returns an [`ndarray`][@stdlib/ndarray/ctor] having a shape matching only the non-reduced dimensions of the input [`ndarray`][@stdlib/ndarray/ctor] (i.e., the reduced dimensions are dropped). To include the reduced dimensions as singleton dimensions in the output [`ndarray`][@stdlib/ndarray/ctor], set the `keepdims` option to `true`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +// Create an input ndarray: +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); +// returns + +var opts = { + 'dims': [ 0 ], + 'keepdims': true +}; + +// Find index: +var out = indexOf( x, -3.0, opts ); +// returns + +var idx = ndarray2array( out ); +// returns [ [ 1, -1 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var idx = indexOf( x, 2.0, { + 'dtype': 'generic' +}); +// returns + +var dt = dtype( idx ); +// returns 'generic' +``` + +#### indexOf.assign( x, searchElement\[, fromIndex], out\[, options] ) + +Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = zeros( [], { + 'dtype': 'int32' +}); + +var out = indexOf.assign( x, 3.0, y ); +// returns + +var idx = out.get(); +// returns 2 + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] initial value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a numeric 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or generic [data type][@stdlib/ndarray/dtypes]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before computing the cumulative sum. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var indexOf = require( '@stdlib/blas/ext/index-of' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Find index: +var idx = indexOf( x, 10.0, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..47e739512b04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.assign.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var indexOf = 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 = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + 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 = indexOf.assign( x, 10.0, 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( pkg+':assign:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.js new file mode 100644 index 000000000000..959df5a92fcc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var indexOf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + 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 = indexOf( x, 10.0 ); + 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( pkg+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt new file mode 100644 index 000000000000..af117ed559e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt @@ -0,0 +1,126 @@ + +{{alias}}( x, searchElement[, fromIndex][, options] ) + Returns the first index of a specified search element along one or more + ndarray dimensions. + + Parameters + ---------- + x: ndarray + Input array. + + searchElement: ndarray|number|ComplexLike + Element in an input ndarray for which to find an index. May be either a + scalar value or an ndarray having a data type same as the data type of + the input ndarray. If provided a scalar value, the value is cast to the + data type of the input ndarray. If provided an ndarray, the value must + have a shape which is broadcast compatible with the complement of the + shape defined by `options.dims`. For example, given the input shape + `[2, 3, 4]` and `options.dims=[0]`, the search element ndarray must have + a shape which is broadcast-compatible with the shape `[3, 4]`. Similarly + when performing the operation over all elements in a provided input + ndarray, a search element ndarray must be a zero-dimensional ndarray. + + fromIndex: ndarray|number (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an `int32` or `generic` data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the + complement of the shape defined by `options.dims`. For example, given + the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray + containing the index from which to begin searching must have a shape + which is broadcast-compatible with the shape `[3, 4]`. Similarly + when performing the operation over all elements in a provided input + ndarray, an ndarray containing the index from which to begin searching + must be a zero-dimensional ndarray. By default, the the index from which + to begin searching is `0`. + + options: Object (optional) + Function options. + + options.dtype: string (optional) + Output array data type. Must be a "integer_index" data type. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var y = {{alias}}( x, 2.0 ); + > var v = y.get() + 1.0 + + +{{alias}}.assign( x, searchElement[, fromIndex], out[, options] ) + Returns the first index of a specified search element along one or more + ndarray dimensions and assigns results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + searchElement: ndarray|number|ComplexLike + Element in an input ndarray for which to find an index. May be either a + scalar value or an ndarray having a data type same as the data type of + the input ndarray. If provided a scalar value, the value is cast to the + data type of the input ndarray. If provided an ndarray, the value must + have a shape which is broadcast compatible with the complement of the + shape defined by `options.dims`. For example, given the input shape + `[2, 3, 4]` and `options.dims=[0]`, the search element ndarray must have + a shape which is broadcast-compatible with the shape `[3, 4]`. Similarly + when performing the operation over all elements in a provided input + ndarray, a search element ndarray must be a zero-dimensional ndarray. + + fromIndex: ndarray|number (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an `int32` or `generic` data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the + complement of the shape defined by `options.dims`. For example, given + the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray + containing the index from which to begin searching must have a shape + which is broadcast-compatible with the shape `[3, 4]`. Similarly + when performing the operation over all elements in a provided input + ndarray, an ndarray containing the index from which to begin searching + must be a zero-dimensional ndarray. By default, the the index from which + to begin searching is `0`. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); + > var y = {{alias}}.assign( x, 2.0, out ) + + > var bool = ( out === y ) + true + > var v = out.get() + 1.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts new file mode 100644 index 000000000000..9164bb105ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts @@ -0,0 +1,226 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { IntegerAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Search element. +*/ +type SearchElement = typedndarray | T; + +/** +* From index. +*/ +type FromIndex = typedndarray | U; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* 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 `indexOf`. +*/ +interface IndexOf { + /** + * Returns the first index of specified search element along one or more ndarray dimensions. + * + * @param x - input ndarray + * @param searchElement - search element + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * + * var y = indexOf( x, 2.0 ); + * // returns + * + * var idx = y.get(); + * // returns 1 + */ + ( x: InputArray, searchElement: SearchElement, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + + /** + * Returns the first index of specified search element along one or more ndarray dimensions. + * + * @param x - input ndarray + * @param searchElement - search element + * @param fromIndex - index from which to begin searching + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0 ] ); + * + * var y = indexOf( x, 2.0, 2 ); + * // returns + * + * var idx = y.get(); + * // returns 3 + */ + ( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + + /** + * Returns the first index of a specified search element along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param searchElement - search element + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = indexOf.assign( x, 2.0, y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var idx = out.get(); + * // returns 1 + */ + assign = OutputArray>( x: InputArray, searchElement: SearchElement, out: U, options?: BaseOptions ): U; + + /** + * Returns the first index of a specified search element along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param searchElement - search element + * @param fromIndex - index from which to begin searching + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0 ] ); + * var y = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = indexOf.assign( x, 2.0, 2, y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var idx = out.get(); + * // returns 3 + */ + assign = OutputArray, V = unknown>( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, out: U, options?: BaseOptions ): U; +} + +/** +* Returns the first index of a specified search element along one or more ndarray dimensions. +* +* @param x - input ndarray +* @param searchElement - search element +* @param fromIndex - index from which to begin searching +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* +* var y = indexOf( x, 2.0 ); +* // returns +* +* var idx = y.get(); +* // returns 1 +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* var y = zeros( x, { +* 'dtype': 'int32' +* } ); +* +* var out = indexOf.assign( x, 2.0, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var idx = out.get(); +* // returns 1 +*/ +declare const indexOf: IndexOf; + + +// EXPORTS // + +export = indexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts new file mode 100644 index 000000000000..d00ce1e4c5ed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts @@ -0,0 +1,531 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import indexOf = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, 0.0 ); // $ExpectType OutputArray + indexOf( x, 0.0, 1 ); // $ExpectType OutputArray + indexOf( x, 0.0, {} ); // $ExpectType OutputArray + indexOf( x, 0.0, 1, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + indexOf( '5', 0.0 ); // $ExpectError + indexOf( 5, 0.0 ); // $ExpectError + indexOf( true, 0.0 ); // $ExpectError + indexOf( false, 0.0 ); // $ExpectError + indexOf( null, 0.0 ); // $ExpectError + indexOf( void 0, 0.0 ); // $ExpectError + indexOf( {}, 0.0 ); // $ExpectError + indexOf( ( x: number ): number => x, 0.0 ); // $ExpectError + + indexOf( '5', 0.0, 0 ); // $ExpectError + indexOf( 5, 0.0, 0 ); // $ExpectError + indexOf( true, 0.0, 0 ); // $ExpectError + indexOf( false, 0.0, 0 ); // $ExpectError + indexOf( null, 0.0, 0 ); // $ExpectError + indexOf( void 0, 0.0, 0 ); // $ExpectError + indexOf( {}, 0.0, 0 ); // $ExpectError + indexOf( ( x: number ): number => x, 0.0, 0 ); // $ExpectError + + indexOf( '5', 0.0, {} ); // $ExpectError + indexOf( 5, 0.0, {} ); // $ExpectError + indexOf( true, 0.0, {} ); // $ExpectError + indexOf( false, 0.0, {} ); // $ExpectError + indexOf( null, 0.0, {} ); // $ExpectError + indexOf( void 0, 0.0, {} ); // $ExpectError + indexOf( {}, 0.0, {} ); // $ExpectError + indexOf( ( x: number ): number => x, 0.0, {} ); // $ExpectError + + indexOf( '5', 0.0, 0, {} ); // $ExpectError + indexOf( 5, 0.0, 0, {} ); // $ExpectError + indexOf( true, 0.0, 0, {} ); // $ExpectError + indexOf( false, 0.0, 0, {} ); // $ExpectError + indexOf( null, 0.0, 0, {} ); // $ExpectError + indexOf( void 0, 0.0, 0, {} ); // $ExpectError + indexOf( {}, 0.0, 0, {} ); // $ExpectError + indexOf( ( x: number ): number => x, 0.0, 0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a search element argument which is not an ndarray or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, '5' ); // $ExpectError + indexOf( x, true ); // $ExpectError + indexOf( x, false ); // $ExpectError + indexOf( x, [] ); // $ExpectError + indexOf( x, ( x: number ): number => x ); // $ExpectError + + indexOf( x, '5', 0 ); // $ExpectError + indexOf( x, true, 0 ); // $ExpectError + indexOf( x, false, 0 ); // $ExpectError + indexOf( x, [], 0 ); // $ExpectError + indexOf( x, ( x: number ): number => x, 0 ); // $ExpectError + + indexOf( x, '5', {} ); // $ExpectError + indexOf( x, true, {} ); // $ExpectError + indexOf( x, false, {} ); // $ExpectError + indexOf( x, [], {} ); // $ExpectError + indexOf( x, ( x: number ): number => x, {} ); // $ExpectError + + indexOf( x, '5', 0, {} ); // $ExpectError + indexOf( x, true, 0, {} ); // $ExpectError + indexOf( x, false, 0, {} ); // $ExpectError + indexOf( x, [], 0, {} ); // $ExpectError + indexOf( x, ( x: number ): number => x, 0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a from index argument which is not an ndarray or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, 0.0, '5' ); // $ExpectError + indexOf( x, 0.0, true ); // $ExpectError + indexOf( x, 0.0, false ); // $ExpectError + indexOf( x, 0.0, [] ); // $ExpectError + indexOf( x, 0.0, ( x: number ): number => x ); // $ExpectError + + indexOf( x, 0.0, '5' ); // $ExpectError + indexOf( x, 0.0, true ); // $ExpectError + indexOf( x, 0.0, false ); // $ExpectError + indexOf( x, 0.0, [] ); // $ExpectError + indexOf( x, 0.0, ( x: number ): number => x ); // $ExpectError + + indexOf( x, 0.0, '5', {} ); // $ExpectError + indexOf( x, 0.0, true, {} ); // $ExpectError + indexOf( x, 0.0, false, {} ); // $ExpectError + indexOf( x, 0.0, [], {} ); // $ExpectError + indexOf( x, 0.0, ( x: number ): number => x, {} ); // $ExpectError + + indexOf( x, 0.0, '5', {} ); // $ExpectError + indexOf( x, 0.0, true, {} ); // $ExpectError + indexOf( x, 0.0, false, {} ); // $ExpectError + indexOf( x, 0.0, [], {} ); // $ExpectError + indexOf( x, 0.0, ( x: number ): number => x, {} ); // $ExpectError +} + + +// The compiler throws an error if the function is provided a options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, 0.0, '5' ); // $ExpectError + indexOf( x, 0.0, true ); // $ExpectError + indexOf( x, 0.0, false ); // $ExpectError + indexOf( x, 0.0, [] ); // $ExpectError + indexOf( x, 0.0, ( x: number ): number => x ); // $ExpectError + + indexOf( x, 0.0, 0, '5' ); // $ExpectError + indexOf( x, 0.0, 0, true ); // $ExpectError + indexOf( x, 0.0, 0, false ); // $ExpectError + indexOf( x, 0.0, 0, null ); // $ExpectError + indexOf( x, 0.0, 0, [] ); // $ExpectError + indexOf( x, 0.0, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, 0.0, { 'dtype': '5' } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': 5 } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': true } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': false } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': null } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': [] } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': {} } ); // $ExpectError + indexOf( x, 0.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError + + indexOf( x, 0.0, 0, { 'dtype': '5' } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': 5 } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': true } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': false } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': null } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': [] } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': {} } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf( x, 0.0, { 'dims': '5' } ); // $ExpectError + indexOf( x, 0.0, { 'dims': 5 } ); // $ExpectError + indexOf( x, 0.0, { 'dims': true } ); // $ExpectError + indexOf( x, 0.0, { 'dims': false } ); // $ExpectError + indexOf( x, 0.0, { 'dims': null } ); // $ExpectError + indexOf( x, 0.0, { 'dims': {} } ); // $ExpectError + indexOf( x, 0.0, { 'dims': ( x: number ): number => x } ); // $ExpectError + + indexOf( x, 0.0, 0, { 'dims': '5' } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': 5 } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': true } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': false } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': null } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': {} } ); // $ExpectError + indexOf( x, 0.0, 0, { 'dims': ( 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' + }); + + indexOf( x, 0.0, { 'keepdims': '5' } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': 5 } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': true } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': false } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': null } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': {} } ); // $ExpectError + indexOf( x, 0.0, { 'keepdims': ( x: number ): number => x } ); // $ExpectError + + indexOf( x, 0.0, 0, { 'keepdims': '5' } ); // $ExpectError + indexOf( x, 0.0, 0, { 'keepdims': 5 } ); // $ExpectError + indexOf( x, 0.0, 0, { 'keepdims': null } ); // $ExpectError + indexOf( x, 0.0, 0, { 'keepdims': {} } ); // $ExpectError + indexOf( x, 0.0, 0, { 'keepdims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf(); // $ExpectError + indexOf( x, 0.0, 0, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, y ); // $ExpectType int32ndarray + indexOf.assign( x, 0.0, y, {} ); // $ExpectType in32ndarray + indexOf.assign( x, 0.0, 1, y ); // $ExpectType in32ndarray + indexOf.assign( x, 0.0, 1, y, {} ); // $ExpectType in32ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( '5', 0.0, y ); // $ExpectError + indexOf.assign( 5, 0.0, y ); // $ExpectError + indexOf.assign( true, 0.0, y ); // $ExpectError + indexOf.assign( false, 0.0, y ); // $ExpectError + indexOf.assign( null, 0.0, y ); // $ExpectError + indexOf.assign( void 0, 0.0, y ); // $ExpectError + indexOf.assign( {}, 0.0, y ); // $ExpectError + indexOf.assign( ( x: number ): number => x, 0.0, y ); // $ExpectError + + indexOf.assign( '5', 0.0, 0, y ); // $ExpectError + indexOf.assign( 5, 0.0, 0, y ); // $ExpectError + indexOf.assign( true, 0.0, 0, y ); // $ExpectError + indexOf.assign( false, 0.0, 0, y ); // $ExpectError + indexOf.assign( null, 0.0, 0, y ); // $ExpectError + indexOf.assign( void 0, 0.0, 0, y ); // $ExpectError + indexOf.assign( {}, 0.0, 0, y ); // $ExpectError + indexOf.assign( ( x: number ): number => x, 0.0, 0, y ); // $ExpectError + + indexOf.assign( '5', 0.0, y, {} ); // $ExpectError + indexOf.assign( 5, 0.0, y, {} ); // $ExpectError + indexOf.assign( true, 0.0, y, {} ); // $ExpectError + indexOf.assign( false, 0.0, y, {} ); // $ExpectError + indexOf.assign( null, 0.0, y, {} ); // $ExpectError + indexOf.assign( void 0, 0.0, y, {} ); // $ExpectError + indexOf.assign( {}, 0.0, y, {} ); // $ExpectError + indexOf.assign( ( x: number ): number => x, 0.0, y, {} ); // $ExpectError + + indexOf.assign( '5', 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( 5, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( true, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( false, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( null, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( void 0, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( {}, 0.0, 0, y, {} ); // $ExpectError + indexOf.assign( ( x: number ): number => x, 0.0, 0, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a search element argument which is not an ndarray or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, '5', y ); // $ExpectError + indexOf.assign( x, 5, y ); // $ExpectError + indexOf.assign( x, true, y ); // $ExpectError + indexOf.assign( x, false, y ); // $ExpectError + indexOf.assign( x, null, y ); // $ExpectError + indexOf.assign( x, void 0, y ); // $ExpectError + indexOf.assign( x, {}, y ); // $ExpectError + indexOf.assign( x, ( x: number ): number => x, y ); // $ExpectError + + indexOf.assign( x, '5', 0, y ); // $ExpectError + indexOf.assign( x, 5, 0, y ); // $ExpectError + indexOf.assign( x, true, 0, y ); // $ExpectError + indexOf.assign( x, false, 0, y ); // $ExpectError + indexOf.assign( x, null, 0, y ); // $ExpectError + indexOf.assign( x, void 0, 0, y ); // $ExpectError + indexOf.assign( x, {}, 0, y ); // $ExpectError + indexOf.assign( x, ( x: number ): number => x, 0, y ); // $ExpectError + + indexOf.assign( x, '5', y, {} ); // $ExpectError + indexOf.assign( x, 5, y, {} ); // $ExpectError + indexOf.assign( x, true, y, {} ); // $ExpectError + indexOf.assign( x, false, y, {} ); // $ExpectError + indexOf.assign( x, null, y, {} ); // $ExpectError + indexOf.assign( x, void 0, y, {} ); // $ExpectError + indexOf.assign( x, {}, y, {} ); // $ExpectError + indexOf.assign( x, ( x: number ): number => x, y, {} ); // $ExpectError + + indexOf.assign( x, '5', 0, y, {} ); // $ExpectError + indexOf.assign( x, 5, 0, y, {} ); // $ExpectError + indexOf.assign( x, true, 0, y, {} ); // $ExpectError + indexOf.assign( x, false, 0, y, {} ); // $ExpectError + indexOf.assign( x, null, 0, y, {} ); // $ExpectError + indexOf.assign( x, void 0, 0, y, {} ); // $ExpectError + indexOf.assign( x, {}, 0, y, {} ); // $ExpectError + indexOf.assign( x, ( x: number ): number => x, 0, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a from index argument which is not an ndarray or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, '5', y ); // $ExpectError + indexOf.assign( x, 0.0, 5, y ); // $ExpectError + indexOf.assign( x, 0.0, true, y ); // $ExpectError + indexOf.assign( x, 0.0, false, y ); // $ExpectError + indexOf.assign( x, 0.0, null, y ); // $ExpectError + indexOf.assign( x, 0.0, void 0, y ); // $ExpectError + indexOf.assign( x, 0.0, {}, y ); // $ExpectError + indexOf.assign( x, 0.0, ( x: number ): number => x, y ); // $ExpectError + + indexOf.assign( x, 0.0, '5', y, {} ); // $ExpectError + indexOf.assign( x, 0.0, 5, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, true, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, false, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, null, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, void 0, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, {}, y, {} ); // $ExpectError + indexOf.assign( x, 0.0, ( x: number ): number => x, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + indexOf.assign( x, 0.0, '5' ); // $ExpectError + indexOf.assign( x, 0.0, 5 ); // $ExpectError + indexOf.assign( x, 0.0, true ); // $ExpectError + indexOf.assign( x, 0.0, false ); // $ExpectError + indexOf.assign( x, 0.0, null ); // $ExpectError + indexOf.assign( x, 0.0, void 0 ); // $ExpectError + indexOf.assign( x, 0.0, ( x: number ): number => x ); // $ExpectError + + indexOf.assign( x, 0.0, '5', {} ); // $ExpectError + indexOf.assign( x, 0.0, 5, {} ); // $ExpectError + indexOf.assign( x, 0.0, true, {} ); // $ExpectError + indexOf.assign( x, 0.0, false, {} ); // $ExpectError + indexOf.assign( x, 0.0, null, {} ); // $ExpectError + indexOf.assign( x, 0.0, void 0, {} ); // $ExpectError + indexOf.assign( x, 0.0, ( x: number ): number => x, {} ); // $ExpectError + + indexOf.assign( x, 0.0, 1, '5' ); // $ExpectError + indexOf.assign( x, 0.0, 1, 5 ); // $ExpectError + indexOf.assign( x, 0.0, 1, true ); // $ExpectError + indexOf.assign( x, 0.0, 1, false ); // $ExpectError + indexOf.assign( x, 0.0, 1, null ); // $ExpectError + indexOf.assign( x, 0.0, 1, void 0 ); // $ExpectError + indexOf.assign( x, 0.0, 1, ( x: number ): number => x ); // $ExpectError + + indexOf.assign( x, 0.0, 1, '5', {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, 5, {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, true, {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, false, {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, null, {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, void 0, {} ); // $ExpectError + indexOf.assign( x, 0.0, 1, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, y, '5' ); // $ExpectError + indexOf.assign( x, 0.0, y, true ); // $ExpectError + indexOf.assign( x, 0.0, y, false ); // $ExpectError + indexOf.assign( x, 0.0, y, null ); // $ExpectError + indexOf.assign( x, 0.0, y, [] ); // $ExpectError + indexOf.assign( x, 0.0, y, ( x: number ): number => x ); // $ExpectError + + indexOf.assign( x, 0.0, 1, y, '5' ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, true ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, false ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, null ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, [] ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, y, { 'dims': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': true } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': false } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': null } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': {} } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dims': ( x: number ): number => x } ); // $ExpectError + + indexOf.assign( x, 0.0, 1, y, { 'dims': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': true } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': false } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': null } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': {} } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, y, { 'dtype': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': true } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': false } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': null } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': {} } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'dtype': ( x: number ): number => x } ); // $ExpectError + + indexOf.assign( x, 0.0, 1, y, { 'dtype': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': true } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': false } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': null } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': {} } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [], { + 'dtype': 'int32' + }); + + indexOf.assign( x, 0.0, y, { 'keepdims': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': true } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': false } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': null } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': {} } ); // $ExpectError + indexOf.assign( x, 0.0, y, { 'keepdims': ( x: number ): number => x } ); // $ExpectError + + indexOf.assign( x, 0.0, 1, y, { 'keepdims': '5' } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': 5 } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': true } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': false } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': null } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': {} } ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, { 'keepdims': ( 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' + }); + + indexOf.assign(); // $ExpectError + indexOf.assign( x ); // $ExpectError + indexOf.assign( x, 0.0 ); // $ExpectError + indexOf.assign( x, 0.0, 1, y, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/index-of/examples/index.js new file mode 100644 index 000000000000..f8c44f943927 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var indexOf = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 10, 0, 20, { + 'dtype': 'float64' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Find index: +var idx = indexOf( x, 10.0, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js new file mode 100644 index 000000000000..d6cb8b5dd85a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -0,0 +1,228 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNumber = require( '@stdlib/assert/is-number' ).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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var nonCoreShape = require( './non_core_shape.js' ); +var base = require( './base.js' ).assign; + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the first index of a specified search element along one or more ndarray dimensions and assigns the results to a provided output ndarray. +* +* @name assign +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number)} searchElement - search element +* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions 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 {string} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} search element argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} from index argument must be either an ndarray-like object or a numeric value +* @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 zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var strides = [ 2, 2, 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( [], { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = assign( x, 4.0, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var idx = out.get(); +* // returns 3 +*/ +function assign( x, searchElement, fromIndex, out, options ) { + var nargs; + var opts; + var ord; + var dt; + var sh; + + nargs = arguments.length; + + // Resolve input ndarray meta data: + dt = getDType( x ); + ord = getOrder( x ); + + if ( nargs === 3 ) { + // Case: assign( x, searchElement, out ) + out = fromIndex; + + if ( isndarrayLike( out ) ) { + // Case: indexOf( x, searchElement_ndarray, out ) + if ( isndarrayLike( searchElement ) ) { + return base( x, searchElement, broadcastScalar( 0, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len + } + // Case: indexOf( x, searchElement_scalar, out ) + if ( isNumber( searchElement ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( 0, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len + } + // Check for other scalars than `Number` i.e. bool + } else { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', out ) ); + } + } + // Case: assign( x, searchElement, fromIndex, out ) + else if ( nargs < 5 ) { + if ( isndarrayLike( out ) ) { + // Case: indexOf( x, searchElement_ndarray, fromIndex_ndarray, out ) + if ( isndarrayLike( searchElement ) & isndarrayLike( fromIndex ) ) { + return base( x, searchElement, fromIndex, out ); + } + // Case: indexOf( x, searchElement_scalar, fromIndex_scalar out ) + if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len + } + // Case: indexOf( x, searchElement_ndarray, fromIndex_scalar, out ) + if ( isndarrayLike( searchElement ) & isNumber( fromIndex ) ) { + return base( x, searchElement, broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len + } + // Case: indexOf( x, searchElement_scalar, fromIndex_ndarray out ) + if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), fromIndex, out ); // eslint-disable-line max-len + } + // Check for other scalars than `Number` i.e. bool + + // Case: assign( x, searchElement, out, options ) + out = fromIndex; + opts = out; + + // Case: indexOf( x, searchElement_ndarray, out, options ) + if ( isndarrayLike( searchElement ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len + } + } + // Case: indexOf( x, searchElement_scalar, opts ) + else if ( isNumber( searchElement ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, sh, ord ); + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', searchElement ) ); + } + return base( x, searchElement, fromIndex, out, opts ); + } + } + + opts = options; + + // Case: assign( x, searchElement_ndarray, fromIndex_ndarray, out, options ) + if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } + } + // Case: assign( x, searchElement_scalar, fromIndex_scalar, out, options ) + else if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); + fromIndex = broadcastScalar( fromIndex, dt, sh, getOrder( x ) ); + } + // Case: assign( x, searchElement_ndarray, fromIndex_scalar, out, options ) + else if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( fromIndex, dt, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len + } + } + // Case: assign( x, searchElement_scalar, fromIndex_ndarray, out, options ) + else if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, ord ); + fromIndex = maybeBroadcastArray( fromIndex, dt, sh, ord ); + } else { + throw new TypeError( format( 'invalid argument. Second and third arguments must be either an ndarray or a scalar value. Value: `%s`.', searchElement, fromIndex ) ); + } + return base( x, searchElement, fromIndex, out, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js new file mode 100644 index 000000000000..0cb354c39743 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gindexOf = require( '@stdlib/blas/ext/base/ndarray/gindex-of' ); +var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); +var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'numeric_and_generic' ); // input ndarray +var idtypes1 = dtypes( 'numeric_and_generic' ); // search element ndarray +var idtypes2 = dtypes( 'integer_index_and_generic' ); // from index ndarray +var odtypes = dtypes( 'integer_index_and_generic' ); +var policies = { + 'output': 'integer_index_and_generic', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', + 'float32' + + // FIXME: add specialized support for `cindexOf` and `zindexOf` once the corresponding packages are implemented + ], + 'fcns': [ + dindexOf, + sindexOf + ], + 'default': gindexOf +}; + + +// MAIN // + +/** +* Returns the first index of a specified search element along one or more ndarray dimensions. +* +* @private +* @name indexOf +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number)} searchElement - search element +* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {string} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} search element argument must be either an ndarray-like object or a scalar value +* @throws {TypeError} from index argument must be either an ndarray-like object or a scalar value +* @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( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Find index: +* var out = indexOf( x, 4.0 ); +* // returns +* +* var idx = out.get(); +* // returns 3 +*/ +var indexOf = factory( table, [ idtypes0, idtypes1, idtypes2 ], odtypes, policies ); // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = indexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js new file mode 100644 index 000000000000..37ce525adf94 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the first index of a specified search element along one or more ndarray dimensions. +* +* @module @stdlib/blas/ext/index-of +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var indexOf = require( '@stdlib/blas/ext/index-of' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Find index: +* var out = indexOf( x, 4.0 ); +* // returns +* +* var idx = out.data; +* // returns [ 3 ] +*/ + +// 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/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js new file mode 100644 index 000000000000..bc5d305765b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js @@ -0,0 +1,204 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNumber = require( '@stdlib/assert/is-number' ).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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var nonCoreShape = require( './non_core_shape.js' ); +var base = require( './base.js' ); + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the first index of a specified search element along one or more ndarray dimensions. +* +* @name indexOf +* @type {Function} +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number)} searchElement - search element +* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions 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 {string} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} search element argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} from index argument must be either an ndarray-like object or a numeric value +* @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( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Find index: +* var out = indexOf( x, 4.0 ); +* // returns +* +* var idx = out.get(); +* // returns 3 +*/ +function indexOf( x, searchElement, fromIndex, options ) { + var nargs; + var opts; + var ord; + var dt; + var sh; + + nargs = arguments.length; + + // Resolve input ndarray meta data: + dt = getDType( x ); + ord = getOrder( x ); + + // Case: indexOf( x, searchElement ) + if ( nargs === 2 ) { + // Case: indexOf( x, searchElement_ndarray ) + if ( isndarrayLike( searchElement ) ) { + // As the operation is performed across all dimensions, `searchElement` is assumed to be a zero-dimensional ndarray... + return base( x, searchElement, broadcastScalar( 0, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len + } + // Case: indexOf( x, searchElement_scalar ) + if ( isNumber( searchElement ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( 0, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len + } + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a scalar value. Value: `%s`.', searchElement ) ); + } + // Case: indexOf( x, searchElement, ??? ) + else if ( nargs < 4 ) { // nargs < 4 + // Case: indexOf( x, searchElement, fromIndex ) + if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { + // As the operation is performed across all dimensions, `se` & `fromIndex` is assumed to be a zero-dimensional ndarray... + return base( x, searchElement, fromIndex ); + } + if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len + } + if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { + // As the operation is performed across all dimensions, `se` & `fromIndex` is assumed to be a zero-dimensional ndarray... + return base( x, searchElement, broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len + } + if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { + return base( x, broadcastScalar( searchElement, dt, [], ord ), fromIndex ); // eslint-disable-line max-len + } + + // Case: indexOf( x, searchElement, options ) + opts = fromIndex; + + // Case: indexOf( x, searchElement_ndarray, opts ) + if ( isndarrayLike( searchElement ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len + } + } + // Case: indexOf( x, searchElement_scalar, opts ) + else if ( isNumber( searchElement ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, sh, ord ); // eslint-disable-line max-len + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', searchElement ) ); + } + return base( x, searchElement, fromIndex, opts ); + } + + // Case: indexOf( x, searchElement, fromIndex, options ) + opts = options; + + // Case: indexOf( x, searchElement_ndarray, fromIndex_ndarray, opts ) + if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } + } + // Case: indexOf( x, searchElement_scalar, fromIndex_scalar, opts ) + else if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); + fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, sh, getOrder( x ) ); // eslint-disable-line max-len + } else if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len + } + } else if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); + fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } else { + throw new TypeError( format( 'invalid argument. Second and third arguments must be either an ndarray or a scalar value. Value: `%s`.', searchElement ) ); + } + return base( x, searchElement, fromIndex, opts ); +} + + +// EXPORTS // + +module.exports = indexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js new file mode 100644 index 000000000000..07e99731e89f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); +var indicesComplement = require( '@stdlib/array/base/indices-complement' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); + + +// MAIN // + +/** +* Returns the shape defined by the dimensions which are **not** included in a list of dimensions. +* +* @private +* @param {NonNegativeIntegerArray} shape - input ndarray +* @param {IntegerArray} dims - list of dimensions +* @returns {NonNegativeIntegerArray} shape +*/ +function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/ndarray/base` utility + var ind = normalizeIndices( dims, shape.length-1 ); + if ( ind === null ) { + // Note: this is an error condition, as `null` is returned when provided out-of-bounds indices... + return []; + } + return takeIndexed( shape, indicesComplement( shape.length, ind ) ); +} + + +// EXPORTS // + +module.exports = nonCoreShape; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/package.json b/lib/node_modules/@stdlib/blas/ext/index-of/package.json new file mode 100644 index 000000000000..ce741c897892 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/index-of", + "version": "0.0.0", + "description": "Return the first index of a specified search element along one or more ndarray dimensions.", + "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", + "element", + "array", + "ndarray", + "strided", + "double", + "float", + "float64", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.js new file mode 100644 index 000000000000..613d92b3d402 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var indexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( indexOf, 'assign' ), true, 'returns expected value' ); + t.end(); +}); From e4c25675decf0e91eaa89f530dc9267891d1556d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 09:24:14 +0000 Subject: [PATCH 02/14] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/index-of/lib/base.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js index 0cb354c39743..df951f5a0a74 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js @@ -61,14 +61,14 @@ var table = { * @name indexOf * @type {Function} * @param {ndarrayLike} x - input ndarray -* @param {(ndarrayLike|number)} searchElement - search element -* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {ndarrayLike} searchElement - search element +* @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 {string} [options.dtype] - output ndarray data type * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} search element argument must be either an ndarray-like object or a scalar value -* @throws {TypeError} from index argument must be either an ndarray-like object or a scalar value +* @throws {TypeError} second argument must be either an ndarray-like object +* @throws {TypeError} third argument must be either an ndarray-like object * @throws {TypeError} options argument must be an object * @throws {RangeError} dimension indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions @@ -77,6 +77,7 @@ var table = { * * @example * var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * // Create a data buffer: @@ -94,8 +95,18 @@ var table = { * // Create an input ndarray: * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * +* // Create a search element ndarray: +* var searchElement = scalar2ndarray( 4.0, { +* 'dtype': 'float64' +* }) +* +* // Create a from index ndarray: +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'int32' +* }) +* * // Find index: -* var out = indexOf( x, 4.0 ); +* var out = indexOf( x, searchElement, fromIndex ); * // returns * * var idx = out.get(); From 22dbb6f94d0b5a5978e353263cc2569c6e32b76e Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 12:44:03 +0000 Subject: [PATCH 03/14] refactor: cleanup & refactor implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/index-of/README.md | 10 +- .../@stdlib/blas/ext/index-of/lib/assign.js | 153 ++++++------------ .../@stdlib/blas/ext/index-of/lib/index.js | 5 +- .../@stdlib/blas/ext/index-of/lib/main.js | 138 ++++++---------- 4 files changed, 103 insertions(+), 203 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/README.md b/lib/node_modules/@stdlib/blas/ext/index-of/README.md index 18f908653c8e..31457170d644 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/README.md +++ b/lib/node_modules/@stdlib/blas/ext/index-of/README.md @@ -53,12 +53,12 @@ The function has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. - **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], the search element [ndarray][@stdlib/ndarray/ctor] must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. -- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a numeric 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer` 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. - **options**: function options (_optional_). The function accepts the following options: -- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a "integer_index" [data type][@stdlib/ndarray/dtypes]. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an "integer_index_and_generic" [data type][@stdlib/ndarray/dtypes]. - **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. - **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. @@ -181,8 +181,8 @@ The method has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. - **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] initial value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. -- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a numeric 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. -- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or generic [data type][@stdlib/ndarray/dtypes]. +- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer` 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 complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the the index from which to begin searching is `0`. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have an `integer` or `generic` [data type][@stdlib/ndarray/dtypes]. - **options**: function options (_optional_). The method accepts the following options: @@ -221,7 +221,7 @@ var xbuf = discreteUniform( 10, 0, 20, { }); // Wrap in an ndarray: -var x = new ndarray( 'float64', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Find index: diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js index d6cb8b5dd85a..9a688abfafa0 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -21,7 +21,8 @@ // MODULES // var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var objectAssign = require( '@stdlib/object/assign' ); +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' ); @@ -47,16 +48,17 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * @name assign * @type {Function} * @param {ndarrayLike} x - input ndarray -* @param {(ndarrayLike|number)} searchElement - search element -* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {(ndarrayLike|*)} searchElement - search element +* @param {(ndarrayLike|integer)} [fromIndex] - index from which to begin searching * @param {ndarrayLike} out - output ndarray * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions 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 {string} [options.dtype] - output ndarray data type +* @throws {TypeError} function must be provided at least two arguments * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} search element argument must be either an ndarray-like object or a numeric value -* @throws {TypeError} from index argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} third argument must be either an ndarray-like object or an integer +* @throws {TypeError} fourth 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 @@ -66,7 +68,6 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * @example * var Float64Array = require( '@stdlib/array/float64' ); * var zeros = require( '@stdlib/ndarray/zeros' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * // Create data buffers: @@ -107,118 +108,62 @@ function assign( x, searchElement, fromIndex, out, options ) { var sh; nargs = arguments.length; + if ( nargs < 3 ) { + throw new TypeError( format( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.', nargs ) ); + } + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.', x ) ); + } // Resolve input ndarray meta data: dt = getDType( x ); ord = getOrder( x ); + // Initialize options object: + opts = {}; + + // Case: assign( x, searchElement, out ) if ( nargs === 3 ) { - // Case: assign( x, searchElement, out ) out = fromIndex; - - if ( isndarrayLike( out ) ) { - // Case: indexOf( x, searchElement_ndarray, out ) - if ( isndarrayLike( searchElement ) ) { - return base( x, searchElement, broadcastScalar( 0, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len - } - // Case: indexOf( x, searchElement_scalar, out ) - if ( isNumber( searchElement ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( 0, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len - } - // Check for other scalars than `Number` i.e. bool - } else { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', out ) ); - } + fromIndex = 0; } - // Case: assign( x, searchElement, fromIndex, out ) - else if ( nargs < 5 ) { - if ( isndarrayLike( out ) ) { - // Case: indexOf( x, searchElement_ndarray, fromIndex_ndarray, out ) - if ( isndarrayLike( searchElement ) & isndarrayLike( fromIndex ) ) { - return base( x, searchElement, fromIndex, out ); - } - // Case: indexOf( x, searchElement_scalar, fromIndex_scalar out ) - if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len - } - // Case: indexOf( x, searchElement_ndarray, fromIndex_scalar, out ) - if ( isndarrayLike( searchElement ) & isNumber( fromIndex ) ) { - return base( x, searchElement, broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ), out ); // eslint-disable-line max-len - } - // Case: indexOf( x, searchElement_scalar, fromIndex_ndarray out ) - if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), fromIndex, out ); // eslint-disable-line max-len - } - // Check for other scalars than `Number` i.e. bool - - // Case: assign( x, searchElement, out, options ) - out = fromIndex; - opts = out; - - // Case: indexOf( x, searchElement_ndarray, out, options ) - if ( isndarrayLike( searchElement ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len - } - } - // Case: indexOf( x, searchElement_scalar, opts ) - else if ( isNumber( searchElement ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } - searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, sh, ord ); - } else { - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', searchElement ) ); - } - return base( x, searchElement, fromIndex, out, opts ); - } + // Case: assign( x, searchElement, out, options ) + else if ( + nargs === 4 && + isndarrayLike( fromIndex ) && + !isndarrayLike( out ) + ) { + opts = objectAssign( opts, out ); + out = fromIndex; + fromIndex = 0; + } else if ( nargs === 5 ) { + opts = objectAssign( opts, options ); } - opts = options; - - // Case: assign( x, searchElement_ndarray, fromIndex_ndarray, out, options ) - if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - } - } - // Case: assign( x, searchElement_scalar, fromIndex_scalar, out, options ) - else if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } - searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); - fromIndex = broadcastScalar( fromIndex, dt, sh, getOrder( x ) ); - } - // Case: assign( x, searchElement_ndarray, fromIndex_scalar, out, options ) - else if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( fromIndex, dt, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len - } + // Resolve shape for broadcasting + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; } - // Case: assign( x, searchElement_scalar, fromIndex_ndarray, out, options ) - else if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } + + // Normalize search element: + if ( isndarrayLike( searchElement ) ) { + searchElement = maybeBroadcastArray( searchElement, sh ); + } else { searchElement = broadcastScalar( searchElement, dt, sh, ord ); - fromIndex = maybeBroadcastArray( fromIndex, dt, sh, ord ); + } + + // Normalize from index: + if ( isndarrayLike( fromIndex ) ) { + fromIndex = maybeBroadcastArray( fromIndex, sh ); + } else if ( isInteger( fromIndex ) ) { + fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, sh, ord ); } else { - throw new TypeError( format( 'invalid argument. Second and third arguments must be either an ndarray or a scalar value. Value: `%s`.', searchElement, fromIndex ) ); + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); } + return base( x, searchElement, fromIndex, out, opts ); } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js index 37ce525adf94..bf6f62182e35 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/index.js @@ -26,7 +26,6 @@ * @example * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var indexOf = require( '@stdlib/blas/ext/index-of' ); * * // Create a data buffer: @@ -48,8 +47,8 @@ * var out = indexOf( x, 4.0 ); * // returns * -* var idx = out.data; -* // returns [ 3 ] +* var idx = out.get(); +* // returns 3 */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js index bc5d305765b6..23b56583d7b4 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js @@ -21,7 +21,8 @@ // MODULES // var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var objectAssign = require( '@stdlib/object/assign' ); +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' ); @@ -47,15 +48,15 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * @name indexOf * @type {Function} * @param {ndarrayLike} x - input ndarray -* @param {(ndarrayLike|number)} searchElement - search element -* @param {(ndarrayLike|number)} [fromIndex] - index from which to begin searching +* @param {(ndarrayLike|*)} searchElement - search element +* @param {(ndarrayLike|integer)} [fromIndex] - index from which to begin searching * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions 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 {string} [options.dtype] - output ndarray data type * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} search element argument must be either an ndarray-like object or a numeric value -* @throws {TypeError} from index argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} the function must be provided at least two arguments +* @throws {TypeError} third argument must be either an ndarray-like object or an integer * @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 @@ -96,105 +97,60 @@ function indexOf( x, searchElement, fromIndex, options ) { var sh; nargs = arguments.length; + if ( nargs < 2 ) { + throw new TypeError( format( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.', nargs ) ); + } + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.', x ) ); + } // Resolve input ndarray meta data: dt = getDType( x ); ord = getOrder( x ); + // Initialize options object: + opts = {}; + // Case: indexOf( x, searchElement ) if ( nargs === 2 ) { - // Case: indexOf( x, searchElement_ndarray ) - if ( isndarrayLike( searchElement ) ) { - // As the operation is performed across all dimensions, `searchElement` is assumed to be a zero-dimensional ndarray... - return base( x, searchElement, broadcastScalar( 0, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len - } - // Case: indexOf( x, searchElement_scalar ) - if ( isNumber( searchElement ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( 0, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len - } - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a scalar value. Value: `%s`.', searchElement ) ); + fromIndex = 0; } - // Case: indexOf( x, searchElement, ??? ) - else if ( nargs < 4 ) { // nargs < 4 - // Case: indexOf( x, searchElement, fromIndex ) - if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { - // As the operation is performed across all dimensions, `se` & `fromIndex` is assumed to be a zero-dimensional ndarray... - return base( x, searchElement, fromIndex ); - } - if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len - } - if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { - // As the operation is performed across all dimensions, `se` & `fromIndex` is assumed to be a zero-dimensional ndarray... - return base( x, searchElement, broadcastScalar( fromIndex, DEFAULT_DTYPE, [], ord ) ); // eslint-disable-line max-len - } - if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { - return base( x, broadcastScalar( searchElement, dt, [], ord ), fromIndex ); // eslint-disable-line max-len - } - - // Case: indexOf( x, searchElement, options ) - opts = fromIndex; - - // Case: indexOf( x, searchElement_ndarray, opts ) - if ( isndarrayLike( searchElement ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len - } - } - // Case: indexOf( x, searchElement_scalar, opts ) - else if ( isNumber( searchElement ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } - searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( 0, DEFAULT_DTYPE, sh, ord ); // eslint-disable-line max-len - } else { - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', searchElement ) ); - } - return base( x, searchElement, fromIndex, opts ); + // Case: indexOf( x, searchElement, options ) + else if ( + nargs === 3 && + !isndarrayLike( fromIndex ) && + !isInteger( fromIndex ) + ) { + opts = objectAssign( opts, fromIndex ); + fromIndex = 0; } - // Case: indexOf( x, searchElement, fromIndex, options ) - opts = options; - - // Case: indexOf( x, searchElement_ndarray, fromIndex_ndarray, opts ) - if ( isndarrayLike( searchElement ) && isndarrayLike( fromIndex ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - } + else if ( nargs === 4 ) { + opts = objectAssign( opts, options ); } - // Case: indexOf( x, searchElement_scalar, fromIndex_scalar, opts ) - else if ( isNumber( searchElement ) && isNumber( fromIndex ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } - searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); - fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, sh, getOrder( x ) ); // eslint-disable-line max-len - } else if ( isndarrayLike( searchElement ) && isNumber( fromIndex ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions... - if ( hasOwnProp( opts, 'dims' ) ) { - searchElement = maybeBroadcastArray( searchElement, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len - fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, nonCoreShape( getShape( x ), opts.dims ), ord ); // eslint-disable-line max-len - } - } else if ( isNumber( searchElement ) && isndarrayLike( fromIndex ) ) { - if ( hasOwnProp( opts, 'dims' ) ) { - sh = nonCoreShape( getShape( x ), opts.dims ); - } else { - sh = []; - } - searchElement = broadcastScalar( searchElement, dt, sh, getOrder( x ) ); - fromIndex = maybeBroadcastArray( fromIndex, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + + // Resolve shape for broadcasting + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); } else { - throw new TypeError( format( 'invalid argument. Second and third arguments must be either an ndarray or a scalar value. Value: `%s`.', searchElement ) ); + sh = []; } + + if ( isndarrayLike( searchElement ) ) { + searchElement = maybeBroadcastArray( searchElement, sh ); + } else { + searchElement = broadcastScalar( searchElement, dt, sh, ord ); + } + + if ( isndarrayLike( fromIndex ) ) { + fromIndex = maybeBroadcastArray( fromIndex, sh ); + } else if ( isInteger( fromIndex ) ) { + fromIndex = broadcastScalar( fromIndex, DEFAULT_DTYPE, sh, ord ); + } else { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + return base( x, searchElement, fromIndex, opts ); } From 86b7c4baa16340e8ed6f950506c7bdd15b6ba08e Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 15:10:26 +0000 Subject: [PATCH 04/14] refactor: refactor & cleanup --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/index-of/docs/repl.txt | 34 +++---- .../blas/ext/index-of/docs/types/index.d.ts | 18 ++-- .../blas/ext/index-of/docs/types/test.ts | 89 ++----------------- 3 files changed, 33 insertions(+), 108 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt index af117ed559e0..7bb169bd9c13 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt @@ -8,7 +8,7 @@ x: ndarray Input array. - searchElement: ndarray|number|ComplexLike + searchElement: ndarray|* Element in an input ndarray for which to find an index. May be either a scalar value or an ndarray having a data type same as the data type of the input ndarray. If provided a scalar value, the value is cast to the @@ -20,24 +20,24 @@ when performing the operation over all elements in a provided input ndarray, a search element ndarray must be a zero-dimensional ndarray. - fromIndex: ndarray|number (optional) + fromIndex: ndarray|integer (optional) Index from which to begin searching. May be either a scalar value or an - ndarray having an `int32` or `generic` data type. If provided an ndarray - the value must have a shape which is broadcast compatible with the - complement of the shape defined by `options.dims`. For example, given - the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray + ndarray having an `integer` or `generic` data type. If provided an + ndarray the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray containing the index from which to begin searching must have a shape which is broadcast-compatible with the shape `[3, 4]`. Similarly when performing the operation over all elements in a provided input ndarray, an ndarray containing the index from which to begin searching - must be a zero-dimensional ndarray. By default, the the index from which - to begin searching is `0`. + must be a zero-dimensional ndarray. By default, the value of the index + from which to begin searching is `0`. options: Object (optional) Function options. options.dtype: string (optional) - Output array data type. Must be a "integer_index" data type. + Output array data type. Must be a "integer_index_and_generic" data type. options.dims: Array (optional) List of dimensions over which to perform a reduction. If not provided, @@ -70,7 +70,7 @@ x: ndarray Input array. - searchElement: ndarray|number|ComplexLike + searchElement: ndarray|* Element in an input ndarray for which to find an index. May be either a scalar value or an ndarray having a data type same as the data type of the input ndarray. If provided a scalar value, the value is cast to the @@ -82,18 +82,18 @@ when performing the operation over all elements in a provided input ndarray, a search element ndarray must be a zero-dimensional ndarray. - fromIndex: ndarray|number (optional) + fromIndex: ndarray|integer (optional) Index from which to begin searching. May be either a scalar value or an - ndarray having an `int32` or `generic` data type. If provided an ndarray - the value must have a shape which is broadcast compatible with the - complement of the shape defined by `options.dims`. For example, given - the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray + ndarray having an `integer` or `generic` data type. If provided an + ndarray the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray containing the index from which to begin searching must have a shape which is broadcast-compatible with the shape `[3, 4]`. Similarly when performing the operation over all elements in a provided input ndarray, an ndarray containing the index from which to begin searching - must be a zero-dimensional ndarray. By default, the the index from which - to begin searching is `0`. + must be a zero-dimensional ndarray. By default, the value of the index + from which to begin searching is `0`. out: ndarray Output array. diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts index 9164bb105ca5..c4fe068a7670 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts @@ -21,7 +21,7 @@ /// import { ArrayLike } from '@stdlib/types/array'; -import { IntegerAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; +import { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; /** * Input array. @@ -36,12 +36,12 @@ type SearchElement = typedndarray | T; /** * From index. */ -type FromIndex = typedndarray | U; +type FromIndex = typedndarray | number; /** * Output array. */ -type OutputArray = typedndarray; +type OutputArray = typedndarray; /** * Interface defining "base" options. @@ -82,7 +82,6 @@ interface IndexOf { * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ -1.0, 2.0, -3.0 ] ); @@ -93,7 +92,7 @@ interface IndexOf { * var idx = y.get(); * // returns 1 */ - ( x: InputArray, searchElement: SearchElement, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + ( x: InputArray, searchElement: SearchElement, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. /** * Returns the first index of specified search element along one or more ndarray dimensions. @@ -105,7 +104,6 @@ interface IndexOf { * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0 ] ); @@ -116,7 +114,7 @@ interface IndexOf { * var idx = y.get(); * // returns 3 */ - ( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + ( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, options?: Options ): OutputArray; /** * Returns the first index of a specified search element along one or more ndarray dimensions and assigns results to a provided output ndarray. @@ -128,7 +126,6 @@ interface IndexOf { * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var array = require( '@stdlib/ndarray/array' ); * @@ -146,7 +143,7 @@ interface IndexOf { * var idx = out.get(); * // returns 1 */ - assign = OutputArray>( x: InputArray, searchElement: SearchElement, out: U, options?: BaseOptions ): U; + assign( x: InputArray, searchElement: SearchElement, out: U, options?: BaseOptions ): U; /** * Returns the first index of a specified search element along one or more ndarray dimensions and assigns results to a provided output ndarray. @@ -159,7 +156,6 @@ interface IndexOf { * @returns output ndarray * * @example - * var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var array = require( '@stdlib/ndarray/array' ); * @@ -177,7 +173,7 @@ interface IndexOf { * var idx = out.get(); * // returns 3 */ - assign = OutputArray, V = unknown>( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, out: U, options?: BaseOptions ): U; + assign( x: InputArray, searchElement: SearchElement, fromIndex: FromIndex, out: U, options?: BaseOptions ): U; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts index d00ce1e4c5ed..e528cd208c7a 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/test.ts @@ -32,10 +32,10 @@ import indexOf = require( './index' ); 'dtype': 'float64' }); - indexOf( x, 0.0 ); // $ExpectType OutputArray - indexOf( x, 0.0, 1 ); // $ExpectType OutputArray - indexOf( x, 0.0, {} ); // $ExpectType OutputArray - indexOf( x, 0.0, 1, {} ); // $ExpectType OutputArray + indexOf( x, 0.0 ); // $ExpectType OutputArray + indexOf( x, 0.0, 1 ); // $ExpectType OutputArray + indexOf( x, 0.0, {} ); // $ExpectType OutputArray + indexOf( x, 0.0, 1, {} ); // $ExpectType OutputArray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... @@ -108,7 +108,7 @@ import indexOf = require( './index' ); indexOf( x, ( x: number ): number => x, 0, {} ); // $ExpectError } -// The compiler throws an error if the function is provided a from index argument which is not an ndarray or scalar value... +// The compiler throws an error if the function is provided a from index argument which is not an ndarray or an integer value... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' @@ -216,8 +216,6 @@ import indexOf = require( './index' ); indexOf( x, 0.0, { 'keepdims': '5' } ); // $ExpectError indexOf( x, 0.0, { 'keepdims': 5 } ); // $ExpectError - indexOf( x, 0.0, { 'keepdims': true } ); // $ExpectError - indexOf( x, 0.0, { 'keepdims': false } ); // $ExpectError indexOf( x, 0.0, { 'keepdims': null } ); // $ExpectError indexOf( x, 0.0, { 'keepdims': {} } ); // $ExpectError indexOf( x, 0.0, { 'keepdims': ( x: number ): number => x } ); // $ExpectError @@ -249,16 +247,13 @@ import indexOf = require( './index' ); }); indexOf.assign( x, 0.0, y ); // $ExpectType int32ndarray - indexOf.assign( x, 0.0, y, {} ); // $ExpectType in32ndarray - indexOf.assign( x, 0.0, 1, y ); // $ExpectType in32ndarray - indexOf.assign( x, 0.0, 1, y, {} ); // $ExpectType in32ndarray + indexOf.assign( x, 0.0, y, {} ); // $ExpectType int32ndarray + indexOf.assign( x, 0.0, 1, y ); // $ExpectType int32ndarray + indexOf.assign( x, 0.0, 1, y, {} ); // $ExpectType int32ndarray } // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); const y = zeros( [], { 'dtype': 'int32' }); @@ -310,43 +305,31 @@ import indexOf = require( './index' ); }); indexOf.assign( x, '5', y ); // $ExpectError - indexOf.assign( x, 5, y ); // $ExpectError indexOf.assign( x, true, y ); // $ExpectError indexOf.assign( x, false, y ); // $ExpectError - indexOf.assign( x, null, y ); // $ExpectError - indexOf.assign( x, void 0, y ); // $ExpectError indexOf.assign( x, {}, y ); // $ExpectError indexOf.assign( x, ( x: number ): number => x, y ); // $ExpectError indexOf.assign( x, '5', 0, y ); // $ExpectError - indexOf.assign( x, 5, 0, y ); // $ExpectError indexOf.assign( x, true, 0, y ); // $ExpectError indexOf.assign( x, false, 0, y ); // $ExpectError - indexOf.assign( x, null, 0, y ); // $ExpectError - indexOf.assign( x, void 0, 0, y ); // $ExpectError indexOf.assign( x, {}, 0, y ); // $ExpectError indexOf.assign( x, ( x: number ): number => x, 0, y ); // $ExpectError indexOf.assign( x, '5', y, {} ); // $ExpectError - indexOf.assign( x, 5, y, {} ); // $ExpectError indexOf.assign( x, true, y, {} ); // $ExpectError indexOf.assign( x, false, y, {} ); // $ExpectError - indexOf.assign( x, null, y, {} ); // $ExpectError - indexOf.assign( x, void 0, y, {} ); // $ExpectError indexOf.assign( x, {}, y, {} ); // $ExpectError indexOf.assign( x, ( x: number ): number => x, y, {} ); // $ExpectError indexOf.assign( x, '5', 0, y, {} ); // $ExpectError - indexOf.assign( x, 5, 0, y, {} ); // $ExpectError indexOf.assign( x, true, 0, y, {} ); // $ExpectError indexOf.assign( x, false, 0, y, {} ); // $ExpectError - indexOf.assign( x, null, 0, y, {} ); // $ExpectError - indexOf.assign( x, void 0, 0, y, {} ); // $ExpectError indexOf.assign( x, {}, 0, y, {} ); // $ExpectError indexOf.assign( x, ( x: number ): number => x, 0, y, {} ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided a from index argument which is not an ndarray or scalar value... +// The compiler throws an error if the `assign` method is provided a from index argument which is not an ndarray or an integer value... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' @@ -356,7 +339,6 @@ import indexOf = require( './index' ); }); indexOf.assign( x, 0.0, '5', y ); // $ExpectError - indexOf.assign( x, 0.0, 5, y ); // $ExpectError indexOf.assign( x, 0.0, true, y ); // $ExpectError indexOf.assign( x, 0.0, false, y ); // $ExpectError indexOf.assign( x, 0.0, null, y ); // $ExpectError @@ -365,7 +347,6 @@ import indexOf = require( './index' ); indexOf.assign( x, 0.0, ( x: number ): number => x, y ); // $ExpectError indexOf.assign( x, 0.0, '5', y, {} ); // $ExpectError - indexOf.assign( x, 0.0, 5, y, {} ); // $ExpectError indexOf.assign( x, 0.0, true, y, {} ); // $ExpectError indexOf.assign( x, 0.0, false, y, {} ); // $ExpectError indexOf.assign( x, 0.0, null, y, {} ); // $ExpectError @@ -463,58 +444,6 @@ import indexOf = require( './index' ); indexOf.assign( x, 0.0, 1, y, { 'dims': ( x: number ): number => x } ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided an invalid `dtype` option... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - const y = zeros( [], { - 'dtype': 'int32' - }); - - indexOf.assign( x, 0.0, y, { 'dtype': '5' } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': 5 } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': true } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': false } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': null } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': {} } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - indexOf.assign( x, 0.0, 1, y, { 'dtype': '5' } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': 5 } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': true } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': false } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': null } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': {} } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an invalid `keepdims` option... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - const y = zeros( [], { - 'dtype': 'int32' - }); - - indexOf.assign( x, 0.0, y, { 'keepdims': '5' } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': 5 } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': true } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': false } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': null } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': {} } ); // $ExpectError - indexOf.assign( x, 0.0, y, { 'keepdims': ( x: number ): number => x } ); // $ExpectError - - indexOf.assign( x, 0.0, 1, y, { 'keepdims': '5' } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': 5 } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': true } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': false } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': null } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': {} } ); // $ExpectError - indexOf.assign( x, 0.0, 1, y, { 'keepdims': ( 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 ], { From 32787d44d6393886e529d19a55d475abc9d2aaa8 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 15:18:02 +0000 Subject: [PATCH 05/14] docs: fix err description --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js index 9a688abfafa0..087191e8531f 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -53,9 +53,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * @param {ndarrayLike} out - output ndarray * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions 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 {string} [options.dtype] - output ndarray data type -* @throws {TypeError} function must be provided at least two arguments +* @throws {TypeError} function must be provided at least three arguments * @throws {TypeError} first argument must be an ndarray-like object * @throws {TypeError} third argument must be either an ndarray-like object or an integer * @throws {TypeError} fourth argument must be an ndarray-like object From 4b2411e32ae1621a3e84aaadc8d3814dbdc91bbd Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 17:41:26 +0000 Subject: [PATCH 06/14] test: add main tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/index-of/lib/assign.js | 4 + .../@stdlib/blas/ext/index-of/lib/main.js | 14 +- .../blas/ext/index-of/test/test.main.js | 1395 +++++++++++++++++ 3 files changed, 1408 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js index 087191e8531f..96ffc63b128f 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -22,6 +22,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var objectAssign = require( '@stdlib/object/assign' ); +var isObject = require( '@stdlib/assert/is-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' ); @@ -136,6 +137,9 @@ function assign( x, searchElement, fromIndex, out, options ) { out = fromIndex; fromIndex = 0; } else if ( nargs === 5 ) { + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. The fifth argument must be an object. Value: `%s`.', options ) ); + } opts = objectAssign( opts, options ); } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js index 23b56583d7b4..440ea88447cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js @@ -22,6 +22,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var objectAssign = require( '@stdlib/object/assign' ); +var isObject = require( '@stdlib/assert/is-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' ); @@ -96,15 +97,15 @@ function indexOf( x, searchElement, fromIndex, options ) { var dt; var sh; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + nargs = arguments.length; if ( nargs < 2 ) { throw new TypeError( format( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.', nargs ) ); } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.', x ) ); - } - // Resolve input ndarray meta data: dt = getDType( x ); ord = getOrder( x ); @@ -120,13 +121,16 @@ function indexOf( x, searchElement, fromIndex, options ) { else if ( nargs === 3 && !isndarrayLike( fromIndex ) && - !isInteger( fromIndex ) + isObject( fromIndex ) ) { opts = objectAssign( opts, fromIndex ); fromIndex = 0; } // Case: indexOf( x, searchElement, fromIndex, options ) else if ( nargs === 4 ) { + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. The fourth argument must be an object. Value: `%s`.', options ) ); + } opts = objectAssign( opts, options ); } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js new file mode 100644 index 000000000000..af63af12f276 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js @@ -0,0 +1,1395 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var indexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOf, '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 (searchElement_scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_ndarray)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, scalar2ndarray( 0, { + 'dtype': 'generic' + })); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_ndarray)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), scalar2ndarray( 0, { + 'dtype': 'generic' + })); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, scalar2ndarray( 0, { + 'dtype': 'generic' + }), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), scalar2ndarray( 0, { + 'dtype': 'generic' + }), {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + function badValue1() { + return function badValue() { + indexOf( x ); + }; + } + + function badValue2() { + return function badValue() { + indexOf(); + }; + } + + t.throws( badValue1(), TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2(), TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); +}); + +tape( 'the function throws an error if provided a search element which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an search element which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 0 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 0 ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar)', 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() { + indexOf( x, 10.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + 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() { + indexOf( x, scalar2ndarray( 10.0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar, fromIndex_scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, 0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 10.0, opts ), scalar2ndarray( 0, opts ), value ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, scalar2ndarray( 0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray, fromIndex_scalar)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 10.0, opts ), 0, 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() { + indexOf( x, 10.0, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + indexOf( x, 10.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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() { + indexOf( x, 10.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [] + }); + expected = [ [ -1, 0 ], [ -1, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [] + }); + expected = [ [ -1, 0 ], [ -1, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [] + }); + expected = [ [ -1, -1 ], [ 0, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [] + }); + expected = [ [ -1, -1 ], [ 0, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', '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 operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, 0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, 0 ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, 0, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, 0, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = indexOf( x, 2.0, fromIdx ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, fromIdx ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = indexOf( x, 2.0, fromIdx, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, fromIdx, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, 0, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'int32' + }); + actual = indexOf( x, 2.0, fromIdx, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, fromIdx, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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(); +}); From baf4098d7da732ed52facf4b0c0a5a010cfd1b0a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:36:33 +0000 Subject: [PATCH 07/14] test: add missing case --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/index-of/test/test.main.js | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js index af63af12f276..e336ed8f1952 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js @@ -23,6 +23,8 @@ var tape = require( 'tape' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var isSameArray = require( '@stdlib/assert/is-same-array' ); +var isEqualInt32Array = require( '@stdlib/assert/is-equal-int32array' ); +var Int32Array = require( '@stdlib/array/int32' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); @@ -870,7 +872,7 @@ tape( 'the function throws an error if provided a `dims` option which contains d } }); -tape( 'the function returns the first index of a specified search element in an ndarray (default, row-major)', function test( t ) { +tape( 'the function returns the first index of a specified search element in an ndarray (row-major)', function test( t ) { var expected; var actual; var xbuf; @@ -900,7 +902,7 @@ tape( 'the function returns the first index of a specified search element in an t.end(); }); -tape( 'the function returns the first index of a specified search element in an ndarray (default, column-major)', function test( t ) { +tape( 'the function returns the first index of a specified search element in an ndarray (column-major)', function test( t ) { var expected; var actual; var xbuf; @@ -1082,6 +1084,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1092,6 +1095,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1105,6 +1109,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1115,6 +1120,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1137,6 +1143,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1147,6 +1154,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1160,6 +1168,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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' ); @@ -1170,12 +1179,50 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( 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 output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = indexOf( x, 2.0, { + 'dtype': 'int32' + }); + expected = new Int32Array( [ 1 ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isEqualInt32Array( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = indexOf( x, 2.0, 0, { + 'dtype': 'int32' + }); + expected = new Int32Array( [ 1 ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isEqualInt32Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports providing a from index (scalar)', function test( t ) { var expected; var actual; From 0396f52a74ef2232bf8a0893170b4c7d7a50b78a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 20:44:47 +0000 Subject: [PATCH 08/14] test: add assign tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/index-of/lib/assign.js | 7 +- .../blas/ext/index-of/test/test.assign.js | 1628 +++++++++++++++++ 2 files changed, 1633 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js index 96ffc63b128f..6a90b5ae6d2e 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -131,12 +131,15 @@ function assign( x, searchElement, fromIndex, out, options ) { else if ( nargs === 4 && isndarrayLike( fromIndex ) && - !isndarrayLike( out ) + !isndarrayLike( out ) && + isObject( out ) ) { opts = objectAssign( opts, out ); out = fromIndex; fromIndex = 0; - } else if ( nargs === 5 ) { + } + // Case: assign( x, searchElement, fromIndex, out, options ) + else if ( nargs === 5 ) { if ( !isObject( options ) ) { throw new TypeError( format( 'invalid argument. The fifth argument must be an object. Value: `%s`.', options ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js new file mode 100644 index 000000000000..1e17283cfe2e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js @@ -0,0 +1,1628 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var indexOf = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof indexOf, '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 (searchElement_scalar)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray)', 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() { + indexOf( value, scalar2ndarray( 2.0 ), y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_scalar)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, 0, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_scalar)', function test( t ) { + var values; + var i; + var y; + + y = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), 0, y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, scalar2ndarray( 0, opts ), y ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), scalar2ndarray( 0, opts ), y ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_scalar, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, 0, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_scalar, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), 0, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_scalar, fromIndex_ndarray, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, 2.0, scalar2ndarray( 0, opts ), y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (searchElement_ndarray, fromIndex_ndarray, options)', function test( t ) { + var values; + var opts; + var i; + var y; + + opts = { + 'dtype': 'generic' + }; + + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( value, scalar2ndarray( 2.0 ), scalar2ndarray( 0, opts ), y, {} ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + function badValue1() { + return function badValue() { + indexOf( x ); + }; + } + + function badValue2() { + return function badValue() { + indexOf( x, 10.0 ); + }; + } + + function badValue3() { + return function badValue() { + indexOf(); + }; + } + + t.throws( badValue1(), TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2(), TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue3(), TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); +}); + +tape( 'the function throws an error if provided a search element which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, value, y ); + }; + } +}); + +tape( 'the function throws an error if provided an search element which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 0 ), value, y ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 0 ), value, y, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 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() { + indexOf( x, 10.0, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 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() { + indexOf( x, scalar2ndarray( 10.0, opts ), y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar, fromIndex_scalar)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, 0, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 10.0, opts ), scalar2ndarray( 0, opts ), y, value ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_scalar, fromIndex_ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, scalar2ndarray( 0, opts ), y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (searchElement_ndarray, fromIndex_scalar)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 10.0, opts ), 0, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ '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() { + indexOf( x, 10.0, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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() { + indexOf( x, 10.0, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + y = zeros( [], opts ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, 10.0, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0, 1 ] + }); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [] + }); + expected = [ [ -1, 0 ], [ -1, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [] + }); + expected = [ [ -1, 0 ], [ -1, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of a specified search element in an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [] + }); + expected = [ [ -1, -1 ], [ 0, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [] + }); + expected = [ [ -1, -1 ], [ 0, -1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 1 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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 operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, y, { + 'dims': [ 1 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 1 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, 0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, 0, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, 0, y, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, 0, y, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = indexOf( x, 2.0, fromIdx, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, fromIdx, y ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = indexOf( x, 2.0, fromIdx, y, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, fromIdx, y, {} ); + expected = [ 1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, 0, y, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( y === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 0, { + 'dtype': 'int32' + }); + actual = indexOf( x, 2.0, fromIdx, y, { + 'dims': [ 0 ] + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = indexOf( x, 2.0, fromIdx, y, { + 'dims': [ 0 ] + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( 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(); +}); From 798e5df2df28120535a2d05b423b36aac34f6374 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 6 Jul 2025 20:49:36 +0000 Subject: [PATCH 09/14] fix: incorrect strides in test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/index-of/test/test.main.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js index e336ed8f1952..637d287b0cb2 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js @@ -1127,19 +1127,19 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.end(); }); -tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { var expected; var actual; var xbuf; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, { 'dims': [ 0 ] }); - expected = [ -1, 0 ]; + expected = [ 1, -1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -1150,7 +1150,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct actual = indexOf( x, 2.0, 0, { 'dims': [ 0 ] }); - expected = [ -1, 0 ]; + expected = [ 1, -1 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -1159,12 +1159,12 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, { 'dims': [ 1 ] }); - expected = [ 1, -1 ]; + expected = [ -1, 0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -1175,7 +1175,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct actual = indexOf( x, 2.0, 0, { 'dims': [ 1 ] }); - expected = [ 1, -1 ]; + expected = [ -1, 0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); @@ -1242,7 +1242,7 @@ tape( 'the function supports providing a from index (scalar)', function test( t t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, 0 ); expected = [ 1 ]; @@ -1275,7 +1275,7 @@ tape( 'the function supports providing a from index (scalar, options)', function t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, 0, {} ); expected = [ 1 ]; @@ -1312,7 +1312,7 @@ tape( 'the function supports providing a from index (0d ndarray)', function test t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, fromIdx ); expected = [ 1 ]; @@ -1349,7 +1349,7 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; - x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = indexOf( x, 2.0, fromIdx, {} ); expected = [ 1 ]; From 5b7e0f8aa1669dc22044a5f40cf9f00707c7a160 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 7 Jul 2025 09:32:54 +0500 Subject: [PATCH 10/14] docs: apply suggestions from cide review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/index-of/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/README.md b/lib/node_modules/@stdlib/blas/ext/index-of/README.md index 31457170d644..49cdde925ef8 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/README.md +++ b/lib/node_modules/@stdlib/blas/ext/index-of/README.md @@ -146,12 +146,12 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); var idx = indexOf( x, 2.0, { - 'dtype': 'generic' + 'dtype': 'int32' }); // returns var dt = dtype( idx ); -// returns 'generic' +// returns 'int32' ``` #### indexOf.assign( x, searchElement\[, fromIndex], out\[, options] ) From 9108cbd101747061c198b39da99c76fa76aa6bab Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 7 Jul 2025 09:38:26 +0500 Subject: [PATCH 11/14] chore: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/index-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts index c4fe068a7670..5b5c2be833cc 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/index-of/docs/types/index.d.ts @@ -92,7 +92,7 @@ interface IndexOf { * var idx = y.get(); * // returns 1 */ - ( x: InputArray, searchElement: SearchElement, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + ( x: InputArray, searchElement: SearchElement, options?: Options ): OutputArray; /** * Returns the first index of specified search element along one or more ndarray dimensions. From 1dd386b143cc53f575dbfe20529032b613f732ad Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 7 Jul 2025 15:10:17 +0500 Subject: [PATCH 12/14] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js index df951f5a0a74..d229c661c1b8 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/base.js @@ -29,8 +29,8 @@ var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-fac // VARIABLES // -var idtypes0 = dtypes( 'numeric_and_generic' ); // input ndarray -var idtypes1 = dtypes( 'numeric_and_generic' ); // search element ndarray +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'all' ); // search element ndarray var idtypes2 = dtypes( 'integer_index_and_generic' ); // from index ndarray var odtypes = dtypes( 'integer_index_and_generic' ); var policies = { From 06bfff4feeaa3c2888f08a37a17df20c5f2d9115 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 8 Jul 2025 11:11:12 +0000 Subject: [PATCH 13/14] test: add missing test case --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/index-of/test/test.assign.js | 34 +++++++++++++++++++ .../blas/ext/index-of/test/test.main.js | 30 ++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js index 1e17283cfe2e..5a7df4f6b0ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js @@ -462,6 +462,40 @@ tape( 'the function throws an error if provided a first argument which is not an } }); +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object, integer or an object', function test( t ) { + var values; + var i; + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + y = zeros( [], { + 'dtype': 'generic' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 2.0 ), y, value, {} ); + }; + } +}); + tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { var x; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js index 637d287b0cb2..797cc400860e 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.main.js @@ -388,6 +388,36 @@ tape( 'the function throws an error if provided a first argument which is not an } }); +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object, integer or an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + indexOf( x, scalar2ndarray( 2.0 ), value, {} ); + }; + } +}); + tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { var x; From 747b7418d6e8a39e2e2c1be909ccf08b69345411 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:19:28 +0500 Subject: [PATCH 14/14] test: fix arguments Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js index 5a7df4f6b0ef..fd68b43201dc 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/test/test.assign.js @@ -491,7 +491,7 @@ tape( 'the function throws an error if provided a third argument which is not an function badValue( value ) { return function badValue() { - indexOf( x, scalar2ndarray( 2.0 ), y, value, {} ); + indexOf( x, scalar2ndarray( 2.0 ), value, y, {} ); }; } });