From 3516d82c4af44370dda6a6cf1750f8de61b9f92a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 25 Aug 2026 19:52:56 +0500 Subject: [PATCH 1/5] feat: add blas/ext/first-index-less-than --- .../blas/ext/first-index-less-than/README.md | 281 +++ .../benchmark/benchmark.assign.js | 113 ++ .../benchmark/benchmark.js | 105 ++ .../ext/first-index-less-than/docs/repl.txt | 126 ++ .../docs/types/index.d.ts | 251 +++ .../first-index-less-than/docs/types/test.ts | 526 ++++++ .../first-index-less-than/examples/index.js | 43 + .../ext/first-index-less-than/lib/assign.js | 227 +++ .../ext/first-index-less-than/lib/base.js | 116 ++ .../ext/first-index-less-than/lib/index.js | 73 + .../ext/first-index-less-than/lib/main.js | 200 ++ .../ext/first-index-less-than/package.json | 67 + .../first-index-less-than/test/test.assign.js | 1626 +++++++++++++++++ .../ext/first-index-less-than/test/test.js | 39 + .../first-index-less-than/test/test.main.js | 1388 ++++++++++++++ 15 files changed, 5181 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md new file mode 100644 index 000000000000..ffdbc822c06a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md @@ -0,0 +1,281 @@ + + +# firstIndexLessThan + +> Return the index of the first element in an [ndarray][@stdlib/ndarray/ctor] which is less than a corresponding element in another [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension. + +
+ +## Usage + +```javascript +var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); +``` + +#### firstIndexLessThan( x, y\[, fromIndex]\[, options] ) + +Returns the index of the first element in an [ndarray][@stdlib/ndarray/ctor] which is less than a corresponding element in another [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 + +// Create a second input ndarray: +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +// Perform operation: +var out = firstIndexLessThan( x, y ); +// returns [ 2 ] +``` + +The function has the following parameters: + +- **x**: first input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **y**: second input [ndarray][@stdlib/ndarray/ctor]. Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the first input [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 an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer index or generic [data type][@stdlib/ndarray/dtypes]. +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +If the function is unable to find an element which is less than a corresponding element in the second input [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +// returns + +// Create a second input ndarray: +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +// Perform operation: +var out = firstIndexLessThan( x, y ); +// returns [ -1 ] +``` + +By default, the function begins searching from the first element along the reduction dimension. To begin searching from a different index, provide a `fromIndex` argument. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 + +// Create a second input ndarray: +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +// Perform operation: +var out = firstIndexLessThan( x, y, 2 ); +// returns [ 3 ] +``` + +By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); + +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +var out = firstIndexLessThan( x, y, { + 'dim': 0 +}); +// returns [ 0, -1 ] +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); + +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +var opts = { + 'dim': 0, + 'keepdims': true +}; + +var out = firstIndexLessThan( x, y, opts ); +// returns [ [ 0, -1 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, -2.0, 3.0, 4.0 ] ); + +var y = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +var idx = firstIndexLessThan( x, y, { + 'dtype': 'generic' +}); +// returns + +var dt = dtype( idx ); +// returns 'generic' +``` + +#### firstIndexLessThan.assign( x, y\[, fromIndex], out\[, options] ) + +Returns the index of the first element in an [ndarray][@stdlib/ndarray/ctor] which is less than a corresponding element in another [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 = scalar2ndarray( 0.0, { + 'dtype': 'float64' +}); + +var z = zeros( [], { + 'dtype': 'int32' +}); + +var out = firstIndexLessThan.assign( x, y, z ); +// returns [ 2 ] + +var bool = ( out === z ); +// returns true +``` + +The method has the following parameters: + +- **x**: first input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension. +- **y**: second input [ndarray][@stdlib/ndarray/ctor]. Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the first input [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 an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. + +
+ + + +
+ +## Notes + +- When comparing elements, the function checks whether an element in the first input [ndarray][@stdlib/ndarray/ctor] is less than a corresponding element in the second input [ndarray][@stdlib/ndarray/ctor] using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 20, { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Create a second input ndarray: +var y = scalar2ndarray( 10.0, { + 'dtype': 'float64' +}); + +// Perform operation: +var idx = firstIndexLessThan( x, y, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..275997614425 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var firstIndexLessThan = 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; + var y; + + x = uniform( [ len ], -50.0, 50.0, options ); + y = scalar2ndarray( -100.0, options ); + out = zeros( [], { + 'dtype': 'int32' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = firstIndexLessThan.assign( x, y, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js new file mode 100644 index 000000000000..8957ac735024 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var firstIndexLessThan = 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 ); + var y = scalar2ndarray( -100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = firstIndexLessThan( x, y ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt new file mode 100644 index 000000000000..8b7e5fec0d93 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt @@ -0,0 +1,126 @@ + +{{alias}}( x, y[, fromIndex][, options] ) + Returns the index of the first element in an ndarray which is less than a + corresponding element in another ndarray along an ndarray dimension. + + When comparing elements, the function checks whether an element in the + first input ndarray is less than a corresponding element in the second + input ndarray using the less-than operator `<`. As a consequence, + comparisons involving `NaN` always evaluate to `false`. + + If unable to find an element which is less than a corresponding element in + the second input ndarray along an ndarray dimension, the corresponding + element in the returned ndarray is `-1`. + + Parameters + ---------- + x: ndarray + First input array. Must have at least one dimension. + + y: ndarray + Second input array. Must have a shape which is broadcast compatible + with the shape of the first input ndarray. + + fromIndex: ndarray|integer (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the non- + reduced dimensions of the input ndarray. For example, given the input + shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a + shape which is broadcast-compatible with the shape `[3, 4]`. If provided + a negative integer, the index at which to begin searching along a + dimension is determined by counting backward from the last element + (where -1 refers to the last element). Default: 0. + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output array data type. Must be an integer index or "generic" data type. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, -3.0, -4.0 ] ); + > var y = {{alias:@stdlib/ndarray/from-scalar}}( 0.0 ); + > var out = {{alias}}( x, y ) + [ 2 ] + + +{{alias}}.assign( x, y[, fromIndex], out[, options] ) + Returns the index of the first element in an ndarray which is less than a + corresponding element in another ndarray along an ndarray dimension and + assigns results to a provided output ndarray. + + When comparing elements, the function checks whether an element in the + first input ndarray is less than a corresponding element in the second + input ndarray using the less-than operator `<`. As a consequence, + comparisons involving `NaN` always evaluate to `false`. + + If unable to find an element which is less than a corresponding element in + the second input ndarray along an ndarray dimension, the corresponding + element in the returned ndarray is `-1`. + + Parameters + ---------- + x: ndarray + First input array. Must have at least one dimension. + + y: ndarray + Second input array. Must have a shape which is broadcast compatible + with the shape of the first input ndarray. + + fromIndex: ndarray|integer (optional) + Index from which to begin searching. May be either a scalar value or an + ndarray having an integer or "generic" data type. If provided an ndarray + the value must have a shape which is broadcast compatible with the non- + reduced dimensions of the input ndarray. For example, given the input + shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a + shape which is broadcast-compatible with the shape `[3, 4]`. If provided + a negative integer, the index at which to begin searching along a + dimension is determined by counting backward from the last element + (where -1 refers to the last element). Default: 0. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dim: integer (optional) + Dimension over which to perform a reduction. If provided a negative + integer, the dimension along which to perform the operation is + determined by counting backward from the last dimension (where -1 refers + to the last dimension). Default: -1. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, -3.0, -4.0 ] ); + > var y = {{alias:@stdlib/ndarray/from-scalar}}( 0.0 ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); + > var idx = {{alias}}.assign( x, y, out ) + [ 2 ] + > var bool = ( out === idx ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts new file mode 100644 index 000000000000..f0babb87158d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts @@ -0,0 +1,251 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { IntegerIndexAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* From index. +*/ +type FromIndex = typedndarray | number; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * Dimension over which to perform operation. Default: `-1`. + * + * ## Notes + * + * - If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). + */ + dim?: number; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + + +/** +* Interface describing `firstIndexLessThan`. +*/ +interface FirstIndexLessThan { + /** + * Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. + * + * ## Notes + * + * - When comparing elements, the function checks whether an element in the first input ndarray is less than a corresponding element in the second input ndarray using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. + * - If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * + * @param x - first input ndarray + * @param y - second input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * + * var x = array( [ 1.0, 2.0, -3.0 ] ); + * var y = scalar2ndarray( 0.0, { + * 'dtype': 'float64' + * } ); + * + * var out = firstIndexLessThan( x, y ); + * // returns [ 2 ] + */ + ( x: InputArray, y: InputArray, options?: Options ): OutputArray; + + /** + * Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. + * + * ## Notes + * + * - When comparing elements, the function checks whether an element in the first input ndarray is less than a corresponding element in the second input ndarray using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. + * - If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * + * @param x - first input ndarray + * @param y - second input ndarray + * @param fromIndex - index from which to begin searching + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * + * var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); + * var y = scalar2ndarray( 0.0, { + * 'dtype': 'float64' + * } ); + * + * var out = firstIndexLessThan( x, y, 2 ); + * // returns [ 2 ] + */ + ( x: InputArray, y: InputArray, fromIndex: FromIndex, options?: Options ): OutputArray; + + /** + * Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - When comparing elements, the function checks whether an element in the first input ndarray is less than a corresponding element in the second input ndarray using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. + * - If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * + * @param x - first input ndarray + * @param y - second input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * + * var x = array( [ 1.0, 2.0, -3.0 ] ); + * var y = scalar2ndarray( 0.0, { + * 'dtype': 'float64' + * } ); + * var z = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = firstIndexLessThan.assign( x, y, z ); + * // returns [ 2 ] + * + * var bool = ( out === z ); + * // returns true + */ + assign( x: InputArray, y: InputArray, out: U, options?: BaseOptions ): U; + + /** + * Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension and assigns results to a provided output ndarray. + * + * ## Notes + * + * - When comparing elements, the function checks whether an element in the first input ndarray is less than a corresponding element in the second input ndarray using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. + * - If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. + * + * @param x - first input ndarray + * @param y - second input ndarray + * @param fromIndex - index from which to begin searching + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * + * var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); + * var y = scalar2ndarray( 0.0, { + * 'dtype': 'float64' + * } ); + * var z = zeros( [], { + * 'dtype': 'int32' + * } ); + * + * var out = firstIndexLessThan.assign( x, y, 2, z ); + * // returns [ 2 ] + * + * var bool = ( out === z ); + * // returns true + */ + assign( x: InputArray, y: InputArray, fromIndex: FromIndex, out: U, options?: BaseOptions ): U; +} + +/** +* Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. +* +* ## Notes +* +* - When comparing elements, the function checks whether an element in the first input ndarray is less than a corresponding element in the second input ndarray using the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`. +* - If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding element in the returned ndarray is `-1`. +* +* @param x - first input ndarray +* @param y - second input ndarray +* @param fromIndex - index from which to begin searching +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = array( [ 1.0, 2.0, -3.0 ] ); +* var y = scalar2ndarray( 0.0, { +* 'dtype': 'float64' +* } ); +* +* var out = firstIndexLessThan( x, y, 0 ); +* // returns [ 2 ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); +* var y = scalar2ndarray( 0.0, { +* 'dtype': 'float64' +* } ); +* var z = zeros( [], { +* 'dtype': 'int32' +* } ); +* +* var out = firstIndexLessThan.assign( x, y, 2, z ); +* // returns [ 2 ] +* +* var bool = ( out === z ); +* // returns true +*/ +declare const firstIndexLessThan: FirstIndexLessThan; + + +// EXPORTS // + +export = firstIndexLessThan; diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/test.ts new file mode 100644 index 000000000000..fca0e559cfe4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/test.ts @@ -0,0 +1,526 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import firstIndexLessThan = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y ); // $ExpectType OutputArray + firstIndexLessThan( x, y, 1 ); // $ExpectType OutputArray + firstIndexLessThan( x, y, {} ); // $ExpectType OutputArray + firstIndexLessThan( x, y, 1, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( '5', y ); // $ExpectError + firstIndexLessThan( 5, y ); // $ExpectError + firstIndexLessThan( true, y ); // $ExpectError + firstIndexLessThan( false, y ); // $ExpectError + firstIndexLessThan( null, y ); // $ExpectError + firstIndexLessThan( void 0, y ); // $ExpectError + firstIndexLessThan( {}, y ); // $ExpectError + firstIndexLessThan( ( x: number ): number => x, y ); // $ExpectError + + firstIndexLessThan( '5', y, 0 ); // $ExpectError + firstIndexLessThan( 5, y, 0 ); // $ExpectError + firstIndexLessThan( true, y, 0 ); // $ExpectError + firstIndexLessThan( false, y, 0 ); // $ExpectError + firstIndexLessThan( null, y, 0 ); // $ExpectError + firstIndexLessThan( void 0, y, 0 ); // $ExpectError + firstIndexLessThan( {}, y, 0 ); // $ExpectError + firstIndexLessThan( ( x: number ): number => x, y, 0 ); // $ExpectError + + firstIndexLessThan( '5', y, {} ); // $ExpectError + firstIndexLessThan( 5, y, {} ); // $ExpectError + firstIndexLessThan( true, y, {} ); // $ExpectError + firstIndexLessThan( false, y, {} ); // $ExpectError + firstIndexLessThan( null, y, {} ); // $ExpectError + firstIndexLessThan( void 0, y, {} ); // $ExpectError + firstIndexLessThan( {}, y, {} ); // $ExpectError + firstIndexLessThan( ( x: number ): number => x, y, {} ); // $ExpectError + + firstIndexLessThan( '5', y, 0, {} ); // $ExpectError + firstIndexLessThan( 5, y, 0, {} ); // $ExpectError + firstIndexLessThan( true, y, 0, {} ); // $ExpectError + firstIndexLessThan( false, y, 0, {} ); // $ExpectError + firstIndexLessThan( null, y, 0, {} ); // $ExpectError + firstIndexLessThan( void 0, y, 0, {} ); // $ExpectError + firstIndexLessThan( {}, y, 0, {} ); // $ExpectError + firstIndexLessThan( ( x: number ): number => x, y, 0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, '5' ); // $ExpectError + firstIndexLessThan( x, 5 ); // $ExpectError + firstIndexLessThan( x, true ); // $ExpectError + firstIndexLessThan( x, false ); // $ExpectError + firstIndexLessThan( x, null ); // $ExpectError + firstIndexLessThan( x, void 0 ); // $ExpectError + firstIndexLessThan( x, [] ); // $ExpectError + firstIndexLessThan( x, {} ); // $ExpectError + firstIndexLessThan( x, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan( x, '5', 0 ); // $ExpectError + firstIndexLessThan( x, 5, 0 ); // $ExpectError + firstIndexLessThan( x, true, 0 ); // $ExpectError + firstIndexLessThan( x, false, 0 ); // $ExpectError + firstIndexLessThan( x, null, 0 ); // $ExpectError + firstIndexLessThan( x, void 0, 0 ); // $ExpectError + firstIndexLessThan( x, [], 0 ); // $ExpectError + firstIndexLessThan( x, {}, 0 ); // $ExpectError + firstIndexLessThan( x, ( x: number ): number => x, 0 ); // $ExpectError + + firstIndexLessThan( x, '5', {} ); // $ExpectError + firstIndexLessThan( x, 5, {} ); // $ExpectError + firstIndexLessThan( x, true, {} ); // $ExpectError + firstIndexLessThan( x, false, {} ); // $ExpectError + firstIndexLessThan( x, null, {} ); // $ExpectError + firstIndexLessThan( x, void 0, {} ); // $ExpectError + firstIndexLessThan( x, [], {} ); // $ExpectError + firstIndexLessThan( x, {}, {} ); // $ExpectError + firstIndexLessThan( x, ( x: number ): number => x, {} ); // $ExpectError + + firstIndexLessThan( x, '5', 0, {} ); // $ExpectError + firstIndexLessThan( x, 5, 0, {} ); // $ExpectError + firstIndexLessThan( x, true, 0, {} ); // $ExpectError + firstIndexLessThan( x, false, 0, {} ); // $ExpectError + firstIndexLessThan( x, null, 0, {} ); // $ExpectError + firstIndexLessThan( x, void 0, 0, {} ); // $ExpectError + firstIndexLessThan( x, [], 0, {} ); // $ExpectError + firstIndexLessThan( x, {}, 0, {} ); // $ExpectError + firstIndexLessThan( 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 an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y, '5' ); // $ExpectError + firstIndexLessThan( x, y, true ); // $ExpectError + firstIndexLessThan( x, y, false ); // $ExpectError + firstIndexLessThan( x, y, [] ); // $ExpectError + firstIndexLessThan( x, y, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan( x, y, '5', {} ); // $ExpectError + firstIndexLessThan( x, y, true, {} ); // $ExpectError + firstIndexLessThan( x, y, false, {} ); // $ExpectError + firstIndexLessThan( x, y, [], {} ); // $ExpectError + firstIndexLessThan( x, y, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y, '5' ); // $ExpectError + firstIndexLessThan( x, y, true ); // $ExpectError + firstIndexLessThan( x, y, false ); // $ExpectError + firstIndexLessThan( x, y, [] ); // $ExpectError + firstIndexLessThan( x, y, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan( x, y, 0, '5' ); // $ExpectError + firstIndexLessThan( x, y, 0, true ); // $ExpectError + firstIndexLessThan( x, y, 0, false ); // $ExpectError + firstIndexLessThan( x, y, 0, null ); // $ExpectError + firstIndexLessThan( x, y, 0, [] ); // $ExpectError + firstIndexLessThan( x, y, 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' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y, { 'dtype': '5' } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': 5 } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': true } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': false } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': null } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': [] } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': {} } ); // $ExpectError + firstIndexLessThan( x, y, { 'dtype': ( x: number ): number => x } ); // $ExpectError + + firstIndexLessThan( x, y, 0, { 'dtype': '5' } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': 5 } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': true } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': false } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': null } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': [] } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': {} } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y, { 'dim': '5' } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': true } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': false } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': null } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': [] } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': {} } ); // $ExpectError + firstIndexLessThan( x, y, { 'dim': ( x: number ): number => x } ); // $ExpectError + + firstIndexLessThan( x, y, 0, { 'dim': '5' } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': true } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': false } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': null } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': [] } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': {} } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan( x, y, { 'keepdims': '5' } ); // $ExpectError + firstIndexLessThan( x, y, { 'keepdims': 5 } ); // $ExpectError + firstIndexLessThan( x, y, { 'keepdims': null } ); // $ExpectError + firstIndexLessThan( x, y, { 'keepdims': {} } ); // $ExpectError + firstIndexLessThan( x, y, { 'keepdims': ( x: number ): number => x } ); // $ExpectError + + firstIndexLessThan( x, y, 0, { 'keepdims': '5' } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'keepdims': 5 } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'keepdims': null } ); // $ExpectError + firstIndexLessThan( x, y, 0, { 'keepdims': {} } ); // $ExpectError + firstIndexLessThan( x, y, 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' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan(); // $ExpectError + firstIndexLessThan( x ); // $ExpectError + firstIndexLessThan( x, y, 0, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( x, y, out ); // $ExpectType int32ndarray + firstIndexLessThan.assign( x, y, out, {} ); // $ExpectType int32ndarray + firstIndexLessThan.assign( x, y, 1, out ); // $ExpectType int32ndarray + firstIndexLessThan.assign( x, y, 1, out, {} ); // $ExpectType int32ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( '5', y, out ); // $ExpectError + firstIndexLessThan.assign( 5, y, out ); // $ExpectError + firstIndexLessThan.assign( true, y, out ); // $ExpectError + firstIndexLessThan.assign( false, y, out ); // $ExpectError + firstIndexLessThan.assign( null, y, out ); // $ExpectError + firstIndexLessThan.assign( void 0, y, out ); // $ExpectError + firstIndexLessThan.assign( {}, y, out ); // $ExpectError + firstIndexLessThan.assign( ( x: number ): number => x, y, out ); // $ExpectError + + firstIndexLessThan.assign( '5', y, 0, out ); // $ExpectError + firstIndexLessThan.assign( 5, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( true, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( false, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( null, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( void 0, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( {}, y, 0, out ); // $ExpectError + firstIndexLessThan.assign( ( x: number ): number => x, y, 0, out ); // $ExpectError + + firstIndexLessThan.assign( '5', y, out, {} ); // $ExpectError + firstIndexLessThan.assign( 5, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( true, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( false, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( null, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( void 0, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( {}, y, out, {} ); // $ExpectError + firstIndexLessThan.assign( ( x: number ): number => x, y, out, {} ); // $ExpectError + + firstIndexLessThan.assign( '5', y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( 5, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( true, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( false, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( null, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( void 0, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( {}, y, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( ( x: number ): number => x, y, 0, out, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( x, '5', out ); // $ExpectError + firstIndexLessThan.assign( x, 5, out ); // $ExpectError + firstIndexLessThan.assign( x, true, out ); // $ExpectError + firstIndexLessThan.assign( x, false, out ); // $ExpectError + firstIndexLessThan.assign( x, null, out ); // $ExpectError + firstIndexLessThan.assign( x, void 0, out ); // $ExpectError + firstIndexLessThan.assign( x, [], out ); // $ExpectError + firstIndexLessThan.assign( x, {}, out ); // $ExpectError + firstIndexLessThan.assign( x, ( x: number ): number => x, out ); // $ExpectError + + firstIndexLessThan.assign( x, '5', 0, out ); // $ExpectError + firstIndexLessThan.assign( x, 5, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, true, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, false, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, null, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, void 0, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, [], 0, out ); // $ExpectError + firstIndexLessThan.assign( x, {}, 0, out ); // $ExpectError + firstIndexLessThan.assign( x, ( x: number ): number => x, 0, out ); // $ExpectError + + firstIndexLessThan.assign( x, '5', out, {} ); // $ExpectError + firstIndexLessThan.assign( x, 5, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, true, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, false, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, null, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, void 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, [], out, {} ); // $ExpectError + firstIndexLessThan.assign( x, {}, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, ( x: number ): number => x, out, {} ); // $ExpectError + + firstIndexLessThan.assign( x, '5', 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, 5, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, true, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, false, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, null, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, void 0, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, [], 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, {}, 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, ( x: number ): number => x, 0, out, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a from index argument which is not an ndarray or an integer value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( x, y, '5', out ); // $ExpectError + firstIndexLessThan.assign( x, y, true, out ); // $ExpectError + firstIndexLessThan.assign( x, y, false, out ); // $ExpectError + firstIndexLessThan.assign( x, y, null, out ); // $ExpectError + firstIndexLessThan.assign( x, y, void 0, out ); // $ExpectError + firstIndexLessThan.assign( x, y, {}, out ); // $ExpectError + firstIndexLessThan.assign( x, y, ( x: number ): number => x, out ); // $ExpectError + + firstIndexLessThan.assign( x, y, '5', out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, true, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, false, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, null, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, void 0, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, {}, out, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, ( x: number ): number => x, out, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an output argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + firstIndexLessThan.assign( x, y, '5' ); // $ExpectError + firstIndexLessThan.assign( x, y, 5 ); // $ExpectError + firstIndexLessThan.assign( x, y, true ); // $ExpectError + firstIndexLessThan.assign( x, y, false ); // $ExpectError + firstIndexLessThan.assign( x, y, null ); // $ExpectError + firstIndexLessThan.assign( x, y, void 0 ); // $ExpectError + firstIndexLessThan.assign( x, y, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan.assign( x, y, '5', {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 5, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, true, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, false, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, null, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, void 0, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, ( x: number ): number => x, {} ); // $ExpectError + + firstIndexLessThan.assign( x, y, 1, '5' ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, 5 ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, true ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, false ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, null ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, void 0 ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan.assign( x, y, 1, '5', {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, 5, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, true, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, false, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, null, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, void 0, {} ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( x, y, out, '5' ); // $ExpectError + firstIndexLessThan.assign( x, y, out, true ); // $ExpectError + firstIndexLessThan.assign( x, y, out, false ); // $ExpectError + firstIndexLessThan.assign( x, y, out, null ); // $ExpectError + firstIndexLessThan.assign( x, y, out, [] ); // $ExpectError + firstIndexLessThan.assign( x, y, out, ( x: number ): number => x ); // $ExpectError + + firstIndexLessThan.assign( x, y, 1, out, '5' ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, true ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, false ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, null ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, [] ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dim` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign( x, y, out, { 'dim': '5' } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': true } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': false } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': null } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': [] } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': {} } ); // $ExpectError + firstIndexLessThan.assign( x, y, out, { 'dim': ( x: number ): number => x } ); // $ExpectError + + firstIndexLessThan.assign( x, y, 1, out, { 'dim': '5' } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': true } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': false } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': null } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': [] } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': {} } ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'int32' + }); + + firstIndexLessThan.assign(); // $ExpectError + firstIndexLessThan.assign( x ); // $ExpectError + firstIndexLessThan.assign( x, y ); // $ExpectError + firstIndexLessThan.assign( x, y, 1, out, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js new file mode 100644 index 000000000000..b0e08c66f655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var firstIndexLessThan = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 2 ], 0, 20, { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Create a second input ndarray: +var y = scalar2ndarray( 10.0, { + 'dtype': 'float64' +}); + +// Perform operation: +var idx = firstIndexLessThan( x, y, { + 'dim': 0 +}); + +// Print the results: +console.log( ndarray2array( idx ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js new file mode 100644 index 000000000000..9ac17efb71f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js @@ -0,0 +1,227 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ).assign; + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - first input ndarray +* @param {ndarrayLike} y - second input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=0] - index from which to begin searching +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} third argument must be either an ndarray-like object or an integer +* @throws {TypeError} output argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* 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 shape = [ 2, 3 ]; +* +* // Define the array strides: +* var strides = [ 3, 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create a second input ndarray: +* var y = scalar2ndarray( 0.0, { +* 'dtype': 'float64' +* }); +* +* // Create an output ndarray: +* var z = zeros( [ 2 ], { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = assign( x, y, z ); +* // returns [ 2, 1 ] +* +* var bool = ( out === z ); +* // returns true +*/ +function assign( x, y, fromIndex, out ) { + var hasOptions; + var options; + var nargs; + var opts; + var fidx; + var iflg; + var ord; + var sh; + var v; + var o; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension + }; + + // Initialize the `fromIndex` to the first element along a dimension: + fidx = 0; + + // Initialize a flag indicating whether the `fromIndex` argument is a scalar: + iflg = true; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: assign( x, y, out ) + if ( nargs <= 3 ) { + o = fromIndex; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', o ) ); + } + } + // Case: assign( x, y, ???, ??? ) + else if ( nargs === 4 ) { + // Case: assign( x, y, from_index, out ) + if ( isndarrayLike( out ) ) { + o = out; + + // Case: assign( x, y, from_index_scalar, out ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: assign( x, y, from_index_ndarray, out ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: assign( x, y, ???, out ) + else { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + } + // Case: assign( x, y, out, options ) + else { + o = fromIndex; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', o ) ); + } + options = out; + hasOptions = true; + } + } + // Case: assign( x, y, from_index, out, options ) + else { // nargs > 4 + // Case: assign( x, y, from_index_scalar, out, options ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: assign( x, y, from_index_ndarray, out, options ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: assign( x, y, ???, out, options ) + else { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + o = out; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be an ndarray. Value: `%s`.', o ) ); + } + options = arguments[ 4 ]; + hasOptions = true; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + } + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + // Broadcast the second input ndarray to match the shape of the first input ndarray: + v = maybeBroadcastArray( y, sh ); + + // Resolve the list of non-reduced dimensions: + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the `fromIndex` to match the shape of the non-reduced dimensions... + if ( iflg ) { + fidx = broadcastScalar( fidx, DEFAULT_DTYPE, sh, ord ); + } else { + fidx = maybeBroadcastArray( fidx, sh ); + } + return base( x, v, fidx, o, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js new file mode 100644 index 000000000000..84d503a215ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gfirstIndexLessThan = require( '@stdlib/blas/ext/base/ndarray/gfirst-index-less-than' ); +var dfirstIndexLessThan = require( '@stdlib/blas/ext/base/ndarray/dfirst-index-less-than' ); +var sfirstIndexLessThan = require( '@stdlib/blas/ext/base/ndarray/sfirst-index-less-than' ); +var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // first input ndarray +var idtypes1 = dtypes( 'all' ); // second input 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', 'float64', // input data types + 'float32', 'float32' // input data types + + // FIXME: add specialized support for `cfirstIndexLessThan` and `zfirstIndexLessThan` once the corresponding packages are implemented + ], + 'fcns': [ + dfirstIndexLessThan, + sfirstIndexLessThan + ], + 'default': gfirstIndexLessThan +}; + + +// MAIN // + +/** +* Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. +* +* @private +* @name firstIndexLessThan +* @type {Function} +* @param {ndarrayLike} x - first input ndarray +* @param {ndarrayLike} y - second input ndarray +* @param {ndarrayLike} fromIndex - indices from which to begin searching +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} third argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* 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 ] ); +* var ybuf = new Float64Array( [ 0.0, 9.0, 0.0, 9.0, 9.0, 9.0 ] ); +* +* // Define the shape of the input arrays: +* var sh = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create input ndarrays: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* var y = new ndarray( 'float64', ybuf, sh, sx, ox, 'row-major' ); +* +* // Create a from index ndarray: +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = firstIndexLessThan( x, y, fromIndex ); +* // returns [ 1 ] +*/ +var firstIndexLessThan = factory( table, [ idtypes0, idtypes1, idtypes2 ], odtypes, policies ); // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = firstIndexLessThan; + +// exports: { "assign": "firstIndexLessThan.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js new file mode 100644 index 000000000000..6cca6f2ec99c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. +* +* @module @stdlib/blas/ext/first-index-less-than +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); +* +* // 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 = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create a second input ndarray: +* var y = scalar2ndarray( 0.0, { +* 'dtype': 'float64' +* }); +* +* // Perform operation: +* var out = firstIndexLessThan( x, y ); +* // returns [ 2, 1 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js new file mode 100644 index 000000000000..f1d1b772552c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ); + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. +* +* @param {ndarrayLike} x - first input ndarray +* @param {ndarrayLike} y - second input ndarray +* @param {(ndarrayLike|integer)} [fromIndex=0] - index from which to begin searching +* @param {Options} [options] - function options +* @param {integer} [options.dim=-1] - dimension over which to perform operation +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @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 index must not exceed input ndarray bounds +* @throws {RangeError} first argument must have at least one dimension +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* 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 = [ 2, 3 ]; +* +* // Define the array strides: +* var sx = [ 3, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create a second input ndarray: +* var y = scalar2ndarray( 0.0, { +* 'dtype': 'float64' +* }); +* +* // Perform operation: +* var out = firstIndexLessThan( x, y ); +* // returns [ 2, 1 ] +*/ +function firstIndexLessThan( x, y, fromIndex ) { + var hasOptions; + var options; + var nargs; + var opts; + var fidx; + var iflg; + var ord; + var sh; + var v; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = { + 'dims': [ -1 ], // default behavior is to perform a reduction over the last dimension + 'keepdims': false + }; + + // Initialize the `fromIndex` to the first element along a dimension: + fidx = 0; + + // Initialize a flag indicating whether the `fromIndex` argument is a scalar: + iflg = true; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: firstIndexLessThan( x, y, ??? ) + if ( nargs === 3 ) { + // Case: firstIndexLessThan( x, y, from_index_scalar ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: firstIndexLessThan( x, y, from_index_ndarray ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: firstIndexLessThan( x, y, options ) + else { + options = fromIndex; + hasOptions = true; + } + } + // Case: firstIndexLessThan( x, y, from_index, options ) + else if ( nargs > 3 ) { + // Case: firstIndexLessThan( x, y, from_index_scalar, options ) + if ( isInteger( fromIndex ) ) { + fidx = fromIndex; + } + // Case: firstIndexLessThan( x, y, from_index_ndarray, options ) + else if ( isndarrayLike( fromIndex ) ) { + fidx = fromIndex; + iflg = false; + } + // Case: firstIndexLessThan( x, y, ???, options ) + else { + throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray or an integer. Value: `%s`.', fromIndex ) ); + } + options = arguments[ 3 ]; + hasOptions = true; + } + if ( hasOptions ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dim' ) ) { + opts.dims[ 0 ] = options.dim; + } + if ( hasOwnProp( options, 'keepdims' ) ) { + opts.keepdims = options.keepdims; + } + if ( hasOwnProp( options, 'dtype' ) ) { + opts.dtype = options.dtype; + } + } + sh = getShape( x ); + if ( sh.length < 1 ) { + throw new RangeError( 'invalid argument. First argument must have at least one dimension.' ); + } + // Broadcast the second input ndarray to match the shape of the first input ndarray: + v = maybeBroadcastArray( y, sh ); + + // Resolve the list of non-reduced dimensions: + sh = nonCoreShape( sh, opts.dims ); + + // Broadcast the `fromIndex` to match the shape of the non-reduced dimensions... + if ( iflg ) { + fidx = broadcastScalar( fidx, DEFAULT_DTYPE, sh, ord ); + } else { + fidx = maybeBroadcastArray( fidx, sh ); + } + return base( x, v, fidx, opts ); +} + + +// EXPORTS // + +module.exports = firstIndexLessThan; diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/package.json b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/package.json new file mode 100644 index 000000000000..842592585d28 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/first-index-less-than", + "version": "0.0.0", + "description": "Return the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "find", + "index", + "search", + "less", + "compare", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js new file mode 100644 index 000000000000..a245401b0b40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js @@ -0,0 +1,1626 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Int32Array = require( '@stdlib/array/int32' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var firstIndexLessThan = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof firstIndexLessThan, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var out; + var i; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar)', function test( t ) { + var values; + var out; + var i; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), 0, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var out; + var i; + + opts = { + 'dtype': 'generic' + }; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, opts ), out ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var opts; + var out; + var i; + + opts = { + 'dtype': 'generic' + }; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var opts; + var out; + var i; + + opts = { + 'dtype': 'generic' + }; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), 0, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray, options)', function test( t ) { + var values; + var opts; + var out; + var i; + + opts = { + 'dtype': 'generic' + }; + + out = 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() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, opts ), out, {} ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var out; + var i; + + opts = { + 'dtype': 'generic' + }; + + out = zeros( [], opts ); + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, opts ), out, {} ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (fromIndex=scalar)', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, value, 0, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, value, 0, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fromIndex argument which is not an ndarray-like object, an integer, or an object', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a fromIndex argument which is not an ndarray-like object, an integer, or an object (options)', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (fromIndex)', function test( t ) { + var values; + var 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (fromIndex, options)', function test( t ) { + var values; + var 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), 2, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + var y; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue3, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + firstIndexLessThan( x ); + } + + function badValue2() { + firstIndexLessThan( x, y ); + } + + function badValue3() { + firstIndexLessThan(); + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), out, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=scalar)', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), 0, out, value ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + out = 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() { + firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), scalar2ndarray( 0, opts ), out, value ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var opts; + var out; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + + x = zeros( [ 2, 2 ], opts ); + out = zeros( [], opts ); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), out, { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first element which is less than a corresponding element in another ndarray (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, out ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, 0, out ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element which is less than a corresponding element in another ndarray (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, out ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 0, out ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, out, { + 'dim': 0 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, 0, out, { + 'dim': 0 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, out, { + 'dim': 1 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = firstIndexLessThan( x, y, 0, out, { + 'dim': 1 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, out, { + 'dim': 0 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 0, out, { + 'dim': 0 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, out, { + 'dim': 1 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 0, out, { + 'dim': 1 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2, out ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2, out ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2, out, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2, out, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = firstIndexLessThan( x, y, fromIdx, out ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx, out ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = firstIndexLessThan( x, y, fromIdx, out, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx, out, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, + * -3.0, 2.0, + * -5.0, 6.0, + * -7.0, 2.0, + * -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2, out, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, 6.0, + * 2.0, -7.0, + * -3.0, 2.0, + * 2.0, -8.0, + * -5.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2, out, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === 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 out; + var x; + var y; + + /* + * [ + * -1.0, 2.0, + * -3.0, 2.0, + * -5.0, 6.0, + * -7.0, 2.0, + * -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + actual = firstIndexLessThan( x, y, fromIdx, out, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + /* + * [ + * -1.0, 6.0, + * 2.0, -7.0, + * -3.0, 2.0, + * 2.0, -8.0, + * -5.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx, out, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var out; + var x; + var y; + + /* + * [ + * 1.0, -2.0, + * 2.0, -3.0, + * 3.0, -4.0, + * 2.0, -3.0, + * 5.0, -6.0 + * ] + */ + xbuf = [ 1.0, -2.0, 2.0, -3.0, 3.0, -4.0, 2.0, -3.0, 5.0, -6.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + y = new ndarray( 'generic', [ 2.0, -3.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + actual = firstIndexLessThan( x, y, fromIdx, out, { + 'dim': 0 + }); + expected = [ -1, 2 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + t.strictEqual( ( out === actual ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.js new file mode 100644 index 000000000000..e2902539fa2e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var firstIndexLessThan = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof firstIndexLessThan, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( firstIndexLessThan, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js new file mode 100644 index 000000000000..011c0195cd0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js @@ -0,0 +1,1388 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var Int32Array = require( '@stdlib/array/int32' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var firstIndexLessThan = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof firstIndexLessThan, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, { + 'dtype': 'generic' + })); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (fromIndex=ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, { + 'dtype': 'generic' + }), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray', function test( t ) { + var values; + var opts; + var i; + + opts = { + 'dtype': 'generic' + }; + + values = [ + scalar2ndarray( 10.0 ), + scalar2ndarray( -3.0 ), + scalar2ndarray( 0.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( value, scalar2ndarray( 0.0 ), scalar2ndarray( 0, opts ), {} ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + 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() { + firstIndexLessThan( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (fromIndex=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + 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() { + firstIndexLessThan( x, value, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + 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() { + firstIndexLessThan( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (fromIndex=scalar, options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + 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() { + firstIndexLessThan( x, value, 0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object, an integer, or an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided insufficient number of arguments', function test( t ) { + var x; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + t.throws( badValue1, TypeError, 'throws an error when provided insufficient arguments' ); + t.throws( badValue2, TypeError, 'throws an error when provided insufficient arguments' ); + t.end(); + + function badValue1() { + firstIndexLessThan( x ); + } + + function badValue2() { + firstIndexLessThan(); + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a from index which is not broadcast-compatible with the first argument (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), 0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (fromIndex=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), scalar2ndarray( 0, opts ), value ); // eslint-disable-line max-len + }; + } +}); + +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() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + firstIndexLessThan( x, scalar2ndarray( 0.0 ), { + 'dim': value + }); + }; + } +}); + +tape( 'the function returns the index of the first element which is less than a corresponding element in another 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0 ); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element which is less than a corresponding element in another 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 = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0 ); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (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 = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, { + 'dim': 0 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'dim': 0 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, { + 'dim': 1 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'dim': 1 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the operation dimension (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, -2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, { + 'dim': 0 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'dim': 0 + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, { + 'dim': 1 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'dim': 1 + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, { + 'keepdims': true + }); + expected = [ [ 1 ], [ 1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'keepdims': true + }); + expected = [ [ 1 ], [ 1 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the `keepdims` option (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, { + 'keepdims': true + }); + expected = [ [ -1 ], [ 0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = firstIndexLessThan( x, y, 0, { + 'keepdims': true + }); + expected = [ [ -1 ], [ 0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ 1.0, -2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, { + 'dtype': 'int32' + }); + expected = [ 1, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, -2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 0, { + 'dtype': 'int32' + }); + expected = [ -1, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2 ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2 ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = firstIndexLessThan( x, y, fromIdx ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, options)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, -3.0, 2.0, -5.0, + * 6.0, -7.0, 2.0, -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = firstIndexLessThan( x, y, fromIdx, {} ); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, -3.0, -5.0, -7.0, -8.0, + * 2.0, 2.0, 6.0, 2.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx, {} ); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, + * -3.0, 2.0, + * -5.0, 6.0, + * -7.0, 2.0, + * -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + actual = firstIndexLessThan( x, y, 2, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, 6.0, + * 2.0, -7.0, + * -3.0, 2.0, + * 2.0, -8.0, + * -5.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, 2, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (0d ndarray, broadcasted)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * -1.0, 2.0, + * -3.0, 2.0, + * -5.0, 6.0, + * -7.0, 2.0, + * -8.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + + fromIdx = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + actual = firstIndexLessThan( x, y, fromIdx, { + 'dim': 0 + }); + expected = [ 2, -1 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + /* + * [ + * -1.0, 6.0, + * 2.0, -7.0, + * -3.0, 2.0, + * 2.0, -8.0, + * -5.0, 2.0 + * ] + */ + xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); + y = scalar2ndarray( 0.0, { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = firstIndexLessThan( x, y, fromIdx, { + 'dim': 0 + }); + expected = [ 2, 3 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a from index (1d ndarray)', function test( t ) { + var expected; + var fromIdx; + var actual; + var xbuf; + var x; + var y; + + /* + * [ + * 1.0, -2.0, + * 2.0, -3.0, + * 3.0, -4.0, + * 2.0, -3.0, + * 5.0, -6.0 + * ] + */ + xbuf = [ 1.0, -2.0, 2.0, -3.0, 3.0, -4.0, 2.0, -3.0, 5.0, -6.0 ]; + x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); + + fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); + y = new ndarray( 'generic', [ 2.0, -3.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + actual = firstIndexLessThan( x, y, fromIdx, { + 'dim': 0 + }); + expected = [ -1, 2 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From 7103e249f8e33230ccccc10bca32480c5ee0032e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 25 Aug 2026 20:00:31 +0500 Subject: [PATCH 2/5] fix: lint err --- .../@stdlib/blas/ext/first-index-less-than/lib/base.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js index 84d503a215ac..db0311a5c722 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js @@ -39,8 +39,10 @@ var policies = { }; var table = { 'types': [ - 'float64', 'float64', // input data types - 'float32', 'float32' // input data types + 'float64', + 'float64', + 'float32', + 'float32' // FIXME: add specialized support for `cfirstIndexLessThan` and `zfirstIndexLessThan` once the corresponding packages are implemented ], From aac8c855ce2f14b841da8dab63795157b640c15a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 25 Aug 2026 20:04:38 +0500 Subject: [PATCH 3/5] fix: lint err --- .../@stdlib/blas/ext/first-index-less-than/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js index a245401b0b40..46795de85ceb 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js @@ -857,7 +857,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), 0, out, value ); // eslint-disable-line max-len + firstIndexLessThan( x, scalar2ndarray( 0.0, opts ), 0, out, value ); }; } }); From a7fb8db0040c8638bafac1b3fd29a965defe6ded Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 28 Sep 2026 15:44:28 +0500 Subject: [PATCH 4/5] fix: apply suggestions from code review --- .../blas/ext/first-index-less-than/README.md | 62 ++++----- .../benchmark/benchmark.assign.js | 3 +- .../benchmark/benchmark.js | 3 +- .../ext/first-index-less-than/docs/repl.txt | 28 ++-- .../docs/types/index.d.ts | 30 +---- .../first-index-less-than/examples/index.js | 6 +- .../ext/first-index-less-than/lib/assign.js | 10 +- .../ext/first-index-less-than/lib/base.js | 8 +- .../ext/first-index-less-than/lib/index.js | 10 +- .../ext/first-index-less-than/lib/main.js | 10 +- .../first-index-less-than/test/test.assign.js | 64 ++++----- .../first-index-less-than/test/test.main.js | 127 ++++++++---------- 12 files changed, 161 insertions(+), 200 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md index ffdbc822c06a..68d910199366 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md @@ -35,7 +35,6 @@ var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); Returns the index of the first element in an [ndarray][@stdlib/ndarray/ctor] which is less than a corresponding element in another [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension. ```javascript -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var array = require( '@stdlib/ndarray/array' ); // Create an input ndarray: @@ -43,9 +42,8 @@ var x = array( [ 1.0, 2.0, -3.0, 4.0, 5.0, 6.0 ] ); // returns // Create a second input ndarray: -var y = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ 1.0, 2.0, 0.0, 4.0, 5.0, 6.0 ] ); +// returns // Perform operation: var out = firstIndexLessThan( x, y ); @@ -65,21 +63,39 @@ The function accepts the following options: - **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`. - **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 an element which is less than a corresponding element in the second input [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`. +The shape of the second input [ndarray][@stdlib/ndarray/ctor] must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the first input [ndarray][@stdlib/ndarray/ctor]. For example, to compare each element in the first input [ndarray][@stdlib/ndarray/ctor] with the same value, provide a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. ```javascript var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var array = require( '@stdlib/ndarray/array' ); // Create an input ndarray: -var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = array( [ 1.0, 2.0, -3.0, 4.0, 5.0, 6.0 ] ); // returns -// Create a second input ndarray: +// Create a zero-dimensional ndarray: var y = scalar2ndarray( 0.0, { 'dtype': 'float64' }); +// Perform operation: +var out = firstIndexLessThan( x, y ); +// returns [ 2 ] +``` + +If the function is unable to find an element which is less than a corresponding element in the second input [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create an input ndarray: +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +// returns + +// Create a second input ndarray: +var y = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +// returns + // Perform operation: var out = firstIndexLessThan( x, y ); // returns [ -1 ] @@ -88,7 +104,6 @@ var out = firstIndexLessThan( x, y ); By default, the function begins searching from the first element along the reduction dimension. To begin searching from a different index, provide a `fromIndex` argument. ```javascript -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var array = require( '@stdlib/ndarray/array' ); // Create an input ndarray: @@ -96,9 +111,8 @@ var x = array( [ -1.0, 2.0, 3.0, -4.0, 2.0, 6.0 ] ); // returns // Create a second input ndarray: -var y = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ 0.0, 2.0, 3.0, 0.0, 2.0, 6.0 ] ); +// returns // Perform operation: var out = firstIndexLessThan( x, y, 2 ); @@ -108,14 +122,11 @@ var out = firstIndexLessThan( x, y, 2 ); By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option. ```javascript -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); -var y = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ [ 0.0, 2.0 ], [ 0.0, 4.0 ] ] ); var out = firstIndexLessThan( x, y, { 'dim': 0 @@ -126,14 +137,11 @@ var out = firstIndexLessThan( x, y, { By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. ```javascript -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); -var y = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ [ 0.0, 2.0 ], [ 0.0, 4.0 ] ] ); var opts = { 'dim': 0, @@ -147,15 +155,12 @@ var out = firstIndexLessThan( x, y, opts ); 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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var dtype = require( '@stdlib/ndarray/dtype' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, -2.0, 3.0, 4.0 ] ); -var y = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ 1.0, 0.0, 3.0, 4.0 ] ); var idx = firstIndexLessThan( x, y, { 'dtype': 'generic' @@ -171,15 +176,12 @@ var dt = dtype( idx ); Returns the index of the first element in an [ndarray][@stdlib/ndarray/ctor] which is less than a corresponding element in another [ndarray][@stdlib/ndarray/ctor] along an [ndarray][@stdlib/ndarray/ctor] dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. ```javascript -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); 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 = scalar2ndarray( 0.0, { - 'dtype': 'float64' -}); +var y = array( [ 1.0, 2.0, 0.0, 4.0 ] ); var z = zeros( [], { 'dtype': 'int32' @@ -228,7 +230,6 @@ The method accepts the following options: ```javascript var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); @@ -238,10 +239,11 @@ var x = discreteUniform( [ 5, 2 ], 0, 20, { }); console.log( ndarray2array( x ) ); -// Create a second input ndarray: -var y = scalar2ndarray( 10.0, { +// Generate a second ndarray of random numbers: +var y = discreteUniform( [ 5, 2 ], 0, 20, { 'dtype': 'float64' }); +console.log( ndarray2array( y ) ); // Perform operation: var idx = firstIndexLessThan( x, y, { diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js index 275997614425..3b162b6f25f8 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.assign.js @@ -24,7 +24,6 @@ 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/uniform' ); -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var zeros = require( '@stdlib/ndarray/zeros' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -53,7 +52,7 @@ function createBenchmark( len ) { var y; x = uniform( [ len ], -50.0, 50.0, options ); - y = scalar2ndarray( -100.0, options ); + y = uniform( [ len ], -100.0, -99.0, options ); out = zeros( [], { 'dtype': 'int32' }); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js index 8957ac735024..be449c7e0c7b 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/benchmark/benchmark.js @@ -24,7 +24,6 @@ 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/uniform' ); -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var firstIndexLessThan = require( './../lib' ); @@ -48,7 +47,7 @@ var options = { */ function createBenchmark( len ) { var x = uniform( [ len ], -50.0, 50.0, options ); - var y = scalar2ndarray( -100.0, options ); + var y = uniform( [ len ], -100.0, -99.0, options ); return benchmark; /** diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt index 8b7e5fec0d93..a4306acabf40 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/repl.txt @@ -3,10 +3,10 @@ Returns the index of the first element in an ndarray which is less than a corresponding element in another ndarray along an ndarray dimension. - When comparing elements, the function checks whether an element in the - first input ndarray is less than a corresponding element in the second - input ndarray using the less-than operator `<`. As a consequence, - comparisons involving `NaN` always evaluate to `false`. + When comparing elements, the function checks whether an element in the first + input ndarray is less than a corresponding element in the second input + ndarray using the less-than operator `<`. As a consequence, comparisons + involving `NaN` always evaluate to `false`. If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding @@ -18,8 +18,8 @@ First input array. Must have at least one dimension. y: ndarray - Second input array. Must have a shape which is broadcast compatible - with the shape of the first input ndarray. + Second input array. Must have a shape which is broadcast compatible with + the shape of the first input ndarray. fromIndex: ndarray|integer (optional) Index from which to begin searching. May be either a scalar value or an @@ -56,7 +56,7 @@ Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, -3.0, -4.0 ] ); - > var y = {{alias:@stdlib/ndarray/from-scalar}}( 0.0 ); + > var y = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 0.0, 0.0 ] ); > var out = {{alias}}( x, y ) [ 2 ] @@ -66,10 +66,10 @@ corresponding element in another ndarray along an ndarray dimension and assigns results to a provided output ndarray. - When comparing elements, the function checks whether an element in the - first input ndarray is less than a corresponding element in the second - input ndarray using the less-than operator `<`. As a consequence, - comparisons involving `NaN` always evaluate to `false`. + When comparing elements, the function checks whether an element in the first + input ndarray is less than a corresponding element in the second input + ndarray using the less-than operator `<`. As a consequence, comparisons + involving `NaN` always evaluate to `false`. If unable to find an element which is less than a corresponding element in the second input ndarray along an ndarray dimension, the corresponding @@ -81,8 +81,8 @@ First input array. Must have at least one dimension. y: ndarray - Second input array. Must have a shape which is broadcast compatible - with the shape of the first input ndarray. + Second input array. Must have a shape which is broadcast compatible with + the shape of the first input ndarray. fromIndex: ndarray|integer (optional) Index from which to begin searching. May be either a scalar value or an @@ -115,7 +115,7 @@ Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, -3.0, -4.0 ] ); - > var y = {{alias:@stdlib/ndarray/from-scalar}}( 0.0 ); + > var y = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 0.0, 0.0 ] ); > var out = {{alias:@stdlib/ndarray/zeros}}( [], { 'dtype': 'int32' } ); > var idx = {{alias}}.assign( x, y, out ) [ 2 ] diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts index f0babb87158d..1ca8da7b71f5 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/docs/types/index.d.ts @@ -86,12 +86,9 @@ interface FirstIndexLessThan { * * @example * var array = require( '@stdlib/ndarray/array' ); - * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ 1.0, 2.0, -3.0 ] ); - * var y = scalar2ndarray( 0.0, { - * 'dtype': 'float64' - * } ); + * var y = array( [ 1.0, 2.0, 0.0 ] ); * * var out = firstIndexLessThan( x, y ); * // returns [ 2 ] @@ -114,12 +111,9 @@ interface FirstIndexLessThan { * * @example * var array = require( '@stdlib/ndarray/array' ); - * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); - * var y = scalar2ndarray( 0.0, { - * 'dtype': 'float64' - * } ); + * var y = array( [ 0.0, 2.0, 0.0, 0.0, 5.0, 6.0 ] ); * * var out = firstIndexLessThan( x, y, 2 ); * // returns [ 2 ] @@ -143,12 +137,9 @@ interface FirstIndexLessThan { * @example * var zeros = require( '@stdlib/ndarray/zeros' ); * var array = require( '@stdlib/ndarray/array' ); - * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ 1.0, 2.0, -3.0 ] ); - * var y = scalar2ndarray( 0.0, { - * 'dtype': 'float64' - * } ); + * var y = array( [ 1.0, 2.0, 0.0 ] ); * var z = zeros( [], { * 'dtype': 'int32' * } ); @@ -179,12 +170,9 @@ interface FirstIndexLessThan { * @example * var zeros = require( '@stdlib/ndarray/zeros' ); * var array = require( '@stdlib/ndarray/array' ); - * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); - * var y = scalar2ndarray( 0.0, { - * 'dtype': 'float64' - * } ); + * var y = array( [ 0.0, 2.0, 0.0, 0.0, 5.0, 6.0 ] ); * var z = zeros( [], { * 'dtype': 'int32' * } ); @@ -214,12 +202,9 @@ interface FirstIndexLessThan { * * @example * var array = require( '@stdlib/ndarray/array' ); -* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ 1.0, 2.0, -3.0 ] ); -* var y = scalar2ndarray( 0.0, { -* 'dtype': 'float64' -* } ); +* var y = array( [ 1.0, 2.0, 0.0 ] ); * * var out = firstIndexLessThan( x, y, 0 ); * // returns [ 2 ] @@ -227,12 +212,9 @@ interface FirstIndexLessThan { * @example * var zeros = require( '@stdlib/ndarray/zeros' ); * var array = require( '@stdlib/ndarray/array' ); -* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var x = array( [ -1.0, 2.0, -3.0, -4.0, 5.0, 6.0 ] ); -* var y = scalar2ndarray( 0.0, { -* 'dtype': 'float64' -* } ); +* var y = array( [ 0.0, 2.0, 0.0, 0.0, 5.0, 6.0 ] ); * var z = zeros( [], { * 'dtype': 'int32' * } ); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js index b0e08c66f655..b1a2e2ac487a 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/examples/index.js @@ -19,7 +19,6 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var firstIndexLessThan = require( './../lib' ); @@ -29,10 +28,11 @@ var x = discreteUniform( [ 5, 2 ], 0, 20, { }); console.log( ndarray2array( x ) ); -// Create a second input ndarray: -var y = scalar2ndarray( 10.0, { +// Generate a second ndarray of random numbers: +var y = discreteUniform( [ 5, 2 ], 0, 20, { 'dtype': 'float64' }); +console.log( ndarray2array( y ) ); // Perform operation: var idx = firstIndexLessThan( x, y, { diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js index 9ac17efb71f7..e1235650a2d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/assign.js @@ -62,14 +62,14 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * -* // Create a data buffer: +* // Create data buffers: * var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ); * -* // Define the shape of the input array: +* // Define the shape of the input arrays: * var shape = [ 2, 3 ]; * * // Define the array strides: @@ -82,9 +82,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); * * // Create a second input ndarray: -* var y = scalar2ndarray( 0.0, { -* 'dtype': 'float64' -* }); +* var y = new ndarray( 'float64', ybuf, shape, strides, offset, 'row-major' ); * * // Create an output ndarray: * var z = zeros( [ 2 ], { diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js index db0311a5c722..d205192458c1 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/base.js @@ -43,8 +43,6 @@ var table = { 'float64', 'float32', 'float32' - - // FIXME: add specialized support for `cfirstIndexLessThan` and `zfirstIndexLessThan` once the corresponding packages are implemented ], 'fcns': [ dfirstIndexLessThan, @@ -83,8 +81,8 @@ var table = { * 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 ] ); -* var ybuf = new Float64Array( [ 0.0, 9.0, 0.0, 9.0, 9.0, 9.0 ] ); +* var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ); * * // Define the shape of the input arrays: * var sh = [ 6 ]; @@ -106,7 +104,7 @@ var table = { * * // Perform operation: * var out = firstIndexLessThan( x, y, fromIndex ); -* // returns [ 1 ] +* // returns [ 2 ] */ var firstIndexLessThan = factory( table, [ idtypes0, idtypes1, idtypes2 ], odtypes, policies ); // eslint-disable-line max-len diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js index 6cca6f2ec99c..66e7770dd50e 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/index.js @@ -25,14 +25,14 @@ * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * var firstIndexLessThan = require( '@stdlib/blas/ext/first-index-less-than' ); * -* // Create a data buffer: +* // Create data buffers: * var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ); * -* // Define the shape of the input array: +* // Define the shape of the input arrays: * var sh = [ 2, 3 ]; * * // Define the array strides: @@ -45,9 +45,7 @@ * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create a second input ndarray: -* var y = scalar2ndarray( 0.0, { -* 'dtype': 'float64' -* }); +* var y = new ndarray( 'float64', ybuf, sh, sx, ox, 'row-major' ); * * // Perform operation: * var out = firstIndexLessThan( x, y ); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js index f1d1b772552c..42d10befc4d2 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/lib/main.js @@ -62,13 +62,13 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * -* // Create a data buffer: +* // Create data buffers: * var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ] ); * -* // Define the shape of the input array: +* // Define the shape of the input arrays: * var sh = [ 2, 3 ]; * * // Define the array strides: @@ -81,9 +81,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create a second input ndarray: -* var y = scalar2ndarray( 0.0, { -* 'dtype': 'float64' -* }); +* var y = new ndarray( 'float64', ybuf, sh, sx, ox, 'row-major' ); * * // Perform operation: * var out = firstIndexLessThan( x, y ); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js index 46795de85ceb..b5518c22a8dc 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.assign.js @@ -942,15 +942,15 @@ tape( 'the function returns the index of the first element which is less than a var expected; var actual; var xbuf; + var ybuf; var out; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic', 'order': 'row-major' @@ -988,15 +988,15 @@ tape( 'the function returns the index of the first element which is less than a var expected; var actual; var xbuf; + var ybuf; var out; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = zeros( [ 2 ], { 'dtype': 'generic', 'order': 'column-major' @@ -1034,15 +1034,15 @@ tape( 'the function supports specifying an operation dimension (row-major)', fun var expected; var actual; var xbuf; + var ybuf; var out; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic', 'order': 'row-major' @@ -1118,15 +1118,15 @@ tape( 'the function supports specifying an operation dimension (column-major)', var expected; var actual; var xbuf; + var ybuf; var out; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = zeros( [ 2 ], { 'dtype': 'generic', 'order': 'column-major' @@ -1202,6 +1202,7 @@ tape( 'the function supports providing a from index (scalar)', function test( t var expected; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1214,9 +1215,8 @@ tape( 'the function supports providing a from index (scalar)', function test( t */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1261,6 +1261,7 @@ tape( 'the function supports providing a from index (scalar, options)', function var expected; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1273,9 +1274,8 @@ tape( 'the function supports providing a from index (scalar, options)', function */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1321,6 +1321,7 @@ tape( 'the function supports providing a from index (0d ndarray)', function test var fromIdx; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1333,9 +1334,8 @@ tape( 'the function supports providing a from index (0d ndarray)', function test */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1384,6 +1384,7 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func var fromIdx; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1396,9 +1397,8 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1446,6 +1446,7 @@ tape( 'the function supports providing a from index (scalar, broadcasted)', func var expected; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1461,9 +1462,8 @@ tape( 'the function supports providing a from index (scalar, broadcasted)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1516,6 +1516,7 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)', var fromIdx; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1531,9 +1532,8 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)', */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); out = zeros( [ 2 ], { 'dtype': 'generic' }); @@ -1589,6 +1589,7 @@ tape( 'the function supports providing a from index (ndarray)', function test( t var fromIdx; var actual; var xbuf; + var ybuf; var out; var x; var y; @@ -1609,7 +1610,8 @@ tape( 'the function supports providing a from index (ndarray)', function test( t }); fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); - y = new ndarray( 'generic', [ 2.0, -3.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + ybuf = [ 2.0, -3.0 ]; + y = new ndarray( 'generic', ybuf, [ 2 ], [ 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, fromIdx, out, { 'dim': 0 }); diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js index 011c0195cd0f..684f8d0a0d2e 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/test/test.main.js @@ -693,14 +693,14 @@ tape( 'the function returns the index of the first element which is less than a var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y ); expected = [ 1, -1 ]; @@ -727,15 +727,14 @@ tape( 'the function returns the index of the first element which is less than a var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y ); expected = [ -1, 0 ]; @@ -762,14 +761,14 @@ tape( 'the function supports specifying the operation dimension (row-major)', fu var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, { 'dim': 0 @@ -822,15 +821,14 @@ tape( 'the function supports specifying the operation dimension (column-major)', var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, { 'dim': 0 @@ -883,14 +881,14 @@ tape( 'the function supports specifying the `keepdims` option (row-major)', func var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, { 'keepdims': true @@ -921,15 +919,14 @@ tape( 'the function supports specifying the `keepdims` option (column-major)', f var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, { 'keepdims': true @@ -960,14 +957,14 @@ tape( 'the function supports specifying the output array data type', function te var expected; var actual; var xbuf; + var ybuf; 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 = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, { 'dtype': 'int32' @@ -982,10 +979,8 @@ tape( 'the function supports specifying the output array data type', function te xbuf = [ 1.0, -2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, 0, { 'dtype': 'int32' @@ -1005,6 +1000,7 @@ tape( 'the function supports providing a from index (scalar)', function test( t var expected; var actual; var xbuf; + var ybuf; var x; var y; @@ -1016,9 +1012,8 @@ tape( 'the function supports providing a from index (scalar)', function test( t */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, 2 ); expected = [ 2, 3 ]; @@ -1037,10 +1032,8 @@ tape( 'the function supports providing a from index (scalar)', function test( t */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, 2 ); expected = [ 2, -1 ]; @@ -1058,6 +1051,7 @@ tape( 'the function supports providing a from index (scalar, options)', function var expected; var actual; var xbuf; + var ybuf; var x; var y; @@ -1069,9 +1063,8 @@ tape( 'the function supports providing a from index (scalar, options)', function */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, 2, {} ); expected = [ 2, 3 ]; @@ -1090,10 +1083,8 @@ tape( 'the function supports providing a from index (scalar, options)', function */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, 2, {} ); expected = [ 2, -1 ]; @@ -1112,6 +1103,7 @@ tape( 'the function supports providing a from index (0d ndarray)', function test var fromIdx; var actual; var xbuf; + var ybuf; var x; var y; @@ -1123,9 +1115,8 @@ tape( 'the function supports providing a from index (0d ndarray)', function test */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); fromIdx = scalar2ndarray( 2, { 'dtype': 'generic' @@ -1147,10 +1138,8 @@ tape( 'the function supports providing a from index (0d ndarray)', function test */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, fromIdx ); expected = [ 2, -1 ]; @@ -1169,6 +1158,7 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func var fromIdx; var actual; var xbuf; + var ybuf; var x; var y; @@ -1180,9 +1170,8 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 5, 1 ], 0, 'row-major' ); fromIdx = scalar2ndarray( 2, { 'dtype': 'generic' @@ -1204,10 +1193,8 @@ tape( 'the function supports providing a from index (0d ndarray, options)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 2, 5 ], [ 1, 2 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, fromIdx, {} ); expected = [ 2, -1 ]; @@ -1225,6 +1212,7 @@ tape( 'the function supports providing a from index (scalar, broadcasted)', func var expected; var actual; var xbuf; + var ybuf; var x; var y; @@ -1239,9 +1227,8 @@ tape( 'the function supports providing a from index (scalar, broadcasted)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, 2, { 'dim': 0 @@ -1265,10 +1252,8 @@ tape( 'the function supports providing a from index (scalar, broadcasted)', func */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, 2, { 'dim': 0 @@ -1289,6 +1274,7 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)', var fromIdx; var actual; var xbuf; + var ybuf; var x; var y; @@ -1303,9 +1289,8 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)', */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); fromIdx = scalar2ndarray( 2, { 'dtype': 'int32' @@ -1332,10 +1317,8 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)', */ xbuf = [ -1.0, 2.0, -3.0, 2.0, -5.0, 6.0, -7.0, 2.0, -8.0, 2.0 ]; x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); - y = scalar2ndarray( 0.0, { - 'dtype': 'generic', - 'order': 'column-major' - }); + ybuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = new ndarray( 'generic', ybuf, [ 5, 2 ], [ 1, 5 ], 0, 'column-major' ); actual = firstIndexLessThan( x, y, fromIdx, { 'dim': 0 @@ -1356,6 +1339,7 @@ tape( 'the function supports providing a from index (1d ndarray)', function test var fromIdx; var actual; var xbuf; + var ybuf; var x; var y; @@ -1372,7 +1356,8 @@ tape( 'the function supports providing a from index (1d ndarray)', function test x = new ndarray( 'generic', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' ); fromIdx = new ndarray( 'int32', new Int32Array( [ 2, 2 ] ), [ 2 ], [ 1 ], 0, 'row-major' ); - y = new ndarray( 'generic', [ 2.0, -3.0 ], [ 2 ], [ 1 ], 0, 'row-major' ); + ybuf = [ 2.0, -3.0 ]; + y = new ndarray( 'generic', ybuf, [ 2 ], [ 1 ], 0, 'row-major' ); actual = firstIndexLessThan( x, y, fromIdx, { 'dim': 0 }); From 91e38ea8e4b0039c59bcf4a495766cf5ec559d5b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 28 Sep 2026 13:11:20 -0700 Subject: [PATCH 5/5] style: remove line breaks Signed-off-by: Athan --- .../@stdlib/blas/ext/first-index-less-than/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md index 68d910199366..141699d98d02 100644 --- a/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md +++ b/lib/node_modules/@stdlib/blas/ext/first-index-less-than/README.md @@ -125,7 +125,6 @@ By default, the function performs the operation over elements in the last dimens var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); - var y = array( [ [ 0.0, 2.0 ], [ 0.0, 4.0 ] ] ); var out = firstIndexLessThan( x, y, { @@ -140,7 +139,6 @@ By default, the function excludes reduced dimensions from the output [ndarray][@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] ); - var y = array( [ [ 0.0, 2.0 ], [ 0.0, 4.0 ] ] ); var opts = { @@ -159,7 +157,6 @@ var dtype = require( '@stdlib/ndarray/dtype' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, -2.0, 3.0, 4.0 ] ); - var y = array( [ 1.0, 0.0, 3.0, 4.0 ] ); var idx = firstIndexLessThan( x, y, { @@ -180,7 +177,6 @@ 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 = array( [ 1.0, 2.0, 0.0, 4.0 ] ); var z = zeros( [], {