Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 4x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 351x 351x 355x 355x 351x 351x 351x 351x 351x 351x 351x 351x 351x 351x 351x 351x 351x 355x 4x 4x 355x 5x 1x 1x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 96x 96x 97x 97x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 97x 1x 1x 97x 1x 5x 5x 5x 2x 2x 2x 2x 2x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/
/* eslint-disable max-len, max-params */
'use strict';
// MODULES //
var dlarf1f = require( '@stdlib/lapack/base/dlarf1f' ).ndarray;
var min = require( '@stdlib/math/base/special/min' );
var Float64Array = require( '@stdlib/array/float64' );
var dlarfg = require( './dlarfg.js' );
// MAIN //
/**
* Reduces a real general `M` by `N` matrix `A` to upper or lower bi-diagonal form `B` by an orthogonal transformation: `Q**T * A * P = B`.
*
* ## Notes
*
* - If `M >= N`,
*
* - `B` is upper bi-diagonal.
* - The diagonal and the first superdiagonal are overwritten with the upper bi-diagonal matrix `B`.
* - The elements below the diagonal, with the array `TAUQ`, represent the orthogonal matrix `Q` as a product of elementary reflectors.
* - The elements above the first superdiagonal, with the array `TAUP`, represent the orthogonal matrix `P` as a product of elementary reflectors.
*
* - If `M < N`,
*
* - `B` is lower bi-diagonal.
* - The diagonal and the first subdiagonal are overwritten with the lower bi-diagonal matrix `B`.
* - The elements below the first subdiagonal, with the array `TAUQ`, represent the orthogonal matrix `Q` as a product of elementary reflectors.
* - The elements above the diagonal, with the array `TAUP`, represent the orthogonal matrix `P` as a product of elementary reflectors.
*
* @private
* @param {NonNegativeInteger} M - number of rows of `A`
* @param {NonNegativeInteger} N - number of columns of `A`
* @param {Float64Array} A - input/output matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @param {Float64Array} D - diagonal elements of the bi-diagonal matrix `B` (length `min(M,N)`)
* @param {integer} strideD - stride length for `D`
* @param {NonNegativeInteger} offsetD - starting index of `D`
* @param {Float64Array} E - off-diagonal elements of the bi-diagonal matrix `B`, (length `min(M,N)`-1)
* @param {integer} strideE - stride length for `E`
* @param {NonNegativeInteger} offsetE - starting index of `E`
* @param {Float64Array} TAUQ - scalar factors of the elementary reflectors which represent the orthogonal matrix `Q` (length `min(M,N)`)
* @param {integer} strideTAUQ - stride length for `TAUQ`
* @param {NonNegativeInteger} offsetTAUQ - starting index of `TAUQ`
* @param {Float64Array} TAUP - scalar factors of the elementary reflectors which represent the orthogonal matrix `P` (length `min(M,N)`)
* @param {integer} strideTAUP - stride length for `TAUP`
* @param {NonNegativeInteger} offsetTAUP - starting index of `TAUP`
* @param {Float64Array} WORK - workspace array (length >= `max(M,N)`)
* @param {integer} strideWORK - stride length for `WORK`
* @param {NonNegativeInteger} offsetWORK - starting index of `WORK`
* @returns {integer} status code
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
* var D = new Float64Array( [ 0.0, 0.0 ] );
* var E = new Float64Array( [ 0.0 ] );
* var TAUQ = new Float64Array( [ 0.0, 0.0 ] );
* var TAUP = new Float64Array( [ 0.0, 0.0 ] );
* var WORK = new Float64Array( [ 0.0, 0.0, 0.0 ] );
*
* dgebd2( 3, 2, A, 1, 3, 0, D, 1, 0, E, 1, 0, TAUQ, 1, 0, TAUP, 1, 0, WORK, 1, 0 );
* // A => <Float64Array>[ ~-3.742, ~0.422, ~0.633, ~-8.552, ~1.964, ~0.86 ]
* // D => <Float64Array>[ ~-3.742, ~1.964 ]
* // E => <Float64Array>[ ~-8.552 ]
* // TAUQ => <Float64Array>[ ~1.267, ~1.15 ]
* // TAUP => <Float64Array>[ 0.0, 0.0 ]
* // WORK => <Float64Array>[ ~9.9, 0.0, 0.0 ]
*/
function dgebd2( M, N, A, strideA1, strideA2, offsetA, D, strideD, offsetD, E, strideE, offsetE, TAUQ, strideTAUQ, offsetTAUQ, TAUP, strideTAUP, offsetTAUP, WORK, strideWORK, offsetWORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point
var aii;
var out;
var i;
if ( M === 0 || N === 0 ) {
return 0;
}
out = new Float64Array( 2 );
if ( M >= N ) {
// Reduce to upper bi-diagonal form
for ( i = 0; i < N; i++ ) {
aii = offsetA + ( i * strideA1 ) + ( i * strideA2 ); // Index of A(i, i)
// Generate elementary reflector H(i) to annihilate A(i+1:M-1, i)
out[ 0 ] = A[ aii ];
dlarfg( M - i, A, strideA1, offsetA + ( min( i + 1, M - 1 ) * strideA1 ) + ( i * strideA2 ), out, 1, 0 );
A[ aii ] = out[ 0 ];
TAUQ[ offsetTAUQ + ( strideTAUQ * i ) ] = out[ 1 ];
// D(i) = A(i,i) (the computed beta)
D[ offsetD + ( i * strideD ) ] = A[ aii ];
// Apply H(i) to A(i:M-1, i+1:N-1) from the left
if ( i < N - 1 ) {
dlarf1f( 'left', M - i, N - i - 1, A, strideA1, aii, TAUQ[ offsetTAUQ + ( i * strideTAUQ ) ], A, strideA1, strideA2, aii + strideA2, WORK, strideWORK, offsetWORK );
}
if ( i < N - 1 ) {
// Generate elementary reflector G(i) to annihilate A(i, i+2:N-1)
out[ 0 ] = A[ aii + strideA2 ];
dlarfg( N - i - 1, A, strideA2, offsetA + ( i * strideA1 ) + ( min( i + 2, N - 1 ) * strideA2 ), out, 1, 0 );
A[ aii + strideA2 ] = out[ 0 ];
TAUP[ offsetTAUP + ( strideTAUP * i ) ] = out[ 1 ];
// E(i) = A(i, i+1) (the computed beta)
E[ offsetE + ( i * strideE ) ] = A[ aii + strideA2 ];
// Apply G(i) to A(i+1:M-1, i+1:N-1) from the right
dlarf1f( 'right', M - i - 1, N - i - 1, A, strideA2, aii + strideA2, TAUP[ offsetTAUP + ( i * strideTAUP ) ], A, strideA1, strideA2, aii + strideA1 + strideA2, WORK, strideWORK, offsetWORK );
} else {
TAUP[ offsetTAUP + ( i * strideTAUP ) ] = 0.0;
}
}
} else {
// Reduce to lower bi-diagonal form
for ( i = 0; i < M; i++ ) {
aii = offsetA + ( i * strideA1 ) + ( i * strideA2 ); // Index of A(i, i)
// Generate elementary reflector G(i) to annihilate A(i, i+1:N-1)
out[ 0 ] = A[ aii ];
dlarfg( N - i, A, strideA2, offsetA + ( i * strideA1 ) + ( min( i + 1, N - 1 ) * strideA2 ), out, 1, 0 );
A[ aii ] = out[ 0 ];
TAUP[ offsetTAUP + ( strideTAUP * i ) ] = out[ 1 ];
// D(i) = A(i,i) (the computed beta)
D[ offsetD + ( i * strideD ) ] = A[ aii ];
// Apply G(i) to A(i+1:M-1, i:N-1) from the right
if ( i < M - 1 ) {
dlarf1f( 'right', M - i - 1, N - i, A, strideA2, aii, TAUP[ offsetTAUP + ( i * strideTAUP ) ], A, strideA1, strideA2, aii + strideA1, WORK, strideWORK, offsetWORK );
}
if ( i < M - 1 ) {
// Generate elementary reflector H(i) to annihilate A(i+2:M-1, i)
out[ 0 ] = A[ aii + strideA1 ];
dlarfg( M - i - 1, A, strideA1, offsetA + ( min( i + 2, M - 1 ) * strideA1 ) + ( i * strideA2 ), out, 1, 0 );
A[ aii + strideA1 ] = out[ 0 ];
TAUQ[ offsetTAUQ + ( strideTAUQ * i ) ] = out[ 1 ];
// E(i) = A(i+1, i) (the computed beta)
E[ offsetE + ( i * strideE ) ] = A[ aii + strideA1 ];
// Apply H(i) to A(i+1:M-1, i+1:N-1) from the left
dlarf1f( 'left', M - i - 1, N - i - 1, A, strideA1, aii + strideA1, TAUQ[ offsetTAUQ + ( i * strideTAUQ ) ], A, strideA1, strideA2, aii + strideA1 + strideA2, WORK, strideWORK, offsetWORK );
} else {
TAUQ[ offsetTAUQ + ( i * strideTAUQ ) ] = 0.0;
}
}
}
return 0;
}
// EXPORTS //
module.exports = dgebd2;
|