Skip to content

feat: add lapack/base/dgtts2 #5882

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

Draft
wants to merge 39 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9e097b9
feat: add base algorithm
aayush0325 Mar 8, 2025
41be81c
fix: remove useless isRowMajor check
aayush0325 Mar 8, 2025
9eaeca2
fix: fix bug
aayush0325 Mar 8, 2025
0e0f694
feat: complete initial implementation
aayush0325 Mar 9, 2025
3e68299
fix: update function return value and add docs and benchmarks
aayush0325 Mar 10, 2025
9a78528
bench: remove benchmarks for now
aayush0325 Mar 11, 2025
bb30a2d
test: add initial tests
aayush0325 Mar 12, 2025
9f1e284
chore: update copyright years
stdlib-bot Mar 12, 2025
9ad6153
test: more test coverage
aayush0325 Mar 12, 2025
e935826
fix: fix tests failing
aayush0325 Mar 13, 2025
6100480
fix: reduce tolerance to zero and use deepequals
aayush0325 Mar 13, 2025
7dd1e0f
test: more test coverage
aayush0325 Mar 13, 2025
9a533bd
chore: reorder tests
aayush0325 Mar 13, 2025
ddf9bbe
test: more test coverage
aayush0325 Mar 13, 2025
78ad0a6
fix: use correct fixture
aayush0325 Mar 13, 2025
dfcc8f8
test: more test coverage
aayush0325 Mar 14, 2025
b948269
test: fix up fixtures
aayush0325 Mar 17, 2025
0947dbb
test: add tests for ndarray offsets
aayush0325 Mar 17, 2025
a0af19c
test: add tests for positive strides
aayush0325 Mar 18, 2025
2623647
test: add tests for negative strides
aayush0325 Mar 19, 2025
172bc38
test: add tests for complex access patterns
aayush0325 Mar 21, 2025
866bded
chore: organize fixtures into different folderrs
aayush0325 Mar 21, 2025
56807f9
chore: update spacing
aayush0325 Mar 21, 2025
518459c
chore: update examples
aayush0325 Mar 22, 2025
f22e05a
docs: add README and update examples
aayush0325 Mar 22, 2025
4c9b7e9
docs: use links for int32array and float64array
aayush0325 Mar 22, 2025
82af8e9
docs: add repl.txt
aayush0325 Mar 22, 2025
2af58b6
docs: update repl.txt
aayush0325 Mar 24, 2025
b2a1360
docs: update repl.txt
aayush0325 Mar 24, 2025
8312416
docs: update repl.txt
aayush0325 Mar 24, 2025
94b73d9
docs: update repl.txt
aayush0325 Mar 24, 2025
aed4c82
docs: update examples
aayush0325 Mar 24, 2025
154588f
docs: add info about itrans
aayush0325 Mar 24, 2025
6670404
docs: update functiond descripton
aayush0325 Mar 24, 2025
c231362
chore: fix typo
aayush0325 Mar 24, 2025
58996d4
Merge branch 'develop' into lapack-dgtts2
aayush0325 Mar 30, 2025
ac1e2d1
bench: add benchmarks
aayush0325 Mar 30, 2025
c581a01
bench: update benchmarks
aayush0325 Mar 31, 2025
b1fb239
chore: update package.json description
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
302 changes: 302 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgtts2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
<!--

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

-->

<!-- lint disable max-len -->

# dgtts2

> Solve a system of linear equations with a tridiagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf].

<section class="usage">

## Usage

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

#### dgtts2( order, itrans, N, nrhs, DL, D, DU, DU2, IPIV, B, LDB )

Solves a system of linear equations with a tri diagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf].

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

var DL = new Float64Array( [ 0.25, 0.26666667 ] );
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
var DU2 = new Float64Array( [ 0.0 ] );
var IPIV = new Int32Array( [ 0, 1, 2 ] );
var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );

var out = dgtts2( 'column-major', 1, 3, 1, DL, D, DU, DU2, IPIV, B, 3 );
// out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
```

The function has the following parameters:

- **order**: storage layout.
- **itrans**: specifies the form of the system of equations.
- **N**: order of the matrix `A`.
- **nrhs**: number of right-hand sides, i.e., the number of columns of the matrix `B`.
- **DL**: multipliers that define the matrix `L` as a [`Float64Array`][mdn-float64array].
- **D**: diagonal elements of the upper triangular matrix `U` as a [`Float64Array`][mdn-float64array].
- **DU**: elements of the first super-diagonal of `U` as a [`Float64Array`][mdn-float64array].
- **DU2**: elements of the second super-diagonal of `U` as a [`Float64Array`][mdn-float64array].
- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array].
- **B**: right-hand side matrix B, overwritten by the solution matrix `X` as a [`Float64Array`][mdn-float64array].
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).

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, 0.25, 0.26666667 ] );
var D0 = new Float64Array( [ 0.0, 4.0, 3.75, 3.73333333 ] );
var DU0 = new Float64Array( [ 0.0, 1.0, 0.73333333 ] );
var DU20 = new Float64Array( [ 0.0, 0.0 ] );
var IPIV0 = new Int32Array( [ 0, 0, 1, 2 ] );
var B0 = new Float64Array( [ 0.0, 7.0, 8.0, 7.0 ] );

// 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
var B = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dgtts2( 'column-major', 1, 3, 1, DL, D, DU, DU2, IPIV, B, 3 );
// B0 => <Float64Array>[ 0.0, ~1.44, ~1.25, ~1.55 ]
```

#### dgtts2.ndarray( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob )

Solves a system of linear equations with a tri diagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf] and alternative indexing semantics.

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

var DL = new Float64Array( [ 0.25, 0.26666667 ] );
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
var DU2 = new Float64Array( [ 0.0 ] );
var IPIV = new Int32Array( [ 0, 1, 2 ] );
var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );

var out = dgtts2.ndarray( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
// out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
```

The function has the following parameters:

- **itrans**: specifies the form of the system of equations.
- **N**: order of the matrix `A`.
- **nrhs**: number of right-hand sides, i.e., the number of columns of the matrix `B`.
- **DL**: multipliers that define the matrix `L` as a [`Float64Array`][mdn-float64array].
- **sdl**: stride length for `DL`.
- **odl**: starting index for `DL`.
- **D**: diagonal elements of the upper triangular matrix `U` as a [`Float64Array`][mdn-float64array].
- **sd**: stride length for `D`.
- **od**: starting index for `D`.
- **DU**: elements of the first super-diagonal of `U` as a [`Float64Array`][mdn-float64array].
- **sdu**: stride length for `DU`.
- **odu**: starting index for `DU`.
- **DU2**: elements of the second super-diagonal of `U` as a [`Float64Array`][mdn-float64array].
- **sdu2**: stride length for `DU2`.
- **odu2**: starting index for `DU2`.
- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array].
- **si**: stride length for `IPIV`.
- **oi**: starting index for `IPIV`.
- **B**: right-hand side matrix B, overwritten by the solution matrix `X` as a [`Float64Array`][mdn-float64array].
- **sb1**: stride length for first dimension of `B`.
- **sb2**: stride length for second dimension of `B`.
- **ob**: starting index for `B`.

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 DL = new Float64Array( [ 0.0, 0.25, 0.26666667 ] );
var D = new Float64Array( [ 0.0, 4.0, 3.75, 3.73333333 ] );
var DU = new Float64Array( [ 0.0, 1.0, 0.73333333 ] );
var DU2 = new Float64Array( [ 0.0, 0.0 ] );
var IPIV = new Int32Array( [ 0, 0, 1, 2 ] );
var B = new Float64Array( [ 0.0, 7.0, 8.0, 7.0 ] );

var out = dgtts2.ndarray( 1, 3, 1, DL, 1, 1, D, 1, 1, DU, 1, 1, DU2, 1, 1, IPIV, 1, 1, B, 1, 1, 1 );
// out => <Float64Array>[ 0.0, ~1.44, ~1.25, ~1.55 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );
var dgtts2 = require( '@stdlib/lapack/base/dgtts2' );

var shape = [ 3, 3 ];
var order = 'row-major';
var strides = shape2strides( shape, order );

var B = new Float64Array( [ 7.0, 8.0, 7.0, 2.0, 3.0, 4.0, 1.0, 1.5, 2.0 ] );
console.log( ndarray2array( B, shape, strides, 0, order ) );

var DL = new Float64Array( [ 0.25, 0.26666667 ] );
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
var DU2 = new Float64Array( [ 0.0 ] );
var IPIV = new Int32Array( [ 0, 1, 2 ] );

var X = dgtts2( 'row-major', 1, 3, 3, DL, D, DU, DU2, IPIV, B, 3 );
console.log( ndarray2array( X, shape, strides, 0, order ) );
```

</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-dgtts2]: https://www.netlib.org/lapack/explore-html/d2/dea/group__gtts2_gae123fb2b13f2398457e4c47f5c7f7fcd.html#gae123fb2b13f2398457e4c47f5c7f7fcd

[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
Loading