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

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

-->

# dsptrf

> Compute the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method.

<section class="usage">

## Usage

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

#### dsptrf( order, uplo, N, AP, IPIV )

Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method.

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

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

/*
A = [
[ 4.0, 1.0, -2.0, 2.0 ],
[ 1.0, 2.0, 0.0, 1.0 ],
[ -2.0, 0.0, 3.0, -2.0 ],
[ 2.0, 1.0, -2.0, -1.0 ]
]
*/

// Store the upper triangle of `A` in column-major packed form:
var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] );
var IPIV = new Int32Array( 4 );

dsptrf( 'column-major', 'upper', 4, AP, IPIV );
// IPIV => <Int32Array>[ 1, 2, 3, 1 ]
```

The function has the following parameters:

- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. Must be either `'upper'` or `'lower'`.
- **N**: order of the matrix `A`.
- **AP**: packed form of the symmetric matrix `A` as a [`Float64Array`][mdn-float64array]. Should have `N*(N+1)/2` indexed elements. On exit, `AP` is overwritten by the block diagonal matrix `D` and the multipliers used to obtain the factor `U` or `L`.
- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array]. Should have `N` indexed elements. On exit, `IPIV` contains details of the interchanges and the block structure of `D` (values are one-based, as in the reference LAPACK implementation).

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, max-len -->

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

// Initial arrays...
var AP0 = new Float64Array( [ 0.0, 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] );
var IPIV0 = new Int32Array( [ 0, 0, 0, 0, 0 ] );

// Create offset views...
var AP = new Float64Array( AP0.buffer, AP0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var IPIV = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dsptrf( 'column-major', 'upper', 4, AP, IPIV );
// IPIV0 => <Int32Array>[ 0, 1, 2, 3, 1 ]
```

#### dsptrf.ndarray( order, uplo, N, AP, sap, oap, IPIV, si, oi )

Computes the factorization of a real symmetric matrix `A` stored in packed format using the Bunch-Kaufman diagonal pivoting method and alternative indexing semantics.

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

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

var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] );
var IPIV = new Int32Array( 4 );

dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 0, IPIV, 1, 0 );
// IPIV => <Int32Array>[ 1, 2, 3, 1 ]
```

The function has the following additional parameters:

- **sap**: stride length for `AP`.
- **oap**: starting index for `AP`.
- **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 AP = new Float64Array( [ 0.0, 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] );
var IPIV = new Int32Array( [ 0, 0, 0, 0, 0 ] );

dsptrf.ndarray( 'column-major', 'upper', 4, AP, 1, 1, IPIV, 1, 1 );
// IPIV => <Int32Array>[ 0, 1, 2, 3, 1 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `AP` and `IPIV`.

- For a symmetric matrix, an upper triangle stored in row-major order is identical in memory to a lower triangle stored in column-major order (and vice versa). Accordingly, when `order` is `'row-major'`, the routine resolves `uplo` to the equivalent column-major factorization (i.e., `'row-major'` + `'upper'` is factorized as `L*D*L^T` and `'row-major'` + `'lower'` is factorized as `U*D*U^T`). The returned `AP` and `IPIV` are self-consistent for the resolved factorization.

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

- `0`: factorization was successful.
- `>0`: `D(k,k)` is exactly zero (one-based, where `k` equals the status code value). The factorization has been completed, but the block diagonal matrix `D` is exactly singular, and division by zero will occur if it is used to solve a system of equations.

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

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

/*
Symmetric matrix `A` (upper triangle):

A = [
[ 4.0, 1.0, -2.0, 2.0 ],
[ 1.0, 2.0, 0.0, 1.0 ],
[ -2.0, 0.0, 3.0, -2.0 ],
[ 2.0, 1.0, -2.0, -1.0 ]
]
*/

// Store the upper triangle of `A` in column-major packed form:
var AP = new Float64Array( [ 4.0, 1.0, 2.0, -2.0, 0.0, 3.0, 2.0, 1.0, -2.0, -1.0 ] );
var IPIV = new Int32Array( 4 );

// Compute the Bunch-Kaufman factorization `A = U*D*U^T`:
var info = dsptrf( 'column-major', 'upper', 4, AP, IPIV );

console.log( AP );
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-dsptrf]: https://www.netlib.org/lapack/explore-html/d8/d08/group__hptrf_ga9adb8a8020b104eaaf72c2aad7861a8c.html#ga9adb8a8020b104eaaf72c2aad7861a8c

[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 -->
104 changes: 104 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dsptrf/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dsptrf = require( './../lib/dsptrf.js' );


// VARIABLES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - order of the matrix
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var IPIV = new Int32Array( N );
var AP = uniform( N*( N+1 ) / 2, -1.0, 1.0, options );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = dsptrf( 'column-major', 'upper', N, AP, IPIV );
if ( d < 0 ) {
b.fail( 'should return a valid status code' );
}
}
b.toc();
if ( d < 0 ) {
b.fail( 'should return a valid status code' );
}
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 = 3; // 10^max

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

main();
Loading