diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/README.md b/lib/node_modules/@stdlib/lapack/base/dgetrf/README.md new file mode 100644 index 000000000000..38903bbb2418 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/README.md @@ -0,0 +1,163 @@ + + +# dgetrf + +> Compute an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges. + +
+ +The `dgetrf` routine computes an LU factorization of a real `M`-by-`N` matrix `A`. The factorization has the form + +```math +A = P * L * U +``` + +where `P` is a permutation matrix, `L` is lower triangular or trapezoidal with unit diagonal elements, and `U` is upper triangular or trapezoidal. The routine supports square, tall, and wide matrices. + +The factors are stored in-place in `A`: the strictly lower triangular part contains the multipliers defining `L`, and the upper triangular part contains `U`. The unit diagonal elements of `L` are not stored. The vector `IPIV` records the row interchanges used during factorization. + +
+ + + +
+ +## Usage + +```javascript +var dgetrf = require( '@stdlib/lapack/base/dgetrf' ); +``` + +#### dgetrf( M, N, A, LDA, IPIV ) + +Computes an LU factorization of a real general `M`-by-`N` matrix `A` using partial pivoting. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); + +var A = new Float64Array( [ + 1.0, 3.0, 2.0, + 2.0, 4.0, 1.0, + 1.0, 2.0, 3.0 +] ); +var IPIV = new Int32Array( 3 ); + +var info = dgetrf( 3, 3, A, 3, IPIV ); +// info => 0 +// IPIV => [ 1, 2, 2 ] +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a [`Float64Array`][mdn-float64array], stored in column-major order. `A` is overwritten by the factors. +- **LDA**: stride between successive columns of `A`. `LDA` must be at least `max(1,M)`. +- **IPIV**: pivot indices as an [`Int32Array`][mdn-int32array]. For each `i` in `0 <= i < min(M,N)`, row `i` is interchanged with row `IPIV(i)`. + +Indexing is relative to the first element. To introduce a byte offset for the public API, use typed array views. + +#### dgetrf.ndarray + +`dgetrf.ndarray( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV )` + +Computes an LU factorization using alternative indexing semantics. + +```javascript +var A = new Float64Array( [ + 1.0, 3.0, 2.0, + 2.0, 4.0, 1.0, + 1.0, 2.0, 3.0 +] ); +var IPIV = new Int32Array( 3 ); + +var info = dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1, 0 ); +// info => 0 +``` + +The function has the following additional parameters: + +- **strideA1**: stride of the first dimension of `A`. +- **strideA2**: stride of the second dimension of `A`. +- **offsetA**: starting index for `A`. +- **strideIPIV**: stride length for `IPIV`. +- **offsetIPIV**: starting index for `IPIV`. + +While typed array views mandate a view offset based on the underlying buffer, ndarray offsets support indexing semantics based on starting indices. Strides may be positive or negative. + +
+ + + +
+ +## Notes + +- Both functions mutate `A` and `IPIV`. +- If `INFO` is zero, the factorization was successful. If `INFO` is greater than zero, `U(INFO,INFO)` is exactly zero; the factorization has been completed, but `U` is singular. +- The pivot indices use zero-based JavaScript indexing. This differs from the one-based pivot indices in the original Fortran LAPACK interface. +- The routine computes the factorization in-place and returns the status code rather than separate `L` and `U` matrices. +- `dgetrf()` corresponds to the [LAPACK][lapack] routine [`DGETRF`][lapack-dgetrf]. + +
+ + + +
+ +## Examples + +```javascript +var dgetrf = require( '@stdlib/lapack/base/dgetrf' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); + +var A = new Float64Array( [ + 4.0, 2.0, 1.0, + 1.0, 3.0, 2.0 +] ); +var IPIV = new Int32Array( 2 ); + +// Factor a 3-by-2 matrix stored in column-major order: +var info = dgetrf( 3, 2, A, 3, IPIV ); +console.log( A ); +console.log( IPIV ); +console.log( info ); +``` + +
+ + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.js new file mode 100644 index 000000000000..3f334464b3d3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.js @@ -0,0 +1,99 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dgetrf = require( './../lib/dgetrf.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var A = uniform( len*len, -1.0, 1.0, options ); + var IPIV = new Int32Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var info; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + info = dgetrf( len, len, A, len, IPIV ); + if ( info < 0 ) { + b.fail( 'should return a valid status code' ); + } + } + b.toc(); + if ( info < 0 ) { + b.fail( 'should return a valid status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; + max = 3; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..88e9093640d3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.ndarray.js @@ -0,0 +1,99 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dgetrf = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var A = uniform( len*len, -1.0, 1.0, options ); + var IPIV = new Int32Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var info; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + info = dgetrf( len, len, A, 1, len, 0, IPIV, 1, 0 ); + if ( info < 0 ) { + b.fail( 'should return a valid status code' ); + } + } + b.toc(); + if ( info < 0 ) { + b.fail( 'should return a valid status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; + max = 3; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/repl.txt new file mode 100644 index 000000000000..59897b7e4d4a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/repl.txt @@ -0,0 +1,101 @@ +{{alias}}( M, N, A, LDA, IPIV ) + Computes an LU factorization of a real general M-by-N matrix `A` using + elimination with partial pivoting and row interchanges. + + The factorization has the form `A = P * L * U`, where `P` is a permutation + matrix, `L` is lower trapezoidal with unit diagonal elements, and `U` is + upper trapezoidal. The function mutates `A` and `IPIV`. + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Float64Array + Input matrix stored in column-major order. On return, the strictly + lower triangular part contains the multipliers defining `L`, and the + upper triangular part contains `U`. The unit diagonal of `L` is not + stored. + + LDA: integer + Stride between successive columns of `A`. `LDA` must be at least + `max(1,M)`. + + IPIV: Int32Array + Pivot indices. For each `i` in `0 <= i < min(M,N)`, row `i` is + interchanged with row `IPIV(i)`. + + Returns + ------- + info: integer + Status code. If equal to zero, then the factorization was successful. + If greater than zero, `U(k,k)` is exactly zero, the factorization has + been completed, and `U` is singular. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0 ] ); + > var IPIV = new {{alias:@stdlib/array/int32}}( 3 ); + > {{alias}}( 3, 3, A, 3, IPIV ) + 0 + > IPIV + [ 1, 2, 2 ] + + +{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV ) + Computes an LU factorization using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. The matrix and pivot vector may also use non-unit or negative + strides. + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Float64Array + Input matrix. + + strideA1: integer + Stride of the first dimension of `A`. + + strideA2: integer + Stride of the second dimension of `A`. + + offsetA: integer + Starting index for `A`. + + IPIV: Int32Array + Pivot indices. + + strideIPIV: integer + Stride length for `IPIV`. + + offsetIPIV: integer + Starting index for `IPIV`. + + Returns + ------- + info: integer + Status code. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 3.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 3.0 ] ); + > var IPIV = new {{alias:@stdlib/array/int32}}( 3 ); + > {{alias}}.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1, 0 ) + 0 + > IPIV + [ 1, 2, 2 ] + + See Also + -------- + {{alias}} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/index.d.ts new file mode 100644 index 000000000000..5a10736f2bd0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/index.d.ts @@ -0,0 +1,102 @@ +/* +* @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 + +/** +* Status code. +*/ +type StatusCode = number; + +/** +* Interface describing `dgetrf`. +*/ +interface Routine { + /** + * Computes an `LU` factorization of a real general matrix `A` using + * elimination with partial pivoting and row interchanges. + * + * The factorization has the form `A = P * L * U`, where `P` is a permutation + * matrix, `L` is lower trapezoidal with unit diagonal elements, and `U` is + * upper trapezoidal. The input matrix `A` is overwritten in-place, and the + * unit diagonal of `L` is not stored. Pivot indices are zero-based. + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix stored in column-major order + * @param LDA - stride between successive columns of `A`; `LDA >= max(1,M)` + * @param IPIV - pivot indices + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * var Int32Array = require( '@stdlib/array/int32' ); + * + * var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0 ] ); + * var IPIV = new Int32Array( 2 ); + * + * dgetrf( 2, 2, A, 2, IPIV ); + * // A => [ 3, 0.333..., 4, 0.666... ] + * // IPIV => [ 1, 1 ] + */ + ( M: number, N: number, A: Float64Array, LDA: number, IPIV: Int32Array ): StatusCode; + + /** + * Computes an `LU` factorization using alternative indexing semantics. + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @param IPIV - 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 A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0 ] ); + * var IPIV = new Int32Array( 2 ); + * + * dgetrf.ndarray( 2, 2, A, 1, 2, 0, IPIV, 1, 0 ); + * // A => [ 3, 0.333..., 4, 0.666... ] + * // IPIV => [ 1, 1 ] + */ + ndarray( M: number, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number, IPIV: Int32Array, strideIPIV: number, offsetIPIV: number ): StatusCode; +} + +/** +* Computes an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges. +* +* @param M - number of rows in `A` +* @param N - number of columns in `A` +* @param A - input matrix, stored in column-major order +* @param LDA - stride between successive columns of `A` +* @param IPIV - vector of pivot indices +* @returns status code +*/ +declare var dgetrf: Routine; + + +// EXPORTS // + +export = dgetrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/test.ts new file mode 100644 index 000000000000..ad22259e0e4c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/docs/types/test.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +import dgetrf = require( './index' ); + + +// TESTS // + +{ + const A = new Float64Array( 9 ); + const IPIV = new Int32Array( 3 ); + + dgetrf( 3, 3, A, 3, IPIV ); // $ExpectType number +} + +{ + const A = new Float64Array( 9 ); + const IPIV = new Int32Array( 3 ); + + dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1, 0 ); // $ExpectType number +} + +{ + const A = new Float64Array( 9 ); + const IPIV = new Int32Array( 3 ); + + dgetrf( '3', 3, A, 3, IPIV ); // $ExpectError + dgetrf( 3, 3, A, 3, new Float64Array( 3 ) ); // $ExpectError + dgetrf( 3, 3, new Int32Array( 9 ), 3, IPIV ); // $ExpectError + dgetrf( 3, 3, A, '3', IPIV ); // $ExpectError + dgetrf( 3, 3, A, 3, IPIV, 0 ); // $ExpectError +} + +{ + const A = new Float64Array( 9 ); + const IPIV = new Int32Array( 3 ); + + dgetrf.ndarray( '3', 3, A, 1, 3, 0, IPIV, 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, new Int32Array( 9 ), 1, 3, 0, IPIV, 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, '1', 3, 0, IPIV, 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, '3', 0, IPIV, 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, '0', IPIV, 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, 0, new Float64Array( 3 ), 1, 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, '1', 0 ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1, '0' ); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1, 0, 10 ); // $ExpectError +} + +{ + const A = new Float64Array( 9 ); + const IPIV = new Int32Array( 3 ); + + dgetrf(); // $ExpectError + dgetrf( 3 ); // $ExpectError + dgetrf( 3, 3, A ); // $ExpectError + dgetrf( 3, 3, A, 3 ); // $ExpectError + dgetrf.ndarray(); // $ExpectError + dgetrf.ndarray( 3, 3, A, 1, 3, 0, IPIV, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/examples/index.js new file mode 100644 index 000000000000..d9206c2afd6c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/examples/index.js @@ -0,0 +1,17 @@ +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var dgetrf = require( './../lib' ); + +var A = new Float64Array( [ + 1.0, 3.0, 2.0, + 2.0, 4.0, 1.0, + 1.0, 2.0, 3.0 +] ); +var IPIV = new Int32Array( 3 ); + +var info = dgetrf( 3, 3, A, 3, IPIV ); +console.log( A ); +console.log( IPIV ); +console.log( info ); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/base.js new file mode 100644 index 000000000000..e8868beeaf79 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/base.js @@ -0,0 +1,100 @@ +/* +* @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 idamax = require( '@stdlib/blas/base/idamax' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var dswap = require( '@stdlib/blas/base/dswap' ).ndarray; +var dger = require( '@stdlib/blas/base/dger' ).ndarray; + + +// MAIN // + +/** +* Computes an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges. +* +* @private +* +* ## Notes +* +* - The factorization has the form `A = P * L * U`, where `P` is a permutation matrix, `L` is lower triangular or trapezoidal with unit diagonal elements, and `U` is upper triangular or trapezoidal. +* - `A` is overwritten in-place. The strictly lower triangular part contains the multipliers defining `L`, and the upper triangular part contains `U`. The unit diagonal of `L` is not stored. +* - `IPIV` contains zero-based pivot indices. For each `i` in `0 <= i < min(M,N)`, row `i` is interchanged with row `IPIV(i)`. +* - If the returned status code is greater than zero, `U(k,k)` is exactly zero for `k` equal to the status code. The factorization has been completed, but `U` is singular. +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @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 A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0 ] ); +* var IPIV = new Int32Array( 2 ); +* +* dgetrf( 2, 2, A, 1, 2, 0, IPIV, 1, 0 ); +* // A => [ 3, 0.333..., 4, 0.666... ] +* // IPIV => [ 1, 1 ] +*/ +function dgetrf( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-params, max-len + var mn; + var info; + var ia; + var jp; + var j; + + mn = M < N ? M : N; + info = 0; + for ( j = 0; j < mn; j++ ) { + ia = offsetA + ( j * strideA2 ) + ( j * strideA1 ); + jp = j + idamax( M-j, A, strideA1, ia ); + IPIV[ offsetIPIV + ( j * strideIPIV ) ] = jp; + if ( A[ offsetA + ( jp * strideA1 ) + ( j * strideA2 ) ] !== 0.0 ) { + if ( jp !== j ) { + dswap( N, A, strideA2, offsetA+(j*strideA1), A, strideA2, offsetA+(jp*strideA1) ); // eslint-disable-line max-len + } + if ( j < M-1 ) { + dscal( M-j-1, 1.0/A[ ia ], A, strideA1, ia+strideA1 ); + } + } + if ( A[ ia ] === 0.0 ) { + if ( info === 0 ) { + info = j+1; + } + } + if ( A[ ia ] !== 0.0 && j < mn-1 ) { + dger( M-j-1, N-j-1, -1.0, A, strideA1, ia+strideA1, A, strideA2, ia+strideA2, A, strideA1, strideA2, ia+strideA1+strideA2 ); + } + } + return info; +} + + +// EXPORTS // + +module.exports = dgetrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/dgetrf.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/dgetrf.js new file mode 100644 index 000000000000..7b28931ecf26 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/dgetrf.js @@ -0,0 +1,66 @@ +/* +* @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 max = require( '@stdlib/math/base/special/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges. +* +* ## Notes +* +* - The factorization has the form `A = P * L * U`, where `P` is a permutation matrix, `L` is lower triangular or trapezoidal with unit diagonal elements, and `U` is upper triangular or trapezoidal. +* - `A` is overwritten in-place. The strictly lower triangular part contains the multipliers defining `L`, and the upper triangular part contains `U`. The unit diagonal of `L` is not stored. +* - `IPIV` contains zero-based pivot indices. For each `i` in `0 <= i < min(M,N)`, row `i` is interchanged with row `IPIV(i)`. +* - If the returned status code is greater than zero, `U(k,k)` is exactly zero for `k` equal to the status code. The factorization has been completed, but `U` is singular. +* +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input matrix +* @param {PositiveInteger} LDA - stride between successive columns of `A` +* @param {Int32Array} IPIV - vector of pivot indices +* @throws {RangeError} first argument must be a nonnegative integer +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} fourth argument must be greater than or equal to max(1,M) +* @returns {integer} status code +*/ +function dgetrf( M, N, A, LDA, IPIV ) { + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( LDA < max( 1, M ) ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to max(1,%d). Value: `%d`.', M, LDA ) ); + } + return base( M, N, A, 1, LDA, 0, IPIV, 1, 0 ); +} + + +// EXPORTS // + +module.exports = dgetrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/index.js new file mode 100644 index 000000000000..8c6afc4be865 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/index.js @@ -0,0 +1,20 @@ +/** +* @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'; + +module.exports = require( './main.js' ); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/main.js new file mode 100644 index 000000000000..f9dc95bcbe33 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/main.js @@ -0,0 +1,34 @@ +/** +* @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 dgetrf = require( './dgetrf.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dgetrf, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dgetrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/ndarray.js new file mode 100644 index 000000000000..e00213e27ac4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/lib/ndarray.js @@ -0,0 +1,58 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges and alternative indexing semantics. +* +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} strideIPIV - stride length for `IPIV` +* @param {NonNegativeInteger} offsetIPIV - starting index for `IPIV` +* @throws {RangeError} first argument must be a nonnegative integer +* @throws {RangeError} second argument must be a nonnegative integer +* @returns {integer} status code +*/ +function dgetrf( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-params, max-len + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + return base( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV ); +} + + +// EXPORTS // + +module.exports = dgetrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/package.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/package.json new file mode 100644 index 000000000000..73f2476f494e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dgetrf", + "version": "0.0.0", + "description": "Compute an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges.", + "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", + "dgetrf", + "lu", + "factorization", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_1.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_1.json new file mode 100644 index 000000000000..48ff39208b01 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_1.json @@ -0,0 +1,14 @@ +{ + "M": 2, + "N": 3, + "A": [ 4.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 0.0, 1.0 ], + "strideA1": 2, + "strideA2": 6, + "offsetA": 0, + "IPIV": [ 0, 0 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 4.0, 0.0, 0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 2.5, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0 ], + "expectedIPIV": [ 0, 1 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_2.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_2.json new file mode 100644 index 000000000000..08798fafec6a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/large_positive_stride_2.json @@ -0,0 +1,14 @@ +{ + "M": 3, + "N": 2, + "A": [ 4.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 3.0, 0.0, 2.0, 0.0 ], + "strideA1": 2, + "strideA2": 8, + "offsetA": 0, + "IPIV": [ 0, 0, 0 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 4.0, 0.0, 0.5, 0.0, 0.25, 0.0, 0.0, 0.0, 1.0, 0.0, 2.5, 0.0, 0.7, 0.0 ], + "expectedIPIV": [ 0, 1, 0 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/mixed_strided.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/mixed_strided.json new file mode 100644 index 000000000000..774951590a17 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/mixed_strided.json @@ -0,0 +1,14 @@ +{ + "M": 2, + "N": 2, + "A": [ 3.0, 4.0, 0.0, 1.0, 2.0, 0.0 ], + "strideA1": -3, + "strideA2": 1, + "offsetA": 3, + "IPIV": [ 1, 1 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 0.3333333333333333, 0.6666666666666666, 0.0, 3.0, 4.0, 0.0 ], + "expectedIPIV": [ 1, 1 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/negative_strides.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/negative_strides.json new file mode 100644 index 000000000000..2d7dbef20b8f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/negative_strides.json @@ -0,0 +1,14 @@ +{ + "M": 2, + "N": 2, + "A": [ 4.0, 2.0, 3.0, 1.0 ], + "strideA1": -1, + "strideA2": -2, + "offsetA": 3, + "IPIV": [ 1, 1 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 0.6666666666666666, 4.0, 0.3333333333333333, 3.0 ], + "expectedIPIV": [ 1, 1 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_1.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_1.json new file mode 100644 index 000000000000..6d1bad6cf434 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_1.json @@ -0,0 +1,14 @@ +{ + "M": 2, + "N": 2, + "A": [ 1.0, 3.0, 2.0, 4.0 ], + "strideA1": 1, + "strideA2": 2, + "offsetA": 0, + "IPIV": [ 0, 0 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 3.0, 0.3333333333333333, 4.0, 0.6666666666666666 ], + "expectedIPIV": [ 1, 1 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_2.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_2.json new file mode 100644 index 000000000000..5e514b312a51 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_no_offset_2.json @@ -0,0 +1,14 @@ +{ + "M": 3, + "N": 2, + "A": [ 4.0, 2.0, 1.0, 1.0, 3.0, 2.0 ], + "strideA1": 1, + "strideA2": 3, + "offsetA": 0, + "IPIV": [ 0, 0, 0 ], + "strideIPIV": 1, + "offsetIPIV": 0, + "expectedA": [ 4.0, 0.5, 0.25, 1.0, 2.5, 0.7 ], + "expectedIPIV": [ 0, 1, 0 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_1.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_1.json new file mode 100644 index 000000000000..aaa229f41201 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_1.json @@ -0,0 +1,14 @@ +{ + "M": 2, + "N": 2, + "A": [ 99.0, 1.0, 3.0, 2.0, 4.0, 88.0 ], + "strideA1": 1, + "strideA2": 2, + "offsetA": 1, + "IPIV": [ 9, 0, 0, 9 ], + "strideIPIV": 1, + "offsetIPIV": 1, + "expectedA": [ 99.0, 3.0, 0.3333333333333333, 4.0, 0.6666666666666666, 88.0 ], + "expectedIPIV": [ 9, 1, 1, 9 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_2.json b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_2.json new file mode 100644 index 000000000000..5e6b4742948d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/fixtures/positive_stride_offset_2.json @@ -0,0 +1,14 @@ +{ + "M": 3, + "N": 2, + "A": [ 99.0, 99.0, 4.0, 2.0, 1.0, 99.0, 1.0, 3.0, 2.0, 88.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 2, + "IPIV": [ 9, 0, 0, 0, 9 ], + "strideIPIV": 1, + "offsetIPIV": 1, + "expectedA": [ 99.0, 99.0, 4.0, 0.5, 0.25, 99.0, 1.0, 2.5, 0.7, 88.0 ], + "expectedIPIV": [ 9, 0, 1, 0, 9 ], + "expectedInfo": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.dgetrf.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.dgetrf.js new file mode 100644 index 000000000000..d116e5422885 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.dgetrf.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dgetrf = require( './../lib/dgetrf.js' ); + + +// FIXTURES // + +var POSITIVE_STRIDES_NO_OFFSET_1 = require( './fixtures/positive_stride_no_offset_1.json' ); // eslint-disable-line id-length +var POSITIVE_STRIDES_NO_OFFSET_2 = require( './fixtures/positive_stride_no_offset_2.json' ); // eslint-disable-line id-length + + +// FUNCTIONS // + +function isApprox( t, actual, expected ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = 2.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgetrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( dgetrf.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided invalid dimensions or leading dimension', function test( t ) { + var A = new Float64Array( 4 ); + var IPIV = new Int32Array( 2 ); + + t.throws( function badRows() { + dgetrf( -1, 2, A, 2, IPIV ); + }, RangeError, 'throws for a negative row count' ); + t.throws( function badColumns() { + dgetrf( 2, -1, A, 2, IPIV ); + }, RangeError, 'throws for a negative column count' ); + t.throws( function badLeadingDimension() { + dgetrf( 2, 2, A, 1, IPIV ); + }, RangeError, 'throws for an invalid leading dimension' ); + t.end(); +}); + +tape( 'the function computes an `LU` factorization with partial pivoting', function test( t ) { + var data = POSITIVE_STRIDES_NO_OFFSET_1; + var A = new Float64Array( data.A ); + var IPIV = new Int32Array( data.IPIV ); + var info = dgetrf( data.M, data.N, A, data.strideA2, IPIV ); + + t.strictEqual( info, data.expectedInfo, 'returns expected status code' ); + t.deepEqual( IPIV, new Int32Array( data.expectedIPIV ), 'returns expected pivot indices' ); + isApprox( t, A, new Float64Array( data.expectedA ) ); + t.end(); +}); + +tape( 'the function supports tall matrices', function test( t ) { + var data = POSITIVE_STRIDES_NO_OFFSET_2; + var A = new Float64Array( data.A ); + var IPIV = new Int32Array( data.IPIV ); + var info = dgetrf( data.M, data.N, A, data.strideA2, IPIV ); + + t.strictEqual( info, data.expectedInfo, 'returns expected status code' ); + t.deepEqual( IPIV, new Int32Array( data.expectedIPIV ), 'returns expected pivot indices' ); + isApprox( t, A, new Float64Array( data.expectedA ) ); + t.end(); +}); + +tape( 'the function supports wide matrices', function test( t ) { + var A = new Float64Array( [ 4.0, 2.0, 1.0, 3.0, 2.0, 1.0 ] ); + var IPIV = new Int32Array( 2 ); + var info = dgetrf( 2, 3, A, 2, IPIV ); + + t.strictEqual( info, 0, 'returns expected status code' ); + t.deepEqual( IPIV, new Int32Array( [ 0, 1 ] ), 'returns expected pivot indices' ); + t.deepEqual( A, new Float64Array( [ 4.0, 0.5, 1.0, 2.5, 2.0, 0.0 ] ), 'returns expected factorization' ); + t.end(); +}); + +tape( 'the function supports a 1-by-1 matrix and zero dimensions', function test( t ) { + var A = new Float64Array( [ 5.0 ] ); + var IPIV = new Int32Array( 1 ); + + t.strictEqual( dgetrf( 1, 1, A, 1, IPIV ), 0, 'returns expected status code' ); + t.deepEqual( A, new Float64Array( [ 5.0 ] ), 'returns expected factorization' ); + t.deepEqual( IPIV, new Int32Array( [ 0 ] ), 'returns expected pivot indices' ); + t.strictEqual( dgetrf( 0, 3, A, 1, IPIV ), 0, 'supports zero rows' ); + t.strictEqual( dgetrf( 3, 0, A, 3, IPIV ), 0, 'supports zero columns' ); + t.end(); +}); + +tape( 'the function returns a non-zero status code for a singular matrix', function test( t ) { + var A = new Float64Array( [ 0.0, 0.0, 1.0, 2.0 ] ); + var IPIV = new Int32Array( 2 ); + var info = dgetrf( 2, 2, A, 2, IPIV ); + + t.strictEqual( info, 1, 'returns the first zero pivot index' ); + t.deepEqual( IPIV, new Int32Array( [ 0, 1 ] ), 'returns expected pivot indices' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.js new file mode 100644 index 000000000000..39d551e9b4c0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 dgetrf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgetrf, '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 dgetrf.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.ndarray.js new file mode 100644 index 000000000000..3c000612ca56 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgetrf/test/test.ndarray.js @@ -0,0 +1,117 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dgetrf = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var POSITIVE_STRIDES_NO_OFFSET_1 = require( './fixtures/positive_stride_no_offset_1.json' ); // eslint-disable-line id-length +var POSITIVE_STRIDES_NO_OFFSET_2 = require( './fixtures/positive_stride_no_offset_2.json' ); // eslint-disable-line id-length +var LARGE_POSITIVE_STRIDE_1 = require( './fixtures/large_positive_stride_1.json' ); +var LARGE_POSITIVE_STRIDE_2 = require( './fixtures/large_positive_stride_2.json' ); +var NEGATIVE_STRIDES = require( './fixtures/negative_strides.json' ); +var MIXED_STRIDES = require( './fixtures/mixed_strided.json' ); +var POSITIVE_STRIDES_OFFSET_1 = require( './fixtures/positive_stride_offset_1.json' ); +var POSITIVE_STRIDES_OFFSET_2 = require( './fixtures/positive_stride_offset_2.json' ); + + +// FUNCTIONS // + +function isApprox( t, actual, expected ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = 2.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance' ); + } + } +} + +function testFixture( t, data ) { + var A = new Float64Array( data.A ); + var IPIV = new Int32Array( data.IPIV ); + var info = dgetrf( data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, IPIV, data.strideIPIV, data.offsetIPIV ); // eslint-disable-line max-len + + t.strictEqual( info, data.expectedInfo, 'returns expected status code' ); + t.deepEqual( IPIV, new Int32Array( data.expectedIPIV ), 'returns expected pivot indices' ); + isApprox( t, A, new Float64Array( data.expectedA ) ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgetrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( dgetrf.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided invalid dimensions', function test( t ) { + var A = new Float64Array( 4 ); + var IPIV = new Int32Array( 2 ); + + t.throws( function badRows() { + dgetrf( -1, 2, A, 1, 2, 0, IPIV, 1, 0 ); + }, RangeError, 'throws for a negative row count' ); + t.throws( function badColumns() { + dgetrf( 2, -1, A, 1, 2, 0, IPIV, 1, 0 ); + }, RangeError, 'throws for a negative column count' ); + t.end(); +}); + +tape( 'the function computes factorizations with positive strides', function test( t ) { + testFixture( t, POSITIVE_STRIDES_NO_OFFSET_1 ); + testFixture( t, POSITIVE_STRIDES_NO_OFFSET_2 ); + testFixture( t, LARGE_POSITIVE_STRIDE_1 ); + testFixture( t, LARGE_POSITIVE_STRIDE_2 ); + t.end(); +}); + +tape( 'the function supports index offsets', function test( t ) { + testFixture( t, POSITIVE_STRIDES_OFFSET_1 ); + testFixture( t, POSITIVE_STRIDES_OFFSET_2 ); + t.end(); +}); + +tape( 'the function supports negative and mixed strides', function test( t ) { + testFixture( t, NEGATIVE_STRIDES ); + testFixture( t, MIXED_STRIDES ); + t.end(); +});