-
-
Notifications
You must be signed in to change notification settings - Fork 851
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
aayush0325
wants to merge
8
commits into
stdlib-js:develop
Choose a base branch
from
aayush0325:lapack-dlaqr1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,576
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
22eb89d
feat: add lapack/base/dlartg
aayush0325 7fb09ef
feat: add main exports
aayush0325 59bed29
test: add initial tests
aayush0325 f753834
test: add ndarray tests
aayush0325 1e90999
docs: add ts files
aayush0325 c0126f6
bench: add benchmaks
aayush0325 98967e9
docs: add docs
aayush0325 122ec07
docs: update description
aayush0325 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link was broken for me, but this one worked: 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 --> |
112 changes: 112 additions & 0 deletions
112
lib/node_modules/@stdlib/lapack/base/dlaqr1/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aayush0325 Is it possible to use a math equation to convey what
K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)
corresponds to?It is a bit ambiguous what
i
corresponds to. I believe it corresponds to imaginary symboli
.I believe capital
I
here corresponds to the identity matrix.If my interpretation is correct, then