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

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

-->

# cpttrf

> Compute the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`.

<section class="usage">

## Usage

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

#### cpttrf( N, D, E )

Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );

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

cpttrf( 3, D, E );
// D => <Float32Array>[ 4, 4.75, ~5.15789 ]

var viewE = reinterpret( E, 0 );
// viewE => <Float32Array>[ 0.25, 0.0, ~0.421053, 0.0 ]
```

The function has the following parameters:

- **N**: order of matrix `A`.
- **D**: the `N` diagonal elements of `A` as a [`Float32Array`][mdn-float32array].
- **E**: the N-1 subdiagonal elements of `A` as a [`Complex64Array`][@stdlib/array/complex64].

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 Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );

// Initial arrays...
var D0 = new Float32Array( [ 0.0, 4.0, 5.0, 6.0 ] );
var E0 = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] );

// Create offset views...
var D1 = new Float32Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var E1 = new Complex64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

cpttrf( 3, D1, E1 );
// D0 => <Float32Array>[ 0.0, 4.0, 4.75, ~5.15789 ]

var viewE = reinterpret( E0, 0 );
// viewE => <Float32Array>[ 0.0, 0.0, 0.25, 0.0, ~0.421053, 0.0 ]
```

#### cpttrf.ndarray( N, D, strideD, offsetD, E, strideE, offsetE )

Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A` using alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );

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

cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 );
// D => <Float32Array>[ 4, 4.75, ~5.15789 ]

var viewE = reinterpret( E, 0 );
// viewE => <Float32Array>[ 0.25, 0.0, ~0.421053, 0.0 ]
```

The function has the following additional parameters:

- **strideD**: stride length for `D`.
- **offsetD**: starting index for `D`.
- **strideE**: stride length for `E`.
- **offsetE**: starting index for `E`.

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 Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );

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

cpttrf.ndarray( 3, D, 1, 1, E, 1, 1 );
// D => <Float32Array>[ 0.0, 4.0, 4.75, ~5.15789 ]

var viewE = reinterpret( E, 0 );
// viewE => <Float32Array>[ 0.0, 0.0, 0.25, 0.0, ~0.421053, 0.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `D` and `E`.

- 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 < k < N`: the leading principal minor of order `k` is not positive and factorization could not be completed, where `k` equals the status code value.
- `N`: the leading principal minor of order `N` is not positive, and factorization was completed.

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Complex64Array = require( '@stdlib/array/complex64' );
var cpttrf = require( '@stdlib/lapack/base/cpttrf' );

var opts = {
'dtype': 'float32'
};
var D = discreteUniform( 5, 1, 5, opts );
console.log( D );

var N = D.length - 1;
var E = new Complex64Array( discreteUniform( 2*N, 0, 2, opts ) );
console.log( E );

// Perform the `L * D * L^H` factorization:
var info = cpttrf( D.length, D, E );
console.log( D );
console.log( E );
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-cpttrf]: https://www.netlib.org/lapack/explore-html/d4/d2c/group__pttrf_ga62b1bf0f377d29013a3bcec3732cea6c.html#ga62b1bf0f377d29013a3bcec3732cea6c

[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64

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

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

</section>

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


// VARIABLES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var ebuf;
var D;
var E;

D = uniform( len, 0.0, 100.0, options );
ebuf = uniform( 2*(len-1), 0.0, 100.0, options );
E = new Complex64Array( ebuf );
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 = cpttrf( len, D, E );
if ( isnanf( d ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( d ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':len='+len, f );

Check warning on line 105 in lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use `@stdlib/string/format` instead of string concatenation for benchmark descriptions
}
}

main();
Loading