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 8 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
259 changes: 259 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,259 @@
<!--

@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

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

<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://www.netlib.org/lapack/explore-html/d1/d72/dlaqr1_8f.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 -->
112 changes: 112 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqr1/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* @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.
*/

'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 Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dlaqr1 = require( './../lib/dlaqr1.js' );


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {PositiveInteger} N - number of elements along each dimension
* @returns {Function} benchmark function
*/
function createBenchmark( order, N ) {
var values;
var H;
var V;

H = uniform( N*N, -10.0, 10.0, {
'dtype': 'float64'
});
values = uniform( N, -10.0, 10.0, {
'dtype': 'float64'
});
V = new Float64Array( N );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dlaqr1( order, N, H, N, values[ i%N ], values[ (i+1)%N ], values[ (i+2)%N ], values[ (i+3)%N ], V ); // eslint-disable-line max-len
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var ord;
var N;
var f;
var i;

for ( i = 0; i < LAYOUTS.length; i++ ) {
ord = LAYOUTS[ i ];
for ( N = 2; N <= 3; N++ ) {
f = createBenchmark( ord, N );
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
}
}
}

main();
Loading