Skip to content

feat: add lapack/base/dlaqr1 #7612

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

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
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
320 changes: 320 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqr1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
<!--

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

-->

# dlaqr1

> Compute the scalar multiple of the first column of `K` where `K = (H - Z1)*(H - Z2)` for a 2-by-2 or a 3-by-3 matrix `H` and where `Z1 = z1*I`, `Z2 = z2*I`, `z1 = a + bi`, `z2 = c + di`, and `I` is the identity matrix.

<section class="intro">

The `dlaqr1` routine computes a scalar multiple of the first column of a matrix `K` defined by the product of two shifted matrices. Given a matrix `H` and two complex shifts (which may be conjugates), the routine constructs:

<!-- <equation class="equation" label="eq:matrix_k" align="center" raw="K = (H - (sr_1 + i \cdot si_1) \cdot I) \cdot (H - (sr_2 + i \cdot si_2) \cdot I)" alt="Definition of matrix K."> -->

```math
K = (H - (sr_1 + i \cdot si_1) \cdot I) \cdot (H - (sr_2 + i \cdot si_2) \cdot I)
```

<!-- </equation> -->

where:

- `H` is an N-by-N matrix (N = 2 or 3)
- `sr1, si1` represent the real and imaginary parts of the first shift
- `sr2, si2` represent the real and imaginary parts of the second shift
- `I` is the identity matrix

The routine extracts the first column of `K` and stores it as a scalar multiple in the output vector `V`. For a 2-by-2 matrix `H`:

<!-- <equation class="equation" label="eq:matrix_h_2x2" align="center" raw="H = \left[\begin{array}{cc}h_{11} & h_{12} \\h_{21} & h_{22}\end{array}\right]" alt="2-by-2 matrix H."> -->

```math
H = \left[
\begin{array}{cc}
h_{11} & h_{12} \\
h_{21} & h_{22}
\end{array}
\right]
```

<!-- </equation> -->

For a 3-by-3 matrix `H`:

<!-- <equation class="equation" label="eq:matrix_h_3x3" align="center" raw="H = \left[\begin{array}{ccc}h_{11} & h_{12} & h_{13} \\h_{21} & h_{22} & h_{23} \\h_{31} & h_{32} & h_{33}\end{array}\right]" alt="3-by-3 matrix H."> -->

```math
H = \left[
\begin{array}{ccc}
h_{11} & h_{12} & h_{13} \\
h_{21} & h_{22} & h_{23} \\
h_{31} & h_{32} & h_{33}
\end{array}
\right]
```

<!-- </equation> -->

The shifts are typically complex conjugate pairs, meaning either:

1. `sr1 = sr2` and `si1 = -si2` (conjugate complex shifts), or
2. `si1 = si2 = 0` (real shifts)

This routine is particularly useful in the QR algorithm for starting double implicit shift bulges, where the computed vector `V` defines the Householder reflector for the implicit shift step.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dlaqr1( order, N, H, LDH, sr1, si1, sr2, si2, V )

Given a 2-by-2 or a 3-by-3 matrix `H`, this function sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)`.

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

var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] ); // => [ [ 1.0, 3.0, 2.0 ], [ 2.0, 4.0, 6.0 ], [ 0.0, 5.0, 7.0 ] ]
var V = new Float64Array( 3 );

var out = dlaqr1( 'row-major', 3, H, 3, 1.5, 0.0, 2.5, 0.0, V );
// returns <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
```

The function has the following parameters:

- **order**: storage layout.
- **N**: number of row/columns in `H`.
- **H**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array].
- **LDH**: stride of the first dimension of `H` (a.k.a., leading dimension of the matrix `H`).
- **sr1**: real part of the first conjugate complex shift.
- **si1**: imaginary part of the first conjugate complex shift.
- **sr2**: real part of the second conjugate complex shift.
- **si2**: imaginary part of the second conjugate complex shift.
- **V**: output [`Float64Array`][mdn-float64array].

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

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

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

// Initial arrays...
var H = new Float64Array( [ 0.0, 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] ); // => [ [ 1.0, 3.0, 2.0 ], [ 2.0, 4.0, 6.0 ], [ 0.0, 5.0, 7.0 ] ]
var V = new Float64Array( 4 );

// Create offset views...
var H1 = new Float64Array( H.buffer, H.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var V1 = new Float64Array( V.buffer, V.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dlaqr1( 'row-major', 3, H1, 3, 1.5, 0.0, 2.5, 0.0, V1 );
// V => <Float64Array>[ 0.0, ~1.93, ~0.57, ~2.86 ]
```

#### dlaqr1.ndarray( N, H, sh1, sh2, oh, sr1, si1, sr2, si2, V, sv, ov )

Given a 2-by-2 or a 3-by-3 matrix `H`, this function sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)` using alternative indexing semantics.

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

var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] ); // => [ [ 1.0, 3.0, 2.0 ], [ 2.0, 4.0, 6.0 ], [ 0.0, 5.0, 7.0 ] ]
var V = new Float64Array( 3 );

var out = dlaqr1.ndarray( 3, H, 3, 1, 0, 1.5, 0.0, 2.5, 0.0, V, 1, 0 );
// returns <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
```

The function has the following additional parameters:

- **N**: number of row/columns in `H`.
- **H**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array].
- **sh1**: stride of the first dimension of `H`.
- **sh2**: stride of the second dimension of `H`.
- **oh**: index offset for `H`.
- **sr1**: real part of the first conjugate complex shift.
- **si1**: imaginary part of the first conjugate complex shift.
- **sr2**: real part of the second conjugate complex shift.
- **si2**: imaginary part of the second conjugate complex shift.
- **V**: output [`Float64Array`][mdn-float64array].
- **sv**: stride length for `V`.
- **ov**: index offset for `V`.

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 H = new Float64Array( [ 0.0, 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] ); // => [ [ 1.0, 3.0, 2.0 ], [ 2.0, 4.0, 6.0 ], [ 0.0, 5.0, 7.0 ] ]
var V = new Float64Array( 4 );

var out = dlaqr1.ndarray( 3, H, 3, 1, 1, 1.5, 0.0, 2.5, 0.0, V, 1, 1 );
// returns <Float64Array>[ 0.0, ~1.93, ~0.57, ~2.86 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values).
- This is useful for starting double implicit shift bulges in the QR algorithm.
- `V` should have at least `N` indexed elements.
- `dlaqr1()` corresponds to the [LAPACK][LAPACK] function [`dlaqr1`][lapack-dlaqr1].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

// Create a random 3x3 matrix:
var H = uniform( 9, -10.0, 10.0, {
'dtype': 'float64'
});

// Create an output vector:
var V = new Float64Array( 3 );

dlaqr1( 'row-major', 3, H, 3, 1.5, 0.0, 2.5, 0.0, V );

// Print the result:
console.log( V );
```

</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-dlaqr1]: https://netlib.org/lapack/explore-html/d3/d57/group__laqr1_ga72fe4989b96418ec66d6ee18b4ac23e8.html

[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

</section>

<!-- /.links -->
Loading