Skip to content

feat: add lapack/base/dgttrf #5754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e31c8b8
feat: add base algorithm
aayush0325 Mar 2, 2025
4686b1a
fix: remove redundant code
aayush0325 Mar 2, 2025
7bcf93c
feat: complete initial implementation for dgttrf
aayush0325 Mar 2, 2025
43f57ea
docs: add ts declaration file and test.ts
aayush0325 Mar 3, 2025
13e7f57
docs: update descriptions as per lapack documentation
aayush0325 Mar 3, 2025
10f32ed
test: add initial tests
aayush0325 Mar 3, 2025
87e755f
chore: update copyright years
stdlib-bot Mar 3, 2025
1e5ea18
docs: shorter var names and add repl.txt
aayush0325 Mar 3, 2025
e88ffbe
test: add tests for dgttrf
aayush0325 Mar 3, 2025
b1bed1b
test: add complete tests for dgttrf
aayush0325 Mar 3, 2025
6e908a9
test: add ndarray tests
aayush0325 Mar 3, 2025
95bd130
fix: resolve lint error
aayush0325 Mar 4, 2025
89b7e76
test: complete all tests
aayush0325 Mar 4, 2025
50e4a64
docs: write some docs
aayush0325 Mar 4, 2025
6ab337b
docs: complete writing readme
aayush0325 Mar 4, 2025
90450eb
chore: cleaning up
aayush0325 Mar 4, 2025
27be42f
docs: add comments in base algo for better understanding
aayush0325 Mar 4, 2025
2e6fb17
docs: add notes in docs
aayush0325 Mar 4, 2025
7b8da2e
test: generate fixtures
aayush0325 Mar 5, 2025
78e0cfd
Update lib/node_modules/@stdlib/lapack/base/dgttrf/README.md
aayush0325 Mar 17, 2025
fef9486
test: use deepEqual instead of isApprox
aayush0325 Mar 22, 2025
a4fb01d
chore: spelling check
aayush0325 Mar 28, 2025
f5f0213
refactor: precompute indices
aayush0325 Mar 31, 2025
996cc82
chore: spell check
aayush0325 Apr 5, 2025
5c80a24
chore: self review
aayush0325 Apr 5, 2025
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
308 changes: 308 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgttrf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
<!--

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

-->

# dgttrf

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

<section class="usage">

## Usage

```javascript
var dgttrf = require( '@stdlib/lapack/base/dgttrf' );
```

#### dgttrf( N, DL, D, DU, DU2, IPIV )

Computes an `LU` factorization of a real tri diagonal matrix `A` using elimination with partial pivoting and row interchanges.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var DL = new Float64Array( [ 1.0, 1.0 ] );
var D = new Float64Array( [ 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 1.0, 1.0 ] );
var DU2 = new Float64Array( 1 );
var IPIV = new Int32Array( 3 );

dgttrf( 3, DL, D, DU, DU2, IPIV );
// DL => <Float64Array>[ 0.5, 0.4 ]
// D => <Float64Array>[ 2, 2.5, 0.6 ]
// DU => <Float64Array>[ 1, 1 ]
// DU2 => <Float64Array>[ 0 ]
// IPIV => <Int32Array>[ 0, 1, 2 ]
```

The function has the following parameters:

- **N**: order of matrix `A`.
- **DL**: the sub diagonal elements of `A` as a [`Float64Array`][mdn-float64array]. On exit, DL is overwritten by the multipliers that define the matrix `L` from the `LU` factorization of `A`.
- **D**: the diagonal elements of `A` as a [`Float64Array`][mdn-float64array]. On exit, D is overwritten by the diagonal elements of the upper triangular matrix `U` from the `LU` factorization of `A`.
- **DU**: the super diagonal elements of `A` as a [`Float64Array`][mdn-float64array]. On exit, DU is overwritten by the elements of the first super-diagonal of `U`.
- **DU2**: On exit, DU2 is overwritten by the elements of the second super-diagonal of `U` as a [`Float64Array`][mdn-float64array].
- **IPIV**: vector of pivot indices as a [`Int32Array`][mdn-int32array].

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

// Initial arrays...
var DL0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var D0 = new Float64Array( [ 0.0, 2.0, 3.0, 1.0 ] );
var DU0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var DU20 = new Float64Array( 2 );
var IPIV0 = new Int32Array( 4 );

// Create offset views...
var DL = new Float64Array( DL0.buffer, DL0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var D = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var DU = new Float64Array( DU0.buffer, DU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var DU2 = new Float64Array( DU20.buffer, DU20.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var IPIV = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dgttrf( 3, DL, D, DU, DU2, IPIV );
// DL0 => <Float64Array>[ 0, 0.5, 0.4 ]
// D0 => <Float64Array>[ 0, 2, 2.5, 0.6 ]
// DU0 => <Float64Array>[ 0, 1, 1 ]
// DU20 => <Float64Array>[ 0, 0 ]
// IPIV0 => <Int32Array>[ 0, 0, 1, 2 ]
```

<!-- lint disable maximum-heading-length -->

#### dgttrf.ndarray( N, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi )

Computes an `LU` factorization of a real tri diagonal matrix `A` using elimination with partial pivoting and row interchanges and alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );
var dgttrf = require( '@stdlib/lapack/base/dgttrf' );

var DL = new Float64Array( [ 1.0, 1.0 ] );
var D = new Float64Array( [ 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 1.0, 1.0 ] );
var DU2 = new Float64Array( 1 );
var IPIV = new Int32Array( 3 );

dgttrf.ndarray( 3, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0 );
// DL => <Float64Array>[ 0.5, 0.4 ]
// D => <Float64Array>[ 2, 2.5, 0.6 ]
// DU => <Float64Array>[ 1, 1 ]
// DU2 => <Float64Array>[ 0 ]
// IPIV => <Int32Array>[ 0, 1, 2 ]
```

The function has the following additional parameters:

- **sdl**: stride length for `DL`.
- **odl**: starting index for `DL`.
- **sd**: stride length for `D`.
- **od**: starting index for `D`.
- **sdu**: stride length for `DU`.
- **odu**: starting index for `DU`.
- **sdu2**: stride length for `DU2`.
- **odu2**: starting index for `DU2`.
- **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,

<!-- eslint-disable max-len -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var DL = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var D = new Float64Array( [ 0.0, 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var DU2 = new Float64Array( 2 );
var IPIV = new Int32Array( 4 );

dgttrf.ndarray( 3, DL, 1, 1, D, 1, 1, DU, 1, 1, DU2, 1, 1, IPIV, 1, 1 );
// DL => <Float64Array>[ 0, 0.5, 0.4 ]
// D => <Float64Array>[ 0, 2, 2.5, 0.6 ]
// DU => <Float64Array>[ 0, 1, 1 ]
// DU2 => <Float64Array>[ 0, 0 ]
// IPIV => <Int32Array>[ 0, 0, 1, 2 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `DL`, `D`, `DU`, `DU2` and `IPIV`.

- Both functions return a status code indicating success or failure. A status code indicates the following conditions:

- `0`: factorization was successful.
- `<0`: the k-th argument had an illegal value, where `-k` equals the status code value.
- `>0`: `U( k, k )` is exactly zero the factorization has been completed, but the factor `U` is exactly singular, and division by zero will occur if it is used to solve a system of equations, where `k` equals the status code value.

- `dgttrf()` corresponds to the [LAPACK][LAPACK] routine [`dgttrf`][lapack-dgttrf].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var dgttrf = require( '@stdlib/lapack/base/dgttrf' );

var N = 9;

var DL = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] );

var D = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );

var DU = new Float64Array( [ 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0 ] );

var DU2 = new Float64Array( N-2 );

var IPIV = new Int32Array( N );

// Perform the `A = LU` factorization:
var info = dgttrf( N, DL, D, DU, DU2, IPIV );

console.log( DL );
console.log( D );
console.log( DU );
console.log( DU2 );
console.log( IPIV );
console.log( info );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

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

[lapack-dgttrf]: https://www.netlib.org/lapack/explore-html/d6/d46/group__gttrf_ga8d1e46216e6c861c89bd4328b8be52a1.html#ga8d1e46216e6c861c89bd4328b8be52a1

[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

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
Loading