From 2eee69306d7caac4bcf6c6d596b877c61e82ede0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 3 Sep 2026 21:31:57 +0500 Subject: [PATCH] feat: add blas/ext/base/glast-index-of-truthy-row --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../base/glast-index-of-truthy-row/README.md | 198 ++++++++ .../benchmark/benchmark.js | 111 +++++ .../benchmark/benchmark.ndarray.js | 122 +++++ .../glast-index-of-truthy-row/docs/repl.txt | 87 ++++ .../docs/types/index.d.ts | 112 +++++ .../docs/types/test.ts | 211 +++++++++ .../examples/index.js | 33 ++ .../glast-index-of-truthy-row/lib/index.js | 57 +++ .../glast-index-of-truthy-row/lib/main.js | 91 ++++ .../glast-index-of-truthy-row/lib/ndarray.js | 84 ++++ .../glast-index-of-truthy-row/package.json | 65 +++ .../test/fixtures/column_major.json | 17 + .../fixtures/column_major_early_return.json | 17 + .../test/fixtures/column_major_no_match.json | 16 + .../fixtures/large-strides/column_major.json | 29 ++ .../large-strides/column_major_no_match.json | 29 ++ .../fixtures/large-strides/row_major.json | 29 ++ .../large-strides/row_major_no_match.json | 29 ++ .../fixtures/mixed-strides/column_major.json | 23 + .../mixed-strides/column_major_no_match.json | 23 + .../fixtures/mixed-strides/row_major.json | 23 + .../mixed-strides/row_major_no_match.json | 23 + .../negative-strides/column_major.json | 23 + .../column_major_no_match.json | 23 + .../fixtures/negative-strides/row_major.json | 23 + .../negative-strides/row_major_no_match.json | 23 + .../test/fixtures/offsets/column_major.json | 24 + .../offsets/column_major_no_match.json | 24 + .../test/fixtures/offsets/row_major.json | 24 + .../fixtures/offsets/row_major_no_match.json | 24 + .../test/fixtures/row_major.json | 17 + .../test/fixtures/row_major_no_match.json | 16 + .../glast-index-of-truthy-row/test/test.js | 38 ++ .../test/test.main.js | 287 ++++++++++++ .../test/test.ndarray.js | 427 ++++++++++++++++++ 35 files changed, 2402 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_early_return.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major_no_match.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/README.md b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/README.md new file mode 100644 index 000000000000..b1a90b449ea9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/README.md @@ -0,0 +1,198 @@ + + +# glastIndexOfTruthyRow + +> Return the index of the last row in an input matrix which contains at least one truthy element. + +
+ +## Usage + +```javascript +var glastIndexOfTruthyRow = require( '@stdlib/blas/ext/base/glast-index-of-truthy-row' ); +``` + +#### glastIndexOfTruthyRow( order, M, N, A, LDA ) + +Returns the index of the last row in an input matrix which contains at least one truthy element. + + + +```javascript +/* + A = [ + [ 0.0, 0.0, 0.0, 0.0 ], + [ 1.0, 0.0, 1.0, 1.0 ], + [ 1.0, 1.0, 1.0, 1.0 ], + [ 0.0, 0.0, 0.0, 0.0 ] + ] +*/ +var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; + +var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A, 4 ); +// returns 2 +``` + +The function has the following parameters: + +- **order**: storage layout. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). + +If the function is unable to find a row with at least one truthy element, the function returns `-1`. + +```javascript +var A = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +var out = glastIndexOfTruthyRow( 'row-major', 4, 2, A, 2 ); +// 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 array: +var A0 = new Float64Array( [ 9999.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset view: +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A1, 4 ); +// returns 2 +``` + +#### glastIndexOfTruthyRow.ndarray( M, N, A, strideA1, strideA2, offsetA ) + +Returns the index of the last row in an input matrix which contains at least one truthy element using alternative indexing semantics. + + + +```javascript +/* + A = [ + [ 0.0, 0.0, 0.0, 0.0 ], + [ 1.0, 0.0, 1.0, 1.0 ], + [ 1.0, 1.0, 1.0, 1.0 ], + [ 0.0, 0.0, 0.0, 0.0 ] + ] +*/ +var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; + +var out = glastIndexOfTruthyRow.ndarray( 4, 4, A, 4, 1, 0 ); +// returns 2 +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **strideA1**: stride length for the first dimension of `A`. +- **strideA2**: stride length for the second dimension of `A`. +- **offsetA**: starting index for `A`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example: + + + +```javascript +/* + A = [ + [ 0.0, 0.0, 0.0, 0.0 ], + [ 1.0, 1.0, 1.0, 1.0 ], + [ 1.0, 1.0, 1.0, 1.0 ], + [ 0.0, 0.0, 0.0, 0.0 ] + ] +*/ +var A = [ 9999.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; + +var out = glastIndexOfTruthyRow.ndarray( 4, 4, A, 4, 1, 1 ); +// returns 2 +``` + +
+ + + +
+ +## Notes + +- A row is considered to contain at least one truthy element when at least one element in the row is not equal to `0.0` and is not `NaN`. +- 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 glastIndexOfTruthyRow = require( '@stdlib/blas/ext/base/glast-index-of-truthy-row' ); + +var shape = [ 4, 2 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var out = glastIndexOfTruthyRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.js new file mode 100644 index 000000000000..068de2c56145 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.js @@ -0,0 +1,111 @@ +/** +* @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 glastIndexOfTruthyRow = 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' ); + 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++ ) { + z = glastIndexOfTruthyRow( order, N, N, A, N ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..a569f26509cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/benchmark/benchmark.ndarray.js @@ -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. +*/ + +'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 glastIndexOfTruthyRow = 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' ); + 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++ ) { + z = glastIndexOfTruthyRow( N, N, A, sa1, sa2, 0 ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/repl.txt new file mode 100644 index 000000000000..944438cb8610 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/repl.txt @@ -0,0 +1,87 @@ + +{{alias}}( order, M, N, A, LDA ) + Returns the index of the last row in an input matrix which contains at least + one truthy element. + + 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 row with at least one truthy element, the function returns `-1` + (i.e., an invalid index). + + Parameters + ---------- + order: string + Storage layout. + + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Array|TypedArray + Input matrix. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + Returns + ------- + out: integer + Row index. + + Examples + -------- + > var A = [ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 4, 2, A, 2 ) + 2 + + +{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA ) + Returns the index of the last row in an input matrix which contains at least + one truthy element using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + If the method is provided an empty matrix or if the method is unable to find + a row with at least one truthy element, 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. + + strideA1: integer + Stride length for the first dimension of `A`. + + strideA2: integer + Stride length for the second dimension of `A`. + + offsetA: integer + Starting index for `A`. + + Returns + ------- + out: integer + Row index. + + Examples + -------- + > var A = [ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 4, 2, A, 2, 1, 0 ) + 2 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/index.d.ts new file mode 100644 index 000000000000..ba5e7f273c22 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/index.d.ts @@ -0,0 +1,112 @@ +/* +* @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 `glastIndexOfTruthyRow`. +*/ +interface Routine { + /** + * Returns the index of the last row in an input matrix which contains at least one truthy element. + * + * ## Notes + * + * - If the function is provided an empty matrix or if the function is unable to find a row with at least one truthy element, 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`) + * @returns row index + * + * @example + * var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A, 4 ); + * // returns 2 + */ + ( order: Layout, M: number, N: number, A: InputArray, LDA: number ): number; + + /** + * Returns the index of the last row in an input matrix which contains at least one truthy element using alternative indexing semantics. + * + * ## Notes + * + * - If the function is provided an empty matrix or if the function is unable to find a row with at least one truthy element, the function returns `-1` (i.e., an invalid index). + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param strideA1 - stride length for the first dimension of `A` + * @param strideA2 - stride length for the second dimension of `A` + * @param offsetA - starting index for `A` + * @returns row index + * + * @example + * var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * var out = glastIndexOfTruthyRow.ndarray( 4, 4, A, 4, 1, 0 ); + * // returns 2 + */ + ndarray( M: number, N: number, A: InputArray, strideA1: number, strideA2: number, offsetA: number ): number; +} + +/** +* Returns the index of the last row in an input matrix which contains at least one truthy element. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a row with at least one truthy element, 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`) +* @returns row index +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A, 4 ); +* // returns 2 +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* var out = glastIndexOfTruthyRow.ndarray( 4, 4, A, 4, 1, 0 ); +* // returns 2 +*/ +declare var glastIndexOfTruthyRow: Routine; + + +// EXPORTS // + +export = glastIndexOfTruthyRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/test.ts new file mode 100644 index 000000000000..2924a6780ffa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/docs/types/test.ts @@ -0,0 +1,211 @@ +/* +* @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 space-in-parens */ + +import glastIndexOfTruthyRow = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + glastIndexOfTruthyRow( 'row-major', 2, 2, A, 2 ); // $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 ]; + + glastIndexOfTruthyRow( 5, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( true, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( false, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( null, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( void 0, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( [], 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( {}, 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( ( x: number ): number => x, 2, 2, A, 2 ); // $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 ]; + + glastIndexOfTruthyRow( 'row-major', '5', 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', true, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', false, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', null, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', void 0, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', [], 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', {}, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', ( x: number ): number => x, 2, A, 2 ); // $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 ]; + + glastIndexOfTruthyRow( 'row-major', 2, '5', A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, true, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, false, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, null, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, void 0, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, [], A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, {}, A, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, ( x: number ): number => x, A, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + glastIndexOfTruthyRow( 'row-major', 2, 2, 5, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, true, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, false, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, null, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, void 0, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, {}, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, ( x: number ): number => x, 2 ); // $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 ]; + + glastIndexOfTruthyRow( 'row-major', 2, 2, A, '5' ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, true ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, false ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, null ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, void 0 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, [] ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, {} ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, ( 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 ]; + + glastIndexOfTruthyRow(); // $ExpectError + glastIndexOfTruthyRow( 'row-major' ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2 ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A ); // $ExpectError + glastIndexOfTruthyRow( 'row-major', 2, 2, A, 2, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 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 ]; + + glastIndexOfTruthyRow.ndarray( '5', 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( true, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( false, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( null, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( void 0, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( [], 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( {}, 2, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( ( x: number ): number => x, 2, A, 2, 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 ]; + + glastIndexOfTruthyRow.ndarray( 2, '5', A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, true, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, false, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, null, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, void 0, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, [], A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, {}, A, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, ( x: number ): number => x, A, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + glastIndexOfTruthyRow.ndarray( 2, 2, 5, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, true, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, false, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, null, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, void 0, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, {}, 2, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, ( x: number ): number => x, 2, 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 ]; + + glastIndexOfTruthyRow.ndarray( 2, 2, A, '5', 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, true, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, false, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, null, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, void 0, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, [], 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, {}, 1, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, ( x: number ): number => 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 ]; + + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, '5', 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, true, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, false, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, null, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, void 0, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, [], 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, {}, 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, ( x: number ): number => x, 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 ]; + + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, '5' ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, true ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, false ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, null ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, void 0 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, [] ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, {} ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 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 ]; + + glastIndexOfTruthyRow.ndarray(); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1 ); // $ExpectError + glastIndexOfTruthyRow.ndarray( 2, 2, A, 2, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/examples/index.js new file mode 100644 index 000000000000..16a09dff67da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 glastIndexOfTruthyRow = require( './../lib' ); + +var shape = [ 4, 2 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var out = glastIndexOfTruthyRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/index.js new file mode 100644 index 000000000000..ef9d347e7278 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the index of the last row in an input matrix which contains at least one truthy element. +* +* @module @stdlib/blas/ext/base/glast-index-of-truthy-row +* +* @example +* var glastIndexOfTruthyRow = require( '@stdlib/blas/ext/base/glast-index-of-truthy-row' ); +* +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 1.0, 1.0 ], [ 1.0, 1.0, 1.0, 1.0 ], [ 0.0, 0.0, 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A, 4 ); +* // returns 2 +* +* @example +* var glastIndexOfTruthyRow = require( '@stdlib/blas/ext/base/glast-index-of-truthy-row' ); +* +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* var out = glastIndexOfTruthyRow.ndarray( 4, 4, A, 4, 1, 0 ); +* // returns 2 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/main.js new file mode 100644 index 000000000000..f11230c48066 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/main.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the index of the last row in an input matrix which contains at least one truthy element. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a row with at least one truthy element, 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`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} fifth argument must be a valid stride length +* @returns {integer} row index +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 1.0, 1.0 ], [ 1.0, 1.0, 1.0, 1.0 ], [ 0.0, 0.0, 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 'row-major', 4, 4, A, 4 ); +* // returns 2 +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 'row-major', 4, 2, A, 2 ); +* // returns -1 +* +* @example +* var A = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 'row-major', 4, 2, A, 2 ); +* // returns 2 +*/ +function glastIndexOfTruthyRow( order, M, N, A, LDA ) { + 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; + sa1 = LDA; + sa2 = 1; + } else { // order === 'column-major' + s = M; + sa1 = 1; + sa2 = LDA; + } + 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 ) ); + } + return ndarray( M, N, A, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = glastIndexOfTruthyRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/ndarray.js new file mode 100644 index 000000000000..7b1d08efc5e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/lib/ndarray.js @@ -0,0 +1,84 @@ +/** +* @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 gindexOfTruthyRow = require( '@stdlib/blas/ext/base/gindex-of-truthy-row' ).ndarray; + + +// MAIN // + +/** +* Returns the index of the last row in an input matrix which contains at least one truthy element. +* +* ## Notes +* +* - If the function is provided an empty matrix or if the function is unable to find a row with at least one truthy element, the function returns `-1` (i.e., an invalid index). +* +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Collection} A - input matrix +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {integer} row index +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 1.0, 1.0 ], [ 1.0, 1.0, 1.0, 1.0 ], [ 0.0, 0.0, 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 4, 4, A, 4, 1, 0 ); +* // returns 2 +* +* @example +* var A = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 4, 2, A, 2, 1, 0 ); +* // returns -1 +* +* @example +* var A = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0 ]; // => [ [ 0.0, 0.0 ], [ 0.0, 1.0 ], [ 1.0, 1.0 ], [ 0.0, 0.0 ] ] +* +* var out = glastIndexOfTruthyRow( 4, 2, A, 2, 1, 0 ); +* // returns 2 +*/ +function glastIndexOfTruthyRow( M, N, A, strideA1, strideA2, offsetA ) { + var idx; + + // Check whether the matrix is an empty matrix... + if ( M <= 0 || N <= 0 ) { + return -1; + } + // Reverse the row iteration order by flipping the stride for the first dimension and adjusting the offset: + offsetA += ( M-1 ) * strideA1; + strideA1 *= -1; + + // Find the index of the first row containing at least one truthy element in the row-reversed "view": + idx = gindexOfTruthyRow( M, N, A, strideA1, strideA2, offsetA ); + if ( idx < 0 ) { + return idx; + } + // Convert the index from the row-reversed "view" to an index in the original "view": + return M - 1 - idx; +} + + +// EXPORTS // + +module.exports = glastIndexOfTruthyRow; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/package.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/package.json new file mode 100644 index 000000000000..8c6ead2c7914 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/glast-index-of-truthy-row", + "version": "0.0.0", + "description": "Return the index of the last row in an input matrix which contains at least one truthy element.", + "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", + "row", + "index", + "truthy", + "find", + "last-index-of", + "lastindexof" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major.json new file mode 100644 index 000000000000..b3412b2d5fee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major.json @@ -0,0 +1,17 @@ +{ + "order": "column-major", + "A": [ 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ], + "M": 4, + "N": 2, + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 0.0 ], + [ 1.0, 1.0 ], + [ 0.0, 0.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_early_return.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_early_return.json new file mode 100644 index 000000000000..d9bdd652e192 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_early_return.json @@ -0,0 +1,17 @@ +{ + "order": "column-major", + "A": [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ], + "M": 4, + "N": 2, + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ], + [ 1.0, 1.0 ] + ], + "expected": 3 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_no_match.json new file mode 100644 index 000000000000..73ca6f93970e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/column_major_no_match.json @@ -0,0 +1,16 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major.json new file mode 100644 index 000000000000..9d2c8055fcf2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major.json @@ -0,0 +1,29 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 9999.0, + 1.0, + 9999.0, + 1.0, + 9999.0, + 0.0, + 9999.0, + 1.0, + 9999.0, + 1.0, + 9999.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 6, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major_no_match.json new file mode 100644 index 000000000000..1881676dae6e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/column_major_no_match.json @@ -0,0 +1,29 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major.json new file mode 100644 index 000000000000..552f9eed3f79 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major.json @@ -0,0 +1,29 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 9999.0, + 0.0, + 9999.0, + 1.0, + 9999.0, + 1.0, + 9999.0, + 1.0, + 9999.0, + 1.0, + 9999.0 + ], + "M": 3, + "N": 2, + "strideA1": 4, + "strideA2": 2, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major_no_match.json new file mode 100644 index 000000000000..50416c75b12b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/large-strides/row_major_no_match.json @@ -0,0 +1,29 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major.json new file mode 100644 index 000000000000..4e66ffe7d175 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major.json @@ -0,0 +1,23 @@ +{ + "order": "column-major", + "A": [ + 0.0, + 1.0, + 1.0, + 0.0, + 1.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": -3, + "offsetA": 3, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major_no_match.json new file mode 100644 index 000000000000..d8af7823044b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/column_major_no_match.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major.json new file mode 100644 index 000000000000..aea3b3104a6e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major.json @@ -0,0 +1,23 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": 1, + "offsetA": 4, + "LDA": 2, + "A_mat": [ + [ 1.0, 1.0 ], + [ 1.0, 1.0 ], + [ 0.0, 0.0 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major_no_match.json new file mode 100644 index 000000000000..cf2d9d05f366 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/mixed-strides/row_major_no_match.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major.json new file mode 100644 index 000000000000..ce3c166e2dc5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major.json @@ -0,0 +1,23 @@ +{ + "order": "column-major", + "A": [ + 1.0, + 1.0, + 0.0, + 1.0, + 1.0, + 0.0 + ], + "M": 3, + "N": 2, + "strideA1": -1, + "strideA2": -3, + "offsetA": 5, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major_no_match.json new file mode 100644 index 000000000000..66c579cd6072 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/column_major_no_match.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major.json new file mode 100644 index 000000000000..d1dcc02114ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major.json @@ -0,0 +1,23 @@ +{ + "order": "row-major", + "A": [ + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": -2, + "strideA2": -1, + "offsetA": 5, + "LDA": 2, + "A_mat": [ + [ 1.0, 1.0 ], + [ 1.0, 1.0 ], + [ 0.0, 0.0 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major_no_match.json new file mode 100644 index 000000000000..54f0db891e33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/negative-strides/row_major_no_match.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major.json new file mode 100644 index 000000000000..06874b0b30d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major.json @@ -0,0 +1,24 @@ +{ + "order": "column-major", + "A": [ + 9999.0, + 0.0, + 1.0, + 1.0, + 0.0, + 1.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": 3, + "offsetA": 1, + "LDA": 3, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major_no_match.json new file mode 100644 index 000000000000..59b9a8f46fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/column_major_no_match.json @@ -0,0 +1,24 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major.json new file mode 100644 index 000000000000..c65d91e969d8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major.json @@ -0,0 +1,24 @@ +{ + "order": "row-major", + "A": [ + 9999.0, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 1.0 + ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 1, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 1.0, 1.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major_no_match.json new file mode 100644 index 000000000000..fb91d1f7908b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/offsets/row_major_no_match.json @@ -0,0 +1,24 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major.json new file mode 100644 index 000000000000..5b2c98e72a51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major.json @@ -0,0 +1,17 @@ +{ + "order": "row-major", + "A": [ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0 ], + "M": 4, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 0.0, 0.0 ], + [ 1.0, 0.0 ], + [ 1.0, 1.0 ], + [ 0.0, 0.0 ] + ], + "expected": 2 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major_no_match.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major_no_match.json new file mode 100644 index 000000000000..20eceeaad571 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/fixtures/row_major_no_match.json @@ -0,0 +1,16 @@ +{ + "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 ] + ], + "expected": -1 +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.js new file mode 100644 index 000000000000..38350a4c1a12 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var glastIndexOfTruthyRow = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfTruthyRow, '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 glastIndexOfTruthyRow.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.main.js new file mode 100644 index 000000000000..152c639bdbcd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.main.js @@ -0,0 +1,287 @@ +/** +* @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 glastIndexOfTruthyRow = 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' ); +var COLUMN_MAJOR_EARLY_RETURN = require( './fixtures/column_major_early_return.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfTruthyRow, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( glastIndexOfTruthyRow.length, 5, '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() { + glastIndexOfTruthyRow( value, data.M, data.N, data.A, data.LDA ); + }; + } +}); + +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() { + glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, value ); + }; + } +}); + +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() { + glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, value ); + }; + } +}); + +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 = glastIndexOfTruthyRow( data.order, 0, data.N, data.A, data.LDA ); + + 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 = glastIndexOfTruthyRow( data.order, data.M, 0, data.A, data.LDA ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row when the last row contains a truthy element (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_EARLY_RETURN; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, data.LDA ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, data.A, data.LDA ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_DATA; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_DATA; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row when the last row contains a truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_EARLY_RETURN; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA ); + + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, accessors)', function test( t ) { + var data; + var out; + + data = ROW_MAJOR_NO_MATCH; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + + data = COLUMN_MAJOR_NO_MATCH; + out = glastIndexOfTruthyRow( data.order, data.M, data.N, toAccessorArray( data.A ), data.LDA ); + + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function treats NaN as falsy', function test( t ) { + var out; + var A; + + A = [ 1.0, 1.0, NaN, 0.0 ]; + out = glastIndexOfTruthyRow( 'row-major', 2, 2, A, 2 ); + t.strictEqual( out, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats NaN as falsy (accessors)', function test( t ) { + var out; + var A; + + A = toAccessorArray( [ 1.0, 1.0, NaN, 0.0 ] ); + out = glastIndexOfTruthyRow( 'row-major', 2, 2, A, 2 ); + t.strictEqual( out, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.ndarray.js new file mode 100644 index 000000000000..11e63a8f6688 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-truthy-row/test/test.ndarray.js @@ -0,0 +1,427 @@ +/** +* @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 glastIndexOfTruthyRow = 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 COLUMN_MAJOR_EARLY_RETURN = require( './fixtures/column_major_early_return.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 glastIndexOfTruthyRow, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( glastIndexOfTruthyRow.length, 6, '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 = ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( 0, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + 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 = ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, 0, data.A, data.strideA1, data.strideA2, data.offsetA ); + 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 = COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( 0, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + 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 = COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, 0, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major)', function test( t ) { + var data = ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major)', function test( t ) { + var data = COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row when the last row contains a truthy element (column-major)', function test( t ) { + var data = COLUMN_MAJOR_EARLY_RETURN; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major)', function test( t ) { + var data = ROW_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major)', function test( t ) { + var data = COLUMN_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, offsets)', function test( t ) { + var data = OFFSET_ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, offsets)', function test( t ) { + var data = OFFSET_COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, offsets)', function test( t ) { + var data = OFFSET_ROW_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, offsets)', function test( t ) { + var data = OFFSET_COLUMN_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, mixed strides)', function test( t ) { + var data = MIXED_STRIDES_ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, mixed strides)', function test( t ) { + var data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, mixed strides)', function test( t ) { + var data = MIXED_STRIDES_ROW_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, mixed strides)', function test( t ) { + var data = MIXED_STRIDES_COLUMN_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, negative strides)', function test( t ) { + var data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, negative strides)', function test( t ) { + var data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, negative strides)', function test( t ) { + var data = NEGATIVE_STRIDES_ROW_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, negative strides)', function test( t ) { + var data = NEGATIVE_STRIDES_COLUMN_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, large strides)', function test( t ) { + var data = LARGE_STRIDES_ROW_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, large strides)', function test( t ) { + var data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, large strides)', function test( t ) { + var data = LARGE_STRIDES_ROW_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, large strides)', function test( t ) { + var data = LARGE_STRIDES_COLUMN_MAJOR_NO_MATCH; + var out = glastIndexOfTruthyRow( data.M, data.N, data.A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, accessors)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row when the last row contains a truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_EARLY_RETURN; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (row-major, accessors)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_NO_MATCH; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index if unable to find a row with at least one truthy element (column-major, accessors)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_NO_MATCH; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, offsets, accessors)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_ROW_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, offsets, accessors)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_COLUMN_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, negative strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, negative strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, mixed strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (row-major, large strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the index of the last row with at least one truthy element (column-major, large strides, accessors)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + A = toAccessorArray( data.A ); + out = glastIndexOfTruthyRow( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + t.strictEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function treats NaN as falsy (row-major)', function test( t ) { + var data; + var out; + + data = [ 1.0, 1.0, NaN, 0.0 ]; + out = glastIndexOfTruthyRow( 2, 2, data, 2, 1, 0 ); + t.strictEqual( out, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function treats NaN as falsy (column-major)', function test( t ) { + var data; + var out; + + data = [ 0.0, NaN, 1.0, 0.0 ]; + out = glastIndexOfTruthyRow( 2, 2, data, 1, 2, 0 ); + t.strictEqual( out, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function treats NaN as falsy (accessors)', function test( t ) { + var data; + var out; + + data = toAccessorArray( [ 1.0, 1.0, NaN, 0.0 ] ); + out = glastIndexOfTruthyRow( 2, 2, data, 2, 1, 0 ); + t.strictEqual( out, 0, 'returns expected value' ); + t.end(); +});