From cbc4ab89aaa0cac32853d504c15647b2f2b9d13d Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 31 Aug 2024 01:09:12 +0530 Subject: [PATCH 1/6] feat: add base implementation --- .../@stdlib/lapack/base/iladlr/lib/base.js | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js 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 00000000000..6a723d63dc2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var max = require( '@stdlib/math/base/special/fast/max' ); + + +// MAIN // + +/** +* Returns last non-zero row of matrix `A`. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @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 - starting index for `A` +* @returns {integer} index of last non-zero row +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr( 2, 2, A, 2, 1, 0 ); +* // returns 1 +*/ +function iladlr( M, N, A, strideA1, strideA2, offsetA ) { + var out; + var i; + var j; + + if ( M === 0 ) { + return 0; + } + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + if ( A[ offsetA + ( ( M - 1 ) * strideA1 ) ] !== 0.0 || A[ offsetA + ( ( M - 1 ) * strideA1 ) + ( ( N - 1 ) * strideA2 ) ] ) { + return M - 1; + } + // Scan up each column tracking the last zero row seen. + out = -1; + for ( j = 0; j < N; j++ ) { + i = M - 1; + while ( i >= 0 && A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] === 0.0 ) { + i -= 1; + } + out = max( out, i ); + } + return out; + } + // column-major + if ( A[ offsetA + ( ( M - 1 ) * strideA2 ) ] !== 0.0 || A[ offsetA + ( ( M - 1 ) * strideA2 ) + ( ( N - 1 ) * strideA1 ) ] ) { + return M - 1; + } + // Scan up each column tracking the last zero row seen. + out = -1; + for ( j = 0; j < N; j++ ) { + i = M - 1; + while ( i >= 0 && A[ offsetA + ( i * strideA2 ) + ( j * strideA1 ) ] === 0.0 ) { + i -= 1; + } + out = max( out, i ); + } + return out; +} + + +// EXPORTS // + +module.exports = iladlr; From 5c783d7bdc8af11e68861222246a835af1d4a707 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 2 Sep 2024 12:05:20 +0530 Subject: [PATCH 2/6] feat: add lib --- .../@stdlib/lapack/base/iladlr/lib/iladlr.js | 69 +++++++++++++++++++ .../@stdlib/lapack/base/iladlr/lib/main.js | 35 ++++++++++ .../@stdlib/lapack/base/iladlr/lib/ndarray.js | 56 +++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/lib/iladlr.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/lib/ndarray.js 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 00000000000..3c9fa21732e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/iladlr.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns last non-zero row of matrix `A`. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {Float64Array} A - input matrix +* @param {PositiveInteger} 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 +* @returns {integer} index of last non-zero row +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr( 'row-major', 2, 2, A, 2 ); +* // returns 1 +*/ +function iladlr( order, M, N, A, LDA ) { + var sa1; + var sa2; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( order === 'column-major' ) { + 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/main.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js new file mode 100644 index 00000000000..4886cc6bee1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 00000000000..820e85bc14a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/ndarray.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 last non-zero row of matrix `A` using alternative indexing semantics. +* +* @name iladlr +* @type {Function} +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @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 - starting index for `A` +* @throws {TypeError} first argument must be a valid order +* @returns {integer} index of last non-zero row +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr( 2, 2, A, 2, 1, 0 ); +* // returns 1 +*/ +var iladlr = base; + + +// EXPORTS // + +module.exports = iladlr; From b1ffa9b3425d18ee9e2dba4f543cc3dc979a2260 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 2 Sep 2024 13:16:31 +0530 Subject: [PATCH 3/6] docs: add readme --- .../@stdlib/lapack/base/iladlr/README.md | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/README.md 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 00000000000..e8cd6dad4fd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/README.md @@ -0,0 +1,232 @@ + + +# iladlr + +> Return last non-zero row of matrix `A`. + +
+ +## Usage + +```javascript +var iladlr = require( '@stdlib/lapack/base/iladlr' ); +``` + +#### iladlr( order, M, N, A, LDA ) + +Returns last non-zero row of matrix `A`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out; +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +out = iladlr( 'row-major', 2, 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 an array. +var A0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Create offset view. +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = iladlr( 'row-major', 2, 2, A1, 2 ); +// out => 1 +``` + +#### iladlr.ndarray( M, N, A, strideA1, strideA2, offsetA ) + +Returns last non-zero row of matrix `A` using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out; +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +out = iladlr.ndarray( 2, 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]. +- **sa1**: stride of the first dimension of `A`. +- **sa2**: stride of the second dimension of `A`. +- **oa**: starting index for `A`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out; +var A = new Float64Array( [ 4.0, 3.0, 2.0, 4.0 ] ); + +out = iladlr.ndarray( 2, 2, A, -2, -1, 3 ); +// returns 1 +``` + +
+ + + +
+ +## Notes + +- `iladlr()` corresponds to the [LAPACK][lapack] routine [`iladlr`][lapack-iladlr]. + +
+ + + +
+ +## Examples + + + +```javascript +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 ] ); +var out = iladlr( 'row-major', 2, 2, A, 2 ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + From d363531fb809ce3ccd24b385d0264dccafddc49e Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 2 Sep 2024 13:23:05 +0530 Subject: [PATCH 4/6] docs: add repl --- .../@stdlib/lapack/base/iladlr/docs/repl.txt | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/docs/repl.txt 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 00000000000..fc0b937ce7d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/repl.txt @@ -0,0 +1,79 @@ + +{{alias}}( order, M, N, A, LDA ) + Return last non-zero row of matrix `A`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + 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`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + Returns + ------- + out: integer + Index of 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, sa1, sa2, oa ) + Returns last non-zero row of 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. + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Float64Array + Input matrix `A`. + + sa1: integer + Stride of the first dimension of `A`. + + sa2: integer + Stride of the second dimension of `A`. + + oa: integer + Starting index for `A`. + + Returns + ------- + out: integer + Index of 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 + -------- From 45f9026671c7bc623be0c7999e9b7a5c84b77632 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 2 Sep 2024 16:37:45 +0530 Subject: [PATCH 5/6] feat: add other files --- .../@stdlib/lapack/base/iladlr/README.md | 2 +- .../lapack/base/iladlr/benchmark/benchmark.js | 97 ++++++++ .../iladlr/benchmark/benchmark.ndarray.js | 97 ++++++++ .../lapack/base/iladlr/docs/types/index.d.ts | 108 +++++++++ .../lapack/base/iladlr/docs/types/test.ts | 215 ++++++++++++++++++ .../lapack/base/iladlr/examples/index.js | 26 +++ .../@stdlib/lapack/base/iladlr/lib/index.js | 68 ++++++ .../@stdlib/lapack/base/iladlr/package.json | 69 ++++++ .../lapack/base/iladlr/test/test.iladlr.js | 94 ++++++++ .../@stdlib/lapack/base/iladlr/test/test.js | 82 +++++++ .../lapack/base/iladlr/test/test.ndarray.js | 82 +++++++ 11 files changed, 939 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/test/test.iladlr.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/test/test.js create mode 100644 lib/node_modules/@stdlib/lapack/base/iladlr/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/README.md b/lib/node_modules/@stdlib/lapack/base/iladlr/README.md index e8cd6dad4fd..f861b4a3ec2 100644 --- a/lib/node_modules/@stdlib/lapack/base/iladlr/README.md +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/README.md @@ -69,7 +69,7 @@ var out = iladlr( 'row-major', 2, 2, A1, 2 ); // out => 1 ``` -#### iladlr.ndarray( M, N, A, strideA1, strideA2, offsetA ) +#### iladlr.ndarray( M, N, A, sa1, sa2, oa ) Returns last non-zero row of matrix `A` using alternative indexing semantics. 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 00000000000..0a0427b672f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var iladlr = require( './../lib/iladlr.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var A = uniform( len * len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = iladlr( 'row-major', len, len, A, len ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 0.5 ) ); + f = createBenchmark( len ); + bench( pkg+':order=row-major,len='+len, 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 00000000000..7a648a9af37 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/benchmark/benchmark.ndarray.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var iladlr = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var A = uniform( len * len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = iladlr( len, len, A, len, 1, 0 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 0.5 ) ); + f = createBenchmark( len ); + bench( pkg+':ndarray:order=row-major,len='+len, f ); + } +} + +main(); 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 00000000000..bb072eb5fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 last non-zero row of matrix `A`. + * + * @param order - storage layout + * @param M - number of rows + * @param N - number of columns + * @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 last non-zero row + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var out; + * var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * out = iladlr( 'row-major', 2, 2, A, 2 ); + * // returns 1 + */ + ( order: Layout, M: number, N: number, A: Float64Array, LDA: number ): number; + + /** + * Returns last non-zero row of matrix `A` using alternative indexing semantics. + * + * @name iladlr.ndarray + * @type {Function} + * @param M - number of rows + * @param N - number of columns + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @returns index of last non-zero row + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var out; + * var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * out = iladlr.ndarray( 2, 2, A, 2, 1, 0 ); + * // returns 1 + */ + ndarray( M: number, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number ): number; +} + +/** +* Returns last non-zero row of matrix `A`. +* +* @param order - storage layout +* @param M - number of rows +* @param N - number of columns +* @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 last non-zero row +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr( 'row-major', 2, 2, A, 2 ); +* // returns 1 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr.ndarray( 2, 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 00000000000..647ec630184 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/docs/types/test.ts @@ -0,0 +1,215 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array... +{ + const A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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 Float64Array... +{ + const A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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( [ 1.0, 2.0, 3.0, 4.0 ] ); + + 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 00000000000..2f619cab53f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/examples/index.js @@ -0,0 +1,26 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var iladlr = require( './../lib' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var out = iladlr( 'row-major', 2, 2, A, 2 ); +console.log( out ); 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 00000000000..5d85ba84dbd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 return last non-zero row of matrix `A`. +* +* @module @stdlib/lapack/base/iladlr +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var iladlr = require( '@stdlib/lapack/base/iladlr' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr( 'row-major', 2, 2, A, 2 ); +* // returns 1 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var iladlr = require( '@stdlib/lapack/base/iladlr' ); +* +* var out; +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* out = iladlr.ndarray( 2, 2, A, 2, 1, 0 ); +* // 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/package.json b/lib/node_modules/@stdlib/lapack/base/iladlr/package.json new file mode 100644 index 00000000000..7f1cc8a9bd3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/iladlr", + "version": "0.0.0", + "description": "Return last non-zero row of matrix `A`.", + "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", + "triangular", + "matrix", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} 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 00000000000..e01031be311 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.iladlr.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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' ); + + +// 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 an invalid first argument', function test( t ) { + var values; + var A; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + 5, + true, + false + ]; + + A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + 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, 2, 2, A, 2 ); + }; + } +}); + +tape( 'the function correctly determines the last non-zero row of a matrix', function test( t ) { + var out; + var A; + + A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = iladlr( 'row-major', 2, 2, A, 2 ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = iladlr( 'column-major', 2, 2, A, 1 ); + t.strictEqual( out, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function correctly determines the last non-zero row of a matrix', function test( t ) { + var out; + var A; + + A = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 0.0 ] ); + out = iladlr( 'row-major', 2, 3, A, 3 ); + t.strictEqual( out, 0, 'returns expected value' ); + + out = iladlr( 'column-major', 2, 3, A, 1 ); + t.strictEqual( out, 1, '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 00000000000..91d2b8a57e4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 00000000000..b88bf36ef3e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/test/test.ndarray.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/ndarray.js' ); + + +// 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 supports accessing elements from non-contiguous order of row and columns', function test( t ) { + var out; + var A; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 4, 999, 5, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + out = iladlr( 3, 3, A, 12, 2, 7 ); + t.strictEqual( out, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports accessing elements from non-contiguous order of row and columns and in different order', function test( t ) { + var out; + var A; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 4, 999, 5, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 0 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + out = iladlr( 3, 3, A, -12, -2, A.length-1 ); + t.strictEqual( out, 2, 'returns expected value' ); + t.end(); +}); From 00b131a9b552fab00d884f610fce4a8c853e929f Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 2 Sep 2024 16:41:09 +0530 Subject: [PATCH 6/6] refactor: base implementation --- .../@stdlib/lapack/base/iladlr/lib/base.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js index 6a723d63dc2..13320164fc0 100644 --- a/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/iladlr/lib/base.js @@ -49,36 +49,30 @@ var max = require( '@stdlib/math/base/special/fast/max' ); */ function iladlr( M, N, A, strideA1, strideA2, offsetA ) { var out; + var sa0; + var sa1; var i; var j; + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + sa0 = strideA1; + sa1 = strideA2; + } else { + sa0 = strideA2; + sa1 = strideA1; + } + if ( M === 0 ) { return 0; } - if ( isRowMajor( [ strideA1, strideA2 ] ) ) { - if ( A[ offsetA + ( ( M - 1 ) * strideA1 ) ] !== 0.0 || A[ offsetA + ( ( M - 1 ) * strideA1 ) + ( ( N - 1 ) * strideA2 ) ] ) { - return M - 1; - } - // Scan up each column tracking the last zero row seen. - out = -1; - for ( j = 0; j < N; j++ ) { - i = M - 1; - while ( i >= 0 && A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] === 0.0 ) { - i -= 1; - } - out = max( out, i ); - } - return out; - } - // column-major - if ( A[ offsetA + ( ( M - 1 ) * strideA2 ) ] !== 0.0 || A[ offsetA + ( ( M - 1 ) * strideA2 ) + ( ( N - 1 ) * strideA1 ) ] ) { + if ( A[ offsetA + ( ( M - 1 ) * sa0 ) ] !== 0.0 || A[ offsetA + ( ( M - 1 ) * sa0 ) + ( ( N - 1 ) * sa1 ) ] ) { return M - 1; } // Scan up each column tracking the last zero row seen. out = -1; for ( j = 0; j < N; j++ ) { i = M - 1; - while ( i >= 0 && A[ offsetA + ( i * strideA2 ) + ( j * strideA1 ) ] === 0.0 ) { + while ( i >= 0 && A[ offsetA + ( i * sa0 ) + ( j * sa1 ) ] === 0.0 ) { i -= 1; } out = max( out, i );