Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgetrf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<!--

@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.

-->

# dgetrf

> Compute an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges.

<section class="intro">

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.

</section>

<!-- /.intro -->

<section class="usage">

## 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 => <Int32Array>[ 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.

</section>

<!-- /.usage -->

<section class="notes">

## 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].

</section>

<!-- /.notes -->

<section class="examples">

## 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 );
```

</section>

<!-- /.examples -->

<section class="links">

[lapack]: https://www.netlib.org/lapack/explore-html/

[lapack-dgetrf]: https://www.netlib.org/lapack/double/dgetrf.f

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[mdn-int32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array

</section>

<!-- /.links -->
99 changes: 99 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgetrf/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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();
Loading
Loading