diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/README.md b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/README.md new file mode 100644 index 000000000000..8f2205dc5fde --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/README.md @@ -0,0 +1,187 @@ + + +# gfirstIndexNotEqual + +> Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gfirstIndexNotEqual = require( '@stdlib/blas/ext/base/gfirst-index-not-equal' ); +``` + +#### gfirstIndexNotEqual( N, x, strideX, y, strideY ) + +Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. + +```javascript +var x = [ 0, 0, 1, 0 ]; +var y = [ 0, 0, 0, 0 ]; + +var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +// returns 2 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. + +If unable to find an element in `x` which is not equal to the corresponding element in `y`, the function returns `-1`. + +```javascript +var x = [ 0, 0, 0, 0 ]; +var y = [ 0, 0, 0, 0 ]; + +var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +// returns -1 +``` + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compare every other element in `x` to every other element in `y`: + +```javascript +var x = [ 0, 0, 1, 0, 0, 0 ]; +var y = [ 0, 0, 1, 0, 9, 0 ]; + +var idx = gfirstIndexNotEqual( 3, x, 2, y, 2 ); +// returns 2 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 0, 0, 0, 1, 0, 0 ] ); +var y0 = new Float64Array( [ 0, 0, 0, 0, 0, 0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var idx = gfirstIndexNotEqual( x1.length, x1, 1, y1, 1 ); +// returns 2 +``` + +#### gfirstIndexNotEqual.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array using alternative indexing semantics. + +```javascript +var x = [ 0, 0, 1, 0 ]; +var y = [ 0, 0, 0, 0 ]; + +var idx = gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// returns 2 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to compare the last three elements of `x` to the last three elements of `y`: + +```javascript +var x = [ 0, 0, 0, 1 ]; +var y = [ 1, 0, 0, 0 ]; + +var idx = gfirstIndexNotEqual.ndarray( 3, x, 1, x.length-3, y, 1, y.length-3 ); +// returns 2 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `-1`. +- Both functions determine whether corresponding elements are equal using strict equality (i.e., the `===` operator). As a consequence, corresponding `NaN` elements are considered unequal (as `NaN !== NaN` always evaluates to `true`), while `-0` and `+0` are considered equal. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gfirstIndexNotEqual = require( '@stdlib/blas/ext/base/gfirst-index-not-equal' ); + +var x = discreteUniform( 10, -5, 5, { + 'dtype': 'generic' +}); +console.log( x ); + +var y = discreteUniform( 10, -5, 5, { + 'dtype': 'generic' +}); +console.log( y ); + +var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.js new file mode 100644 index 000000000000..e12dde8c4f68 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.js @@ -0,0 +1,98 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfirstIndexNotEqual = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + var y = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6bcddbd9e06e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/benchmark/benchmark.ndarray.js @@ -0,0 +1,98 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfirstIndexNotEqual = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + var y = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/repl.txt new file mode 100644 index 000000000000..9128454f1d04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/repl.txt @@ -0,0 +1,112 @@ + +{{alias}}( N, x, strideX, y, strideY ) + Returns the index of the first element in a strided array which is not + equal to the corresponding element in another strided array. + + The `N` and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use + typed array views. + + If `N <= 0` or unable to find an element in `x` which is not equal to the + corresponding element in `y`, the function returns `-1`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + // Standard usage: + > var x = [ 0, 0, 1, 0 ]; + > var y = [ 0, 0, 0, 0 ]; + > var idx = {{alias}}( x.length, x, 1, y, 1 ) + 2 + + // Using `N` and stride parameters: + > var x = [ 2, 4, 6, 8, 10 ]; + > var y = [ 2, 3, 4, 5, 6 ]; + > var idx = {{alias}}( 3, x, 2, y, 1 ) + 1 + + // View offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0, 0, 1, 0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y = [ 0, 0, 0 ]; + > var idx = {{alias}}( x1.length, x1, 1, y, 1 ) + 1 + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Returns the index of the first element in a strided array which is not + equal to the corresponding element in another strided array using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + // Standard usage: + > var x = [ 0, 0, 1, 0 ]; + > var y = [ 0, 0, 0, 0 ]; + > var idx = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + 2 + + // Advanced indexing: + > var x = [ 2, 4, 6, 8, 10 ]; + > var y = [ 2, 3, 4, 5, 6 ]; + > var idx = {{alias}}.ndarray( 3, x, 2, 0, y, 1, 0 ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/index.d.ts new file mode 100644 index 000000000000..d2912c974a27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gfirstIndexNotEqual`. +*/ +interface Routine { + /** + * Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. + * + * ## Notes + * + * - If unable to find an element in `x` which is not equal to the corresponding element in `y`, the function returns `-1`. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - stride length for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @returns index + * + * @example + * var x = [ 0, 0, 1, 0 ]; + * var y = [ 0, 0, 0, 0 ]; + * + * var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + * // returns 2 + */ + ( N: number, x: InputArray, strideX: number, y: InputArray, strideY: number ): number; + + /** + * Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array using alternative indexing semantics. + * + * ## Notes + * + * - If unable to find an element in `x` which is not equal to the corresponding element in `y`, the function returns `-1`. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @returns index + * + * @example + * var x = [ 0, 0, 1, 0 ]; + * var y = [ 0, 0, 0, 0 ]; + * + * var idx = gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // returns 2 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number ): number; +} + +/** +* Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. +* +* ## Notes +* +* - If unable to find an element in `x` which is not equal to the corresponding element in `y`, the function returns `-1`. +* +* @param N - number of indexed elements +* @param x - first input array +* @param strideX - stride length for `x` +* @param y - second input array +* @param strideY - stride length for `y` +* @returns index +* +* @example +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +* // returns 2 +* +* @example +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 2 +*/ +declare var gfirstIndexNotEqual: Routine; + + +// EXPORTS // + +export = gfirstIndexNotEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/test.ts new file mode 100644 index 000000000000..16ab0fbf3ed9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/docs/types/test.ts @@ -0,0 +1,215 @@ +/* +* @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. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import gfirstIndexNotEqual = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual( x.length, x, 1, y, 1 ); // $ExpectType number + gfirstIndexNotEqual( x.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual( '1', x, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( true, x, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( false, x, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( null, x, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( {}, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual( x.length, 5, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, true, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, false, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, null, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, undefined, 1, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, {}, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual( x.length, x, '1', y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, true, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, false, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, null, y, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, {}, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const x = [ 0, 0, 1, 0 ]; + + gfirstIndexNotEqual( x.length, x, 1, 5, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, true, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, false, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, null, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, undefined, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual( x.length, x, 1, y, '1' ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y, true ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y, false ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y, null ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual(); // $ExpectError + gfirstIndexNotEqual( x.length ); // $ExpectError + gfirstIndexNotEqual( x.length, x ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1 ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y ); // $ExpectError + gfirstIndexNotEqual( x.length, x, 1, y, 1, {} ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType number + gfirstIndexNotEqual.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( '1', x, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, 5, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, '1', 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, 1, '1', y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... +{ + const x = [ 0, 0, 1, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, 5, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, '1', 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, '1' ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = [ 0, 0, 1, 0 ]; + const y = [ 0, 0, 0, 0 ]; + + gfirstIndexNotEqual.ndarray(); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/examples/index.js new file mode 100644 index 000000000000..0126c17a60b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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/array/discrete-uniform' ); +var gfirstIndexNotEqual = require( './../lib' ); + +var x = discreteUniform( 10, -5, 5, { + 'dtype': 'generic' +}); +console.log( x ); + +var y = discreteUniform( 10, -5, 5, { + 'dtype': 'generic' +}); +console.log( y ); + +var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/accessors.js new file mode 100644 index 000000000000..bdecb9046ac9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/accessors.js @@ -0,0 +1,79 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - first input array object +* @param {Collection} x.data - first input array data +* @param {Array} x.accessors - first array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} y - second input array object +* @param {Collection} y.data - second input array data +* @param {Array} y.accessors - second array element accessors +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {integer} index +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0 ); +* // returns 2 +*/ +function gfirstIndexNotEqual( N, x, strideX, offsetX, y, strideY, offsetY ) { + var xbuf; + var ybuf; + var xget; + var yget; + var ix; + var iy; + var i; + + xbuf = x.data; + ybuf = y.data; + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + if ( xget( xbuf, ix ) !== yget( ybuf, iy ) ) { + return i; + } + ix += strideX; + iy += strideY; + } + return -1; +} + + +// EXPORTS // + +module.exports = gfirstIndexNotEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/index.js new file mode 100644 index 000000000000..566db2a17318 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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 a strided array which is not equal to the corresponding element in another strided array. +* +* @module @stdlib/blas/ext/base/gfirst-index-not-equal +* +* @example +* var gfirstIndexNotEqual = require( '@stdlib/blas/ext/base/gfirst-index-not-equal' ); +* +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +* // returns 2 +* +* @example +* var gfirstIndexNotEqual = require( '@stdlib/blas/ext/base/gfirst-index-not-equal' ); +* +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 2 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/main.js new file mode 100644 index 000000000000..4e4574936111 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/main.js @@ -0,0 +1,53 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @returns {integer} index +* +* @example +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); +* // returns 2 +*/ +function gfirstIndexNotEqual( N, x, strideX, y, strideY ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gfirstIndexNotEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/ndarray.js new file mode 100644 index 000000000000..e8c244bbc23c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/lib/ndarray.js @@ -0,0 +1,78 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the index of the first element in a strided array which is not equal to the corresponding element in another strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {integer} index +* +* @example +* var x = [ 0, 0, 1, 0 ]; +* var y = [ 0, 0, 0, 0 ]; +* +* var idx = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); +* // returns 2 +*/ +function gfirstIndexNotEqual( N, x, strideX, offsetX, y, strideY, offsetY ) { + var ix; + var iy; + var ox; + var oy; + var i; + + if ( N <= 0 ) { + return -1; + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + if ( ox.accessorProtocol || oy.accessorProtocol ) { + return accessors( N, ox, strideX, offsetX, oy, strideY, offsetY ); + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + if ( x[ ix ] !== y[ iy ] ) { + return i; + } + ix += strideX; + iy += strideY; + } + return -1; +} + + +// EXPORTS // + +module.exports = gfirstIndexNotEqual; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/package.json b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/package.json new file mode 100644 index 000000000000..60594a62cec3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/ext/base/gfirst-index-not-equal", + "version": "0.0.0", + "description": "Return the index of the first element in a strided array which is not equal to the corresponding element in another strided array.", + "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", + "search", + "index", + "first", + "compare", + "comparison", + "equal", + "equality", + "not equal", + "unequal", + "mismatch", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.js new file mode 100644 index 000000000000..d107b9dcd33d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gfirstIndexNotEqual = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfirstIndexNotEqual, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gfirstIndexNotEqual.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.main.js new file mode 100644 index 000000000000..93ca9efcbd8d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.main.js @@ -0,0 +1,339 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gfirstIndexNotEqual = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfirstIndexNotEqual, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gfirstIndexNotEqual.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in `x` which is not equal to the corresponding element in `y`', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + y = [ 1.0, 1.0, 2.0, 5.0, 3.0, 3.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = [ 9.0, 1.0, 2.0 ]; + y = [ 1.0, 1.0, 2.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in `x` which is not equal to the corresponding element in `y` (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + y = toAccessorArray( [ 1.0, 1.0, 2.0, 5.0, 3.0, 3.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = toAccessorArray( [ 9.0, 1.0, 2.0 ] ); + y = toAccessorArray( [ 1.0, 1.0, 2.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in `x` is equal to the corresponding element in `y`', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 1.0, 2.0, 3.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in `x` is equal to the corresponding element in `y` (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + y = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter less than or equal to zero', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + actual = gfirstIndexNotEqual( 0, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfirstIndexNotEqual( -1, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + y = toAccessorArray( [ 4.0, 5.0, 6.0 ] ); + + actual = gfirstIndexNotEqual( 0, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfirstIndexNotEqual( -1, x, 1, y, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats corresponding `NaN` elements as unequal', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, [ NaN ], 1, [ NaN ], 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats corresponding `NaN` elements as unequal (accessors)', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, toAccessorArray( [ NaN ] ), 1, toAccessorArray( [ NaN ] ), 1 ); // eslint-disable-line max-len + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, [ -0.0 ], 1, [ 0.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, toAccessorArray( [ -0.0 ] ), 1, toAccessorArray( [ 0.0 ] ), 1 ); // eslint-disable-line max-len + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 2, y, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 1, y, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 1, toAccessorArray( y ), 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var actual; + var x; + var y; + + x = [ 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 ]; + y = [ 5.0, 4.0, 3.0, 9.0, 1.0, 0.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, -1, y, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 ]; + y = [ 5.0, 4.0, 3.0, 9.0, 1.0, 0.0 ]; + + actual = gfirstIndexNotEqual( x.length, toAccessorArray( x ), -1, toAccessorArray( y ), -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 9.0, + 9.0 + ]; + + actual = gfirstIndexNotEqual( 3, x, 2, y, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var actual; + var x0; + var y0; + var x1; + var y1; + + x0 = new Float64Array( [ 9.0, 0.0, 1.0, 0.0 ] ); + y0 = new Float64Array( [ 9.0, 9.0, 0.0, 0.0 ] ); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); + + actual = gfirstIndexNotEqual( 3, x1, 1, y1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.ndarray.js new file mode 100644 index 000000000000..d93e337a660b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfirst-index-not-equal/test/test.ndarray.js @@ -0,0 +1,437 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gfirstIndexNotEqual = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfirstIndexNotEqual, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gfirstIndexNotEqual.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in `x` which is not equal to the corresponding element in `y`', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + y = [ 1.0, 1.0, 2.0, 5.0, 3.0, 3.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = [ 9.0, 1.0, 2.0 ]; + y = [ 1.0, 1.0, 2.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in `x` which is not equal to the corresponding element in `y` (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + y = toAccessorArray( [ 1.0, 1.0, 2.0, 5.0, 3.0, 3.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = toAccessorArray( [ 9.0, 1.0, 2.0 ] ); + y = toAccessorArray( [ 1.0, 1.0, 2.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in `x` is equal to the corresponding element in `y`', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 1.0, 2.0, 3.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in `x` is equal to the corresponding element in `y` (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + y = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + + actual = gfirstIndexNotEqual( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter less than or equal to zero', function test( t ) { + var actual; + var x; + var y; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + actual = gfirstIndexNotEqual( 0, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfirstIndexNotEqual( -1, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + y = toAccessorArray( [ 4.0, 5.0, 6.0 ] ); + + actual = gfirstIndexNotEqual( 0, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gfirstIndexNotEqual( -1, x, 1, 0, y, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats corresponding `NaN` elements as unequal', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, [ NaN ], 1, 0, [ NaN ], 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats corresponding `NaN` elements as unequal (accessors)', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, toAccessorArray( [ NaN ] ), 1, 0, toAccessorArray( [ NaN ] ), 1, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, [ -0.0 ], 1, 0, [ 0.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gfirstIndexNotEqual( 1, toAccessorArray( [ -0.0 ] ), 1, 0, toAccessorArray( [ 0.0 ] ), 1, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 2, 0, y, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var actual; + var x; + var y; + + x = [ + 9.0, + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 2, 1, y, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ + 9.0, + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 1, 0, y, 2, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 9.0, + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, x, 1, 0, y, 2, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` offset (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ 0.0, 0.0, 1.0 ]; + y = [ + 9.0, + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 0.0 // 2 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var actual; + var x; + var y; + + x = [ 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 ]; + y = [ 5.0, 4.0, 3.0, 9.0, 1.0, 0.0 ]; + + actual = gfirstIndexNotEqual( x.length, x, -1, x.length-1, y, -1, y.length-1 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 ]; + y = [ 5.0, 4.0, 3.0, 9.0, 1.0, 0.0 ]; + + actual = gfirstIndexNotEqual( x.length, toAccessorArray( x ), -1, x.length-1, toAccessorArray( y ), -1, y.length-1 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 9.0, + 9.0 + ]; + + actual = gfirstIndexNotEqual( 3, x, 2, 0, y, -1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var actual; + var x; + var y; + + x = [ + 0.0, // 0 + 9.0, + 0.0, // 1 + 9.0, + 1.0 // 2 + ]; + y = [ + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 9.0, + 9.0 + ]; + + actual = gfirstIndexNotEqual( 3, toAccessorArray( x ), 2, 0, toAccessorArray( y ), -1, 2 ); // eslint-disable-line max-len + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +});