From 58c8ee6734caac9e203687951ab1fe201b4677e2 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Mon, 5 Aug 2024 21:52:02 +0530 Subject: [PATCH 1/6] feat: init lapack/base/dtrti2 --- .../lapack/base/dtrti2/examples/index.js | 26 ++++ .../@stdlib/lapack/base/dtrti2/lib/base.js | 126 ++++++++++++++++++ .../@stdlib/lapack/base/dtrti2/lib/dtrti2.js | 78 +++++++++++ .../@stdlib/lapack/base/dtrti2/lib/main.js | 35 +++++ .../@stdlib/lapack/base/dtrti2/lib/ndarray.js | 65 +++++++++ 5 files changed, 330 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js new file mode 100644 index 000000000000..1bd31b9b779b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/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 dtrti2 = require( './../lib/base.js' ); + +var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +dtrti2( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +console.log( A ); diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js new file mode 100644 index 000000000000..68247ea71145 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js @@ -0,0 +1,126 @@ +/** +* @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 dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var dtrmv = require( '@stdlib/blas/base/dtrmv' ).ndarray; + + +// MAIN // + +/** +* Computes the inverse of a triangular matrix. +* +* @private +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {string} diag - specifies whether or not `A` is unit triangular +* @param {NonNegativeInteger} N - order of matrix `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 - starting index for `A` +* @returns {Float64Array} output matrix +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +*/ +function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { + var nounit; + var upper; + var ajj; + var j; + + upper = ( uplo === 'upper' ); + nounit = ( diag === 'non-unit' ); + + if ( upper ) { + // Compute inverse of upper triangular matrix + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( j = 0; j < N; j++ ) { + if ( nounit ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; + ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; + } else { + ajj = -1.0; + } + // Compute elements 1:j-1 of j-th column + dtrmv( 'upper', 'no-transpose', diag, j, A, strideA1, strideA2, offsetA, A, strideA1, offsetA + ( j * strideA2 ) ); + dscal( j, ajj, A, strideA1, offsetA + ( j * strideA2 ) ); + } + return A; + } + // column-major + for ( j = 0; j < N; j++ ) { + if ( nounit ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; + } else { + ajj = -1.0; + } + // Compute elements 1:j-1 of j-th column + dtrmv( 'upper', 'transpose', diag, j, A, strideA1, strideA2, offsetA, A, strideA2, offsetA + ( j * strideA1 ) ); + dscal( j, ajj, A, strideA2, offsetA + ( j * strideA1 ) ); + } + return A; + } + // Compute inverse of lower triangular matrix + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( j = N - 1; j >= 0; j-- ) { + if ( nounit ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; + } else { + ajj = -1.0; + } + if ( j < N ) { + // Compute elements j+1:N of j-th column + dtrmv( 'lower', 'no-transpose', diag, N - j + 1, A, strideA1, strideA2, offsetA + ( j * strideA1 ) + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); + dscal( N - j, ajj, A, strideA1, offsetA + ( j * strideA2 ) ); + } + } + return A; + } + // column-major + for ( j = N - 1; j >= 0; j-- ) { + if ( nounit ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; + } else { + ajj = -1.0; + } + if ( j < N ) { + // Compute elements j+1:N of j-th column + dtrmv( 'lower', 'transpose', diag, N - j + 1, A, strideA1, strideA2, offsetA + ( j * strideA1 ) + ( j * strideA2 ), A, strideA2, offsetA + ( j * strideA1 ) ); + dscal( N - j, ajj, A, strideA2, offsetA + ( j * strideA1 ) ); + } + } + return A; +} + + +// EXPORTS // + +module.exports = dtrti2; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js new file mode 100644 index 000000000000..8ee7cb7698d2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js @@ -0,0 +1,78 @@ +/** +* @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 isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); +var isDiagonalType = require( '@stdlib/blas/base/assert/is-diagonal-type' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the inverse of a triangular matrix. +* +* @param {string} order - storage layout +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {string} diag - specifies whether or not `A` is unit triangular +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} A - input matrix +* @param {NonNegativeInteger} 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 {TypeError} second argument must specify whether the lower or upper triangular matrix is supplied +* @throws {TypeError} third argument must specify whether the matrix is unit triangular or not +* @returns {Float64Array} output matrix +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +*/ +function dtrti2( order, uplo, diag, 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 ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( !isDiagonalType( diag ) ) { + throw new TypeError( format( 'invalid argument. Third argument must specify whether the matrix is unit triangular or not. Value: `%s`.', diag ) ); + } + if ( order === 'column-major' ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return base( uplo, diag, N, A, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = dtrti2; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js new file mode 100644 index 000000000000..513c508b0973 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/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 dtrti2 = require( './dtrti2.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dtrti2, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dtrti2; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js new file mode 100644 index 000000000000..d6307144cae6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js @@ -0,0 +1,65 @@ +/** +* @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 isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); +var isDiagonalType = require( '@stdlib/blas/base/assert/is-diagonal-type' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the inverse of a triangular matrix using alternative indexing semantics. +* +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {string} diag - specifies whether or not `A` is unit triangular +* @param {NonNegativeInteger} N - order of matrix `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 - starting index for `A` +* @throws {TypeError} first argument must specify whether the lower or upper triangular matrix is supplied +* @throws {TypeError} second argument must specify whether the matrix is unit triangular or not +* @returns {Float64Array} output matrix +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +*/ +function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. First argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( !isDiagonalType( diag ) ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the matrix is unit triangular or not. Value: `%s`.', diag ) ); + } + return base( uplo, diag, N, A, strideA1, strideA2, offsetA ); +} + + +// EXPORTS // + +module.exports = dtrti2; From 6b22155a5e7db15fef3df38848b02042509c7275 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 6 Aug 2024 21:16:22 +0530 Subject: [PATCH 2/6] docs: add README.md --- .../@stdlib/lapack/base/dtrti2/README.md | 229 ++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/README.md diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md new file mode 100644 index 000000000000..d45dc037a78e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md @@ -0,0 +1,229 @@ + + +# dtrti2 + +> Computes the inverse of a triangular matrix. + +
+ +## Usage + +```javascript +var dtrti2 = require( '@stdlib/lapack/base/dtrti2' ); +``` + +#### dtrti2( order, uplo, diag, N, A, LDA ) + +Computes the inverse of a triangular matrix. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); +// A => [ 1.0, -0.5, 0.0, 0.25 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of a matrix `A`. +- **diag**: specifies whether or not `A` is unit triangular. +- **N**: order of matrix `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 arrays... +var A0 = new Float64Array( [ 0.0, 1.0, 2.0, 0.0, 4.0 ] ); + +// Create offset views... +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dtrti2( 'row-major', 'upper', 'non-unit', 2, A1, 2 ); +// A0 => [ 0.0, 1.0, -0.5, 0.0, 0.25 ] +``` + +#### dtrti2.ndarray( uplo, diag, N, A, strideA1, strideA2, offsetA ) + +Computes the inverse of a triangular matrix using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +// A => [ 1.0, -0.5, 0.0, 0.25 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of a matrix `A`. +- **diag**: specifies whether or not `A` is unit triangular. +- **N**: order of matrix `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 A = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 0.0, 4.0 ] ); +dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 2 ); +// A => [ 0.0, 0.0, 1.0, -0.5, 0.0, 0.25 ] +``` + +
+ + + +
+ +## Notes + +- `dtrti2()` corresponds to the [LAPACK][lapack] routine [`dtrti2`][lapack-dtrti2]. + +
+ + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var dtrti2 = require( '@stdlib/lapack/base/dtrti2' ); + +var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); +console.log( A ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + From ffbdb88063595b2d3e9088e6b4dcc25a64fe75dc Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 6 Aug 2024 21:21:37 +0530 Subject: [PATCH 3/6] chore: add other files --- .../@stdlib/lapack/base/dtrti2/README.md | 2 +- .../lapack/base/dtrti2/benchmark/benchmark.js | 97 +++++++ .../dtrti2/benchmark/benchmark.ndarray.js | 97 +++++++ .../@stdlib/lapack/base/dtrti2/docs/repl.txt | 87 ++++++ .../lapack/base/dtrti2/docs/types/index.d.ts | 101 +++++++ .../lapack/base/dtrti2/docs/types/test.ts | 245 ++++++++++++++++ .../lapack/base/dtrti2/examples/index.js | 4 +- .../@stdlib/lapack/base/dtrti2/lib/base.js | 22 +- .../@stdlib/lapack/base/dtrti2/lib/index.js | 64 +++++ .../@stdlib/lapack/base/dtrti2/package.json | 70 +++++ .../lapack/base/dtrti2/test/test.dtrti2.js | 261 ++++++++++++++++++ .../@stdlib/lapack/base/dtrti2/test/test.js | 82 ++++++ .../lapack/base/dtrti2/test/test.ndarray.js | 194 +++++++++++++ 13 files changed, 1312 insertions(+), 14 deletions(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md index d45dc037a78e..03102c0daa5a 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md @@ -20,7 +20,7 @@ limitations under the License. # dtrti2 -> Computes the inverse of a triangular matrix. +> Compute the inverse of a triangular matrix.
diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js new file mode 100644 index 000000000000..b72256729cea --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/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 dtrti2 = require( './../lib/dtrti2.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 x = 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 = dtrti2( 'row-major', 'upper', 'non-unit', len, x, len ); + if ( isnan( out[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 1 ] ) ) { + 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/dtrti2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..141d9890c987 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/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 dtrti2 = 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 x = 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 = dtrti2( 'upper', 'non-unit', len, x, len, 1, 0 ); + if ( isnan( out[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 1 ] ) ) { + 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/dtrti2/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/repl.txt new file mode 100644 index 000000000000..3585512d0509 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/repl.txt @@ -0,0 +1,87 @@ + +{{alias}}( order, uplo, diag, N, A, LDA ) + Computes the inverse of a triangular matrix. + + 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'. + + uplo: string + Specifies whether to copy the upper or lower triangular/trapezoidal part + of a matrix `A`. + + diag: string + Specifies whether or not `A` is unit triangular. + + N: integer + Order of the matrix `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 + ------- + A: Float64Array + Output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 0.0, 4.0 ] ); + > {{alias}}( 'row-major', 'upper', 'non-unit', 2, A, 2 ) + [ 1.0, -0.5, 0.0, 0.25 ] + + +{{alias}}.ndarray( uplo, diag, N, A, strideA1, strideA2, offsetA ) + Computes the inverse of a triangular matrix 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 + ---------- + uplo: string + Specifies whether to copy the upper or lower triangular/trapezoidal part + of a matrix `A`. + + diag: string + Specifies whether or not `A` is unit triangular. + + N: integer + Order of the matrix `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 + ------- + A: Float64Array + Output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 0.0, 4.0 ] ); + > {{alias}}.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 1 ) + [ 0.0, 1.0, -0.5, 0.0, 0.25 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts new file mode 100644 index 000000000000..bc3bd882a897 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts @@ -0,0 +1,101 @@ +/** +* @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, MatrixTriangle, DiagonalType } from '@stdlib/types/blas'; + +/** +* Interface describing `dtrti2`. +*/ +interface Routine { + /** + * Computes the inverse of a triangular matrix. + * + * @param order - storage layout + * @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` + * @param diag - specifies whether or not `A` is unit triangular + * @param N - order of matrix `A` + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @returns output matrix + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + * dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); + * // A => [ 1.0, -0.5, 0.0, 0.25 ] + */ + ( order: Layout, uplo: MatrixTriangle, diag: DiagonalType, N: number, A: Float64Array, LDA: number ): Float64Array; + + /** + * Computes the inverse of a triangular matrix using alternative indexing semantics. + * + * @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` + * @param diag - specifies whether or not `A` is unit triangular + * @param N - order of matrix `A` + * @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 output matrix + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + * dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0 ); + * // A => [ 1.0, -0.5, 0.0, 0.25 ] + */ + ndarray( uplo: MatrixTriangle, diag: DiagonalType, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number ): Float64Array; +} + +/** +* Computes the inverse of a triangular matrix. +* +* @param order - storage layout +* @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param diag - specifies whether or not `A` is unit triangular +* @param N - order of matrix `A` +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @returns output matrix +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +*/ +declare var dtrti2: Routine; + + +// EXPORTS // + +export = dtrti2; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts new file mode 100644 index 000000000000..77fd81404d07 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts @@ -0,0 +1,245 @@ +/* +* @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 dtrti2 = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); // $ExpectType Float64Array +} + +// 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, 0.0, 4.0 ] ); + + dtrti2( 5, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( true, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( false, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( null, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( void 0, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( [], 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( {}, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( ( x: number ): number => x, 'upper', 'non-unit', 2, A, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + dtrti2( 'row-major', 5, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', true, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', false, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', null, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', void 0, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', [], 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', {}, 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', ( x: number ): number => x, 'non-unit', 2, A, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a string... +{ + const A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + dtrti2( 'row-major', 'upper', 5, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', true, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', false, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', null, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', void 0, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', [], 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', {}, 2, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', ( x: number ): number => x, 2, A, 2 ); // $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, 0.0, 4.0 ] ); + + dtrti2( 'row-major', 'upper', 'non-unit', '5', A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', true, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', false, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', null, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', void 0, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', [], A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', {}, A, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', ( x: number ): number => x, A, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + + dtrti2( 'row-major', 'upper', 'non-unit', 2, '5', 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, 5, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, true, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, false, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, null, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, void 0, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, [], 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, {}, 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, ( x: number ): number => x, 2 ); // $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, 0.0, 4.0 ] ); + + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, '5' ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, true ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, false ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, null ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, void 0 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, [] ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A, {} ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 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, 0.0, 4.0 ] ); + + dtrti2(); // $ExpectError + dtrti2( 'row-major' ); // $ExpectError + dtrti2( 'row-major', 'upper' ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit' ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2 ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 2, A ); // $ExpectError + dtrti2( 'row-major', 'upper', 'non-unit', 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, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0 ); // $ExpectType Float64Array +} + +// 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, 0.0, 4.0 ] ); + + dtrti2.ndarray( 5, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( true, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( false, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( null, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( void 0, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( [], 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( {}, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( ( x: number ): number => x, 'non-unit', 2, A, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 5, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', true, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', false, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', null, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', void 0, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', [], 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', {}, 2, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', ( x: number ): number => x, 2, A, 2, 1, 0 ); // $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, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 'non-unit', '5', A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', true, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', false, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', null, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', void 0, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', [], A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', {}, A, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', ( x: number ): number => x, A, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + + dtrti2.ndarray( 'upper', 'non-unit', 2, '5', 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, 5, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, true, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, false, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, null, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, void 0, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, [], 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, {}, 2, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, ( x: number ): number => x, 2, 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, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 'non-unit', 2, A, '5', 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, true, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, false, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, null, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, void 0, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, [], 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, {}, 1, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, ( x: number ): number => x, 1, 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, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, '5', 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, true, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, false, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, null, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, void 0, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, [], 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, {}, 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, '5' ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, true ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, false ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, null ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, void 0 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, [] ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, {} ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 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, 0.0, 4.0 ] ); + + dtrti2.ndarray(); // $ExpectError + dtrti2.ndarray( 'upper' ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit' ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1 ); // $ExpectError + dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js index 1bd31b9b779b..5f058f7275a4 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js @@ -19,8 +19,8 @@ 'use strict'; var Float64Array = require( '@stdlib/array/float64' ); -var dtrti2 = require( './../lib/base.js' ); +var dtrti2 = require( './../lib' ); var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); -dtrti2( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); console.log( A ); diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js index 68247ea71145..950908404a4c 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js @@ -75,14 +75,14 @@ function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { // column-major for ( j = 0; j < N; j++ ) { if ( nounit ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; } else { ajj = -1.0; } // Compute elements 1:j-1 of j-th column - dtrmv( 'upper', 'transpose', diag, j, A, strideA1, strideA2, offsetA, A, strideA2, offsetA + ( j * strideA1 ) ); - dscal( j, ajj, A, strideA2, offsetA + ( j * strideA1 ) ); + dtrmv( 'upper', 'no-transpose', diag, j, A, strideA1, strideA2, offsetA, A, strideA1, offsetA + ( j * strideA2 ) ); + dscal( j, ajj, A, strideA1, offsetA + ( j * strideA2 ) ); } return A; } @@ -90,15 +90,15 @@ function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { if ( isRowMajor( [ strideA1, strideA2 ] ) ) { for ( j = N - 1; j >= 0; j-- ) { if ( nounit ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; } else { ajj = -1.0; } - if ( j < N ) { + if ( j < N - 1 ) { // Compute elements j+1:N of j-th column - dtrmv( 'lower', 'no-transpose', diag, N - j + 1, A, strideA1, strideA2, offsetA + ( j * strideA1 ) + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); - dscal( N - j, ajj, A, strideA1, offsetA + ( j * strideA2 ) ); + dtrmv( 'lower', 'no-transpose', diag, N - j - 1, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA1 ) + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + dscal( N - j - 1, ajj, A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); } } return A; @@ -106,15 +106,15 @@ function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { // column-major for ( j = N - 1; j >= 0; j-- ) { if ( nounit ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] /= 1.0; + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; } else { ajj = -1.0; } - if ( j < N ) { + if ( j < N - 1 ) { // Compute elements j+1:N of j-th column - dtrmv( 'lower', 'transpose', diag, N - j + 1, A, strideA1, strideA2, offsetA + ( j * strideA1 ) + ( j * strideA2 ), A, strideA2, offsetA + ( j * strideA1 ) ); - dscal( N - j, ajj, A, strideA2, offsetA + ( j * strideA1 ) ); + dtrmv( 'lower', 'no-transpose', diag, N - j - 1, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA1 ) + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + dscal( N - j - 1, ajj, A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); } } return A; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js new file mode 100644 index 000000000000..13514522f0ce --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js @@ -0,0 +1,64 @@ +/** +* @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 compute the inverse of a triangular matrix. +* +* @module @stdlib/lapack/base/dtrti2 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dtrti2 = require( '@stdlib/lapack/base/dtrti2' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dtrti2 = require( '@stdlib/lapack/base/dtrti2' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); +* dtrti2.ndarray( 'upper', 'non-unit', 2, A, 2, 1, 0 ); +* // A => [ 1.0, -0.5, 0.0, 0.25 ] +*/ + +// 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 dtrti2; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dtrti2 = main; +} else { + dtrti2 = tmp; +} + + +// EXPORTS // + +module.exports = dtrti2; diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/package.json b/lib/node_modules/@stdlib/lapack/base/dtrti2/package.json new file mode 100644 index 000000000000..1fb867224ecf --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/lapack/base/dtrti2", + "version": "0.0.0", + "description": "Compute the inverse of a triangular 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", + "dtrti2", + "inverse", + "triangular", + "matrix", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js new file mode 100644 index 000000000000..3ab2d00d9573 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js @@ -0,0 +1,261 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dtrti2 = require( './../lib/dtrti2.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dtrti2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dtrti2.length, 6, '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() { + dtrti2( value, 'upper', 'non-unit', 2, A, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second 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() { + dtrti2( 'row-major', value, 'non-unit', 2, A, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third 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() { + dtrti2( 'row-major', 'upper', value, 2, A, 2 ); + }; + } +}); + +tape( 'the function correctly computes inverse of upper triangular non-unit matrix ( row-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + expected = new Float64Array( [ 1, -0.5, 0, 0.25 ] ); + out = dtrti2( 'row-major', 'upper', 'non-unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of lower triangular non-unit rectangular matrix ( row-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 2.0, 4.0 ] ); + expected = new Float64Array( [ 1, 0.0, -0.5, 0.25 ] ); + out = dtrti2( 'row-major', 'lower', 'non-unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of lower triangular non-unit matrix ( column-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + expected = new Float64Array( [ 1, -0.5, 0.0, 0.25 ] ); + out = dtrti2( 'column-major', 'lower', 'non-unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of upper triangular non-unit matrix ( column-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 2.0, 4.0 ] ); + expected = new Float64Array( [ 1, 0.0, -0.5, 0.25 ] ); + out = dtrti2( 'column-major', 'upper', 'non-unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of upper triangular unit matrix ( column-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1, 0.0, -2.0, 1.0 ] ); + out = dtrti2( 'column-major', 'upper', 'unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of lower triangular unit matrix ( column-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 2.0, 0.0, 1.0 ] ); + expected = new Float64Array( [ 1, -2.0, 0.0, 1.0 ] ); + out = dtrti2( 'column-major', 'lower', 'unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of upper triangular unit matrix ( row-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 2.0, 0.0, 1.0 ] ); + expected = new Float64Array( [ 1, -2.0, 0.0, 1.0 ] ); + out = dtrti2( 'row-major', 'upper', 'unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function correctly computes inverse of lower triangular unit matrix ( row-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1, 0.0, -2.0, 1.0 ] ); + out = dtrti2( 'row-major', 'lower', 'unit', 2, A, 2 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js new file mode 100644 index 000000000000..b164d664035e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/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 dtrti2 = 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 dtrti2, '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 dtrti2.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 dtrti2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dtrti2, 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 dtrti2; + var main; + + main = require( './../lib/dtrti2.js' ); + + dtrti2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dtrti2, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js new file mode 100644 index 000000000000..71a40dbf3ffb --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js @@ -0,0 +1,194 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dtrti2 = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dtrti2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( dtrti2.length, 7, '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() { + dtrti2( value, 'non-unit', 2, A, 2, 1, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second 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() { + dtrti2( 'upper', value, 2, A, 2, 1, 0 ); + }; + } +}); + +tape( 'the function supports accessing elements from non-contiguous alignment of row and column ( row-major )', function test( t ) { + var expected; + 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, 4, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 4, 999, 2, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 4, + 999, 999, 999, 999, 999, 999 + ]); + + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, -0.5, 999, -0.75, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0.25, 999, -0.125, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 0.25, + 999, 999, 999, 999, 999, 999 + ]); + + out = dtrti2( 'upper', 'non-unit', 3, A, 12, 2, 7 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function supports accessing elements from non-contiguous alignment of row and column in reverse order ( row-major )', function test( t ) { + var expected; + var out; + var A; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 4, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 2, 999, 4, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 4, 999, 2, 999, 1, + 999, 999, 999, 999, 999, 999 + ]); + + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 0.25, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, -0.125, 999, 0.25, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, -0.75, 999, -0.5, 999, 1, + 999, 999, 999, 999, 999, 999 + ]); + + out = dtrti2( 'upper', 'non-unit', 3, A, -12, -2, 35); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); From 7cdd8c536818a64a6ba468c189a1337dec93198c Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 6 Aug 2024 21:28:09 +0530 Subject: [PATCH 4/6] refactor: base implementation --- .../@stdlib/lapack/base/dtrti2/lib/base.js | 41 ++++--------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js index 950908404a4c..4b8c5bb758e8 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js @@ -51,28 +51,20 @@ function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { var nounit; var upper; var ajj; + var tmp; var j; upper = ( uplo === 'upper' ); nounit = ( diag === 'non-unit' ); + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + upper = !upper; + tmp = strideA1; + strideA1 = strideA2; + strideA2 = tmp; + } + if ( upper ) { - // Compute inverse of upper triangular matrix - if ( isRowMajor( [ strideA1, strideA2 ] ) ) { - for ( j = 0; j < N; j++ ) { - if ( nounit ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; - ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; - } else { - ajj = -1.0; - } - // Compute elements 1:j-1 of j-th column - dtrmv( 'upper', 'no-transpose', diag, j, A, strideA1, strideA2, offsetA, A, strideA1, offsetA + ( j * strideA2 ) ); - dscal( j, ajj, A, strideA1, offsetA + ( j * strideA2 ) ); - } - return A; - } - // column-major for ( j = 0; j < N; j++ ) { if ( nounit ) { A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; @@ -87,23 +79,6 @@ function dtrti2( uplo, diag, N, A, strideA1, strideA2, offsetA ) { return A; } // Compute inverse of lower triangular matrix - if ( isRowMajor( [ strideA1, strideA2 ] ) ) { - for ( j = N - 1; j >= 0; j-- ) { - if ( nounit ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; - ajj = -A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; - } else { - ajj = -1.0; - } - if ( j < N - 1 ) { - // Compute elements j+1:N of j-th column - dtrmv( 'lower', 'no-transpose', diag, N - j - 1, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA1 ) + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); - dscal( N - j - 1, ajj, A, strideA1, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); - } - } - return A; - } - // column-major for ( j = N - 1; j >= 0; j-- ) { if ( nounit ) { A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = 1.0 / A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ]; From 3ede852dd1628fa48f2aab9a5f003b3e0bad9e37 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Wed, 7 Aug 2024 16:23:29 +0530 Subject: [PATCH 5/6] bench: check nan for other out values --- .../@stdlib/lapack/base/dtrti2/benchmark/benchmark.js | 4 ++-- .../@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js index b72256729cea..bb97333dd959 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js @@ -56,12 +56,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { out = dtrti2( 'row-major', 'upper', 'non-unit', len, x, len ); - if ( isnan( out[ 0 ] ) ) { + if ( isnan( out[ i%out.length ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( out[ 1 ] ) ) { + if ( isnan( out[ i%out.length ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js index 141d9890c987..cf0b3906c351 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js @@ -56,12 +56,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { out = dtrti2( 'upper', 'non-unit', len, x, len, 1, 0 ); - if ( isnan( out[ 0 ] ) ) { + if ( isnan( out[ i%out.length ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( out[ 1 ] ) ) { + if ( isnan( out[ i%out.length ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From 1424e5dbd420a681902e1619c58754c01c35a83d Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 14 Jan 2025 19:06:40 +0000 Subject: [PATCH 6/6] chore: update copyright years --- lib/node_modules/@stdlib/lapack/base/dtrti2/README.md | 2 +- .../@stdlib/lapack/base/dtrti2/benchmark/benchmark.js | 2 +- .../@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js | 2 +- .../@stdlib/lapack/base/dtrti2/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js | 2 +- lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js | 2 +- .../@stdlib/lapack/base/dtrti2/test/test.ndarray.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md index 03102c0daa5a..dd871e93e66e 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js index bb97333dd959..cf7125bbecf9 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js index cf0b3906c351..5c6e7c8407a2 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts index bc3bd882a897..a400d0f6a07d 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/index.d.ts @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts index 77fd81404d07..5b3221e9df0a 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js index 5f058f7275a4..bfb48d269425 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js index 4b8c5bb758e8..95df07cbf123 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/base.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js index 8ee7cb7698d2..c37ceb904483 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/dtrti2.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js index 13514522f0ce..85866491f338 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js index 513c508b0973..ccb4d6607a8f 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js index d6307144cae6..9492436ebda9 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js index 3ab2d00d9573..39cb08c535db 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.dtrti2.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js index b164d664035e..04188310174a 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js index 71a40dbf3ffb..08236fdc352b 100644 --- a/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dtrti2/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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.