From abea099a24ca79a46156309148f1db4356185f71 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 11:59:13 +0530 Subject: [PATCH 1/7] feat: init lapack/base/dpotf2 --- .../lapack/base/dpotf2/examples/index.js | 28 ++++ .../@stdlib/lapack/base/dpotf2/lib/base.js | 147 ++++++++++++++++++ .../@stdlib/lapack/base/dpotf2/lib/dpotf2.js | 74 +++++++++ .../@stdlib/lapack/base/dpotf2/lib/main.js | 35 +++++ .../@stdlib/lapack/base/dpotf2/lib/ndarray.js | 61 ++++++++ 5 files changed, 345 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js new file mode 100644 index 000000000000..3163c2bb5cc6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js @@ -0,0 +1,28 @@ +/** +* @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 dpotf2 = require( './../lib/base.js' ); + +var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + +var out = dpotf2( 'upper', 2, A, 2, 1, 0 ); +console.log( A ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js new file mode 100644 index 000000000000..ce0ea8cb3748 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js @@ -0,0 +1,147 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var dgemv = require( '@stdlib/blas/base/dgemv' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; + + +// MAIN // + +/** +* Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. +* +* @private +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} A - input symmetric positive definite 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} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2( 'upper', 2, A, 2, 1, 0 ); +* // returns 0 +*/ +function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { + var upper; + var ajj; + var j; + + upper = ( uplo === 'upper' ); + + if ( N === 0 ) { + return 0; + } + if ( upper ) { + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + // Compute the Cholesky factorization A = U^T*U. + for ( j = 0; j < N; j++ ) { + // Compute U( j, j ) and test for non-positive-definiteness... + ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA1, offsetA + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); + if ( ajj <= 0.0 || isnan( ajj ) ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; + return j; + } + ajj = sqrt( ajj ); + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; + + // Compute elements j+1:N of row j... + if ( j < N - 1 ) { + dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ), 1.0, A, strideA1, offsetA + ( j * strideA1 ) + ( ( j + 1 ) * strideA2 ) ); + dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( j * strideA1 ) + ( ( j + 1 ) * strideA2 ) ); + } + } + return 0; + } + // column-major + for ( j = 0; j < N; j++ ) { + // Compute U( j, j ) and test for non-positive-definiteness... + ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, strideA1, offsetA + ( j * strideA1 ), A, strideA2, strideA1, offsetA + ( j * strideA1 ) ); + if ( ajj <= 0.0 || isnan( ajj ) ) { + A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + return j; + } + ajj = sqrt( ajj ); + A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + + // Compute elements j+1:N of row j... + if ( j < N - 1 ) { + dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA2, strideA1, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ), 1.0, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + dscal( N - j - 1, 1.0 / ajj, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + } + } + return 0; + } + // Lower + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + // Compute the Cholesky factorization A = L*L^T. + for ( j = 0; j < N; j++ ) { + // Compute L( j, j ) and test for non-positive-definiteness... + ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA1, strideA2, offsetA + ( j * strideA1 ), A, strideA1, strideA2, offsetA + ( j * strideA1 ) ); + if ( ajj <= 0.0 || isnan( ajj ) ) { + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; + return j; + } + ajj = sqrt( ajj ); + A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; + + // Compute elements j+1:N of column j... + if ( j < N - 1 ) { + dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA1 ), 1.0, A, strideA1, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ) ); + dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ) ); + } + } + return 0; + } + // column-major + for ( j = 0; j < N; j++ ) { + // Compute L( j, j ) and test for non-positive-definiteness... + ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, strideA1, offsetA + ( j * strideA2 ), A, strideA2, strideA1, offsetA + ( j * strideA2 ) ); + if ( ajj <= 0.0 || isnan( ajj ) ) { + A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + return j; + } + ajj = sqrt( ajj ); + A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + + // Compute elements j+1:N of column j... + if ( j < N - 1 ) { + dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA2, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA2 ), 1.0, A, strideA2, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); + dscal( N - j - 1, 1.0 / ajj, A, strideA2, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); + } + } + return 0; +} + + +// EXPORTS // + +module.exports = dpotf2; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js new file mode 100644 index 000000000000..c034603777bd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js @@ -0,0 +1,74 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} A - input symmetric positive definite 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 +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); +* // returns 0 +*/ +function dpotf2( order, uplo, 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 ( order === 'column-major' ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return base( uplo, N, A, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = dpotf2; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/main.js new file mode 100644 index 000000000000..ebdfe7931bb1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/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 dpotf2 = require( './dpotf2.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dpotf2, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dpotf2; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js new file mode 100644 index 000000000000..ce52b26eb8f8 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js @@ -0,0 +1,61 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the Cholesky factorization of a real symmetric positive definite matrix `A`using alternative semantic indexing. +* +* @private +* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} A - input symmetric positive definite 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} frist argument must specify whether the lower or upper triangular matrix is supplied +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2( 'upper', 2, A, 2, 1, 0 ); +* // returns 0 +*/ +function dpotf2( uplo, 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 ) ); + } + return base( uplo, N, A, strideA1, strideA2, offsetA ); +} + + +// EXPORTS // + +module.exports = dpotf2; From 492b381c04ceb7addf1fc880a9de768f1567ec01 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 11:59:53 +0530 Subject: [PATCH 2/7] fix: spelling mistakes --- lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js index ce52b26eb8f8..c9b36b9739f8 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js @@ -37,7 +37,7 @@ var base = require( './base.js' ); * @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} frist argument must specify whether the lower or upper triangular matrix is supplied +* @throws {TypeError} first argument must specify whether the lower or upper triangular matrix is supplied * @returns {integer} status code * * @example From 11f180ef054b23bbd77f1566d834f0d2c6110207 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 13:27:32 +0530 Subject: [PATCH 3/7] docs: add readme --- .../@stdlib/lapack/base/dpotf2/README.md | 242 ++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/README.md diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md b/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md new file mode 100644 index 000000000000..2e58bcce9f46 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md @@ -0,0 +1,242 @@ + + +# dpotf2 + +> Compute the Cholesky factorization of a real symmetric positive definite matrix `A`. + +
+ +## Usage + +```javascript +var dpotf2 = require( '@stdlib/lapack/base/dpotf2' ); +``` + +#### dpotf2( order, uplo, N, A, LDA ) + +Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + +var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); +// returns 0 +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A`. +- **N**: order of matrix `A`. +- **A**: input symmetric positive definite [`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, 0.0, 0.0, 4.0 ] ); + +// Create offset views... +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = dpotf2( 'row-major', 'upper', 2, A1, 2 ); +// returns 0 +``` + +#### dpotf2.ndarray( uplo, N, A, strideA1, strideA2, offsetA ) + +Computes the Cholesky factorization of a real symmetric positive definite matrix `A` using alternative semantic indexing. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + +var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0 ); +// returns 0 +``` + +The function has the following parameters: + +- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A`. +- **N**: order of matrix `A`. +- **A**: input symmetric positive definite [`Float64Array`][mdn-float64array]. +- **strideA1**: stride of the first dimension of `A`. +- **strideA2**: stride of the second dimension of `A`. +- **offsetA**: starting index for `A`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 4.0 ] ); + +var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0, 1 ); +// returns 0 +``` + +
+ + + +
+ +## Notes + +- Both functions mutate the input array `A`. + +- Both functions return a status code indicating success or failure. A status code indicates the following conditions: + + - `0`: factorization was successful. + - `<0`: the k-th argument had an illegal value, where `-k` equals the status code value. + - `0 < k < N`: the leading principal minor of order `k` is not positive and factorization could not be completed, where `k` equals the status code value. + - `N`: the leading principal minor of order `N` is not positive, and factorization was completed. + +- `dpotf2()` corresponds to the [LAPACK][LAPACK] routine [`dpotf2`][lapack-dpotf2]. + +
+ + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var dpotf2 = require( '@stdlib/lapack/base/dpotf2' ); + +var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + +var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); +console.log( A ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + From 1cc9d4e15ca7ef8dda245031e3ae3baf4dca9ce5 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 13:40:59 +0530 Subject: [PATCH 4/7] docs: add repl --- .../@stdlib/lapack/base/dpotf2/docs/repl.txt | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/docs/repl.txt diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/repl.txt new file mode 100644 index 000000000000..a3025e953d2f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/repl.txt @@ -0,0 +1,108 @@ + +{{alias}}( order, uplo, N, A, LDA ) + Computes the Cholesky factorization of a real symmetric positive definite + matrix `A`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + The function mutates `A`. + + 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`. + + N: integer + Order of 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 + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if less than zero, then the k-th argument had an illegal value, where + `k = -info`. + - if greater than zero, then the leading principal minor of order `k` is + not positive, where `k = info`. If `k < N`, then the factorization + could not be completed. If `k = N`, then the factorization was + completed, but `D(N) <= 0`, meaning that the matrix `A` is not + positive definite. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 0.0, 0.0, 4.0 ] ); + > {{alias}}( 'row-major', 'upper', 2, A, 2 ) + 0 + > A + [ 1.0, 0.0, 0.0, 2.0 ] + + +{{alias}}.ndarray( uplo, N, A, strideA1, strideA2, offsetA ) + Computes the Cholesky factorization of a real symmetric positive definite + matrix `A` using alternative semantic indexing. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + The function mutates `A`. + + Parameters + ---------- + uplo: string + Specifies whether to copy the upper or lower triangular/trapezoidal part + of a matrix `A`. + + N: integer + Number of columns in `A`. + + A: Float64Array + Input matrix `A`. + + strideA1: integer + Stride length for the first dimension of `A`. + + strideA2: integer + Stride length for the second dimension of `A`. + + offsetA: integer + Index offset for the first element in `A`. + + Returns + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if less than zero, then the k-th argument had an illegal value, where + `k = -info`. + - if greater than zero, then the leading principal minor of order `k` is + not positive, where `k = info`. If `k < N`, then the factorization + could not be completed. If `k = N`, then the factorization was + completed, but `D(N) <= 0`, meaning that the matrix `A` is not + positive definite. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 0.0, 0.0, 4.0 ] ); + > {{alias}}.ndarray( 'upper', 2, A, 2, 1, 1 ) + 0 + > A + [ 0.0, 1.0, 0.0, 0.0, 2.0 ] + + See Also + -------- From 33eefa9a1441b86f151c1e238ffedad98d7b92b5 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 13:41:55 +0530 Subject: [PATCH 5/7] chore: add other files --- .../@stdlib/lapack/base/dpotf2/README.md | 2 +- .../lapack/base/dpotf2/benchmark/benchmark.js | 96 ++++++++ .../dpotf2/benchmark/benchmark.ndarray.js | 96 ++++++++ .../lapack/base/dpotf2/docs/types/index.d.ts | 115 ++++++++++ .../lapack/base/dpotf2/docs/types/test.ts | 215 ++++++++++++++++++ .../lapack/base/dpotf2/examples/index.js | 4 +- .../@stdlib/lapack/base/dpotf2/lib/base.js | 14 +- .../@stdlib/lapack/base/dpotf2/lib/index.js | 67 ++++++ .../@stdlib/lapack/base/dpotf2/lib/ndarray.js | 2 +- .../@stdlib/lapack/base/dpotf2/package.json | 71 ++++++ .../lapack/base/dpotf2/test/test.dpotf2.js | 178 +++++++++++++++ .../@stdlib/lapack/base/dpotf2/test/test.js | 83 +++++++ .../lapack/base/dpotf2/test/test.ndarray.js | 196 ++++++++++++++++ 13 files changed, 1128 insertions(+), 11 deletions(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.dpotf2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md b/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md index 2e58bcce9f46..2a1f209360e1 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/README.md @@ -99,7 +99,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var A = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 4.0 ] ); -var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0, 1 ); +var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 1 ); // returns 0 ``` diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js new file mode 100644 index 000000000000..39bff2ec4b8b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dpotf2 = require( './../lib/dpotf2.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, 1.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dpotf2( 'row-major', 'upper', len, A, len ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + 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 = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..922fd5ab8df6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dpotf2 = 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, 1.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dpotf2( 'upper', len, A, len, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + 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 = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/index.d.ts new file mode 100644 index 000000000000..52f1c7ca8c57 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/index.d.ts @@ -0,0 +1,115 @@ +/** +* @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 } from '@stdlib/types/blas'; + +/** +* Status code. +* +* ## Notes +* +* The status code indicates the following conditions: +* +* - if equal to zero, then the factorization was successful. +* - if less than zero, then the k-th argument had an illegal value, where `k = -StatusCode`. +* - if greater than zero, then the leading principal minor of order `k` is not positive, where `k = StatusCode`. If `k < N`, then the factorization could not be completed. If `k = N`, then the factorization was completed, but `D(N) <= 0`, meaning that the matrix `A` is not positive definite. +*/ +type StatusCode = number; + +/** +* Interface describing `dpotf2`. +*/ +interface Routine { + /** + * Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. + * + * @param order - storage layout + * @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` + * @param N - order of matrix `A` + * @param A - input symmetric positive definite matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + * + * var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); + * // returns 0 + */ + ( order: Layout, uplo: MatrixTriangle, N: number, A: Float64Array, LDA: number ): StatusCode; + + /** + * Computes the Cholesky factorization of a real symmetric positive definite matrix `A` using alternative semantic indexing. + * + * @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` + * @param N - order of matrix `A` + * @param A - input symmetric positive definite 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 status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + * + * var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0 ); + * // returns 0 + */ + ndarray( uplo: MatrixTriangle, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number ): StatusCode; +} + +/** +* Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. +* +* @param order - storage layout +* @param uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` +* @param N - order of matrix `A` +* @param A - input symmetric positive definite matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @returns status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); +* // returns 0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0 ); +* // returns 0 +*/ +declare var dpotf2: Routine; + + +// EXPORTS // + +export = dpotf2; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dpotf2/docs/types/test.ts new file mode 100644 index 000000000000..db985af66870 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/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 dpotf2 = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + + dpotf2( 'row-major', 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2( 5, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( true, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( false, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( null, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( void 0, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( [], 'upper', 2, A, 2 ); // $ExpectError + dpotf2( {}, 'upper', 2, A, 2 ); // $ExpectError + dpotf2( ( x: number ): number => x, 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2( 'row-major', 5, 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', true, 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', false, 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', null, 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', void 0, 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', [], 2, A, 2 ); // $ExpectError + dpotf2( 'row-major', {}, 2, A, 2 ); // $ExpectError + dpotf2( '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, 0.0, 0.0, 4.0 ] ); + + dpotf2( 'row-major', 'upper', '5', A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', true, A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', false, A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', null, A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', void 0, A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', [], A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', {}, A, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', ( 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... +{ + + dpotf2( 'row-major', 'upper', 2, '5', 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, 5, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, true, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, false, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, null, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, void 0, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, [], 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, {}, 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2( 'row-major', 'upper', 2, A, '5' ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, true ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, false ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, null ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, void 0 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, [] ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, {} ); // $ExpectError + dpotf2( 'row-major', 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2(); // $ExpectError + dpotf2( 'row-major' ); // $ExpectError + dpotf2( 'row-major', 'upper' ); // $ExpectError + dpotf2( 'row-major', 'upper', 2 ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A ); // $ExpectError + dpotf2( 'row-major', 'upper', 2, A, 2, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 'upper', 2, A, 2, 1, 0 ); // $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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 5, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( true, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( false, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( null, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( void 0, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( [], 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( {}, 2, A, 2, 1, 0 ); // $ExpectError + dpotf2.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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 'upper', '5', A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', true, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', false, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', null, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', void 0, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', [], A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', {}, A, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', ( 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... +{ + + dpotf2.ndarray( 'upper', 2, '5', 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, 5, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, true, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, false, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, null, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, void 0, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, [], 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, {}, 2, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 'upper', 2, A, '5', 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, true, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, false, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, null, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, void 0, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, [], 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, {}, 1, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 'upper', 2, A, 2, '5', 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, true, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, false, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, null, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, void 0, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, [], 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, {}, 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray( 'upper', 2, A, 2, 1, '5' ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, true ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, false ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, null ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, void 0 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, [] ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, {} ); // $ExpectError + dpotf2.ndarray( 'upper', 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, 0.0, 0.0, 4.0 ] ); + + dpotf2.ndarray(); // $ExpectError + dpotf2.ndarray( 'upper' ); // $ExpectError + dpotf2.ndarray( 'upper', 2 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1 ); // $ExpectError + dpotf2.ndarray( 'upper', 2, A, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js index 3163c2bb5cc6..b22df54f1ffc 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/examples/index.js @@ -19,10 +19,10 @@ 'use strict'; var Float64Array = require( '@stdlib/array/float64' ); -var dpotf2 = require( './../lib/base.js' ); +var dpotf2 = require( './../lib/' ); var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); -var out = dpotf2( 'upper', 2, A, 2, 1, 0 ); +var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); console.log( A ); console.log( out ); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js index ce0ea8cb3748..77d5b34df1eb 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js @@ -84,7 +84,7 @@ function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { // column-major for ( j = 0; j < N; j++ ) { // Compute U( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, strideA1, offsetA + ( j * strideA1 ), A, strideA2, strideA1, offsetA + ( j * strideA1 ) ); + ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ) ); if ( ajj <= 0.0 || isnan( ajj ) ) { A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; return j; @@ -94,7 +94,7 @@ function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { // Compute elements j+1:N of row j... if ( j < N - 1 ) { - dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA2, strideA1, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ), 1.0, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA2, strideA1, offsetA + ( ( j + 1 ) * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ), 1.0, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); dscal( N - j - 1, 1.0 / ajj, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); } } @@ -105,7 +105,7 @@ function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { // Compute the Cholesky factorization A = L*L^T. for ( j = 0; j < N; j++ ) { // Compute L( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA1, strideA2, offsetA + ( j * strideA1 ), A, strideA1, strideA2, offsetA + ( j * strideA1 ) ); + ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA2, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ) ); if ( ajj <= 0.0 || isnan( ajj ) ) { A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; return j; @@ -124,7 +124,7 @@ function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { // column-major for ( j = 0; j < N; j++ ) { // Compute L( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, strideA1, offsetA + ( j * strideA2 ), A, strideA2, strideA1, offsetA + ( j * strideA2 ) ); + ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA1, offsetA + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); if ( ajj <= 0.0 || isnan( ajj ) ) { A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; return j; @@ -133,9 +133,9 @@ function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; // Compute elements j+1:N of column j... - if ( j < N - 1 ) { - dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA2, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA2 ), 1.0, A, strideA2, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); - dscal( N - j - 1, 1.0 / ajj, A, strideA2, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); + if ( j < N ) { + dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ), 1.0, A, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); + dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); } } return 0; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js new file mode 100644 index 000000000000..d2763152b869 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js @@ -0,0 +1,67 @@ + +/** +* @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 Cholesky factorization of a real symmetric positive definite matrix `A`. +* +* @module @stdlib/lapack/base/dpotf2 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dpotf2 = require( '@stdlib/lapack/base/dpotf2' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2( 'row-major', 'upper', 2, A, 2 ); +* // returns 0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dpotf2 = require( '@stdlib/lapack/base/dpotf2' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); +* +* var out = dpotf2.ndarray( 'upper', 2, A, 2, 1, 0 ); +* // returns 0 +*/ + +// 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 dpotf2; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dpotf2 = main; +} else { + dpotf2 = tmp; +} + + +// EXPORTS // + +module.exports = dpotf2; diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js index c9b36b9739f8..efe96125201b 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/ndarray.js @@ -28,7 +28,7 @@ var base = require( './base.js' ); // MAIN // /** -* Computes the Cholesky factorization of a real symmetric positive definite matrix `A`using alternative semantic indexing. +* Computes the Cholesky factorization of a real symmetric positive definite matrix `A` using alternative semantic indexing. * * @private * @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/package.json b/lib/node_modules/@stdlib/lapack/base/dpotf2/package.json new file mode 100644 index 000000000000..f48debc56e93 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/lapack/base/dpotf2", + "version": "0.0.0", + "description": "Compute the Cholesky factorization of a real symmetric positive definite 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", + "dpotf2", + "cholesky", + "triangular", + "symmetric", + "matrix", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.dpotf2.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.dpotf2.js new file mode 100644 index 000000000000..5bdabfcb7707 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.dpotf2.js @@ -0,0 +1,178 @@ +/** +* @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 dpotf2 = require( './../lib/dpotf2.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 dpotf2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( dpotf2.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, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + A = new Float64Array( [ 1.0, 0.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() { + dpotf2( value, 'upper', 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, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + dpotf2( 'row-major', value, 2, A, 2 ); + }; + } +}); + +tape( 'the function correctly computes cholesky factorization of a square symmetric matrix ( row-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, 0.0, 0.0, 2.0 ] ); + + out = dpotf2( 'row-major', 'upper', 2, A, 2 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + + A = new Float64Array( [ 1.0, 0.0, 0.0, 4.0 ] ); + out = dpotf2( 'row-major', 'lower', 2, A, 2 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + t.end(); +}); + +tape( 'the function correctly computes cholesky factorization of a square symmetric matrix ( column-major )', function test( t ) { + var expected; + var out; + var A; + + A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); + expected = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 1.4142135623730951, 0.0, 0.0, 0.0, 1.7320508075688772 ] ); + + out = dpotf2( 'column-major', 'upper', 3, A, 3 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + + A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); + out = dpotf2( 'column-major', 'lower', 3, A, 3 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js new file mode 100644 index 000000000000..b7508c35dbef --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js @@ -0,0 +1,83 @@ + +/** +* @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 dpotf2 = 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 dpotf2, '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 dpotf2.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 dpotf2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dpotf2, 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 dpotf2; + var main; + + main = require( './../lib/dpotf2.js' ); + + dpotf2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dpotf2, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.ndarray.js new file mode 100644 index 000000000000..16f493c5b612 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.ndarray.js @@ -0,0 +1,196 @@ +/** +* @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 dpotf2 = 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 dpotf2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dpotf2.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, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + A = new Float64Array( [ 1.0, 0.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() { + dpotf2( value, 2, A, 2, 1, 0 ); + }; + } +}); + +tape( 'the function supports accessing elements from non-contiguous rows and columns ( 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, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 2, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 3, + 999, 999, 999, 999, 999, 999 + ]); + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 1.4142135623730951, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 1.7320508075688772, + 999, 999, 999, 999, 999, 999 + ]); + + out = dpotf2( 'upper', 3, A, 12, 2, 7 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 2, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 3, + 999, 999, 999, 999, 999, 999 + ]); + out = dpotf2( 'lower', 3, A, 12, 2, 7 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + t.end(); +}); + +tape( 'the function supports accessing elements 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, 3, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 2, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 1, + 999, 999, 999, 999, 999, 999 + ]); + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1.7320508075688772, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 1.4142135623730951, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 1, + 999, 999, 999, 999, 999, 999 + ]); + + out = dpotf2( 'upper', 3, A, -12, -2, 35 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 3, 999, 0, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 2, 999, 0, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 1, + 999, 999, 999, 999, 999, 999 + ]); + + out = dpotf2( 'lower', 3, A, -12, -2, 35 ); + t.strictEqual( out, 0, 'returns expected value' ); + isApprox( t, A, expected, 1.0 ); + t.end(); +}); From 00a6d5ebb1b7846516f146b4110c404fc9ce1a88 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sat, 10 Aug 2024 13:52:21 +0530 Subject: [PATCH 6/7] refactor: base implementation --- .../@stdlib/lapack/base/dpotf2/lib/base.js | 74 ++++++------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js index 77d5b34df1eb..844e22fd7beb 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/base.js @@ -53,89 +53,59 @@ var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; function dpotf2( uplo, N, A, strideA1, strideA2, offsetA ) { var upper; var ajj; + var sa0; + var sa1; var j; upper = ( uplo === 'upper' ); + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + // For row-major matrices, the last dimension has the fastest changing index... + sa0 = strideA2; // stride for innermost loop + sa1 = strideA1; // stride for outermost loop + } else { // 'column-major' + // For column-major matrices, the first dimension has the fastest changing index... + sa0 = strideA1; // stride for innermost loop + sa1 = strideA2; // stride for outermost loop + } + if ( N === 0 ) { return 0; } if ( upper ) { - if ( isRowMajor( [ strideA1, strideA2 ] ) ) { - // Compute the Cholesky factorization A = U^T*U. - for ( j = 0; j < N; j++ ) { - // Compute U( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA1, offsetA + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); - if ( ajj <= 0.0 || isnan( ajj ) ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; - return j; - } - ajj = sqrt( ajj ); - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; - - // Compute elements j+1:N of row j... - if ( j < N - 1 ) { - dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ), 1.0, A, strideA1, offsetA + ( j * strideA1 ) + ( ( j + 1 ) * strideA2 ) ); - dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( j * strideA1 ) + ( ( j + 1 ) * strideA2 ) ); - } - } - return 0; - } - // column-major for ( j = 0; j < N; j++ ) { // Compute U( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA2, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ) ); + ajj = A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] - ddot( j, A, sa1, offsetA + ( j * sa0 ), A, sa1, offsetA + ( j * sa0 ) ); if ( ajj <= 0.0 || isnan( ajj ) ) { - A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] = ajj; return j; } ajj = sqrt( ajj ); - A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] = ajj; // Compute elements j+1:N of row j... if ( j < N - 1 ) { - dgemv( 'transpose', j, N - j - 1, -1.0, A, strideA2, strideA1, offsetA + ( ( j + 1 ) * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ), 1.0, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); - dscal( N - j - 1, 1.0 / ajj, A, strideA2, offsetA + ( j * strideA2 ) + ( ( j + 1 ) * strideA1 ) ); + dgemv( 'transpose', j, N - j - 1, -1.0, A, sa1, sa0, offsetA + ( ( j + 1 ) * sa0 ), A, sa1, offsetA + ( j * sa0 ), 1.0, A, sa1, offsetA + ( j * sa1 ) + ( ( j + 1 ) * sa0 ) ); + dscal( N - j - 1, 1.0 / ajj, A, sa1, offsetA + ( j * sa1 ) + ( ( j + 1 ) * sa0 ) ); } } return 0; } // Lower - if ( isRowMajor( [ strideA1, strideA2 ] ) ) { - // Compute the Cholesky factorization A = L*L^T. - for ( j = 0; j < N; j++ ) { - // Compute L( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] - ddot( j, A, strideA2, offsetA + ( j * strideA1 ), A, strideA2, offsetA + ( j * strideA1 ) ); - if ( ajj <= 0.0 || isnan( ajj ) ) { - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; - return j; - } - ajj = sqrt( ajj ); - A[ offsetA + ( j * strideA1 ) + ( j * strideA2 ) ] = ajj; - - // Compute elements j+1:N of column j... - if ( j < N - 1 ) { - dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA1 ), 1.0, A, strideA1, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ) ); - dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( ( j + 1 ) * strideA1 ) + ( j * strideA2 ) ); - } - } - return 0; - } - // column-major for ( j = 0; j < N; j++ ) { // Compute L( j, j ) and test for non-positive-definiteness... - ajj = A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] - ddot( j, A, strideA1, offsetA + ( j * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ) ); + ajj = A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] - ddot( j, A, sa0, offsetA + ( j * sa1 ), A, sa0, offsetA + ( j * sa1 ) ); if ( ajj <= 0.0 || isnan( ajj ) ) { - A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] = ajj; return j; } ajj = sqrt( ajj ); - A[ offsetA + ( j * strideA2 ) + ( j * strideA1 ) ] = ajj; + A[ offsetA + ( j * sa1 ) + ( j * sa0 ) ] = ajj; // Compute elements j+1:N of column j... if ( j < N ) { - dgemv( 'no-transpose', N - j - 1, j, -1.0, A, strideA1, strideA2, offsetA + ( ( j + 1 ) * strideA2 ), A, strideA1, offsetA + ( j * strideA2 ), 1.0, A, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); - dscal( N - j - 1, 1.0 / ajj, A, strideA1, offsetA + ( ( j + 1 ) * strideA2 ) + ( j * strideA1 ) ); + dgemv( 'no-transpose', N - j - 1, j, -1.0, A, sa0, sa1, offsetA + ( ( j + 1 ) * sa1 ), A, sa0, offsetA + ( j * sa1 ), 1.0, A, sa0, offsetA + ( ( j + 1 ) * sa1 ) + ( j * sa0 ) ); + dscal( N - j - 1, 1.0 / ajj, A, sa0, offsetA + ( ( j + 1 ) * sa1 ) + ( j * sa0 ) ); } } return 0; From 6b5eb91ca56af65c2af0b6096fd81c10006636a1 Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Sat, 10 Aug 2024 13:58:18 +0530 Subject: [PATCH 7/7] chore: Apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../@stdlib/lapack/base/dpotf2/benchmark/benchmark.js | 2 +- .../@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js | 2 +- lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js | 1 - lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js | 1 - lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js | 1 - 5 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js index 39bff2ec4b8b..452b85491b12 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.js @@ -89,7 +89,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( pkg+':order=row-major,len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js index 922fd5ab8df6..90dc123162c4 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/benchmark/benchmark.ndarray.js @@ -89,7 +89,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); + bench( pkg+':ndarray:order=row-major,len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js index c034603777bd..660432f9436a 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/dpotf2.js @@ -31,7 +31,6 @@ var base = require( './base.js' ); /** * Computes the Cholesky factorization of a real symmetric positive definite matrix `A`. * -* @private * @param {string} order - storage layout * @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` * @param {NonNegativeInteger} N - order of matrix `A` diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js index d2763152b869..8908885bec7f 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/lib/index.js @@ -1,4 +1,3 @@ - /** * @license Apache-2.0 * diff --git a/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js index b7508c35dbef..d3c492c0fb75 100644 --- a/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js +++ b/lib/node_modules/@stdlib/lapack/base/dpotf2/test/test.js @@ -1,4 +1,3 @@ - /** * @license Apache-2.0 *