diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/README.md b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/README.md new file mode 100644 index 000000000000..72954b81d530 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/README.md @@ -0,0 +1,214 @@ + + +# glastIndexOfRow + +> Return the index of the last row in an input matrix which has the same elements as a provided search vector. + +
+ +
+ + + +
+ +## Usage + +```javascript +var glastIndexOfRow = require( '@stdlib/blas/ext/base/glast-index-of-row' ); +``` + +#### glastIndexOfRow( order, M, N, A, LDA, x, strideX ) + +Returns the index of the last row in an input matrix which has the same elements as a provided search vector. + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; + +var x = [ 3.0, 4.0 ]; +var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); +// returns 2 +``` + +The function has the following parameters: + +- **order**: storage layout. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **LDA**: stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **x**: search vector. +- **strideX**: stride length for `x`. + +If the function is unable to find a matching row, the function returns `-1`. + +```javascript +var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; + +var x = [ -3.0, -4.0 ]; +var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); +// returns -1 +``` + +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 A0 = new Float64Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] ); +var x0 = new Float64Array( [ 9999.0, 3.0, 4.0 ] ); + +// Create offset views: +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = glastIndexOfRow( 'row-major', 3, 2, A1, 2, x1, 1 ); +// returns 1 +``` + + + +#### glastIndexOfRow.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) + + + +Returns the index of the last row in an input matrix which has the same elements as a provided search vector using alternative indexing semantics. + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; + +var x = [ 3.0, 4.0 ]; +var out = glastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); +// returns 2 +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **strideA1**: stride length for the first dimension of `A`. +- **strideA2**: stride length for the second dimension of `A`. +- **offsetA**: starting index for `A`. +- **x**: search vector. +- **strideX**: stride length for `x`. +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ] +*/ +var A = [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + +var x = [ 9999.0, 3.0, 4.0 ]; +var out = glastIndexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1 ); +// returns 1 +``` + +
+ + + +
+ +## Notes + +- If `M <= 0` or `N <= 0`, both functions return `-1`. +- When searching for a matching row, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same. +- 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 ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var glastIndexOfRow = require( '@stdlib/blas/ext/base/glast-index-of-row' ); + +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var x = [ 4.0, 5.0, 6.0 ]; +console.log( x ); + +var out = glastIndexOfRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.js new file mode 100644 index 000000000000..abe3fc6e58c8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.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 zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var glastIndexOfRow = require( './../lib' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var A = zeros( N*N, 'generic' ); + var x = zeros( N, 'generic' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ N-1 ] += 1; + z = glastIndexOfRow( order, N, N, A, N, x, 1 ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1d72d569a54e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/benchmark/benchmark.ndarray.js @@ -0,0 +1,124 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var zeros = require( '@stdlib/array/zeros' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var glastIndexOfRow = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var A = zeros( N*N, 'generic' ); + var x = zeros( N, 'generic' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var sa1; + var sa2; + var z; + var i; + + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = N; + } else { // order === 'row-major' + sa1 = N; + sa2 = 1; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ N-1 ] += 1; + z = glastIndexOfRow( N, N, A, sa1, sa2, 0, x, 1, 0 ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/repl.txt new file mode 100644 index 000000000000..6a73a1ecebdf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/repl.txt @@ -0,0 +1,103 @@ + +{{alias}}( order, M, N, A, LDA, x, strideX ) + Returns the index of the last row in an input matrix which has the same + elements as a provided search vector. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If the function is provided an empty matrix or if the function is unable to + find a matching row, the function returns `-1` (i.e., an invalid index). + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Array|TypedArray + Input matrix `A`. + + LDA: integer + Stride length for the first dimension of `A` (a.k.a., leading dimension + of the matrix `A`). + + x: Array|TypedArray + Search vector. + + strideX: integer + Stride length for `x`. + + Returns + ------- + out: integer + Row index. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; + > var x = [ 3.0, 4.0 ]; + > {{alias}}( 'row-major', 3, 2, A, 2, x, 1 ) + 2 + + +{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) + Returns the index of the last row in an input matrix which has the same + elements as a provided search vector using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, offset parameters support indexing semantics based on starting + indices. + + If the method is provided an empty matrix or if the method is unable to find + a matching row, the method returns `-1` (i.e., an invalid index). + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Array|TypedArray + Input matrix `A`. + + strideA1: integer + Stride length for the first dimension of `A`. + + strideA2: integer + Stride length for the second dimension of `A`. + + offsetA: integer + Starting index for `A`. + + x: Array|TypedArray + Search vector. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + out: integer + Row index. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; + > var x = [ 3.0, 4.0 ]; + > {{alias}}.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ) + 2 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/index.d.ts new file mode 100644 index 000000000000..4478d70ff0da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/index.d.ts @@ -0,0 +1,123 @@ +/* +* @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'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `glastIndexOfRow`. +*/ +interface Routine { + /** + * Returns the index of the last row in an input matrix which has the same elements as a provided search vector. + * + * ## Notes + * + * - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). + * + * @param order - storage layout + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param x - search vector + * @param strideX - stride length for `x` + * @returns row index + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] + * var x = [ 3.0, 4.0 ]; + * + * var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); + * // returns 2 + */ + ( order: Layout, M: number, N: number, A: InputArray, LDA: number, x: InputArray, strideX: number ): number; + + /** + * Returns the index of the last row in an input matrix which has the same elements as a provided search vector using alternative indexing semantics. + * + * ## Notes + * + * - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param strideA1 - stride length for the first dimension of `A` + * @param strideA2 - stride length for the second dimension of `A` + * @param offsetA - starting index for `A` + * @param x - search vector + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @returns row index + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] + * var x = [ 3.0, 4.0 ]; + * + * var out = glastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); + * // returns 2 + */ + ndarray( M: number, N: number, A: InputArray, strideA1: number, strideA2: number, offsetA: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the index of the last row in an input matrix which has the same elements as a provided search vector. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). +* +* @param order - storage layout +* @param M - number of rows in `A` +* @param N - number of columns in `A` +* @param A - input matrix +* @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param x - search vector +* @param strideX - stride length for `x` +* @returns row index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 2 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); +* // returns 2 +*/ +declare var glastIndexOfRow: Routine; + + +// EXPORTS // + +export = glastIndexOfRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/test.ts new file mode 100644 index 000000000000..dfa95f307e73 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/docs/types/test.ts @@ -0,0 +1,302 @@ +/* +* @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 glastIndexOfRow = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 5, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( true, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( false, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( null, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( void 0, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( [], 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( {}, 2, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( ( x: number ): number => x, 2, 2, A, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', '5', 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', true, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', false, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', null, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', void 0, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', [], 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', {}, 2, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', ( x: number ): number => x, 2, A, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, '5', A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, true, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, false, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, null, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, void 0, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, [], A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, {}, A, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, ( x: number ): number => x, A, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, 2, 5, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, true, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, false, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, null, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, void 0, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, {}, 2, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, ( x: number ): number => x, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, 2, A, '5', x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, true, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, false, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, null, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, void 0, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, [], x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, {}, x, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, 2, A, 2, 5, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, true, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, false, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, null, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, void 0, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, {}, 1 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, '5' ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, true ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, false ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, null ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, void 0 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, [] ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, {} ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow(); // $ExpectError + glastIndexOfRow( 'row-major' ); // $ExpectError + glastIndexOfRow( 'row-major', 2 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2 ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x ); // $ExpectError + glastIndexOfRow( 'row-major', 2, 2, A, 2, x, 1, 0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( '5', 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( true, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( false, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( null, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( void 0, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( [], 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( {}, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( ( x: number ): number => x, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, '5', A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, true, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, false, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, null, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, void 0, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, [], A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, {}, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, ( x: number ): number => x, A, 2, 1, 0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, 5, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, true, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, false, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, null, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, void 0, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, {}, 2, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, ( x: number ): number => x, 2, 1, 0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, '5', 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, true, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, false, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, null, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, void 0, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, [], 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, {}, 1, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, ( x: number ): number => x, 1, 0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, '5', 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, true, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, false, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, null, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, void 0, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, [], 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, {}, 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, ( x: number ): number => x, 0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, '5', x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, true, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, false, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, null, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, void 0, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, [], x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, {}, x, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, 5, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, true, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, false, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, null, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, void 0, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, {}, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, '5', 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, true, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, false, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, null, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, void 0, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, [], 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, {}, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, '5' ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, true ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, false ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, null ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, void 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, [] ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, {} ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 3.0, 4.0 ]; + + glastIndexOfRow.ndarray(); // $ExpectError + glastIndexOfRow.ndarray( 2 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1 ); // $ExpectError + glastIndexOfRow.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/examples/index.js new file mode 100644 index 000000000000..5f613e0b741f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var glastIndexOfRow = require( './../lib' ); + +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var x = [ 4.0, 5.0, 6.0 ]; +console.log( x ); + +var out = glastIndexOfRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/accessors.js new file mode 100644 index 000000000000..6de912787b47 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/accessors.js @@ -0,0 +1,188 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var ones = require( '@stdlib/array/base/ones' ); + + +// MAIN // + +/** +* Returns the index of the last row in an input matrix which has the same elements as a provided search vector. +* +* ## Notes +* +* - If the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). +* +* @private +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Object} A - input matrix object +* @param {Collection} A.data - input matrix data +* @param {Array} A.accessors - matrix element accessors +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Object} x - search vector object +* @param {Collection} x.data - search vector data +* @param {Array} x.accessors - search vector element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} row index +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, arraylike2object( toAccessorArray( A ) ), 2, 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 2 +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 3.0, 3.0, 2.0, 4.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, arraylike2object( toAccessorArray( A ) ), 1, 3, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 2 +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 1.0, 2.0 ]; +* +* var out = glastIndexOfRow( 3, 2, arraylike2object( toAccessorArray( A ) ), 1, 3, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 0 +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 0.0, 0.0 ]; +* +* var out = glastIndexOfRow( 3, 2, arraylike2object( toAccessorArray( A ) ), 1, 3, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 2 +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ -3.0, -4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, arraylike2object( toAccessorArray( A ) ), 1, 3, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns -1 +*/ +function glastIndexOfRow( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) { // eslint-disable-line max-len + var matches; + var abuf; + var xbuf; + var aget; + var xget; + var da0; + var da1; + var S0; + var S1; + var ia; + var ix; + var i0; + var i1; + + // Cache references to array data: + abuf = A.data; + xbuf = x.data; + + // Cache references to the element accessors: + aget = A.accessors[ 0 ]; + xget = x.accessors[ 0 ]; + + // Search for the last row matching the search vector... + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + S0 = N; + S1 = M; + + // Scan a row-major linear buffer from the last indexed element to the first indexed element, always moving in the same direction when both strides are the same sign, thus ensuring cache optimal traversal... + for ( i1 = S1-1; i1 >= 0; i1-- ) { + ia = offsetA + ( i1*strideA1 ) + ( (S0-1)*strideA2 ); + ix = offsetX + ( (S0-1)*strideX ); + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( aget( abuf, ia ) !== xget( xbuf, ix ) ) { + // We found an element which is not in the search vector... + break; + } + ia -= strideA2; + ix -= strideX; + } + // If we successfully iterated over all columns, then that means we've found a match... + if ( i0 === -1 ) { + return i1; + } + } + // If we've made it here, then no rows match the search vector: + return -1; + } + // Column-major... + S0 = M; + S1 = N; + + // Resolve loop offset (pointer) increments: + da0 = -strideA1; + da1 = ( S0*strideA1 ) - strideA2; + + // Create an array for tracking which rows contain matching elements: + matches = ones( M ); + + // Finding the last matching row when a matrix is stored in column-major order requires effectively performing a full linear scan. In order to ensure cache-efficient traversal, scan up each column (otherwise, if we went row-by-row, we'd hop around linear memory, resulting in poor cache behavior)... + ia = offsetA + ( (S0-1)*strideA1 ) + ( (S1-1)*strideA2 ); + ix = offsetX + ( (S1-1)*strideX ); + for ( i1 = S1-1; i1 >= 0; i1-- ) { + // Scan up the rows in a column looking for a matching element... + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( aget( abuf, ia ) !== xget( xbuf, ix ) ) { + // We found a non-matching element, which means we can exclude this row from the list of row candidates... + matches[ i0 ] = 0; + } + ia += da0; + } + ia += da1; + ix -= strideX; + } + // Search for the last matching row... + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( matches[ i0 ] === 1 ) { + break; + } + } + return i0; +} + + +// EXPORTS // + +module.exports = glastIndexOfRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/index.js new file mode 100644 index 000000000000..41ddb26eb93a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/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 last row in an input matrix which has the same elements as a provided search vector. +* +* @module @stdlib/blas/ext/base/glast-index-of-row +* +* @example +* var glastIndexOfRow = require( '@stdlib/blas/ext/base/glast-index-of-row' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 2 +* +* @example +* var glastIndexOfRow = require( '@stdlib/blas/ext/base/glast-index-of-row' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 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/glast-index-of-row/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/main.js new file mode 100644 index 000000000000..b833de211e18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the index of the last row in an input matrix which has the same elements as a provided search vector. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). +* +* @param {string} order - storage layout +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Collection} A - input matrix +* @param {integer} LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Collection} x - search vector +* @param {integer} strideX - stride length for `x` +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} fifth argument must be a valid stride +* @returns {integer} row index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 2 +*/ +function glastIndexOfRow( order, M, N, A, LDA, x, strideX ) { + var sa1; + var sa2; + var s; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isRowMajor( order ) ) { + s = N; + } else { + s = M; + } + if ( LDA < max( 1, s ) ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be a valid stride. Value: `%d`.', LDA ) ); + } + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return ndarray( M, N, A, sa1, sa2, 0, x, strideX, stride2offset( N, strideX ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = glastIndexOfRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/ndarray.js new file mode 100644 index 000000000000..7ebf12af1ea6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/lib/ndarray.js @@ -0,0 +1,169 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var ones = require( '@stdlib/array/base/ones' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the index of the last row in an input matrix which has the same elements as a provided search vector using alternative indexing semantics. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index). +* +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Collection} A - input matrix +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Collection} x - search vector +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} row index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, A, 2, 1, 0, x, 1, 0 ); +* // returns 2 +* +* @example +* var A = [ 1.0, 3.0, 3.0, 2.0, 4.0, 4.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 3.0, 4.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, A, 1, 3, 0, x, 1, 0 ); +* // returns 2 +* +* @example +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 1.0, 2.0 ]; +* +* var out = glastIndexOfRow( 3, 2, A, 1, 3, 0, x, 1, 0 ); +* // returns 0 +* +* @example +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 0.0, 0.0 ]; +* +* var out = glastIndexOfRow( 3, 2, A, 1, 3, 0, x, 1, 0 ); +* // returns 2 +* +* @example +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ -3.0, -4.0 ]; +* +* var out = glastIndexOfRow( 3, 2, A, 1, 3, 0, x, 1, 0 ); +* // returns -1 +*/ +function glastIndexOfRow( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) { // eslint-disable-line max-len + var matches; + var da0; + var da1; + var S0; + var S1; + var ia; + var ix; + var i0; + var i1; + var oa; + var ox; + + // Check whether the matrix is an empty matrix... + if ( M <= 0 || N <= 0 ) { + return -1; + } + oa = arraylike2object( A ); + ox = arraylike2object( x ); + if ( oa.accessorProtocol || ox.accessorProtocol ) { + return accessors( M, N, oa, strideA1, strideA2, offsetA, ox, strideX, offsetX ); // eslint-disable-line max-len + } + // Search for the last row matching the search vector... + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + S0 = N; + S1 = M; + + // Scan a row-major linear buffer from the last indexed element to the first indexed element, always moving in the same direction when both strides are the same sign, thus ensuring cache optimal traversal... + for ( i1 = S1-1; i1 >= 0; i1-- ) { + ia = offsetA + ( i1*strideA1 ) + ( (S0-1)*strideA2 ); + ix = offsetX + ( (S0-1)*strideX ); + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( A[ ia ] !== x[ ix ] ) { + // We found an element which is not in the search vector... + break; + } + ia -= strideA2; + ix -= strideX; + } + // If we successfully iterated over all columns, then that means we've found a match... + if ( i0 === -1 ) { + return i1; + } + } + // If we've made it here, then no rows match the search vector: + return -1; + } + // Column-major... + S0 = M; + S1 = N; + + // Resolve loop offset (pointer) increments: + da0 = -strideA1; + da1 = ( S0*strideA1 ) - strideA2; + + // Create an array for tracking which rows contain matching elements: + matches = ones( M ); + + // Finding the last matching row when a matrix is stored in column-major order requires effectively performing a full linear scan. In order to ensure cache-efficient traversal, scan up each column (otherwise, if we went row-by-row, we'd hop around linear memory, resulting in poor cache behavior)... + ia = offsetA + ( (S0-1)*strideA1 ) + ( (S1-1)*strideA2 ); + ix = offsetX + ( (S1-1)*strideX ); + for ( i1 = S1-1; i1 >= 0; i1-- ) { + // Scan up the rows in a column looking for a matching element... + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( A[ ia ] !== x[ ix ] ) { + // We found a non-matching element, which means we can exclude this row from the list of row candidates... + matches[ i0 ] = 0; + } + ia += da0; + } + ia += da1; + ix -= strideX; + } + // Search for the last matching row... + for ( i0 = S0-1; i0 >= 0; i0-- ) { + if ( matches[ i0 ] === 1 ) { + break; + } + } + return i0; +} + + +// EXPORTS // + +module.exports = glastIndexOfRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/package.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/package.json new file mode 100644 index 000000000000..690aa485b6d7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/glast-index-of-row", + "version": "0.0.0", + "description": "Return the index of the last row in an input matrix which has the same elements as a provided search vector.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "blas", + "matrix", + "strided", + "array", + "ndarray", + "vector", + "row", + "index", + "search", + "find", + "last-index-of", + "lastindexof" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major.json new file mode 100644 index 000000000000..1b3f885bb1bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "A": [ 1.0, 2.0, 2.0, 0.0, 3.0, 4.0, 4.0, 0.0 ], + "M": 4, + "N": 2, + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 4.0 ], + "strideX": 1, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major_no_match.json new file mode 100644 index 000000000000..8c3262a27da1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/column_major_no_match.json @@ -0,0 +1,19 @@ +{ + "order": "column-major", + "A": [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": 3, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 4.0 ], + "strideX": 1, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major.json new file mode 100644 index 000000000000..d5c9f674b041 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major.json @@ -0,0 +1,37 @@ +{ + "order": "column-major", + "A": [ + 1.0, + 9999.0, + 2.0, + 9999.0, + 2.0, + 9999.0, + 0.0, + 9999.0, + 3.0, + 9999.0, + 4.0, + 9999.0, + 4.0, + 9999.0, + 0.0, + 9999.0 + ], + "M": 4, + "N": 2, + "strideA1": 2, + "strideA2": 8, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major_no_match.json new file mode 100644 index 000000000000..29de47f49af6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/column_major_no_match.json @@ -0,0 +1,32 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 6, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major.json new file mode 100644 index 000000000000..334a2220a3a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major.json @@ -0,0 +1,37 @@ +{ + "order": "row-major", + "A": [ + 1.0, + 9999.0, + 2.0, + 9999.0, + 3.0, + 9999.0, + 4.0, + 9999.0, + 3.0, + 9999.0, + 4.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0 + ], + "M": 4, + "N": 2, + "strideA1": 4, + "strideA2": 2, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major_no_match.json new file mode 100644 index 000000000000..5337eee8283c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/large-strides/row_major_no_match.json @@ -0,0 +1,32 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0 + ], + "M": 3, + "N": 2, + "strideA1": 4, + "strideA2": 2, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major.json new file mode 100644 index 000000000000..c61c4091d06f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major.json @@ -0,0 +1,29 @@ +{ + "order": "column-major", + "A": [ + 3.0, + 4.0, + 4.0, + 0.0, + 1.0, + 2.0, + 2.0, + 0.0 + ], + "M": 4, + "N": 2, + "strideA1": 1, + "strideA2": -4, + "offsetA": 4, + "LDA": 4, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 4.0, 9999.0, 2.0, 9999.0 ], + "strideX": -2, + "offsetX": 2, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major_no_match.json new file mode 100644 index 000000000000..efd5cb66e8c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/column_major_no_match.json @@ -0,0 +1,26 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": -3, + "offsetA": 3, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 4.0, 9999.0, 3.0, 9999.0 ], + "strideX": -2, + "offsetX": 2, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major.json new file mode 100644 index 000000000000..a82acc546e47 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major.json @@ -0,0 +1,29 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 3.0, + 4.0, + 3.0, + 4.0, + 1.0, + 2.0 + ], + "M": 4, + "N": 2, + "strideA1": -2, + "strideA2": 1, + "offsetA": 6, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 4.0, 9999.0, 3.0, 9999.0 ], + "strideX": -2, + "offsetX": 3, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major_no_match.json new file mode 100644 index 000000000000..0270879b82ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/mixed-strides/row_major_no_match.json @@ -0,0 +1,26 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": 1, + "offsetA": 4, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 4.0, 9999.0, 3.0, 9999.0 ], + "strideX": -2, + "offsetX": 3, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major.json new file mode 100644 index 000000000000..5bb82a1c0e1c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major.json @@ -0,0 +1,29 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 4.0, + 4.0, + 3.0, + 0.0, + 2.0, + 2.0, + 1.0 + ], + "M": 4, + "N": 2, + "strideA1": -1, + "strideA2": -4, + "offsetA": 7, + "LDA": 4, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major_no_match.json new file mode 100644 index 000000000000..5fc0e96d96a2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/column_major_no_match.json @@ -0,0 +1,26 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": -1, + "strideA2": -3, + "offsetA": 5, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major.json new file mode 100644 index 000000000000..287989ddcaa5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major.json @@ -0,0 +1,29 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 4.0, + 3.0, + 4.0, + 3.0, + 2.0, + 1.0 + ], + "M": 4, + "N": 2, + "strideA1": -2, + "strideA2": -1, + "offsetA": 7, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major_no_match.json new file mode 100644 index 000000000000..4e430bab2070 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/negative-strides/row_major_no_match.json @@ -0,0 +1,26 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": -1, + "offsetA": 5, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major.json new file mode 100644 index 000000000000..284d9786905b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major.json @@ -0,0 +1,30 @@ +{ + "order": "column-major", + "A": [ + 9999.0, + 1.0, + 2.0, + 2.0, + 0.0, + 3.0, + 4.0, + 4.0, + 0.0 + ], + "M": 4, + "N": 2, + "strideA1": 1, + "strideA2": 4, + "offsetA": 1, + "LDA": 4, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 2.0, 4.0 ], + "strideX": 1, + "offsetX": 1, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major_no_match.json new file mode 100644 index 000000000000..391801cfb10e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/column_major_no_match.json @@ -0,0 +1,27 @@ +{ + "order": "column-major", + "A": [ + 9999.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": 3, + "offsetA": 1, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 3.0, 4.0 ], + "strideX": 1, + "offsetX": 1, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major.json new file mode 100644 index 000000000000..d81fab2629f9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major.json @@ -0,0 +1,30 @@ +{ + "order": "row-major", + "A": [ + 9999.0, + 1.0, + 2.0, + 3.0, + 4.0, + 3.0, + 4.0, + 0.0, + 0.0 + ], + "M": 4, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 1, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 3.0, 4.0 ], + "strideX": 1, + "offsetX": 1, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major_no_match.json new file mode 100644 index 000000000000..c7ef9df5d92a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/offsets/row_major_no_match.json @@ -0,0 +1,27 @@ +{ + "order": "row-major", + "A": [ + 9999.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 1, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 3.0, 4.0 ], + "strideX": 1, + "offsetX": 1, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major.json new file mode 100644 index 000000000000..077da11e148d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "A": [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 0.0, 0.0 ], + "M": 4, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 4.0 ], + "strideX": 1, + "offsetX": 0, + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major_no_match.json new file mode 100644 index 000000000000..d556a7f35cd4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/fixtures/row_major_no_match.json @@ -0,0 +1,19 @@ +{ + "order": "row-major", + "A": [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 4.0 ], + "strideX": 1, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.js new file mode 100644 index 000000000000..13620484d023 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/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 glastIndexOfRow = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfRow, '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 glastIndexOfRow.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.main.js new file mode 100644 index 000000000000..1c3d7f54ee20 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.main.js @@ -0,0 +1,242 @@ +/** +* @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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var glastIndexOfRow = require( './../lib' ); + + +// FIXTURES // + +var ROW_MAJOR_DATA = require( './fixtures/row_major.json' ); +var ROW_MAJOR_NO_MATCH = require( './fixtures/row_major_no_match.json' ); +var COLUMN_MAJOR_DATA = require( './fixtures/column_major.json' ); +var COLUMN_MAJOR_NO_MATCH = require( './fixtures/column_major_no_match.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfRow, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( glastIndexOfRow.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a valid order', function test( t ) { + var values; + var data; + var i; + + data = ROW_MAJOR_DATA; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -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() { + glastIndexOfRow( value, data.M, data.N, data.A, data.LDA, data.x, data.strideX ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument which is not a valid `LDA` value (row-major)', function test( t ) { + var values; + var data; + var i; + + data = ROW_MAJOR_DATA; + + values = [ + 0, + 1 + ]; + + 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() { + glastIndexOfRow( data.order, data.M, data.N, data.A, value, data.x, data.strideX ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument which is not a valid `LDA` value (column-major)', function test( t ) { + var values; + var data; + var i; + + data = COLUMN_MAJOR_DATA; + + values = [ + 0, + 1 + ]; + + 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() { + glastIndexOfRow( data.order, data.M, data.N, data.A, value, data.x, data.strideX ); + }; + } +}); + +tape( 'the function returns an invalid index when M is less than or equal to zero', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.order, 0, data.N, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index when N is less than or equal to zero', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.order, data.M, 0, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.order, data.M, data.N, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.order, data.M, data.N, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.order, data.M, data.N, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.order, data.M, data.N, data.A, data.LDA, data.x, data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA, toAccessorArray( data.x ), data.strideX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA, toAccessorArray( data.x ), data.strideX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA, toAccessorArray( data.x ), data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA, toAccessorArray( data.x ), data.strideX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.ndarray.js new file mode 100644 index 000000000000..6143c7af6e2d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-row/test/test.ndarray.js @@ -0,0 +1,549 @@ +/** +* @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 max-len, id-length */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var glastIndexOfRow = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var ROW_MAJOR_DATA = require( './fixtures/row_major.json' ); +var ROW_MAJOR_NO_MATCH = require( './fixtures/row_major_no_match.json' ); +var COLUMN_MAJOR_DATA = require( './fixtures/column_major.json' ); +var COLUMN_MAJOR_NO_MATCH = require( './fixtures/column_major_no_match.json' ); +var OFFSET_ROW_MAJOR_DATA = require( './fixtures/offsets/row_major.json' ); +var OFFSET_ROW_MAJOR_NO_MATCH = require( './fixtures/offsets/row_major_no_match.json' ); +var OFFSET_COLUMN_MAJOR_DATA = require( './fixtures/offsets/column_major.json' ); +var OFFSET_COLUMN_MAJOR_NO_MATCH = require( './fixtures/offsets/column_major_no_match.json' ); +var NEGATIVE_STRIDES_ROW_MAJOR_DATA = require( './fixtures/negative-strides/row_major.json' ); +var NEGATIVE_STRIDES_ROW_MAJOR_NO_MATCH = require( './fixtures/negative-strides/row_major_no_match.json' ); +var NEGATIVE_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/negative-strides/column_major.json' ); +var NEGATIVE_STRIDES_COLUMN_MAJOR_NO_MATCH = require( './fixtures/negative-strides/column_major_no_match.json' ); +var MIXED_STRIDES_ROW_MAJOR_DATA = require( './fixtures/mixed-strides/row_major.json' ); +var MIXED_STRIDES_ROW_MAJOR_NO_MATCH = require( './fixtures/mixed-strides/row_major_no_match.json' ); +var MIXED_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/mixed-strides/column_major.json' ); +var MIXED_STRIDES_COLUMN_MAJOR_NO_MATCH = require( './fixtures/mixed-strides/column_major_no_match.json' ); +var LARGE_STRIDES_ROW_MAJOR_DATA = require( './fixtures/large-strides/row_major.json' ); +var LARGE_STRIDES_ROW_MAJOR_NO_MATCH = require( './fixtures/large-strides/row_major_no_match.json' ); +var LARGE_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/large-strides/column_major.json' ); +var LARGE_STRIDES_COLUMN_MAJOR_NO_MATCH = require( './fixtures/large-strides/column_major_no_match.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfRow, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( glastIndexOfRow.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index when M is less than or equal to zero (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( 0, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index when N is less than or equal to zero (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, 0, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index when M is less than or equal to zero (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( 0, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index when N is less than or equal to zero (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, 0, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA, data.x, data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (row-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row matching a search vector (column-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (row-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a search vector (column-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfRow( data.M, data.N, toAccessorArray( data.A ), data.strideA1, data.strideA2, data.offsetA, toAccessorArray( data.x ), data.strideX, data.offsetX ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +});