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

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

-->

# dlasq2

> Compute all eigenvalues of the symmetric positive definite tridiagonal matrix associated with the QD Array `Z` to high relative accuracy.

<section class="intro">

The `dlasq2` routine computes all the eigenvalues of the symmetric positive definite tri-diagonal matrix associated with the QD (quotient-difference) array `Z` to high relative accuracy, in the absence of denormalization, underflow and overflow.

To see the relation of Z to the tridiagonal matrix, let `L` be a unit lower bidiagonal matrix with subdiagonals `Z(2,4,6,,..)` and let `U` be an upper bidiagonal matrix with 1's above and diagonal `Z(1,3,5,,..)`. The tridiagonal is `L*U` or, if you prefer, the symmetric tridiagonal to which it is similar.

The QD array `Z` of length `4*N` contains pairs `(q_i, qq_i, e_i, ee_i)` for `i = 1, 2, ..., N`, where `q_i` and `e_i` are derived from the diagonal and off-diagonal elements of `T` and `qq_i` and `ee_i` are working storage.

Upon successful completion, the first `N` indexed elements contain the eigenvalues in descending order, and `Z( 2*N+1 )` holds the trace, and `Z( 2*N+2 )` holds the sum of the eigenvalues.

If `N > 2`, then `Z( 2*N+3 )` holds the iteration count, `Z( 2*N+4 )` holds `NDIVS/NIN^2`, and `Z( 2*N+5 )` holds the percentage of shifts that failed.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dlasq2( N, Z )

Computes all eigenvalues of the symmetric positive definite tridiagonal matrix associated with the QD Array `Z` to high relative accuracy.

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

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

var Z = new Float64Array( [ 100, 4, 81, 3, 64, 2.5, 49, 2, 36, 1.5, 25, 1, 16, 0.5, 9, 0 ] );

var out = dlasq2( 4, Z );
// Z => <Float64Array>[ ~115.713, ~83.153, ~62.17, ~42.464, ~83.153, ~20.987, ~0.0, ~0.0, 303.5, ~303.5, 15, 4.0625, 0.0, ~0.0, ~0.172, ~0.096 ]
// out => 0
```

The function has the following parameters:

- **N**: number of rows/columns in the tridiagonal matrix.
- **Z**: the QD array as a [`Float64Array`][@stdlib/array/float64]. Must have at least `4*N` indexed elements. `Z` is overwritten during computation. Upon successful exit, the first `N` indexed elements of `Z` contain the eigenvalues in decreasing order.

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' );

// Initial arrays...
var Z0 = new Float64Array( [ 0.0, 100, 4, 81, 3, 64, 2.5, 49, 2, 36, 1.5, 25, 1, 16, 0.5, 9, 0 ] );

// Create offset views...
var Z1 = new Float64Array( Z0.buffer, Z0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dlasq2( 4, Z1 );
// Z0 => <Float64Array>[ 0.0, ~115.713, ~83.153, ~62.17, ~42.464, ~83.153, ~20.987, ~0.0, ~0.0, 303.5, ~303.5, 15, 4.0625, 0.0, ~0.0, ~0.172, ~0.096 ]
```

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

#### dlasq2.ndarray( N, Z, strideZ, offsetZ )

Computes all eigenvalues of the symmetric positive definite tridiagonal matrix associated with the QD Array `Z` to high relative accuracy using alternative indexing semantics.

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

var Z = new Float64Array( [ 100, 4, 81, 3, 64, 2.5, 49, 2, 36, 1.5, 25, 1, 16, 0.5, 9, 0 ] );

dlasq2.ndarray( 4, Z, 1, 0 );
// Z => <Float64Array>[ ~115.713, ~83.153, ~62.17, ~42.464, ~83.153, ~20.987, ~0.0, ~0.0, 303.5, ~303.5, 15, 4.0625, 0.0, ~0.0, ~0.172, ~0.096 ]
```

The function has the following additional parameters:

- **strideZ**: stride length for `Z`.
- **offsetZ**: starting index for `Z`.

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 Z = new Float64Array( [ 0.0, 100, 4, 81, 3, 64, 2.5, 49, 2, 36, 1.5, 25, 1, 16, 0.5, 9, 0 ] );

dlasq2.ndarray( 4, Z, 1, 1 );
// Z => <Float64Array>[ 0.0, ~115.713, ~83.153, ~62.17, ~42.464, ~83.153, ~20.987, ~0.0, ~0.0, 303.5, ~303.5, 15, 4.0625, 0.0, ~0.0, ~0.172, ~0.096 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input array `Z`.

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

- If `=0`, then the algorithm completed successfully.
- If `<0`:

- If the i-th argument is a scalar and had an illegal value, then `INFO = -i`.
- If the i-th argument is an array and the j-entry had an illegal value, then `INFO = -(i*100+j)`.

- If `>0`, the algorithm failed:

- `=1`, a split was marked by a positive value in `E`.
- `=2`, current block of `Z` not diagonalized after `100*N` iterations (in inner while loop). On exit `Z` holds a QD array with the same eigenvalues as the given `Z`.
- `=3`, termination criterion of outer while loop not met (program created more than N unreduced blocks).

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

var Z = new Float64Array( [ 144, 6, 121, 5, 100, 4, 81, 3, 64, 2, 49, 1.5, 36, 1, 25, 0.5 ] );

var info = dlasq2( 4, Z );
console.log( Z );
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-dlasq2]: https://www.netlib.org/lapack/explore-html/d4/d4b/group__lasq2_gad2bd91b6a5e4dcc4614d319951f11109.html

[@stdlib/array/float64]: https://stdlib.io/docs/api/latest/@stdlib/array/float64

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

</section>

<!-- /.links -->
102 changes: 102 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlasq2/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @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 dlasq2 = require( './../lib/dlasq2.js' );


// VARIABLES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var Z = uniform( len*4, 0.0, 100.0, options );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
dlasq2( len, Z );
if ( isnan( Z[ i%Z.length ] ) ) {
b.fail( 'unexpected NaN value' );
}
}
b.toc();
if ( isnan( Z[ i%Z.length ] ) ) {
b.fail( 'unexpected NaN value' );
}
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( format( '%s:len=%d', pkg, len ), f );
}
}

main();
Loading
Loading