Skip to content
Draft
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
251 changes: 251 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dptts2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<!--

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

-->

# dptts2

> Solve a tridiagonal system of the form `A * X = B` using the `L * D * L^T` factorization of `A` computed by [`dpttrf`][@stdlib/lapack/base/dpttrf].

<section class="usage">

## Usage

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

#### dptts2( order, N, nrhs, D, E, B, LDB )

Solves a tridiagonal system of the form `A * X = B` using the `L * D * L^T` factorization of `A` computed by [`dpttrf`][@stdlib/lapack/base/dpttrf].

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

var D = new Float64Array( [ 4.0, 4.75, 5.157894736842105 ] );
var E = new Float64Array( [ 0.25, 0.42105263157894735 ] );
var B = new Float64Array( [ 1.0, 2.0, 3.0 ] );

dptts2( 'column-major', 3, 1, D, E, B, 3 );
// B => <Float64Array>[ ~0.204, ~0.184, ~0.439 ]
```

The function has the following parameters:

- **order**: storage layout of `B`.
- **N**: order of the tridiagonal matrix `A`.
- **nrhs**: number of right-hand sides (i.e., the number of columns of the matrix `B`).
- **D**: the `N` diagonal elements of the diagonal matrix `D` from the `L * D * L^T` factorization of `A` as a [`Float64Array`][mdn-float64array].
- **E**: the `N-1` subdiagonal elements of the unit bidiagonal factor `L` from the `L * D * L^T` factorization of `A` as a [`Float64Array`][mdn-float64array].
- **B**: input matrix as a [`Float64Array`][mdn-float64array]. On entry, the right-hand side vectors `B`. On exit, the solution vectors `X`.
- **LDB**: leading dimension of `B`.

The input matrix `D` and `E` are typically computed by [`dpttrf`][@stdlib/lapack/base/dpttrf].

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

var D = new Float64Array( [ 4.0, 5.0, 6.0 ] );
var E = new Float64Array( [ 1.0, 2.0 ] );

dpttrf( 3, D, E );

var B = new Float64Array( [ 1.0, 2.0, 3.0 ] );

dptts2( 'column-major', 3, 1, D, E, B, 3 );
// B => <Float64Array>[ ~0.204, ~0.184, ~0.439 ]
```

#### dptts2.ndarray( N, nrhs, D, sd, od, E, se, oe, B, sb1, sb2, ob )

Solves a tridiagonal system of the form `A * X = B` using the `L * D * L^T` factorization of `A` computed by [`dpttrf`][@stdlib/lapack/base/dpttrf] and alternative indexing semantics.

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

var D = new Float64Array( [ 4.0, 4.75, 5.157894736842105 ] );
var E = new Float64Array( [ 0.25, 0.42105263157894735 ] );
var B = new Float64Array( [ 1.0, 2.0, 3.0 ] );

dptts2.ndarray( 3, 1, D, 1, 0, E, 1, 0, B, 1, 3, 0 );
// B => <Float64Array>[ ~0.204, ~0.184, ~0.439 ]
```

The function has the following parameters:

- **sd**: stride length for `D`.
- **od**: starting index for `D`.
- **se**: stride length for `E`.
- **oe**: starting index for `E`.
- **sb1**: stride of the first dimension of `B`.
- **sb2**: stride of the 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.

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

var D = new Float64Array( [ 0.0, 4.0, 4.75, 5.157894736842105 ] );
var E = new Float64Array( [ 0.0, 0.25, 0.42105263157894735 ] );
var B = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );

dptts2.ndarray( 3, 1, D, 1, 1, E, 1, 1, B, 1, 3, 1 );
// B => <Float64Array>[ 0.0, ~0.204, ~0.184, ~0.439 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var dpttrf = require( '@stdlib/lapack/base/dpttrf' );
var dptts2 = require( '@stdlib/lapack/base/dptts2' );

// Define a symmetric positive definite matrix `A` via its diagonal and subdiagonal:
var D = new Float64Array( [ 4.0, 5.0, 6.0, 7.0 ] );
var E = new Float64Array( [ 1.0, 2.0, 3.0 ] );

// Compute the `L * D * L^T` factorization of `A` (overwrites `D` and `E`):
dpttrf( D.length, D, E );

// Define the right-hand side matrix `B` (column-major, two right-hand sides):
var B = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 2.0, 1.0, 0.0, 1.0 ] );

// Solve `A * X = B`, overwriting `B` with the solution `X`:
dptts2( 'column-major', 4, 2, D, E, B, 4 );
console.log( B );
```

</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-dptts2]: https://netlib.org/lapack/explore-html/d5/d5d/group__ptts2_ga35fdfa6109e8f9cbfbde271814bf0b27.html#ga35fdfa6109e8f9cbfbde271814bf0b27

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

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

[@stdlib/lapack/base/dpttrf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/lapack/base/dpttrf

</section>

<!-- /.links -->
105 changes: 105 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dptts2/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dptts2 = require( './../lib/dptts2.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - number of elements along each dimension
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var D = uniform( N, 1.0, 5.0, options );
var E = uniform( N-1, 0.0, 1.0, options );
var B = uniform( N, -1.0, 1.0, options );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dptts2( 'column-major', N, 1, D, E, B, N );
if ( isnan( out[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
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 = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = pow( 10, i );
f = createBenchmark( N );
bench( format( '%s:size=%d', pkg, N ), f );
}
}

main();
Loading