diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/README.md b/lib/node_modules/@stdlib/lapack/base/iladlr/README.md new file mode 100644 index 000000000000..accfadf1039a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/README.md @@ -0,0 +1,262 @@ + + +# iladlr + +> Find the index of the last non-zero row in a matrix `A`. + +
+ +## Usage + +```javascript +var iladlr = require( '@stdlib/lapack/base/iladlr' ); +``` + +#### iladlr( order, M, N, A, LDA ) + +Returns the index of the last non-zero row in a matrix `A`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] ); + +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ] +*/ + +var out = iladlr( 'row-major', 3, 2, A, 2 ); +// 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 [`Float64Array`][mdn-float64array]. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). + +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, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] ); + +// Create an offset view: +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = iladlr( 'row-major', 3, 2, A1, 2 ); +// returns 1 +``` + +#### iladlr.ndarray( M, N, A, strideA1, strideA2, offsetA ) + +Returns the index of the last non-zero row in a matrix `A` using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] ); + +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ] +*/ + +var out = iladlr.ndarray( 3, 2, A, 2, 1, 0 ); +// returns 1 +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input [`Float64Array`][mdn-float64array]. +- **strideA1**: stride of the first dimension of `A`. +- **strideA2**: stride of 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 +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] ); + +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ] +*/ + +var out = iladlr.ndarray( 3, 2, A, 2, 1, 1 ); +// returns 1 +``` + +
+ + + +
+ +## Notes + +- This routine is commonly used throughout LAPACK to shrink work domains (e.g., before bulge-chasing, deflation, or when trimming Householder panels), thus ensuring that higher-level routines operate only on numerically relevant sub-matrices. +- `iladlr()` corresponds to the [LAPACK][lapack] routine [`iladlr`][lapack-iladlr]. + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var iladlr = require( '@stdlib/lapack/base/iladlr' ); + +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0 ] ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var out = iladlr( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.js new file mode 100644 index 000000000000..1df857ef424f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 pkg = require( './../package.json' ).name; +var iladlr = require( './../lib/iladlr.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, 'float64' ); + 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++ ) { + A[ 0 ] = i; + z = iladlr( 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( pkg+'::square_matrix:order='+ord+',size='+(N*N), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..71a76c92f479 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.ndarray.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 pkg = require( './../package.json' ).name; +var iladlr = 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, 'float64' ); + 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++ ) { + A[ 0 ] = i; + z = iladlr( 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( pkg+'::square_matrix:order='+ord+',size='+(N*N), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/repl.txt new file mode 100644 index 000000000000..6a9c6b35d3c1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/repl.txt @@ -0,0 +1,81 @@ + +{{alias}}( order, M, N, A, LDA ) + Returns the index of the last non-zero row in a matrix `A`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If provided an empty matrix or a matrix containing only zeros, 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: Float64Array + Input matrix `A`. + + Returns + ------- + out: integer + Zero-based index of the last non-zero row. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias}}( 'row-major', 2, 2, A, 2 ) + 1 + + +{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA ) + Returns the index of the last non-zero row in a matrix `A` using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + If provided an empty matrix or a matrix containing only zeros, 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: Float64Array + 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`. + + Returns + ------- + out: integer + Zero-based index of the last non-zero row. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias}}.ndarray( 2, 2, A, 2, 1, 0 ) + 1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/index.d.ts new file mode 100644 index 000000000000..5f0b3b67d58c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/index.d.ts @@ -0,0 +1,113 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { Layout } from '@stdlib/types/blas'; + +/** +* Interface describing `iladlr`. +*/ +interface Routine { + /** + * Returns the index of the last non-zero row in a matrix `A`. + * + * ## Notes + * + * - If provided an empty matrix or a matrix containing only zeros, 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 index of the last non-zero row + * + * @example + * var Float64array = require( '@stdlib/array/float64' ); + * + * var A = new Float64array( [ 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 out = iladlr( 'row-major', 3, 2, A, 2 ); + * // returns 1 + */ + ( order: Layout, M: number, N: number, A: Float64Array, LDA: number ): number; + + /** + * Returns the index of the last non-zero row in a matrix `A` using alternative indexing semantics. + * + * ## Notes + * + * - If provided an empty matrix or a matrix containing only zeros, 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` + * @returns index of the last non-zero row + * + * @example + * var Float64array = require( '@stdlib/array/float64' ); + * + * var A = new Float64array( [ 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 out = iladlr.ndarray( 3, 2, A, 2, 1, 0 ); + * // returns 1 + */ + ndarray( M: number, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number ): number; +} + +/** +* Returns the index of the last non-zero row in a matrix `A`. +* +* ## Notes +* +* - If provided an empty matrix or a matrix containing only zeros, 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 index of the last non-zero row +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 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 out = iladlr( 'row-major', 3, 2, A, 2 ); +* // returns 1 +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 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 out = iladlr.ndarray( 3, 2, A, 2, 1, 0 ); +* // returns 1 +*/ +declare var iladlr: Routine; + + +// EXPORTS // + +export = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/test.ts new file mode 100644 index 000000000000..63d392dcfb60 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/test.ts @@ -0,0 +1,213 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 iladlr = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const A = new Float64Array( 4 ); + + iladlr( '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 = new Float64Array( 4 ); + + iladlr( 5, 2, 2, A, 2 ); // $ExpectError + iladlr( true, 2, 2, A, 2 ); // $ExpectError + iladlr( false, 2, 2, A, 2 ); // $ExpectError + iladlr( null, 2, 2, A, 2 ); // $ExpectError + iladlr( void 0, 2, 2, A, 2 ); // $ExpectError + iladlr( [], 2, 2, A, 2 ); // $ExpectError + iladlr( {}, 2, 2, A, 2 ); // $ExpectError + iladlr( ( 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 = new Float64Array( 4 ); + + iladlr( 'row-major', '5', 2, A, 2 ); // $ExpectError + iladlr( 'row-major', true, 2, A, 2 ); // $ExpectError + iladlr( 'row-major', false, 2, A, 2 ); // $ExpectError + iladlr( 'row-major', null, 2, A, 2 ); // $ExpectError + iladlr( 'row-major', void 0, 2, A, 2 ); // $ExpectError + iladlr( 'row-major', [], 2, A, 2 ); // $ExpectError + iladlr( 'row-major', {}, 2, A, 2 ); // $ExpectError + iladlr( '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 = new Float64Array( 4 ); + + iladlr( 'row-major', 2, '5', A, 2 ); // $ExpectError + iladlr( 'row-major', 2, true, A, 2 ); // $ExpectError + iladlr( 'row-major', 2, false, A, 2 ); // $ExpectError + iladlr( 'row-major', 2, null, A, 2 ); // $ExpectError + iladlr( 'row-major', 2, void 0, A, 2 ); // $ExpectError + iladlr( 'row-major', 2, [], A, 2 ); // $ExpectError + iladlr( 'row-major', 2, {}, A, 2 ); // $ExpectError + iladlr( '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 Float64Array... +{ + iladlr( 'row-major', 2, 2, '5', 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, 5, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, true, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, false, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, null, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, void 0, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, [], 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, {}, 2 ); // $ExpectError + iladlr( '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 = new Float64Array( 4 ); + + iladlr( 'row-major', 2, 2, A, '5' ); // $ExpectError + iladlr( 'row-major', 2, 2, A, true ); // $ExpectError + iladlr( 'row-major', 2, 2, A, false ); // $ExpectError + iladlr( 'row-major', 2, 2, A, null ); // $ExpectError + iladlr( 'row-major', 2, 2, A, void 0 ); // $ExpectError + iladlr( 'row-major', 2, 2, A, [] ); // $ExpectError + iladlr( 'row-major', 2, 2, A, {} ); // $ExpectError + iladlr( '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 = new Float64Array( 4 ); + + iladlr(); // $ExpectError + iladlr( 'row-major' ); // $ExpectError + iladlr( 'row-major', 2 ); // $ExpectError + iladlr( 'row-major', 2, 2 ); // $ExpectError + iladlr( 'row-major', 2, 2, A ); // $ExpectError + iladlr( 'row-major', 2, 2, A, 2, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const A = new Float64Array( 4 ); + + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray( '5', 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( true, 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( false, 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( null, 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( void 0, 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( [], 2, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( {}, 2, A, 2, 1, 0 ); // $ExpectError + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray( 2, '5', A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, true, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, false, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, null, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, void 0, A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, [], A, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, {}, A, 2, 1, 0 ); // $ExpectError + iladlr.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 Float64Array... +{ + iladlr.ndarray( 2, 2, '5', 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, 5, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, true, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, false, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, null, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, void 0, 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, [], 2, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, {}, 2, 1, 0 ); // $ExpectError + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray( 2, 2, A, '5', 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, true, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, false, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, null, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, void 0, 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, [], 1, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, {}, 1, 0 ); // $ExpectError + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray( 2, 2, A, 2, '5', 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, true, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, false, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, null, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, void 0, 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, [], 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, {}, 0 ); // $ExpectError + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray( 2, 2, A, 2, 1, '5' ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, true ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, false ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, null ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, void 0 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, [] ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, {} ); // $ExpectError + iladlr.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 = new Float64Array( 4 ); + + iladlr.ndarray(); // $ExpectError + iladlr.ndarray( 2 ); // $ExpectError + iladlr.ndarray( 2, 2 ); // $ExpectError + iladlr.ndarray( 2, 2, A ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1 ); // $ExpectError + iladlr.ndarray( 2, 2, A, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/examples/index.js b/lib/node_modules/@stdlib/lapack/base/iladlr/examples/index.js new file mode 100644 index 000000000000..9aa4f6f652ed --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var iladlr = require( './../lib' ); + +var shape = [ 3, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0 ] ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var out = iladlr( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js new file mode 100644 index 000000000000..fb0c1397441c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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' ); + + +// MAIN // + +/** +* Returns the index of the last non-zero row in a matrix `A`. +* +* ## Notes +* +* - If provided an empty matrix or a matrix containing only zeros, 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 {Float64Array} 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` +* @returns {integer} index of the last non-zero row +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 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 out = iladlr( 3, 2, A, 2, 1, 0 ); +* // returns 1 +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 1.0, 3.0, 0.0, 2.0, 4.0, 0.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ] +* +* var out = iladlr( 3, 2, A, 1, 3, 0 ); +* // returns 1 +*/ +function iladlr( M, N, A, strideA1, strideA2, offsetA ) { + var last; + var da0; + var da1; + var S0; + var S1; + var ia; + var i0; + var i1; + var k; + + // Check whether the matrix is an empty matrix... + if ( M <= 0 || N <= 0 ) { + return -1; + } + // Compute the index of the first element in the last row: + ia = offsetA + ( (M-1) * strideA1 ); + + // Compute the index offset for the last element in the last row: + last = ( N-1 ) * strideA2; + + // Check for the common case where the first and last elements in the last row are non-zero... + if ( A[ ia ] !== 0.0 || A[ ia+last ] !== 0.0 ) { + return M - 1; + } + // Search for the last row containing at least one non-zero element... + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + S0 = N; + S1 = M; + + // Resolve loop offset (pointer) increments: + da0 = strideA2; + da1 = strideA1 - ( S0*strideA2 ); + + // Scan a row-major linear buffer from the last indexed element to the first indexed element, always moving in the same direction when both strides are the same sign, thus ensuring cache optimal traversal... + ia += last; + for ( i1 = S1-1; i1 >= 0; i1-- ) { + for ( i0 = 0; i0 < S0; i0++ ) { + if ( A[ ia ] !== 0.0 ) { + // We found a row with a non-zero element! + return i1; + } + ia -= da0; + } + ia -= da1; + } + // If we've made it here, then all entries in the matrix are zero: + return -1; + } + // Column-major... + S0 = M; + S1 = N; + + // Resolve loop offset (pointer) increments: + da0 = strideA1; + da1 = strideA2; + + // Compute the index offset for the last element in each row: + last = offsetA + ( (S0-1)*da0 ); + + // Initialize an index of the last row in which a non-zero element was seen: + k = -1; + + // Finding the last non-zero row when a matrix is stored in column-major order requires effectively performing a full linear scan. In order to ensure cache-efficient traversal, scan up each column (otherwise, if we went row-by-row, we'd hop around linear memory, resulting in poor cache behavior)... + for ( i1 = 0; i1 < S1; i1++ ) { + // Reset the pointer to point to the last element in the current column: + ia = last + ( i1*da1 ); + + // Scan up the rows in a column looking for a non-zero element... + for ( i0 = S0-1; i0 > k; i0-- ) { // note: `k` serves as a lower row index bound, thus shrinking the number of rows we need to check when scanning columns + if ( A[ ia ] !== 0.0 ) { + // We found a non-zero element, which means we no longer have to search this row... + k = i0; + break; // note: in principle, if `k == M-1`, we could early return; however, this is a hot loop and adding an additional conditional is likely to degrade average performance in order to cater to what is effectively an edge case + } + ia -= da0; + } + } + return k; +} + + +// EXPORTS // + +module.exports = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/iladlr.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/iladlr.js new file mode 100644 index 000000000000..2be94ef3fa32 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/iladlr.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 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 last non-zero row in a matrix `A`. +* +* @param {string} order - storage layout +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Float64Array} 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 greater than or equal to max(1,N) +* @returns {integer} index of the last non-zero row +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 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 out = iladlr( 'row-major', 3, 2, A, 2 ); +* // returns 1 +*/ +function iladlr( 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; + } 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 ); +} + + +// EXPORTS // + +module.exports = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/index.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/index.js new file mode 100644 index 000000000000..5d90f3841faf --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* LAPACK routine to find the index of the last non-zero row in a input matrix. +* +* @module @stdlib/lapack/base/iladlr +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* var iladlr = require( '@stdlib/lapack/base/iladlr' ); +* +* var A = new Float64array( [ 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 out = iladlr( 'row-major', 3, 2, A, 2 ); +* // returns 1 +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var iladlr; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + iladlr = main; +} else { + iladlr = tmp; +} + + +// EXPORTS // + +module.exports = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js new file mode 100644 index 000000000000..9984e10eee17 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var iladlr = require( './iladlr.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( iladlr, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/ndarray.js new file mode 100644 index 000000000000..bc7f86fe358f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/ndarray.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 last non-zero row in a matrix `A` using alternative indexing semantics. +* +* @param {PositiveInteger} M - number of rows in `A` +* @param {PositiveInteger} N - number of columns in `A` +* @param {Float64Array} 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` +* @returns {integer} index of the last non-zero row +* +* @example +* var Float64array = require( '@stdlib/array/float64' ); +* +* var A = new Float64array( [ 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 out = iladlr( 3, 2, A, 2, 1, 0 ); +* // returns 1 +*/ +function iladlr( M, N, A, strideA1, strideA2, offsetA ) { + return base( M, N, A, strideA1, strideA2, offsetA ); +} + + +// EXPORTS // + +module.exports = iladlr; diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/package.json b/lib/node_modules/@stdlib/lapack/base/iladlr/package.json new file mode 100644 index 000000000000..be6f79b0635b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/lapack/base/iladlr", + "version": "0.0.0", + "description": "LAPACK routine to find the index of the last non-zero row in a input matrix.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "lapack", + "iladlr", + "last", + "row", + "index", + "matrix", + "auxilary", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major.json new file mode 100644 index 000000000000..8fac692d36b4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major.json @@ -0,0 +1,16 @@ +{ + "order": "column-major", + "A": [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ], + "M": 3, + "N": 2, + "strideA1": 1, + "strideA2": 3, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major_zeros.json new file mode 100644 index 000000000000..73ca6f93970e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/column_major_zeros.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/lapack/base/iladlr/test/fixtures/large_strides/column_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/column_major.json new file mode 100644 index 000000000000..1dac55f33884 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/column_major.json @@ -0,0 +1,29 @@ +{ + "order": "column-major", + "A": [ + 1, + 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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/column_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/column_major_zeros.json new file mode 100644 index 000000000000..1881676dae6e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/column_major_zeros.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/lapack/base/iladlr/test/fixtures/large_strides/row_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/row_major.json new file mode 100644 index 000000000000..e00599ebd71e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/row_major.json @@ -0,0 +1,29 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/row_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/row_major_zeros.json new file mode 100644 index 000000000000..50416c75b12b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/large_strides/row_major_zeros.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/lapack/base/iladlr/test/fixtures/mixed_strides/column_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/column_major.json new file mode 100644 index 000000000000..a07752170cac --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/column_major.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/column_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/column_major_zeros.json new file mode 100644 index 000000000000..d8af7823044b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/column_major_zeros.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/lapack/base/iladlr/test/fixtures/mixed_strides/row_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/row_major.json new file mode 100644 index 000000000000..1b4459caead4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/row_major.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/row_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/row_major_zeros.json new file mode 100644 index 000000000000..cf2d9d05f366 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/mixed_strides/row_major_zeros.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/lapack/base/iladlr/test/fixtures/negative_strides/column_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/column_major.json new file mode 100644 index 000000000000..367b7894d378 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/column_major.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/column_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/column_major_zeros.json new file mode 100644 index 000000000000..66c579cd6072 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/column_major_zeros.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/lapack/base/iladlr/test/fixtures/negative_strides/row_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/row_major.json new file mode 100644 index 000000000000..839439058755 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/row_major.json @@ -0,0 +1,23 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/row_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/row_major_zeros.json new file mode 100644 index 000000000000..54f0db891e33 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/negative_strides/row_major_zeros.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/lapack/base/iladlr/test/fixtures/offsets/column_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/column_major.json new file mode 100644 index 000000000000..0596ba5e7b81 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/column_major.json @@ -0,0 +1,24 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/column_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/column_major_zeros.json new file mode 100644 index 000000000000..59b9a8f46fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/column_major_zeros.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/lapack/base/iladlr/test/fixtures/offsets/row_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/row_major.json new file mode 100644 index 000000000000..b9507f8e23c4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/row_major.json @@ -0,0 +1,24 @@ +{ + "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 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/row_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/row_major_zeros.json new file mode 100644 index 000000000000..fb91d1f7908b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/offsets/row_major_zeros.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/lapack/base/iladlr/test/fixtures/row_major.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/row_major.json new file mode 100644 index 000000000000..cb56f8bee2e4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/row_major.json @@ -0,0 +1,16 @@ +{ + "order": "row-major", + "A": [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ], + "M": 3, + "N": 2, + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 0.0, 0.0 ] + ], + "expected": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/row_major_zeros.json b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/row_major_zeros.json new file mode 100644 index 000000000000..20eceeaad571 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/fixtures/row_major_zeros.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/lapack/base/iladlr/test/test.iladlr.js b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.iladlr.js new file mode 100644 index 000000000000..3e46359642f9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.iladlr.js @@ -0,0 +1,223 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var iladlr = require( './../lib/iladlr.js' ); + + +// FIXTURES // + +var ROW_MAJOR_DATA = require( './fixtures/row_major.json' ); +var ROW_MAJOR_ZEROS = require( './fixtures/row_major_zeros.json' ); +var COLUMN_MAJOR_DATA = require( './fixtures/column_major.json' ); +var COLUMN_MAJOR_ZEROS = require( './fixtures/column_major_zeros.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iladlr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( iladlr.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 A; + var i; + + data = ROW_MAJOR_DATA; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + A = new Float64Array( data.A ); + + 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() { + iladlr( value, data.M, data.N, 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 A; + var i; + + data = ROW_MAJOR_DATA; + + values = [ + 0, + 1 + ]; + + A = new Float64Array( data.A ); + + 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() { + iladlr( data.order, data.M, data.N, 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 A; + var i; + + data = COLUMN_MAJOR_DATA; + + values = [ + 0, + 1 + ]; + + A = new Float64Array( data.A ); + + 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() { + iladlr( data.order, data.M, data.N, A, value ); + }; + } +}); + +tape( 'the function returns an invalid index (-1) when M is less than or equal to zero', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.order, 0, data.N, A, data.LDA ); + + t.deepEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when N is less than or equal to zero', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.order, data.M, 0, A, data.LDA ); + + t.deepEqual( out, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.order, data.M, data.N, A, data.LDA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.order, data.M, data.N, A, data.LDA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.order, data.M, data.N, A, data.LDA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.order, data.M, data.N, A, data.LDA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.js b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.js new file mode 100644 index 000000000000..a9c5f6fa1872 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var iladlr = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iladlr, '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 iladlr.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var iladlr = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( iladlr, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var iladlr; + var main; + + main = require( './../lib/iladlr.js' ); + + iladlr = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( iladlr, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.ndarray.js new file mode 100644 index 000000000000..4556456a2eec --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.ndarray.js @@ -0,0 +1,349 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var iladlr = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var ROW_MAJOR_DATA = require( './fixtures/row_major.json' ); +var ROW_MAJOR_ZEROS = require( './fixtures/row_major_zeros.json' ); +var COLUMN_MAJOR_DATA = require( './fixtures/column_major.json' ); +var COLUMN_MAJOR_ZEROS = require( './fixtures/column_major_zeros.json' ); + +var OFFSET_ROW_MAJOR_DATA = require( './fixtures/offsets/row_major.json' ); +var OFFSET_ROW_MAJOR_ZEROS = require( './fixtures/offsets/row_major_zeros.json' ); +var OFFSET_COLUMN_MAJOR_DATA = require( './fixtures/offsets/column_major.json' ); +var OFFSET_COLUMN_MAJOR_ZEROS = require( './fixtures/offsets/column_major_zeros.json' ); + +var NEGATIVE_STRIDES_ROW_MAJOR_DATA = require( './fixtures/negative_strides/row_major.json' ); +var NEGATIVE_STRIDES_ROW_MAJOR_ZEROS = require( './fixtures/negative_strides/row_major_zeros.json' ); +var NEGATIVE_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/negative_strides/column_major.json' ); +var NEGATIVE_STRIDES_COLUMN_MAJOR_ZEROS = require( './fixtures/negative_strides/column_major_zeros.json' ); + +var MIXED_STRIDES_ROW_MAJOR_DATA = require( './fixtures/mixed_strides/row_major.json' ); +var MIXED_STRIDES_ROW_MAJOR_ZEROS = require( './fixtures/mixed_strides/row_major_zeros.json' ); +var MIXED_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/mixed_strides/column_major.json' ); +var MIXED_STRIDES_COLUMN_MAJOR_ZEROS = require( './fixtures/mixed_strides/column_major_zeros.json' ); + +var LARGE_STRIDES_ROW_MAJOR_DATA = require( './fixtures/large_strides/row_major.json' ); +var LARGE_STRIDES_ROW_MAJOR_ZEROS = require( './fixtures/large_strides/row_major_zeros.json' ); +var LARGE_STRIDES_COLUMN_MAJOR_DATA = require( './fixtures/large_strides/column_major.json' ); +var LARGE_STRIDES_COLUMN_MAJOR_ZEROS = require( './fixtures/large_strides/column_major_zeros.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iladlr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( iladlr.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major)', function test( t ) { + var data; + var out; + var A; + + data = ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major)', function test( t ) { + var data; + var out; + var A; + + data = COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major) (offsets)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major) (offsets)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major) (offsets)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major) (offsets)', function test( t ) { + var data; + var out; + var A; + + data = OFFSET_COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major) (mixed strides)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major) (mixed strides)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major) (mixed strides)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major) (mixed strides)', function test( t ) { + var data; + var out; + var A; + + data = MIXED_STRIDES_COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major) (negative strides)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major) (negative strides)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major) (negative strides)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major) (negative strides)', function test( t ) { + var data; + var out; + var A; + + data = NEGATIVE_STRIDES_COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (row-major) (large strides)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_ROW_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the expected zero-based index of the last non-zero row of a matrix (column-major) (large strides)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_COLUMN_MAJOR_DATA; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (row-major) (large strides)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_ROW_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an invalid index (-1) when all elements in a matrix are zero (column-major) (large strides)', function test( t ) { + var data; + var out; + var A; + + data = LARGE_STRIDES_COLUMN_MAJOR_ZEROS; + + A = new Float64Array( data.A ); + out = iladlr( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA ); + + t.deepEqual( out, data.expected, 'returns expected value' ); + t.end(); +});