|
| 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 abs = require( '@stdlib/math/base/special/fast/abs' ); |
| 24 | + |
| 25 | + |
| 26 | +// MAIN // |
| 27 | + |
| 28 | +/** |
| 29 | +* 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)`. |
| 30 | +* |
| 31 | +* ## Notes |
| 32 | +* |
| 33 | +* - It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values). |
| 34 | +* - This is useful for starting double implicit shift bulges in the QR algorithm. |
| 35 | +* - `H` should be an upper hessenberg matrix if it's a 3-by-3 matrix. |
| 36 | +* - `V` should have at least `N` indexed elements. |
| 37 | +* |
| 38 | +* @private |
| 39 | +* @param {PositiveInteger} N - number of row/columns in `H` |
| 40 | +* @param {Float64Array} H - input matrix |
| 41 | +* @param {integer} strideH1 - stride of the first dimension of `H` |
| 42 | +* @param {integer} strideH2 - stride of the second dimension of `H` |
| 43 | +* @param {NonNegativeInteger} offsetH - index offset for `H` |
| 44 | +* @param {number} sr1 - real part of the first conjugate complex shift |
| 45 | +* @param {number} si1 - imaginary part of the first conjugate complex shift |
| 46 | +* @param {number} sr2 - real part of the second conjugate complex shift |
| 47 | +* @param {number} si2 - imaginary part of the second conjugate complex shift |
| 48 | +* @param {Float64Array} V - output array |
| 49 | +* @param {integer} strideV - stride length for `V` |
| 50 | +* @param {NonNegativeInteger} offsetV - index offset for `V` |
| 51 | +* @returns {Float64Array} `V` |
| 52 | +* |
| 53 | +* @example |
| 54 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 55 | +* |
| 56 | +* 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 ] ] |
| 57 | +* var V = new Float64Array( 3 ); |
| 58 | +* |
| 59 | +* var out = dlaqr1( 3, H, 3, 1, 0, 1.5, 0.0, 2.5, 0.0, V, 1, 0 ); |
| 60 | +* // returns <Float64Array>[ ~1.93, ~0.57, ~2.86 ] |
| 61 | +*/ |
| 62 | +function dlaqr1( N, H, strideH1, strideH2, offsetH, sr1, si1, sr2, si2, V, strideV, offsetV ) { // eslint-disable-line max-params, max-len |
| 63 | + var h21s; |
| 64 | + var h31s; |
| 65 | + var h11; |
| 66 | + var h12; |
| 67 | + var h13; |
| 68 | + var h21; |
| 69 | + var h22; |
| 70 | + var h23; |
| 71 | + var h31; |
| 72 | + var h32; |
| 73 | + var h33; |
| 74 | + var iv; |
| 75 | + var s; |
| 76 | + var i; |
| 77 | + |
| 78 | + h11 = offsetH; |
| 79 | + h12 = offsetH + strideH2; |
| 80 | + h21 = offsetH + strideH1; |
| 81 | + h22 = h21 + strideH2; |
| 82 | + |
| 83 | + if ( N === 2 ) { |
| 84 | + s = abs( H[ h11 ] - sr2 ) + abs( si2 ) + abs( H[ h21 ] ); |
| 85 | + if ( s === 0.0 ) { |
| 86 | + V[ offsetV ] = 0.0; |
| 87 | + V[ strideV + offsetV ] = 0.0; |
| 88 | + return V; |
| 89 | + } |
| 90 | + h21s = H[ h21 ] / s; |
| 91 | + V[ offsetV ] = ( h21s * H[ h12 ] ) + ( ( H[ h11 ]-sr1 ) * ( ( H[ h11 ]-sr2 ) / s ) ) - ( si1*( si2 / s ) ); // eslint-disable-line max-len |
| 92 | + V[ offsetV + strideV ] = h21s*( H[ h11 ]+H[ h22 ]-sr1-sr2 ); |
| 93 | + return V; |
| 94 | + } |
| 95 | + |
| 96 | + h13 = h12 + strideH2; |
| 97 | + h31 = h21 + strideH1; |
| 98 | + h33 = h22 + strideH1 + strideH2; |
| 99 | + h23 = h22 + strideH2; |
| 100 | + h32 = h22 + strideH1; |
| 101 | + |
| 102 | + s = abs( H[ h11 ]-sr2 ) + abs( si2 ) + abs( H[ h21 ] ) + abs( H[ h31 ] ); |
| 103 | + if ( s === 0.0 ) { |
| 104 | + iv = offsetV; |
| 105 | + for ( i = 0; i < 3; i++ ) { |
| 106 | + V[ iv ] = 0.0; |
| 107 | + iv += strideV; |
| 108 | + } |
| 109 | + return V; |
| 110 | + } |
| 111 | + h21s = H[ h21 ] / s; |
| 112 | + h31s = H[ h31 ] / s; |
| 113 | + iv = offsetV; |
| 114 | + V[ iv ] = (( H[ h11 ]-sr1 )*( ( H[ h11 ]-sr2 ) / s )) - (si1*( si2 / s )) + ((H[ h12 ]*h21s) + (H[ h13 ]*h31s)); // eslint-disable-line max-len |
| 115 | + iv += strideV; |
| 116 | + V[ iv ] = (h21s*( H[ h11 ]+H[ h22 ]-sr1-sr2 )) + (H[ h23 ]*h31s); |
| 117 | + iv += strideV; |
| 118 | + V[ iv ] = (h31s*( H[ h11 ]+H[ h33 ]-sr1-sr2 )) + (h21s*H[ h32 ]); |
| 119 | + return V; |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | +// EXPORTS // |
| 124 | + |
| 125 | +module.exports = dlaqr1; |
0 commit comments