diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/README.md b/lib/node_modules/@stdlib/lapack/base/dsptrf/README.md new file mode 100644 index 000000000000..cfd3aa58abec --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/README.md @@ -0,0 +1,284 @@ + + +# dsptrf + +> Compute the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. + +
+ +## Usage + +```javascript +var dsptrf = require( '@stdlib/lapack/base/dsptrf' ); +``` + +#### dsptrf( order, uplo, N, AP, IPIV ) + +Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); + +/* + A = [ + [ 4.0, 1.0, -2.0, 2.0 ], + [ 1.0, 2.0, 0.0, 1.0 ], + [ -2.0, 0.0, 3.0, -2.0 ], + [ 2.0, 1.0, -2.0, -1.0 ] + ] +*/ + +// Store the upper triangle of `A` in column-major packed form: +var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +var IPIV = new Int32Array( 4 ); + +dsptrf( 'column-major', 'upper', 4, AP, IPIV ); +// IPIV => [ 1, 2, 3, 1 ] +``` + +The function has the following parameters: + +- **order**: storage layout. Must be either `'row-major'` or `'column-major'`. +- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. Must be either `'upper'` or `'lower'`. +- **N**: order of the matrix `A`. +- **AP**: packed form of the symmetric matrix `A` as a [`Float64Array`][mdn-float64array]. Should have `N*(N+1)/2` indexed elements. On exit, `AP` is overwritten by the block diagonal matrix `D` and the multipliers used to obtain the factor `U` or `L`. +- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array]. Should have `N` indexed elements. On exit, `IPIV` contains details of the interchanges and the block structure of `D` (values are one-based, as in the reference LAPACK implementation). + +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' ); +var Int32Array = require( '@stdlib/array/int32' ); + +// Initial arrays... +var AP0 = new Float64Array( [ 0.0, 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +var IPIV0 = new Int32Array( [ 0, 0, 0, 0, 0 ] ); + +// Create offset views... +var AP = new Float64Array( AP0.buffer, AP0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var IPIV = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dsptrf( 'column-major', 'upper', 4, AP, IPIV ); +// IPIV0 => [ 0, 1, 2, 3, 1 ] +``` + +#### dsptrf.ndarray( order, uplo, N, AP, sap, oap, IPIV, si, oi ) + +Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method and alternative indexing semantics. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); + +var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +var IPIV = new Int32Array( 4 ); + +dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); +// IPIV => [ 1, 2, 3, 1 ] +``` + +The function has the following additional parameters: + +- **sap**: stride length for `AP`. +- **oap**: starting index for `AP`. +- **si**: stride length for `IPIV`. +- **oi**: starting index for `IPIV`. + +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 Int32Array = require( '@stdlib/array/int32' ); + +var AP = new Float64Array( [ 0.0, 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +var IPIV = new Int32Array( [ 0, 0, 0, 0, 0 ] ); + +dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 1, IPIV, 1, 1 ); +// IPIV => [ 0, 1, 2, 3, 1 ] +``` + +
+ + + +
+ +## Notes + +- Both functions mutate the input arrays `AP` and `IPIV`. + +- For a symmetric matrix, an upper triangle stored in row-major order is identical in memory to a lower triangle stored in column-major order (and vice versa). Accordingly, when `order` is `'row-major'`, the routine resolves `uplo` to the equivalent column-major factorization (i.e., `'row-major'` + `'upper'` is factorized as `L*D*L^T` and `'row-major'` + `'lower'` is factorized as `U*D*U^T`). The returned `AP` and `IPIV` are self-consistent for the resolved factorization. + +- Both functions return a status code indicating success or failure. The status code indicates the following conditions: + + - `0`: factorization was successful. + - `>0`: `D(k,k)` is exactly zero (one-based, where `k` equals the status code value). The factorization has been completed, but the block diagonal matrix `D` is exactly singular, and division by zero will occur if it is used to solve a system of equations. + +- `dsptrf()` corresponds to the [LAPACK][LAPACK] routine [`dsptrf`][lapack-dsptrf]. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsptrf = require( '@stdlib/lapack/base/dsptrf' ); + +/* + Symmetric matrix `A` (upper triangle): + + A = [ + [ 4.0, 1.0, -2.0, 2.0 ], + [ 1.0, 2.0, 0.0, 1.0 ], + [ -2.0, 0.0, 3.0, -2.0 ], + [ 2.0, 1.0, -2.0, -1.0 ] + ] +*/ + +// Store the upper triangle of `A` in column-major packed form: +var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +var IPIV = new Int32Array( 4 ); + +// Compute the Bunch-Kaufman factorization `A = U*D*U^T`: +var info = dsptrf( 'column-major', 'upper', 4, AP, IPIV ); + +console.log( AP ); +console.log( IPIV ); +console.log( info ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.js new file mode 100644 index 000000000000..f6306bbd4a3d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Int32Array = require( '@stdlib/array/int32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dsptrf = require( './../lib/dsptrf.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - order of the matrix +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var IPIV = new Int32Array( N ); + var AP = uniform( N*( N+1 ) / 2, -1.0, 1.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dsptrf( 'column-major', 'upper', N, AP, IPIV ); + if ( d < 0 ) { + b.fail( 'should return a valid status code' ); + } + } + b.toc(); + if ( d < 0 ) { + b.fail( 'should return a valid status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( format( '%s:N=%d', pkg, N ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..f9606d5fbab7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.ndarray.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Int32Array = require( '@stdlib/array/int32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dsptrf = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - order of the matrix +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var IPIV = new Int32Array( N ); + var AP = uniform( N*( N+1 ) / 2, -1.0, 1.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dsptrf( 'column-major', 'upper', N, AP, 1, 0, IPIV, 1, 0 ); + if ( d < 0 ) { + b.fail( 'should return a valid status code' ); + } + } + b.toc(); + if ( d < 0 ) { + b.fail( 'should return a valid status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( format( '%s:ndarray:N=%d', pkg, N ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/repl.txt new file mode 100644 index 000000000000..c1ff411c5296 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/repl.txt @@ -0,0 +1,132 @@ + +{{alias}}( order, uplo, N, AP, IPIV ) + Computes the factorization of a real symmetric matrix `A` stored in packed + format using the Bunch-Kaufman diagonal pivoting method. + + The factorization has the form + + A = U*D*U^T or A = L*D*L^T + + where `U` (or `L`) is a product of permutation and unit upper (lower) + triangular matrices, and `D` is symmetric and block diagonal with 1-by-1 and + 2-by-2 diagonal blocks. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + The function mutates `AP` and `IPIV`. + + 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 the upper or lower triangular part of the symmetric + matrix `A` is supplied. Must be either 'upper' or 'lower'. + + N: integer + Order of the matrix `A`. + + AP: Float64Array + Packed form of the symmetric matrix `A`. Should have `N*(N+1)/2` indexed + elements. On exit, `AP` is overwritten by the block diagonal matrix `D` + and the multipliers used to obtain the factor `U` or `L`. + + IPIV: Int32Array + Vector of pivot indices. Should have `N` indexed elements. Contains + details of the interchanges and the block structure of `D` (values are + one-based, as in the reference LAPACK implementation). + + Returns + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if greater than zero and equal to `i`, then `D(i,i)` is exactly zero + (one-based); the factorization has been completed, but the block + diagonal matrix `D` is exactly singular, and division by zero will occur + if it is used to solve a system of equations. + + Examples + -------- + > var v = [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ]; + > var AP = new {{alias:@stdlib/array/float64}}( v ); + > var IPIV = new {{alias:@stdlib/array/int32}}( 4 ); + > {{alias}}( 'column-major', 'upper', 4, AP, IPIV ) + 0 + > IPIV + [ 1, 2, 3, 1 ] + + +{{alias}}.ndarray( order, uplo, N, AP, sap, oap, IPIV, si, oi ) + Computes the factorization of a real symmetric matrix `A` stored in packed + format using the Bunch-Kaufman diagonal pivoting method and 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. + + The function mutates `AP` and `IPIV`. + + 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 the upper or lower triangular part of the symmetric + matrix `A` is supplied. Must be either 'upper' or 'lower'. + + N: integer + Order of the matrix `A`. + + AP: Float64Array + Packed form of the symmetric matrix `A`. Should have `N*(N+1)/2` indexed + elements. On exit, `AP` is overwritten by the block diagonal matrix `D` + and the multipliers used to obtain the factor `U` or `L`. + + sap: integer + Stride length for `AP`. + + oap: integer + Starting index for `AP`. + + IPIV: Int32Array + Vector of pivot indices. Should have `N` indexed elements. Contains + details of the interchanges and the block structure of `D` (values are + one-based, as in the reference LAPACK implementation). + + si: integer + Stride length for `IPIV`. + + oi: integer + Starting index for `IPIV`. + + Returns + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if greater than zero and equal to `i`, then `D(i,i)` is exactly zero + (one-based); the factorization has been completed, but the block + diagonal matrix `D` is exactly singular, and division by zero will occur + if it is used to solve a system of equations. + + Examples + -------- + > var v = [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ]; + > var AP = new {{alias:@stdlib/array/float64}}( v ); + > var IPIV = new {{alias:@stdlib/array/int32}}( 4 ); + > {{alias}}.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ) + 0 + > IPIV + [ 1, 2, 3, 1 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/index.d.ts new file mode 100644 index 000000000000..0325effe611c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/index.d.ts @@ -0,0 +1,140 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { 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 greater than zero and equal to `i`, then `D(i,i)` is exactly zero (one-based); the factorization has been completed, but the block diagonal matrix `D` is exactly singular, and division by zero will occur if it is used to solve a system of equations. +*/ +type StatusCode = number; + +/** +* Interface describing `dsptrf`. +*/ +interface Routine { + /** + * Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. + * + * ## Notes + * + * - `AP` should have `N*(N+1)/2` elements. On exit, `AP` is overwritten by the block diagonal matrix `D` and the multipliers used to obtain the factor `U` or `L`, stored as a packed triangular matrix. + * - `IPIV` should have `N` elements and contains details of the interchanges and the block structure of `D` (values are one-based, as in the reference LAPACK implementation). + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied + * @param N - order of the matrix `A` + * @param AP - packed form of a symmetric matrix `A` + * @param IPIV - vector of pivot indices + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * var Int32Array = require( '@stdlib/array/int32' ); + * + * var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); + * var IPIV = new Int32Array( 4 ); + * + * dsptrf( 'column-major', 'upper', 4, AP, IPIV ); + * // IPIV => [ 1, 2, 3, 1 ] + */ + ( order: Layout, uplo: MatrixTriangle, N: number, AP: Float64Array, IPIV: Int32Array ): StatusCode; + + /** + * Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method and alternative indexing semantics. + * + * ## Notes + * + * - `AP` should have `N*(N+1)/2` indexed elements. On exit, `AP` is overwritten by the block diagonal matrix `D` and the multipliers used to obtain the factor `U` or `L`, stored as a packed triangular matrix. + * - `IPIV` should have `N` indexed elements and contains details of the interchanges and the block structure of `D` (values are one-based, as in the reference LAPACK implementation). + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied + * @param N - order of the matrix `A` + * @param AP - packed form of a symmetric matrix `A` + * @param strideAP - stride length for `AP` + * @param offsetAP - starting index for `AP` + * @param IPIV - vector of pivot indices + * @param strideIPIV - stride length for `IPIV` + * @param offsetIPIV - starting index for `IPIV` + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * var Int32Array = require( '@stdlib/array/int32' ); + * + * var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); + * var IPIV = new Int32Array( 4 ); + * + * dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); + * // IPIV => [ 1, 2, 3, 1 ] + */ + ndarray( order: Layout, uplo: MatrixTriangle, N: number, AP: Float64Array, strideAP: number, offsetAP: number, IPIV: Int32Array, strideIPIV: number, offsetIPIV: number ): StatusCode; +} + +/** +* Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. +* +* ## Notes +* +* - `AP` should have `N*(N+1)/2` elements. On exit, `AP` is overwritten by the block diagonal matrix `D` and the multipliers used to obtain the factor `U` or `L`, stored as a packed triangular matrix. +* - `IPIV` should have `N` elements and contains details of the interchanges and the block structure of `D` (values are one-based, as in the reference LAPACK implementation). +* +* @param order - storage layout +* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param N - order of the matrix `A` +* @param AP - packed form of a symmetric matrix `A` +* @param IPIV - vector of pivot indices +* @returns status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf( 'column-major', 'upper', 4, AP, IPIV ); +* // IPIV => [ 1, 2, 3, 1 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); +* // IPIV => [ 1, 2, 3, 1 ] +*/ +declare var dsptrf: Routine; + + +// EXPORTS // + +export = dsptrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/test.ts new file mode 100644 index 000000000000..8599c093c759 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/docs/types/test.ts @@ -0,0 +1,280 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +import dsptrf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf( 'column-major', 'upper', 4, AP, IPIV ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf( 10, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( true, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( false, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( null, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( void 0, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( [], 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( {}, 'upper', 4, AP, IPIV ); // $ExpectError + dsptrf( ( x: number ): number => x, 'upper', 4, AP, IPIV ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf( 'column-major', 10, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', true, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', false, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', null, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', void 0, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', [ '1' ], 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', {}, 4, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', ( x: number ): number => x, 4, AP, IPIV ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf( 'column-major', 'upper', '4', AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', true, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', false, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', null, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', void 0, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', [], AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', {}, AP, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', ( x: number ): number => x, AP, IPIV ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + const IPIV = new Int32Array( 4 ); + + dsptrf( 'column-major', 'upper', 4, '5', IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, 5, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, true, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, false, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, null, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, void 0, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, [], IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, {}, IPIV ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, ( x: number ): number => x, IPIV ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not an Int32Array... +{ + const AP = new Float64Array( 10 ); + + dsptrf( 'column-major', 'upper', 4, AP, '5' ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, 5 ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, true ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, false ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, null ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, void 0 ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, [] ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, {} ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf(); // $ExpectError + dsptrf( 'column-major' ); // $ExpectError + dsptrf( 'column-major', 'upper' ); // $ExpectError + dsptrf( 'column-major', 'upper', 4 ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP ); // $ExpectError + dsptrf( 'column-major', 'upper', 4, AP, IPIV, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a string... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 10, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( true, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( false, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( null, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( void 0, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( [], 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( {}, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( ( x: number ): number => x, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a string... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 10, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', true, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', false, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', null, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', void 0, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', [ '1' ], 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', {}, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', ( x: number ): number => x, 4, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', '4', AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', true, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', false, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', null, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', void 0, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', [], AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', {}, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', ( x: number ): number => x, AP, 1, 0, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a Float64Array... +{ + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, '5', 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, 5, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, true, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, false, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, null, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, void 0, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, [], 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, {}, 1, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, ( x: number ): number => x, 1, 0, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, '1', 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, true, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, false, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, null, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, void 0, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, [], 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, {}, 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, ( x: number ): number => x, 0, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, '0', IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, true, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, false, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, null, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, void 0, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, [], IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, {}, IPIV, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, ( x: number ): number => x, IPIV, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not an Int32Array... +{ + const AP = new Float64Array( 10 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, '5', 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, 5, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, true, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, false, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, null, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, void 0, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, [], 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, {}, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, '1', 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, true, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, false, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, null, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, void 0, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, [], 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, {}, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, '0' ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, true ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, false ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, null ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, void 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, [] ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, {} ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const AP = new Float64Array( 10 ); + const IPIV = new Int32Array( 4 ); + + dsptrf.ndarray(); // $ExpectError + dsptrf.ndarray( 'column-major' ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper' ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1 ); // $ExpectError + dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/examples/index.js new file mode 100644 index 000000000000..2eb492c8e2b2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsptrf = require( './../lib' ); + +/* + Symmetric matrix `A` (upper triangle): + + A = [ + [ 4.0, 1.0, -2.0, 2.0 ], + [ 1.0, 2.0, 0.0, 1.0 ], + [ -2.0, 0.0, 3.0, -2.0 ], + [ 2.0, 1.0, -2.0, -1.0 ] + ] +*/ + +// Store the upper triangle of `A` in column-major packed form: +var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); // eslint-disable-line max-len +var IPIV = new Int32Array( 4 ); + +// Compute the Bunch-Kaufman factorization `A = U*D*U^T`: +var info = dsptrf( 'column-major', 'upper', 4, AP, IPIV ); + +console.log( AP ); +console.log( IPIV ); +console.log( info ); diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/base.js new file mode 100644 index 000000000000..4f72bc04f343 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/base.js @@ -0,0 +1,429 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-statements */ + +'use strict'; + +// MODULES // + +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var idamax = require( '@stdlib/blas/base/idamax' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var dswap = require( '@stdlib/blas/base/dswap' ).ndarray; +var dspr = require( '@stdlib/blas/base/dspr' ).ndarray; +var abs = require( '@stdlib/math/base/special/abs' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var max = require( '@stdlib/math/base/special/max' ); + + +// VARIABLES // + +// Factor used to determine the pivot block size (see LAPACK reference DSPTRF): +var ALPHA = ( 1.0 + sqrt( 17.0 ) ) / 8.0; + + +// FUNCTIONS // + +/** +* Factorizes a real symmetric matrix `A = U*D*U^T` using the upper triangle of `A` supplied in column-major packed form. +* +* @private +* @param {NonNegativeInteger} N - order of the matrix `A` +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {integer} sa - stride length for `AP` +* @param {NonNegativeInteger} oa - starting index for `AP` +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} si - stride length for `IPIV` +* @param {NonNegativeInteger} oi - starting index for `IPIV` +* @returns {integer} status code +*/ +function factorU( N, AP, sa, oa, IPIV, si, oi ) { + var absakk; + var colmax; + var rowmax; + var kstep; + var info; + var imax; + var jmax; + var wkm1; + var d11; + var d12; + var d22; + var knc; + var kpc; + var r1; + var wk; + var kc; + var kk; + var kp; + var kx; + var i; + var j; + var k; + var t; + + /** + * Resolves the physical index of the (one-based) packed element `idx`. + * + * @private + * @param {PositiveInteger} idx - one-based packed index + * @returns {integer} physical index into `AP` + */ + function pos( idx ) { + return oa + ( ( idx-1 ) * sa ); + } + + info = 0; + + // `k` is the main loop index, decreasing from `N` to `1` in steps of `1` or `2`: + k = N; + kc = ( ( N-1 )*N / 2 ) + 1; + while ( k >= 1 ) { + knc = kc; + kstep = 1; + + // Determine rows and columns to be interchanged and whether a 1-by-1 or 2-by-2 pivot block will be used... + absakk = abs( AP[ pos( kc+k-1 ) ] ); + + // `imax` is the row-index of the largest off-diagonal element in column `k`, and `colmax` is its absolute value... + if ( k > 1 ) { + imax = idamax( k-1, AP, sa, pos( kc ) ) + 1; + colmax = abs( AP[ pos( kc+imax-1 ) ] ); + } else { + colmax = 0.0; + } + if ( max( absakk, colmax ) === 0.0 ) { + // Column `k` is zero: set `info` and continue... + if ( info === 0 ) { + info = k; + } + kp = k; + } else { + if ( absakk >= ALPHA*colmax ) { + // No interchange, use 1-by-1 pivot block... + kp = k; + } else { + rowmax = 0.0; + jmax = imax; + kx = ( imax*( imax+1 ) / 2 ) + imax; + for ( j = imax+1; j <= k; j++ ) { + if ( abs( AP[ pos( kx ) ] ) > rowmax ) { + rowmax = abs( AP[ pos( kx ) ] ); + jmax = j; + } + kx += j; + } + kpc = ( ( imax-1 )*imax / 2 ) + 1; + if ( imax > 1 ) { + jmax = idamax( imax-1, AP, sa, pos( kpc ) ) + 1; + rowmax = max( rowmax, abs( AP[ pos( kpc+jmax-1 ) ] ) ); + } + if ( absakk >= ALPHA*colmax*( colmax / rowmax ) ) { + // No interchange, use 1-by-1 pivot block... + kp = k; + } else if ( abs( AP[ pos( kpc+imax-1 ) ] ) >= ALPHA*rowmax ) { + // Interchange rows and columns `k` and `imax`, use 1-by-1 pivot block... + kp = imax; + } else { + // Interchange rows and columns `k-1` and `imax`, use 2-by-2 pivot block... + kp = imax; + kstep = 2; + } + } + kk = k - kstep + 1; + if ( kstep === 2 ) { + knc = knc - k + 1; + } + if ( kp !== kk ) { + // Interchange rows and columns `kk` and `kp` in the leading submatrix `A(1:k,1:k)`... + dswap( kp-1, AP, sa, pos( knc ), AP, sa, pos( kpc ) ); + kx = kpc + kp - 1; + for ( j = kp+1; j <= kk-1; j++ ) { + kx = kx + j - 1; + t = AP[ pos( knc+j-1 ) ]; + AP[ pos( knc+j-1 ) ] = AP[ pos( kx ) ]; + AP[ pos( kx ) ] = t; + } + t = AP[ pos( knc+kk-1 ) ]; + AP[ pos( knc+kk-1 ) ] = AP[ pos( kpc+kp-1 ) ]; + AP[ pos( kpc+kp-1 ) ] = t; + if ( kstep === 2 ) { + t = AP[ pos( kc+k-2 ) ]; + AP[ pos( kc+k-2 ) ] = AP[ pos( kc+kp-1 ) ]; + AP[ pos( kc+kp-1 ) ] = t; + } + } + // Update the leading submatrix... + if ( kstep === 1 ) { + // 1-by-1 pivot block `D(k)`: column `k` now holds `W(k) = U(k)*D(k)`, where `U(k)` is the k-th column of `U`. Perform a rank-1 update of `A(1:k-1,1:k-1)` as `A := A - U(k)*D(k)*U(k)^T = A - W(k)*(1/D(k))*W(k)^T` and store `U(k)` in column `k`... + r1 = 1.0 / AP[ pos( kc+k-1 ) ]; + dspr( 'column-major', 'upper', k-1, -r1, AP, sa, pos( kc ), AP, sa, oa ); + dscal( k-1, r1, AP, sa, pos( kc ) ); + } else if ( k > 2 ) { + // 2-by-2 pivot block `D(k)`. Perform a rank-2 update of `A(1:k-2,1:k-2)`... + d12 = AP[ pos( k-1 + ( ( k-1 )*k / 2 ) ) ]; + d22 = AP[ pos( k-1 + ( ( k-2 )*( k-1 ) / 2 ) ) ] / d12; + d11 = AP[ pos( k + ( ( k-1 )*k / 2 ) ) ] / d12; + t = 1.0 / ( ( d11*d22 ) - 1.0 ); + d12 = t / d12; + for ( j = k-2; j >= 1; j-- ) { + wkm1 = d12 * ( ( d11*AP[ pos( j + ( ( k-2 )*( k-1 ) / 2 ) ) ] ) - AP[ pos( j + ( ( k-1 )*k / 2 ) ) ] ); + wk = d12 * ( ( d22*AP[ pos( j + ( ( k-1 )*k / 2 ) ) ] ) - AP[ pos( j + ( ( k-2 )*( k-1 ) / 2 ) ) ] ); + for ( i = j; i >= 1; i-- ) { + AP[ pos( i + ( ( j-1 )*j / 2 ) ) ] = AP[ pos( i + ( ( j-1 )*j / 2 ) ) ] - ( AP[ pos( i + ( ( k-1 )*k / 2 ) ) ]*wk ) - ( AP[ pos( i + ( ( k-2 )*( k-1 ) / 2 ) ) ]*wkm1 ); + } + AP[ pos( j + ( ( k-1 )*k / 2 ) ) ] = wk; + AP[ pos( j + ( ( k-2 )*( k-1 ) / 2 ) ) ] = wkm1; + } + } + } + // Store details of the interchanges in `IPIV`... + if ( kstep === 1 ) { + IPIV[ oi + ( ( k-1 )*si ) ] = kp; + } else { + IPIV[ oi + ( ( k-1 )*si ) ] = -kp; + IPIV[ oi + ( ( k-2 )*si ) ] = -kp; + } + // Decrease `k` and return to the start of the main loop... + k -= kstep; + kc = knc - k; + } + return info; +} + +/** +* Factorizes a real symmetric matrix `A = L*D*L^T` using the lower triangle of `A` supplied in column-major packed form. +* +* @private +* @param {NonNegativeInteger} N - order of the matrix `A` +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {integer} sa - stride length for `AP` +* @param {NonNegativeInteger} oa - starting index for `AP` +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} si - stride length for `IPIV` +* @param {NonNegativeInteger} oi - starting index for `IPIV` +* @returns {integer} status code +*/ +function factorL( N, AP, sa, oa, IPIV, si, oi ) { + var absakk; + var colmax; + var rowmax; + var kstep; + var info; + var imax; + var jmax; + var wkp1; + var npp; + var d11; + var d21; + var d22; + var knc; + var kpc; + var r1; + var wk; + var kc; + var kk; + var kp; + var kx; + var i; + var j; + var k; + var t; + + /** + * Resolves the physical index of the (one-based) packed element `idx`. + * + * @private + * @param {PositiveInteger} idx - one-based packed index + * @returns {integer} physical index into `AP` + */ + function pos( idx ) { + return oa + ( ( idx-1 ) * sa ); + } + + info = 0; + + // `k` is the main loop index, increasing from `1` to `N` in steps of `1` or `2`: + k = 1; + kc = 1; + npp = N*( N+1 ) / 2; + while ( k <= N ) { + knc = kc; + kstep = 1; + + // Determine rows and columns to be interchanged and whether a 1-by-1 or 2-by-2 pivot block will be used... + absakk = abs( AP[ pos( kc ) ] ); + + // `imax` is the row-index of the largest off-diagonal element in column `k`, and `colmax` is its absolute value... + if ( k < N ) { + imax = k + idamax( N-k, AP, sa, pos( kc+1 ) ) + 1; + colmax = abs( AP[ pos( kc+imax-k ) ] ); + } else { + colmax = 0.0; + } + if ( max( absakk, colmax ) === 0.0 ) { + // Column `k` is zero: set `info` and continue... + if ( info === 0 ) { + info = k; + } + kp = k; + } else { + if ( absakk >= ALPHA*colmax ) { + // No interchange, use 1-by-1 pivot block... + kp = k; + } else { + // `jmax` is the column-index of the largest off-diagonal element in row `imax`, and `rowmax` is its absolute value... + rowmax = 0.0; + kx = kc + imax - k; + for ( j = k; j <= imax-1; j++ ) { + if ( abs( AP[ pos( kx ) ] ) > rowmax ) { + rowmax = abs( AP[ pos( kx ) ] ); + jmax = j; + } + kx = kx + N - j; + } + kpc = npp - ( ( N-imax+1 )*( N-imax+2 ) / 2 ) + 1; + if ( imax < N ) { + jmax = imax + idamax( N-imax, AP, sa, pos( kpc+1 ) ) + 1; + rowmax = max( rowmax, abs( AP[ pos( kpc+jmax-imax ) ] ) ); + } + if ( absakk >= ALPHA*colmax*( colmax / rowmax ) ) { + // No interchange, use 1-by-1 pivot block... + kp = k; + } else if ( abs( AP[ pos( kpc ) ] ) >= ALPHA*rowmax ) { + // Interchange rows and columns `k` and `imax`, use 1-by-1 pivot block... + kp = imax; + } else { + // Interchange rows and columns `k+1` and `imax`, use 2-by-2 pivot block... + kp = imax; + kstep = 2; + } + } + kk = k + kstep - 1; + if ( kstep === 2 ) { + knc = knc + N - k + 1; + } + if ( kp !== kk ) { + // Interchange rows and columns `kk` and `kp` in the trailing submatrix `A(k:n,k:n)`... + if ( kp < N ) { + dswap( N-kp, AP, sa, pos( knc+kp-kk+1 ), AP, sa, pos( kpc+1 ) ); + } + kx = knc + kp - kk; + for ( j = kk+1; j <= kp-1; j++ ) { + kx = kx + N - j + 1; + t = AP[ pos( knc+j-kk ) ]; + AP[ pos( knc+j-kk ) ] = AP[ pos( kx ) ]; + AP[ pos( kx ) ] = t; + } + t = AP[ pos( knc ) ]; + AP[ pos( knc ) ] = AP[ pos( kpc ) ]; + AP[ pos( kpc ) ] = t; + if ( kstep === 2 ) { + t = AP[ pos( kc+1 ) ]; + AP[ pos( kc+1 ) ] = AP[ pos( kc+kp-k ) ]; + AP[ pos( kc+kp-k ) ] = t; + } + } + // Update the trailing submatrix... + if ( kstep === 1 ) { + // 1-by-1 pivot block `D(k)`: column `k` now holds `W(k) = L(k)*D(k)`, where `L(k)` is the k-th column of `L`. Perform a rank-1 update of `A(k+1:n,k+1:n)` as `A := A - L(k)*D(k)*L(k)^T = A - W(k)*(1/D(k))*W(k)^T` and store `L(k)` in column `k`... + if ( k < N ) { + r1 = 1.0 / AP[ pos( kc ) ]; + dspr( 'column-major', 'lower', N-k, -r1, AP, sa, pos( kc+1 ), AP, sa, pos( kc+N-k+1 ) ); + dscal( N-k, r1, AP, sa, pos( kc+1 ) ); + } + } else if ( k < N-1 ) { + // 2-by-2 pivot block `D(k)`. Perform a rank-2 update of `A(k+2:n,k+2:n)`... + d21 = AP[ pos( k+1 + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ]; + d11 = AP[ pos( k+1 + ( k*( ( 2*N )-k-1 ) / 2 ) ) ] / d21; + d22 = AP[ pos( k + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ] / d21; + t = 1.0 / ( ( d11*d22 ) - 1.0 ); + d21 = t / d21; + for ( j = k+2; j <= N; j++ ) { + wk = d21 * ( ( d11*AP[ pos( j + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ] ) - AP[ pos( j + ( k*( ( 2*N )-k-1 ) / 2 ) ) ] ); + wkp1 = d21 * ( ( d22*AP[ pos( j + ( k*( ( 2*N )-k-1 ) / 2 ) ) ] ) - AP[ pos( j + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ] ); + for ( i = j; i <= N; i++ ) { + AP[ pos( i + ( ( j-1 )*( ( 2*N )-j ) / 2 ) ) ] = AP[ pos( i + ( ( j-1 )*( ( 2*N )-j ) / 2 ) ) ] - ( AP[ pos( i + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ]*wk ) - ( AP[ pos( i + ( k*( ( 2*N )-k-1 ) / 2 ) ) ]*wkp1 ); + } + AP[ pos( j + ( ( k-1 )*( ( 2*N )-k ) / 2 ) ) ] = wk; + AP[ pos( j + ( k*( ( 2*N )-k-1 ) / 2 ) ) ] = wkp1; + } + } + } + // Store details of the interchanges in `IPIV`... + if ( kstep === 1 ) { + IPIV[ oi + ( ( k-1 )*si ) ] = kp; + } else { + IPIV[ oi + ( ( k-1 )*si ) ] = -kp; + IPIV[ oi + ( k*si ) ] = -kp; + } + // Increase `k` and return to the start of the main loop... + k += kstep; + kc = knc + N - k + 2; + } + return info; +} + + +// MAIN // + +/** +* Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - order of the matrix `A` +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {integer} strideAP - stride length for `AP` +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} strideIPIV - stride length for `IPIV` +* @param {NonNegativeInteger} offsetIPIV - starting index for `IPIV` +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); +* // IPIV => [ 1, 2, 3, 1 ] +*/ +function dsptrf( order, uplo, N, AP, strideAP, offsetAP, IPIV, strideIPIV, offsetIPIV ) { + if ( N === 0 ) { + return 0; + } + // For a symmetric matrix, an upper triangle stored in row-major order is identical in memory to a lower triangle stored in column-major order (and vice versa), so resolve `order`+`uplo` to the equivalent column-major factorization branch... + if ( + ( isColumnMajor( order ) && uplo === 'upper' ) || + ( isRowMajor( order ) && uplo === 'lower' ) + ) { + return factorU( N, AP, strideAP, offsetAP, IPIV, strideIPIV, offsetIPIV ); + } + return factorL( N, AP, strideAP, offsetAP, IPIV, strideIPIV, offsetIPIV ); +} + + +// EXPORTS // + +module.exports = dsptrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/dsptrf.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/dsptrf.js new file mode 100644 index 000000000000..8cda6c99db6b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/dsptrf.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. +* +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - order of the matrix `A` +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {Int32Array} IPIV - vector of pivot indices +* @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 {RangeError} third argument must be a nonnegative integer +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf( 'column-major', 'upper', 4, AP, IPIV ); +* // IPIV => [ 1, 2, 3, 1 ] +*/ +function dsptrf( order, uplo, N, AP, IPIV ) { + 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 ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + return base( order, uplo, N, AP, 1, 0, IPIV, 1, 0 ); +} + + +// EXPORTS // + +module.exports = dsptrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/index.js new file mode 100644 index 000000000000..0f4a665df0d2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/index.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* LAPACK routine to compute the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method. +* +* @module @stdlib/lapack/base/dsptrf +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* var dsptrf = require( '@stdlib/lapack/base/dsptrf' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf( 'column-major', 'upper', 4, AP, IPIV ); +* // IPIV => [ 1, 2, 3, 1 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* var dsptrf = require( '@stdlib/lapack/base/dsptrf' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); +* // IPIV => [ 1, 2, 3, 1 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dsptrf; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dsptrf = main; +} else { + dsptrf = tmp; +} + + +// EXPORTS // + +module.exports = dsptrf; + +// exports: { "ndarray": "dsptrf.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/main.js new file mode 100644 index 000000000000..417239624bc1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsptrf = require( './dsptrf.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dsptrf, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsptrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/ndarray.js new file mode 100644 index 000000000000..dcece9d04a63 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/lib/ndarray.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method and alternative indexing semantics. +* +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - order of the matrix `A` +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {integer} strideAP - stride length for `AP` +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} strideIPIV - stride length for `IPIV` +* @param {NonNegativeInteger} offsetIPIV - starting index for `IPIV` +* @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 {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} fifth argument must be non-zero +* @throws {RangeError} eighth argument must be non-zero +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Int32Array = require( '@stdlib/array/int32' ); +* +* var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] ); +* var IPIV = new Int32Array( 4 ); +* +* dsptrf( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); +* // IPIV => [ 1, 2, 3, 1 ] +*/ +function dsptrf( order, uplo, N, AP, strideAP, offsetAP, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-len + 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 ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideAP === 0 ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideAP ) ); + } + if ( strideIPIV === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideIPIV ) ); + } + return base( order, uplo, N, AP, strideAP, offsetAP, IPIV, strideIPIV, offsetIPIV ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dsptrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/package.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/package.json new file mode 100644 index 000000000000..0e1492c2317e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/lapack/base/dsptrf", + "version": "0.0.0", + "description": "Compute the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method", + "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", + "dsptrf", + "symmetric", + "packed", + "factorization", + "bunch-kaufman", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower.json new file mode 100644 index 000000000000..4f5c954a2b9f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower.json @@ -0,0 +1,95 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 5, + "AP": [ + 1, + 2, + 3, + 0, + 1, + 1, + 0, + 4, + 0, + 1, + 0, + 5, + 1, + 2, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 1, + 2, + 3, + 0, + 1 + ], + [ + 2, + 1, + 0, + 4, + 0 + ], + [ + 3, + 0, + 1, + 0, + 5 + ], + [ + 0, + 4, + 0, + 1, + 2 + ], + [ + 1, + 0, + 5, + 2, + 1 + ] + ], + "expectedAP": [ + 1, + 3, + -0.25, + 0, + 1.75, + 1, + 0.75, + 0, + -0.24999999999999994, + 1.5, + 4, + 0.7931034482758621, + 1, + -1.1724137931034482, + 5.620689655172413 + ], + "expectedIPIV": [ + -3, + -3, + -4, + -4, + 5 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_1x1_rowmax.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_1x1_rowmax.json new file mode 100644 index 000000000000..be56f5a53ccf --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_1x1_rowmax.json @@ -0,0 +1,53 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "AP": [ + 1, + 2, + 1, + 5, + 8, + 5 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 1, + 2, + 1 + ], + [ + 2, + 5, + 8 + ], + [ + 1, + 8, + 5 + ] + ], + "expectedAP": [ + 1, + 2, + 1, + 4, + 1.5, + -8 + ], + "expectedIPIV": [ + 1, + 3, + 3 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_2x2_pivots.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_2x2_pivots.json new file mode 100644 index 000000000000..ef125eb1166a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_2x2_pivots.json @@ -0,0 +1,72 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 4, + "AP": [ + 0, + 1, + 2, + 3, + 0, + 4, + 5, + 0, + 6, + 0 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 0, + 1, + 2, + 3 + ], + [ + 1, + 0, + 4, + 5 + ], + [ + 2, + 4, + 0, + 6 + ], + [ + 3, + 5, + 6, + 0 + ] + ], + "expectedAP": [ + 0, + 3, + 2, + 1.6666666666666665, + 0, + 0.6666666666666666, + 0.3333333333333333, + -8, + 0.16666666666666663, + -3.1111111111111107 + ], + "expectedIPIV": [ + -4, + -4, + 3, + 4 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_large_strides.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_large_strides.json new file mode 100644 index 000000000000..f677436d3522 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_large_strides.json @@ -0,0 +1,96 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 4, + "AP": [ + 4, + 0, + 1, + 0, + -2, + 0, + 2, + 0, + 2, + 0, + 0, + 0, + 1, + 0, + 3, + 0, + -2, + 0, + -1 + ], + "strideAP": 2, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 2, + "offsetIPIV": 0, + "A": [ + [ + 4, + 1, + -2, + 2 + ], + [ + 1, + 2, + 0, + 1 + ], + [ + -2, + 0, + 3, + -2 + ], + [ + 2, + 1, + -2, + -1 + ] + ], + "expectedAP": [ + 4, + 0, + 0.25, + 0, + -0.5, + 0, + 0.5, + 0, + 1.75, + 0, + 0.2857142857142857, + 0, + 0.2857142857142857, + 0, + 1.8571428571428572, + 0, + -0.6153846153846153, + 0, + -2.846153846153846 + ], + "expectedIPIV": [ + 1, + 0, + 2, + 0, + 3, + 0, + 4 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_singular.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_singular.json new file mode 100644 index 000000000000..da55b8776d71 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_lower_singular.json @@ -0,0 +1,72 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 4, + "AP": [ + 2, + 1, + 0, + 0, + 3, + 0, + 0, + 0, + 0, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 2, + 1, + 0, + 0 + ], + [ + 1, + 3, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "expectedAP": [ + 2, + 0.5, + 0, + 0, + 2.5, + 0, + 0, + 0, + 0, + 1 + ], + "expectedIPIV": [ + 1, + 2, + 3, + 4 + ], + "expectedInfo": 3 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper.json new file mode 100644 index 000000000000..747ff1dfb16d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper.json @@ -0,0 +1,95 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 5, + "AP": [ + 1, + 2, + 1, + 3, + 0, + 1, + 0, + 4, + 0, + 1, + 1, + 0, + 5, + 2, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 1, + 2, + 3, + 0, + 1 + ], + [ + 2, + 1, + 0, + 4, + 0 + ], + [ + 3, + 0, + 1, + 0, + 5 + ], + [ + 0, + 4, + 0, + 1, + 2 + ], + [ + 1, + 0, + 5, + 2, + 1 + ] + ], + "expectedAP": [ + 1.8314606741573032, + -0.47191011235955055, + 1, + 0.6179775280898876, + 4, + 1.1666666666666667, + 0.08333333333333331, + 0, + 0.4166666666666667, + 1, + 0.5833333333333334, + 0, + -0.08333333333333334, + 5, + 1 + ], + "expectedIPIV": [ + 1, + -2, + -2, + -3, + -3 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_1x1_rowmax.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_1x1_rowmax.json new file mode 100644 index 000000000000..bfecbea264bb --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_1x1_rowmax.json @@ -0,0 +1,53 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 3, + "AP": [ + 5, + 8, + 5, + 1, + 2, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 5, + 8, + 1 + ], + [ + 8, + 5, + 2 + ], + [ + 1, + 2, + 1 + ] + ], + "expectedAP": [ + -8, + 1.5, + 4, + 1, + 2, + 1 + ], + "expectedIPIV": [ + 1, + 1, + 3 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_2x2_pivots.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_2x2_pivots.json new file mode 100644 index 000000000000..02e86a0b08fa --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_2x2_pivots.json @@ -0,0 +1,72 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 4, + "AP": [ + 0, + 1, + 0, + 2, + 4, + 0, + 3, + 5, + 6, + 0 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 0, + 1, + 2, + 3 + ], + [ + 1, + 0, + 4, + 5 + ], + [ + 2, + 4, + 0, + 6 + ], + [ + 3, + 5, + 6, + 0 + ] + ], + "expectedAP": [ + -0.9333333333333333, + 0.4, + -6.666666666666666, + 0.5, + 0.8333333333333333, + 0, + 0.3333333333333333, + 0.6666666666666666, + 6, + 0 + ], + "expectedIPIV": [ + 1, + 2, + -3, + -3 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_negative_strides.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_negative_strides.json new file mode 100644 index 000000000000..5000945729e4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_negative_strides.json @@ -0,0 +1,72 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 4, + "AP": [ + -1, + -2, + 1, + 2, + 3, + 0, + -2, + 2, + 1, + 4 + ], + "strideAP": -1, + "offsetAP": 9, + "IPIV": [ + 0, + 0, + 0, + 0 + ], + "strideIPIV": -1, + "offsetIPIV": 3, + "A": [ + [ + 4, + 1, + -2, + 2 + ], + [ + 1, + 2, + 0, + 1 + ], + [ + -2, + 0, + 3, + -2 + ], + [ + 2, + 1, + -2, + -1 + ] + ], + "expectedAP": [ + 4, + -0.5, + 0.25, + 0.5, + 2, + 0.25, + -0.5, + 1.625, + 0.46153846153846156, + -2.8461538461538463 + ], + "expectedIPIV": [ + 1, + 3, + 2, + 1 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_offset.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_offset.json new file mode 100644 index 000000000000..7a6f4d90b421 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_offset.json @@ -0,0 +1,82 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 4, + "AP": [ + 0, + 0, + 0, + 4, + 1, + 2, + -2, + 0, + 3, + 2, + 1, + -2, + -1 + ], + "strideAP": 1, + "offsetAP": 3, + "IPIV": [ + 0, + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 2, + "A": [ + [ + 4, + 1, + -2, + 2 + ], + [ + 1, + 2, + 0, + 1 + ], + [ + -2, + 0, + 3, + -2 + ], + [ + 2, + 1, + -2, + -1 + ] + ], + "expectedAP": [ + 0, + 0, + 0, + -2.8461538461538463, + 0.46153846153846156, + 1.625, + -0.5, + 0.25, + 2, + 0.5, + 0.25, + -0.5, + 4 + ], + "expectedIPIV": [ + 0, + 0, + 1, + 2, + 3, + 1 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_singular.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_singular.json new file mode 100644 index 000000000000..bdff7bb18c53 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/column_major_upper_singular.json @@ -0,0 +1,72 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 4, + "AP": [ + 2, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 2, + 1, + 0, + 0 + ], + [ + 1, + 3, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 1 + ] + ], + "expectedAP": [ + 1.6666666666666667, + 0.3333333333333333, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 1 + ], + "expectedIPIV": [ + 1, + 2, + 3, + 4 + ], + "expectedInfo": 3 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/n2_2x2_pivot.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/n2_2x2_pivot.json new file mode 100644 index 000000000000..cff567c2d048 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/n2_2x2_pivot.json @@ -0,0 +1,38 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 2, + "AP": [ + 0, + 1, + 0 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 0, + 1 + ], + [ + 1, + 0 + ] + ], + "expectedAP": [ + 0, + 1, + 0 + ], + "expectedIPIV": [ + -1, + -1 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower.json new file mode 100644 index 000000000000..bebe7ccc7e9a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower.json @@ -0,0 +1,95 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 5, + "AP": [ + 1, + 2, + 3, + 0, + 1, + 1, + 0, + 4, + 0, + 1, + 0, + 5, + 1, + 2, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 1, + 2, + 3, + 0, + 1 + ], + [ + 2, + 1, + 0, + 4, + 0 + ], + [ + 3, + 0, + 1, + 0, + 5 + ], + [ + 0, + 4, + 0, + 1, + 2 + ], + [ + 1, + 0, + 5, + 2, + 1 + ] + ], + "expectedAP": [ + 1.4000000000000001, + 0.4, + -2.500000000000001, + -0.5000000000000002, + -1.2500000000000004, + 0.7272727272727272, + -0.09090909090909093, + 0.27272727272727276, + 0.18181818181818185, + 3, + 0.4545454545454546, + 0.6363636363636364, + 0.09090909090909093, + 5, + 1 + ], + "expectedIPIV": [ + 1, + 2, + 3, + -2, + -2 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower_mixed_strides.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower_mixed_strides.json new file mode 100644 index 000000000000..358aa8d9f133 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_lower_mixed_strides.json @@ -0,0 +1,145 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 5, + "AP": [ + 0, + 1, + 0, + 2, + 0, + 3, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 4, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 5, + 0, + 1, + 0, + 2, + 0, + 1 + ], + "strideAP": 2, + "offsetAP": 1, + "IPIV": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 3, + "offsetIPIV": 2, + "A": [ + [ + 1, + 2, + 3, + 0, + 1 + ], + [ + 2, + 1, + 0, + 4, + 0 + ], + [ + 3, + 0, + 1, + 0, + 5 + ], + [ + 0, + 4, + 0, + 1, + 2 + ], + [ + 1, + 0, + 5, + 2, + 1 + ] + ], + "expectedAP": [ + 0, + 1.4000000000000001, + 0, + 0.4, + 0, + -2.500000000000001, + 0, + -0.5000000000000002, + 0, + -1.2500000000000004, + 0, + 0.7272727272727272, + 0, + -0.09090909090909093, + 0, + 0.27272727272727276, + 0, + 0.18181818181818185, + 0, + 3, + 0, + 0.4545454545454546, + 0, + 0.6363636363636364, + 0, + 0.09090909090909093, + 0, + 5, + 0, + 1 + ], + "expectedIPIV": [ + 0, + 0, + 1, + 0, + 0, + 2, + 0, + 0, + 3, + 0, + 0, + -2, + 0, + 0, + -2 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_upper.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_upper.json new file mode 100644 index 000000000000..a5be8049cd2c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/row_major_upper.json @@ -0,0 +1,95 @@ +{ + "order": "row-major", + "uplo": "upper", + "N": 5, + "AP": [ + 1, + 2, + 1, + 3, + 0, + 1, + 0, + 4, + 0, + 1, + 1, + 0, + 5, + 2, + 1 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0, + 0, + 0, + 0, + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 1, + 2, + 3, + 0, + 1 + ], + [ + 2, + 1, + 0, + 4, + 0 + ], + [ + 3, + 0, + 1, + 0, + 5 + ], + [ + 0, + 4, + 0, + 1, + 2 + ], + [ + 1, + 0, + 5, + 2, + 1 + ] + ], + "expectedAP": [ + 5, + 0.8, + 0.2, + 0.6000000000000001, + 0.4, + -2.2, + 0.36363636363636365, + 0.18181818181818196, + 0.7272727272727273, + 1.090909090909091, + 0.5, + 0.16666666666666669, + -1.0000000000000002, + 0.9999999999999997, + 2.333333333333333 + ], + "expectedIPIV": [ + 4, + 2, + 3, + 4, + 5 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/single_element.json b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/single_element.json new file mode 100644 index 000000000000..d7716e9b43e5 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/fixtures/single_element.json @@ -0,0 +1,27 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 1, + "AP": [ + 5 + ], + "strideAP": 1, + "offsetAP": 0, + "IPIV": [ + 0 + ], + "strideIPIV": 1, + "offsetIPIV": 0, + "A": [ + [ + 5 + ] + ], + "expectedAP": [ + 5 + ], + "expectedIPIV": [ + 1 + ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.dsptrf.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.dsptrf.js new file mode 100644 index 000000000000..15ae1ac3d892 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.dsptrf.js @@ -0,0 +1,387 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var dsptrf = require( './../lib/dsptrf.js' ); + + +// FIXTURES // + +var COLUMN_MAJOR_UPPER = require( './fixtures/column_major_upper.json' ); +var COLUMN_MAJOR_LOWER = require( './fixtures/column_major_lower.json' ); +var ROW_MAJOR_UPPER = require( './fixtures/row_major_upper.json' ); +var ROW_MAJOR_LOWER = require( './fixtures/row_major_lower.json' ); +var COLUMN_MAJOR_UPPER_2X2 = require( './fixtures/column_major_upper_2x2_pivots.json' ); +var COLUMN_MAJOR_LOWER_2X2 = require( './fixtures/column_major_lower_2x2_pivots.json' ); +var COLUMN_MAJOR_UPPER_SINGULAR = require( './fixtures/column_major_upper_singular.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_LOWER_SINGULAR = require( './fixtures/column_major_lower_singular.json' ); // eslint-disable-line id-length +var SINGLE_ELEMENT = require( './fixtures/single_element.json' ); +var N2_2X2_PIVOT = require( './fixtures/n2_2x2_pivot.json' ); +var COLUMN_MAJOR_UPPER_1X1_ROWMAX = require( './fixtures/column_major_upper_1x1_rowmax.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_LOWER_1X1_ROWMAX = require( './fixtures/column_major_lower_1x1_rowmax.json' ); // eslint-disable-line id-length + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsptrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( dsptrf.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument (order)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + '', + 1, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( value, 'upper', 4, AP, IPIV ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument (triangle specifier)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + '', + 1, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', value, 4, AP, IPIV ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument (N) which is less than zero', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', 'upper', value, AP, IPIV ); + }; + } +}); + +tape( 'the function computes the Bunch-Kaufman factorization of a real symmetric matrix `A` stored in packed format (column-major)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Bunch-Kaufman factorization of a real symmetric matrix `A` stored in packed format (row-major)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = ROW_MAJOR_UPPER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = ROW_MAJOR_LOWER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports 2x2 pivot blocks', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_2X2; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_2X2; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = N2_2X2_PIVOT; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a 1x1 pivot selected via a row interchange', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_1X1_ROWMAX; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_1X1_ROWMAX; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports factorizing a single-element matrix', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = SINGLE_ELEMENT; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a non-zero status code when a diagonal block is exactly zero (singular matrix)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_SINGULAR; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.strictEqual( info > 0, true, 'returns a positive status code' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_SINGULAR; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, IPIV ); + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.strictEqual( info > 0, true, 'returns a positive status code' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the input arrays unchanged when `N` is equal to zero', function test( t ) { + var expectedIPIV; + var expectedAP; + var info; + var IPIV; + var AP; + + AP = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + IPIV = new Int32Array( [ 0, 0 ] ); + + expectedAP = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + expectedIPIV = new Int32Array( [ 0, 0 ] ); + + info = dsptrf( 'column-major', 'upper', 0, AP, IPIV ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.js new file mode 100644 index 000000000000..41d28461a0fa --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dsptrf = 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 dsptrf, '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 dsptrf.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 dsptrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dsptrf, 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 dsptrf; + var main; + + main = require( './../lib/dsptrf.js' ); + + dsptrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dsptrf, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.ndarray.js new file mode 100644 index 000000000000..3410e2d06573 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dsptrf/test/test.ndarray.js @@ -0,0 +1,476 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var dsptrf = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var COLUMN_MAJOR_UPPER = require( './fixtures/column_major_upper.json' ); +var COLUMN_MAJOR_LOWER = require( './fixtures/column_major_lower.json' ); +var ROW_MAJOR_UPPER = require( './fixtures/row_major_upper.json' ); +var ROW_MAJOR_LOWER = require( './fixtures/row_major_lower.json' ); +var COLUMN_MAJOR_UPPER_2X2 = require( './fixtures/column_major_upper_2x2_pivots.json' ); +var COLUMN_MAJOR_LOWER_2X2 = require( './fixtures/column_major_lower_2x2_pivots.json' ); +var COLUMN_MAJOR_UPPER_SINGULAR = require( './fixtures/column_major_upper_singular.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_LOWER_SINGULAR = require( './fixtures/column_major_lower_singular.json' ); // eslint-disable-line id-length +var SINGLE_ELEMENT = require( './fixtures/single_element.json' ); +var N2_2X2_PIVOT = require( './fixtures/n2_2x2_pivot.json' ); +var COLUMN_MAJOR_UPPER_OFFSET = require( './fixtures/column_major_upper_offset.json' ); +var COLUMN_MAJOR_LOWER_LARGE_STRIDES = require( './fixtures/column_major_lower_large_strides.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_UPPER_NEGATIVE_STRIDES = require( './fixtures/column_major_upper_negative_strides.json' ); // eslint-disable-line id-length +var ROW_MAJOR_LOWER_MIXED_STRIDES = require( './fixtures/row_major_lower_mixed_strides.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_UPPER_1X1_ROWMAX = require( './fixtures/column_major_upper_1x1_rowmax.json' ); // eslint-disable-line id-length +var COLUMN_MAJOR_LOWER_1X1_ROWMAX = require( './fixtures/column_major_lower_1x1_rowmax.json' ); // eslint-disable-line id-length + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsptrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( dsptrf.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument (order)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + '', + 1, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( value, 'upper', 4, AP, 1, 0, IPIV, 1, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument (triangle specifier)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + '', + 1, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', value, 4, AP, 1, 0, IPIV, 1, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument (N) which is less than zero', function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', 'upper', value, AP, 1, 0, IPIV, 1, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument (strideAP) equal to zero', function test( t ) { + t.throws( badValue, RangeError, 'throws an error when provided a stride equal to zero' ); + t.end(); + + function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', 'upper', 4, AP, 0, 0, IPIV, 1, 0 ); + } +}); + +tape( 'the function throws an error if provided an eighth argument (strideIPIV) equal to zero', function test( t ) { + t.throws( badValue, RangeError, 'throws an error when provided a stride equal to zero' ); + t.end(); + + function badValue() { + var IPIV = new Int32Array( 4 ); + var AP = new Float64Array( 10 ); + dsptrf( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 0, 0 ); + } +}); + +tape( 'the function computes the Bunch-Kaufman factorization of a real symmetric matrix `A` stored in packed format (column-major)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Bunch-Kaufman factorization of a real symmetric matrix `A` stored in packed format (row-major)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = ROW_MAJOR_UPPER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = ROW_MAJOR_LOWER; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports 2x2 pivot blocks', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_2X2; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_2X2; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = N2_2X2_PIVOT; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a 1x1 pivot selected via a row interchange', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_1X1_ROWMAX; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_1X1_ROWMAX; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports factorizing a single-element matrix', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = SINGLE_ELEMENT; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a non-zero status code when a diagonal block is exactly zero (singular matrix)', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_SINGULAR; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.strictEqual( info > 0, true, 'returns a positive status code' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_SINGULAR; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.strictEqual( info > 0, true, 'returns a positive status code' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying strides and offsets for `AP` and `IPIV`', function test( t ) { + var expectedIPIV; + var expectedAP; + var data; + var info; + var IPIV; + var AP; + + data = COLUMN_MAJOR_UPPER_OFFSET; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_LOWER_LARGE_STRIDES; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = COLUMN_MAJOR_UPPER_NEGATIVE_STRIDES; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + data = ROW_MAJOR_LOWER_MIXED_STRIDES; + + AP = new Float64Array( data.AP ); + IPIV = new Int32Array( data.IPIV ); + + expectedAP = new Float64Array( data.expectedAP ); + expectedIPIV = new Int32Array( data.expectedIPIV ); + + info = dsptrf( data.order, data.uplo, data.N, AP, data.strideAP, data.offsetAP, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + t.strictEqual( info, data.expectedInfo, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the input arrays unchanged when `N` is equal to zero', function test( t ) { + var expectedIPIV; + var expectedAP; + var info; + var IPIV; + var AP; + + AP = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + IPIV = new Int32Array( [ 0, 0 ] ); + + expectedAP = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + expectedIPIV = new Int32Array( [ 0, 0 ] ); + + info = dsptrf( 'column-major', 'upper', 0, AP, 1, 0, IPIV, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( AP, expectedAP, 'returns expected value' ); + t.deepEqual( IPIV, expectedIPIV, 'returns expected value' ); + + t.end(); +});