diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/README.md new file mode 100644 index 000000000000..167d35495aed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/README.md @@ -0,0 +1,207 @@ + + +# gindexOfColumn + +> Return the index of the first column in an input matrix which has the same elements as a provided search vector. + +
+ +## Usage + +```javascript +var gindexOfColumn = require( '@stdlib/blas/ext/base/gindex-of-column' ); +``` + +#### gindexOfColumn( order, M, N, A, LDA, x, strideX ) + +Returns the index of the first column in an input matrix which has the same elements as a provided search vector. + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + +var x = [ 2.0, 4.0, 0.0 ]; +var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 ); +// returns 1 +``` + +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 of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **x**: search vector. +- **strideX**: stride length of `x`. + +If the function is unable to find a matching column, the function returns `-1`. + +```javascript +var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + +var x = [ -2.0, -4.0, 0.0 ]; +var out = gindexOfColumn( '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, 2.0, 4.0, 0.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 = gindexOfColumn( 'row-major', 3, 2, A1, 2, x1, 1 ); +// returns 1 +``` + + + +#### gindexOfColumn.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) + + + +Returns the index of the first column 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 ], + [ 0.0, 0.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + +var x = [ 2.0, 4.0, 0.0 ]; +var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); +// returns 1 +``` + +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 of the first dimension of `A`. +- **strideA2**: stride of the second dimension of `A`. +- **offsetA**: starting index for `A`. +- **x**: search vector. +- **strideX**: stride length of `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, 2.0, 4.0, 0.0 ]; +var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1 ); +// returns 1 +``` + +
+ + + +
+ +## Notes + +- When searching for a matching column, 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 gindexOfColumn = require( '@stdlib/blas/ext/base/gindex-of-column' ); + +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, 7.0, 8.0, 9.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var x = [ 2.0, 5.0, 8.0 ]; +console.log( x ); + +var out = gindexOfColumn( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1, 0 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/benchmark/benchmark.js new file mode 100644 index 000000000000..fb267acdaefb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = 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 = gindexOfColumn( 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/gindex-of-column/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..0b79ff3e8be2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = 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 = gindexOfColumn( 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/gindex-of-column/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/repl.txt new file mode 100644 index 000000000000..a5a472ecfee6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/repl.txt @@ -0,0 +1,103 @@ + +{{alias}}( order, M, N, A, LDA, x, strideX ) + Returns the index of the first column 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 column, 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 of 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 + Column index. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + > var x = [ 2.0, 4.0 ]; + > {{alias}}( 'row-major', 2, 2, A, 2, x, 1 ) + 1 + + +{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) + Returns the index of the first column 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 column, 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 of the first dimension of `A`. + + strideA2: integer + Stride of 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 + Column index. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; + > var x = [ 2.0, 4.0 ]; + > {{alias}}.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0 ) + 1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/types/index.d.ts new file mode 100644 index 000000000000..c57e7aef71e9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/types/index.d.ts @@ -0,0 +1,122 @@ +/* +* @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 `gindexOfColumn`. +*/ +interface Routine { + /** + * Returns the index of the first column 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 of 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 column index + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] + * var x = [ 2.0, 4.0, 0.0 ]; + * + * var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 ); + * // returns 1 + */ + ( order: Layout, M: number, N: number, A: InputArray, LDA: number, x: InputArray, strideX: number ): number; + + /** + * Returns the index of the first column 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 of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param x - search vector + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @returns column index + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] + * var x = [ 2.0, 4.0, 0.0 ]; + * + * var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); + * // returns 1 + */ + 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 first column 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 of 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 column index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 2.0, 4.0, 0.0 ]; +* +* var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 1 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 2.0, 4.0, 0.0 ]; +* +* var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 ); +* // returns 1 +*/ +declare var gindexOfColumn: Routine; + + +// EXPORTS // + +export = gindexOfColumn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/docs/types/test.ts new file mode 100644 index 000000000000..b895c1dc2f89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const x = [ 2.0, 4.0 ]; + + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 5, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( true, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( false, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( null, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( void 0, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( [], 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( {}, 2, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( ( 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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 'row-major', '5', 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', true, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', false, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', null, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', void 0, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', [], 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', {}, 2, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 'row-major', 2, '5', A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, true, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, false, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, null, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, void 0, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, [], A, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, {}, A, 2, x, 1 ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 'row-major', 2, 2, 5, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, true, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, false, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, null, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, void 0, 2, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, {}, 2, x, 1 ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 'row-major', 2, 2, A, '5', x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, true, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, false, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, null, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, void 0, x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, [], x, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, {}, x, 1 ); // $ExpectError + gindexOfColumn( '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 ]; + + gindexOfColumn( 'row-major', 2, 2, A, 2, 5, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, true, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, false, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, null, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, void 0, 1 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, {}, 1 ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn( 'row-major', 2, 2, A, 2, x, '5' ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, true ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, false ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, null ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, void 0 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, [] ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x, {} ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn(); // $ExpectError + gindexOfColumn( 'row-major' ); // $ExpectError + gindexOfColumn( 'row-major', 2 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2 ); // $ExpectError + gindexOfColumn( 'row-major', 2, 2, A, 2, x ); // $ExpectError + gindexOfColumn( '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 = [ 2.0, 4.0 ]; + + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( '5', 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( true, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( false, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( null, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( void 0, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( [], 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( {}, 2, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, '5', A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, true, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, false, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, null, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, void 0, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, [], A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, {}, A, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, 5, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, true, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, false, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, null, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, void 0, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, {}, 2, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, A, '5', 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, true, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, false, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, null, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, void 0, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, [], 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, {}, 1, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, A, 2, '5', 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, true, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, false, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, null, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, void 0, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, [], 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, {}, 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, A, 2, 1, '5', x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, true, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, false, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, null, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, void 0, x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, [], x, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, {}, x, 1, 0 ); // $ExpectError + gindexOfColumn.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 ]; + + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, 5, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, true, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, false, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, null, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, void 0, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, {}, 1, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, '5', 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, true, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, false, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, null, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, void 0, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, [], 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, {}, 0 ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, '5' ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, true ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, false ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, null ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, void 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, [] ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, {} ); // $ExpectError + gindexOfColumn.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 = [ 2.0, 4.0 ]; + + gindexOfColumn.ndarray(); // $ExpectError + gindexOfColumn.ndarray( 2 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1 ); // $ExpectError + gindexOfColumn.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/examples/index.js new file mode 100644 index 000000000000..1866eaf64992 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = 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, 7.0, 8.0, 9.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var x = [ 2.0, 5.0, 8.0 ]; +console.log( x ); + +var out = gindexOfColumn( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1, 0 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/accessors.js new file mode 100644 index 000000000000..13ef44a3091c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major' ); +var ones = require( '@stdlib/array/base/ones' ); + + +// MAIN // + +/** +* Returns the index of the first column 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 of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset 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 - index offset for `x` +* @returns {integer} column index +* +* @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, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = gindexOfColumn( 2, 3, arraylike2object( toAccessorArray( A ) ), 3, 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 1 +* +* @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, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = gindexOfColumn( 2, 3, arraylike2object( toAccessorArray( A ) ), 1, 2, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 1 +* +* @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, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 1.0, 2.0 ]; +* +* var out = gindexOfColumn( 2, 3, arraylike2object( toAccessorArray( A ) ), 1, 2, 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, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 0.0, 0.0 ]; +* +* var out = gindexOfColumn( 2, 3, arraylike2object( toAccessorArray( A ) ), 1, 2, 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, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ -3.0, -4.0 ]; +* +* var out = gindexOfColumn( 2, 3, arraylike2object( toAccessorArray( A ) ), 1, 2, 0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns -1 +*/ +function gindexOfColumn( 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 first column matching the search vector... + if ( isColumnMajor( [ strideA1, strideA2 ] ) ) { + S0 = M; + S1 = N; + + // Scan a column-major linear buffer from the first indexed element to the last indexed element, always moving in the same direction when both strides are the same sign, thus ensuring cache optimal traversal... + for ( i1 = 0; i1 < S1; i1++ ) { + ia = offsetA + ( i1*strideA2 ); + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + if ( aget( abuf, ia ) !== xget( xbuf, ix ) ) { + // We found an element which is not in the search vector... + break; + } + ia += strideA1; + ix += strideX; + } + // If we successfully iterated over all rows, then that means we've found a match... + if ( i0 === S0 ) { + return i1; + } + } + // If we've made it here, then no columns match the search vector: + return -1; + } + // Row-major... + S0 = N; + S1 = M; + + // Resolve loop offset (pointer) increments: + da0 = strideA2; + da1 = strideA1 - ( S0*strideA2 ); + + // Create an array for tracking which columns contain matching elements: + matches = ones( N ); + + // Finding the first matching column when a matrix is stored in row-major order requires effectively performing a full linear scan. In order to ensure cache-efficient traversal, scan across each row (otherwise, if we went column-by-column, we'd hop around linear memory, resulting in poor cache behavior)... + ia = offsetA; + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + // Scan across the columns in a row looking for a matching element... + for ( i0 = 0; i0 < S0; i0++ ) { + if ( aget( abuf, ia ) !== xget( xbuf, ix ) ) { + // We found a non-matching element, which means we can exclude this column from the list of column candidates... + matches[ i0 ] = 0; + } + ia += da0; + } + ia += da1; + ix += strideX; + } + // Search for the first matching column... + for ( i0 = 0; i0 < S0; i0++ ) { + if ( matches[ i0 ] === 1 ) { + break; + } + } + return ( i0 === S0 ) ? -1 : i0; +} + + +// EXPORTS // + +module.exports = gindexOfColumn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/base.js new file mode 100644 index 000000000000..97c8e3f47f32 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/base.js @@ -0,0 +1,170 @@ +/** +* @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 isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-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 first column 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). +* +* @private +* @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 of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset for `A` +* @param {Collection} x - search vector +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - index offset for `x` +* @returns {integer} column index +* +* @example +* var A = [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = gindexOfColumn( 2, 3, A, 3, 1, 0, x, 1, 0 ); +* // returns 1 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 3.0, 4.0 ]; +* +* var out = gindexOfColumn( 2, 3, A, 1, 2, 0, x, 1, 0 ); +* // returns 1 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 1.0, 2.0 ]; +* +* var out = gindexOfColumn( 2, 3, A, 1, 2, 0, x, 1, 0 ); +* // returns 0 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ 0.0, 0.0 ]; +* +* var out = gindexOfColumn( 2, 3, A, 1, 2, 0, x, 1, 0 ); +* // returns 2 +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 3.0, 0.0 ], [ 2.0, 4.0, 0.0 ] ] +* var x = [ -3.0, -4.0 ]; +* +* var out = gindexOfColumn( 2, 3, A, 1, 2, 0, x, 1, 0 ); +* // returns -1 +*/ +function gindexOfColumn( 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 first column matching the search vector... + if ( isColumnMajor( [ strideA1, strideA2 ] ) ) { + S0 = M; + S1 = N; + + // Scan a column-major linear buffer from the first indexed element to the last indexed element, always moving in the same direction when both strides are the same sign, thus ensuring cache optimal traversal... + for ( i1 = 0; i1 < S1; i1++ ) { + ia = offsetA + ( i1*strideA2 ); + ix = offsetX; + for ( i0 = 0; i0 < S0; i0++ ) { + if ( A[ ia ] !== x[ ix ] ) { + // We found an element which is not in the search vector... + break; + } + ia += strideA1; + ix += strideX; + } + // If we successfully iterated over all rows, then that means we've found a match... + if ( i0 === S0 ) { + return i1; + } + } + // If we've made it here, then no columns match the search vector: + return -1; + } + // Row-major... + S0 = N; + S1 = M; + + // Resolve loop offset (pointer) increments: + da0 = strideA2; + da1 = strideA1 - ( S0*strideA2 ); + + // Create an array for tracking which columns contain matching elements: + matches = ones( N ); + + // Finding the first matching column when a matrix is stored in row-major order requires effectively performing a full linear scan. In order to ensure cache-efficient traversal, scan across each row (otherwise, if we went column-by-column, we'd hop around linear memory, resulting in poor cache behavior)... + ia = offsetA; + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + // Scan across the columns in a row looking for a matching element... + for ( i0 = 0; i0 < S0; i0++ ) { + if ( A[ ia ] !== x[ ix ] ) { + // We found a non-matching element, which means we can exclude this column from the list of column candidates... + matches[ i0 ] = 0; + } + ia += da0; + } + ia += da1; + ix += strideX; + } + // Search for the first matching column... + for ( i0 = 0; i0 < S0; i0++ ) { + if ( matches[ i0 ] === 1 ) { + break; + } + } + return ( i0 === S0 ) ? -1 : i0; +} + + +// EXPORTS // + +module.exports = gindexOfColumn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/index.js new file mode 100644 index 000000000000..7b51733e3332 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the index of the first column in an input matrix which has the same elements as a provided search vector. +* +* @module @stdlib/blas/ext/base/gindex-of-column +* +* @example +* var gindexOfColumn = require( '@stdlib/blas/ext/base/gindex-of-column' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 2.0, 4.0, 0.0 ]; +* +* var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 1 +*/ + +// 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/gindex-of-column/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/main.js new file mode 100644 index 000000000000..0d51f86097bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the index of the first column 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 of 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 greater than or equal to max(1,N) +* @returns {integer} column index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 2.0, 4.0, 0.0 ]; +* +* var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 ); +* // returns 1 +*/ +function gindexOfColumn( 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 greater than or equal to max(1,%d). Value: `%d`.', s, LDA ) ); + } + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return base( M, N, A, sa1, sa2, 0, x, strideX, stride2offset( M, strideX ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gindexOfColumn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/ndarray.js new file mode 100644 index 000000000000..73b3c5b44bd1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/lib/ndarray.js @@ -0,0 +1,60 @@ +/** +* @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 base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the index of the first column 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 of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset for `A` +* @param {Collection} x - search vector +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - index offset for `x` +* @returns {integer} column index +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* var x = [ 2.0, 4.0, 0.0 ]; +* +* var out = gindexOfColumn( 3, 2, A, 2, 1, 0, x, 1, 0 ); +* // returns 1 +*/ +function gindexOfColumn( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) { // eslint-disable-line max-len + return base( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ); +} + + +// EXPORTS // + +module.exports = gindexOfColumn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/package.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/package.json new file mode 100644 index 000000000000..c65d9f4e9e1e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/gindex-of-column", + "version": "0.0.0", + "description": "Return the index of the first column 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", + "column", + "index", + "search", + "find", + "index-of", + "indexof" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/column_major.json new file mode 100644 index 000000000000..8f1d3cbceed3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 3.0, 4.0, 4.0, 0.0 ], + "strideX": 1, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/column_major_no_match.json new file mode 100644 index 000000000000..ffd69b299114 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 3.0, 4.0, 5.0 ], + "strideX": 1, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/column_major.json new file mode 100644 index 000000000000..44d2889c4217 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/column_major.json @@ -0,0 +1,32 @@ +{ + "order": "column-major", + "A": [ + 1.0, + 9999.0, + 2.0, + 9999.0, + 0.0, + 9999.0, + 3.0, + 9999.0, + 4.0, + 9999.0, + 0.0, + 9999.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 6, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0, 0.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/column_major_no_match.json new file mode 100644 index 000000000000..92a2f628c2a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/row_major.json new file mode 100644 index 000000000000..7297b186102d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/row_major.json @@ -0,0 +1,32 @@ +{ + "order": "row-major", + "A": [ + 1.0, + 9999.0, + 2.0, + 9999.0, + 3.0, + 9999.0, + 4.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": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 9999.0, 4.0, 9999.0, 0.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/large_strides/row_major_no_match.json new file mode 100644 index 000000000000..02cb9617a8e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/column_major.json new file mode 100644 index 000000000000..152988e47052 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/column_major.json @@ -0,0 +1,26 @@ +{ + "order": "column-major", + "A": [ + 3.0, + 4.0, + 0.0, + 1.0, + 2.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": -3, + "offsetA": 3, + "LDA": 3, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 0.0, 9999.0, 4.0, 9999.0, 3.0 ], + "strideX": -2, + "offsetX": 4, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/column_major_no_match.json new file mode 100644 index 000000000000..296bdbe3a26b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 5.0, 9999.0, 4.0, 9999.0, 3.0 ], + "strideX": -2, + "offsetX": 4, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/row_major.json new file mode 100644 index 000000000000..70e009cd0f68 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/row_major.json @@ -0,0 +1,26 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 3.0, + 4.0, + 1.0, + 2.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": 1, + "offsetA": 4, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 0.0, 9999.0, 4.0, 9999.0, 2.0 ], + "strideX": -2, + "offsetX": 4, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/mixed_strides/row_major_no_match.json new file mode 100644 index 000000000000..f00295a2096e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 5.0, 9999.0, 4.0, 9999.0, 3.0 ], + "strideX": -2, + "offsetX": 4, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/column_major.json new file mode 100644 index 000000000000..923304fe25f8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/column_major.json @@ -0,0 +1,26 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 4.0, + 3.0, + 0.0, + 2.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": -1, + "strideA2": -3, + "offsetA": 5, + "LDA": 3, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 3.0, 9999.0, 4.0, 9999.0, 0.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/column_major_no_match.json new file mode 100644 index 000000000000..7d538fb9ba4c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 3.0, 9999.0, 4.0, 9999.0, 5.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/row_major.json new file mode 100644 index 000000000000..c2d92dbc586e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/row_major.json @@ -0,0 +1,26 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 4.0, + 3.0, + 2.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": -1, + "offsetA": 5, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 2.0, 9999.0, 4.0, 9999.0, 0.0 ], + "strideX": 2, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/negative_strides/row_major_no_match.json new file mode 100644 index 000000000000..e86a1e4e55d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 2, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/column_major.json new file mode 100644 index 000000000000..7ebf372db006 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/column_major.json @@ -0,0 +1,27 @@ +{ + "order": "column-major", + "A": [ + 9999.0, + 1.0, + 2.0, + 0.0, + 3.0, + 4.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": 3, + "offsetA": 1, + "LDA": 3, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 3.0, 4.0, 0.0 ], + "strideX": 1, + "offsetX": 1, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/column_major_no_match.json new file mode 100644 index 000000000000..c20037246a89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 1, + "offsetX": 1, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/row_major.json new file mode 100644 index 000000000000..43119617f582 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/row_major.json @@ -0,0 +1,27 @@ +{ + "order": "row-major", + "A": [ + 9999.0, + 1.0, + 2.0, + 3.0, + 4.0, + 0.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 1, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "x": [ 9999.0, 2.0, 4.0, 0.0 ], + "strideX": 1, + "offsetX": 1, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/offsets/row_major_no_match.json new file mode 100644 index 000000000000..039d3a6dc1d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 1, + "offsetX": 1, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/row_major.json new file mode 100644 index 000000000000..6a54b30a1732 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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": [ 2.0, 4.0, 4.0, 0.0 ], + "strideX": 1, + "offsetX": 0, + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/fixtures/row_major_no_match.json new file mode 100644 index 000000000000..ed5a1f18366b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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, 5.0 ], + "strideX": 1, + "offsetX": 0, + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/test.js new file mode 100644 index 000000000000..7fc7dc64a69b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfColumn, '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 gindexOfColumn.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/test.main.js new file mode 100644 index 000000000000..85082a5ce1b4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = 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 gindexOfColumn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gindexOfColumn.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() { + gindexOfColumn( 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() { + gindexOfColumn( 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() { + gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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/gindex-of-column/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/test/test.ndarray.js new file mode 100644 index 000000000000..298245b86ce5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/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 gindexOfColumn = 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 gindexOfColumn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( gindexOfColumn.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 = gindexOfColumn( data.order, 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 = gindexOfColumn( data.order, 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 = gindexOfColumn( data.order, 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 = gindexOfColumn( data.order, 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 first column matching a search vector (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, offsets)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, mixed strides)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, negative strides)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, large strides)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, offsets, accessors)', function test( t ) { + var data; + var out; + + data = OFFSET_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, negative strides, accessors)', function test( t ) { + var data; + var out; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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 first column matching a search vector (row-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + out = gindexOfColumn( 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 first column matching a search vector (column-major, large strides, accessors)', function test( t ) { + var data; + var out; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + out = gindexOfColumn( 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 = gindexOfColumn( 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 = gindexOfColumn( 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(); +});