|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2025 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +// MODULES // |
| 22 | + |
| 23 | +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); |
| 24 | +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); |
| 25 | +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); |
| 26 | +var max = require( '@stdlib/math/base/special/max' ); |
| 27 | +var format = require( '@stdlib/string/format' ); |
| 28 | +var base = require( './base.js' ); |
| 29 | + |
| 30 | + |
| 31 | +// MAIN // |
| 32 | + |
| 33 | +/** |
| 34 | +* Given a 2-by-2 or a 3-by-3 matrix, 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)`. |
| 35 | +* |
| 36 | +* ## Notes |
| 37 | +* |
| 38 | +* - It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values). |
| 39 | +* - This is useful for starting double implicit shift bulges in the QR algorithm. |
| 40 | +* - `H` should be an upper hessenberg matrix if it's a 3-by-3 matrix. |
| 41 | +* - `V` should have at least `N` indexed elements. |
| 42 | +* |
| 43 | +* @param {string} order - storage layout |
| 44 | +* @param {PositiveInteger} N - number of row/columns in `H` |
| 45 | +* @param {Float64Array} H - input matrix |
| 46 | +* @param {PositiveInteger} LDH - stride of the first dimension of `H` (a.k.a., leading dimension of the matrix `H`) |
| 47 | +* @param {number} sr1 - real part of the first conjugate complex shift |
| 48 | +* @param {number} si1 - imaginary part of the first conjugate complex shift |
| 49 | +* @param {number} sr2 - real part of the second conjugate complex shift |
| 50 | +* @param {number} si2 - imaginary part of the second conjugate complex shift |
| 51 | +* @param {Float64Array} V - output array |
| 52 | +* @throws {RangeError} first argument must be either 2 or 3 |
| 53 | +* @throws {TypeError} first argument must be a valid order |
| 54 | +* @throws {RangeError} fourth argument must be greater than or equal to max(1,N) |
| 55 | +* @returns {Float64Array} `V` |
| 56 | +* |
| 57 | +* @example |
| 58 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 59 | +* |
| 60 | +* 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 ] ] |
| 61 | +* var V = new Float64Array( 3 ); |
| 62 | +* |
| 63 | +* var out = dlaqr1( 'row-major', 3, H, 3, 1.5, 0.0, 2.5, 0.0, V ); |
| 64 | +* // returns <Float64Array>[ ~1.93, ~0.57, ~2.86 ] |
| 65 | +*/ |
| 66 | +function dlaqr1( order, N, H, LDH, sr1, si1, sr2, si2, V ) { |
| 67 | + var sh1; |
| 68 | + var sh2; |
| 69 | + |
| 70 | + if ( !isLayout( order ) ) { |
| 71 | + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); |
| 72 | + } |
| 73 | + if ( isRowMajor( order ) && LDH < max( 1, N ) ) { |
| 74 | + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDH ) ); |
| 75 | + } |
| 76 | + if ( N !== 2 && N !== 3 ) { |
| 77 | + throw new RangeError( format( 'invalid argument. First argument must be either %d or %d. Value: `%d`.', 2, 3, N ) ); |
| 78 | + } |
| 79 | + if ( isColumnMajor( order ) ) { |
| 80 | + sh1 = 1; |
| 81 | + sh2 = LDH; |
| 82 | + } else { // order === 'row-major' |
| 83 | + sh1 = LDH; |
| 84 | + sh2 = 1; |
| 85 | + } |
| 86 | + return base( N, H, sh1, sh2, 0, sr1, si1, sr2, si2, V, 1, 0 ); |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +// EXPORTS // |
| 91 | + |
| 92 | +module.exports = dlaqr1; |
0 commit comments