diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js new file mode 100644 index 000000000000..d96c696575f8 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js @@ -0,0 +1,171 @@ +/** +* @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 max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var dorglq = require( './dorglq.js' ); +var dorgqr = require( './dorgqr.js' ); + + +// MAIN // + +/** +* Generates one of the real orthogonal matrices `Q` or `P**T` determined by `DGEBRD` when reducing a real matrix `A` to bi-diagonal form: `A = Q * B * P^T`. +* `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. +* +* +* @private +* @param {NonNegativeInteger} M - number of rows of `Q` +* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {NonNegativeInteger} K - number of elementary reflectors +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride length of the first dimension of `A` +* @param {integer} strideA2 - stride length of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float64Array} TAU - scalar factors of reflectors +* @param {integer} strideTAU - stride length of `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index for `TAU` +* @param {Float64Array} WORK - workspace array +* @param {integer} strideWORK - stride length of `WORK` +* @param {NonNegativeInteger} offsetWORK - starting index for `WORK` +* @param {NonNegativeInteger} LWORK - dimension of the array `WORK` +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1, 0, 0, -1, -2, 0 ] ); +* var TAU = new Float64Array( [ 1, 1 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorgbr( 2, 3, 2, A, 1, 2, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ 0, 0, 0, 0, 2, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ +function dorgbr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { + var ldwork; + var lquery; + var lwkopt; + var nbmin; + var iws; + var nb; + var nx; + var kk; + var ki; + var ib; + var i; + var j; + var l; + + nb = 32; // Optimal block size derived from the Fortran LAPACK call `ilaenv( 1, 'DORGLQ', ' ', m, n, k, -1 )` + lwkopt = max( 1, M ) * nb; + WORK[ offsetWORK ] = lwkopt; + lquery = ( LWORK === -1 ); + + if ( lquery ) { + return 0; + } + + // Quick return if possible + if ( M === 0 ) { + WORK[ offsetWORK ] = 1; + return 0; + } + + nbmin = 2; + nx = 0; + iws = M; + + if ( ( nb > 1 ) && ( nb < K ) ) { + // Determine when to cross over from blocked to unblocked code. + nx = 128; // The crossover point derived from the Fortran LAPACK call `ilaenv( 3, 'DORGLQ', ' ', m, n, k, -1 )` + + if ( nx < K ) { + // Determine if workspace is large enough for blocked code. + ldwork = M; + iws = ldwork * nb; + if ( LWORK < iws ) { + // Not enough workspace to use optimal NB: reduce NB and determine the minimum value of NB. + nb = floor( LWORK / ldwork ); + nbmin = 2; // The minimum block size derived from the Fortran LAPACK call `ilaenv( 2, 'DORGLQ', ' ', m, n, k, -1 )` + } + } + } + + if ( ( nb >= nbmin ) && ( nb < K ) && ( nx < K ) ) { + // Use blocked code after the last block. + // The first kk rows are handled by the block method. + ki = floor( ( K - nx - 1 ) / nb ) * nb; + kk = min( K, ki + nb ); + + // Set A(kk+1:m,1:kk) to zero. + for ( j = 0; j < kk; j++ ) { + for ( i = kk; i < M; i++ ) { + A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] = 0; + } + } + } else { + kk = 0; + } + + // Use unblocked code for the last or only block. + if ( kk < M ) { + dorgl2( M - kk, N - kk, K - kk, A, strideA1, strideA2, offsetA + ( kk * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( kk * strideTAU ), WORK, strideWORK, offsetWORK ); + } + + if ( kk > 0 ) { + // Use blocked code + for ( i = ki; i >= 0; i -= nb ) { + ib = min( nb, K - i ); + + if ( i + ib < M ) { + // Form the triangular factor of the block reflector, H = H(i) H(i+1) . . . H(i+ib-1) + dlarft( 'forward', 'rows', N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, 1, ldwork, offsetWORK ); + + // Apply H**T to A(i+ib:m,i:n) from the right + dlarfb( 'right', 'transpose', 'forward', 'rows', M - i - ib, N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), WORK, 1, ldwork, offsetWORK, A, strideA1, strideA2, offsetA + ( ( i + ib ) * strideA1 ) + ( i * strideA2 ), WORK, 1, ldwork, offsetWORK + ( ib * strideWORK ) ); + } + + // Apply H**T to columns i:n of current block + dorgl2( ib, N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, strideWORK, offsetWORK ); + + // Set columns 1:i-1 of current block to zero + for ( j = 0; j < i; j++ ) { + for ( l = i; l < i + ib; l++ ) { + A[ offsetA + ( l * strideA1 ) + ( j * strideA2 ) ] = 0.0; + } + } + } + } + + WORK[ offsetWORK ] = iws; + return 0; +} + + +// EXPORTS // + +module.exports = dorgbr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarf1f.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarf1f.js new file mode 100644 index 000000000000..1c1fcb234d65 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarf1f.js @@ -0,0 +1,184 @@ +/** +* @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. +*/ + +'use strict'; + +/* eslint-disable max-len */ + +// MODULES // + +var iladlc = require( '@stdlib/lapack/base/iladlc' ).ndarray; +var iladlr = require( '@stdlib/lapack/base/iladlr' ).ndarray; +var dgemv = require( '@stdlib/blas/base/dgemv' ).ndarray; +var dger = require( '@stdlib/blas/base/dger' ).ndarray; +var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; + + +// FUNCTIONS // + +/** +* Tests whether an operation should be applied to the left side. +* +* @private +* @param {string} side - operation side +* @returns {boolean} boolean indicating if an operation should be applied to the left side +*/ +function isLeftSide( side ) { + return side === 'left'; +} + + +// MAIN // + +/** +* Applies a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C`. +* +* ## Notes +* +* - If `side = 'left'`, +* +* - `work` should have `N` indexed elements. +* - `V` should have `1 + (M-1) * abs(strideV)` indexed elements. +* - `C` is overwritten by `H * C`. +* +* - If `side = 'right'`, +* +* - `work` should have `M` indexed elements. +* - `V` should have `1 + (N-1) * abs(strideV)` indexed elements. +* - `C` is overwritten by `C * H`. +* +* @private +* @param {string} side - specifies the side of multiplication with `C` +* @param {NonNegativeInteger} M - number of rows in `C` +* @param {NonNegativeInteger} N - number of columns in `C` +* @param {Float64Array} V - the vector `v` +* @param {integer} strideV - stride length for `V` +* @param {NonNegativeInteger} offsetV - starting index for `V` +* @param {number} tau - scalar constant +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of `C` +* @param {integer} strideC2 - stride of the second dimension of `C` +* @param {NonNegativeInteger} offsetC - starting index for `C` +* @param {Float64Array} work - workspace array +* @param {integer} strideWork - stride length for `work` +* @param {NonNegativeInteger} offsetWork - starting index for `work` +* @returns {Float64Array} `C * H` or `H * C` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); +* var V = new Float64Array( [ 0.5, 0.5, 0.5, 0.5 ] ); +* var work = new Float64Array( 3 ); +* +* var out = dlarf1f( 'left', 4, 3, V, 1, 0, 1.0, C, 3, 1, 0, work, 1, 0 ); +* // returns [ -4.5, -10.5, -16.5, -0.75, -1.75, -2.75, 0.25, -0.75, -1.75, 1.25, 0.25, -0.75 ] +*/ +function dlarf1f( side, M, N, V, strideV, offsetV, tau, C, strideC1, strideC2, offsetC, work, strideWork, offsetWork ) { // eslint-disable-line max-params + var lastv; + var lastc; + var i; + + if ( tau === 0.0 ) { + return C; + } + lastc = 0; + if ( isLeftSide( side ) ) { + lastv = M; + } else { + lastv = N; + } + // Initialize `i` to point to the last element in `V`: + i = offsetV + ( ( lastv-1 ) * strideV ); + + // Move `i` to the last non-zero element in `V`, where we assume that V[0] = 1, and it is not stored, so we shouldn't access it... + while ( lastv > 1 && V[ i ] === 0.0 ) { + lastv -= 1; + i -= strideV; + } + if ( isLeftSide( side ) ) { + // Scan for the last non-zero column in `C`: + lastc = iladlc( lastv + 1, N, C, strideC1, strideC2, offsetC ) + 1; // adjust by `+1` to account for the difference between zero-based and one-based indexing + } else { + // Scan for the last non-zero row in `C`: + lastc = iladlr( M, lastv + 1, C, strideC1, strideC2, offsetC ) + 1; // // adjust by `+1` to account for the difference between zero-based and one-based indexing + } + // Return `C` unchanged if all elements in `C` are zero... + if ( lastc === 0 ) { + return C; + } + if ( isLeftSide( side ) ) { + // Form: H*C + + // If `lastv = 1`, this means `V = 1`, so we just need to compute `C = H*C = (1-tau)*C`... + if ( lastv === 1 ) { + // C[0,0:lastc] = (1-tau)*C[0,0:lastc] + dscal( lastc, 1.0-tau, C, strideC2, offsetC ); // scale the first row + } else { + // work[0:lastc,0] = C[0:lastv,0:lastc]^T * V[0:lastv,0] + + // work[0:lastc,0] = C[1:lastv,0:lastc]^T * V[1:lastv,0] + dgemv( 'transpose', lastv-1, lastc, 1.0, C, strideC1, strideC2, offsetC+strideC1, V, strideV, offsetV+strideV, 0.0, work, strideWork, offsetWork ); + + // work[0:lastc,0] += C[0,0:lastc]^T * V[0,0] = C[0,0:lastc]^T + daxpy( lastc, 1.0, C, strideC2, offsetC, work, strideWork, offsetWork ); // operates on the first row of C + + // C[0:lastv,0:lastc] = C[...] - ( tau * V[0:lastv,0] * work[0:lastc,0]^T) + + // C[0,0:lastc] = C[...] - ( tau * V[0,0] * work[0:lastc,0]^^T ) = C[...] - ( tau * work[0:lastc,0]^T ) + daxpy( lastc, -tau, work, strideWork, offsetWork, C, strideC2, offsetC ); // operates on the first row of C + + // C[1:lastv,0:lastc] = C[...] - ( tau * V[1:lastv,0] * work[0:lastc,0]^T ) + dger( lastv-1, lastc, -tau, V, strideV, offsetV+strideV, work, strideWork, offsetWork, C, strideC1, strideC2, offsetC+strideC1 ); + } + return C; + } + // side === 'right' + + // Form: C*H + + // If `lastv = 1`, then `V = 1`, so we just need to compute `C = CH = C*(1-tau)`... + if ( lastv === 1 ) { + // C[0:lastc,0] = ( 1-tau ) * C[0:lastc,0] + dscal( lastc, 1.0-tau, C, strideC1, offsetC ); // scale the first column + return C; + } + // work[0:lastc,0] = ( 1-tau ) * C[0:lastc,0] + + // work[0:lastc,0] = C[0:lastc,1:lastv] * V[1:lastv,0] + dgemv( 'no-transpose', lastc, lastv-1, 1.0, C, strideC1, strideC2, offsetC+strideC2, V, strideV, offsetV+strideV, 0.0, work, strideWork, offsetWork ); + + // work[0:lastc,0] += C[0:lastc,0] * V[0,0] = C[0:lastc,0] + daxpy( lastc, 1.0, C, strideC1, offsetC, work, strideWork, offsetWork ); // operates on the first column of C + + // C[0:lastc,0:lastv] = C[...] - ( tau * work[0:lastc,0] * V[0:lastv,0]^T ) + + // C[0:lastc,0] = C[...] - ( tau * work[0:lastc,0] * V[0,0]^T ) = C[...] - ( tau * work[0:lastc,0] ) + daxpy( lastc, -tau, work, strideWork, offsetWork, C, strideC1, offsetC ); // operates on the first column of C + + // C[0:lastc,1:lastv] = C[...] - ( tau * work[0:lastc,0] * V[1:lastv]^T ) + dger( lastc, lastv-1, -tau, work, strideWork, offsetWork, V, strideV, offsetV+strideV, C, strideC1, strideC2, offsetC+strideC2 ); + + return C; +} + + +// EXPORTS // + +module.exports = dlarf1f; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarfb.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarfb.js new file mode 100644 index 000000000000..9829013b213b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarfb.js @@ -0,0 +1,118 @@ +/** +* @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 leftForwardColumns = require( './left_forward_columns.js' ); +var leftBackwardColumns = require( './left_backward_columns.js' ); +var leftForwardRows = require( './left_forward_rows.js' ); +var leftBackwardRows = require( './left_backward_rows.js' ); +var rightForwardColumns = require( './right_forward_columns.js' ); +var rightBackwardColumns = require( './right_backward_columns.js' ); +var rightForwardRows = require( './right_forward_rows.js' ); +var rightBackwardRows = require( './right_backward_rows.js' ); + + +// MAIN // + +/** +* Applies a real block reflector `H` or its transpose `H^T` to a real `M` by `N` matrix `C`, from either the left or the right. +* +* ## Notes +* +* - `V` is a double-precision array with dimension `(LDV,K)` if `storev = 'C'`, `(LDV,M)` if `storev = 'R'` and `side = 'L'`, or `(LDV,N)` if `storev = 'R'` and `side = 'R'`. +* - `T` is a double-precision array with dimension `(LDT,K)`. The triangular `K` by `K` matrix `T` in the representation of the block reflector. +* - `C` is a double-precision array with dimension `(LDC,N)`. On entry, the `M` by `N` matrix `C`. On exit, `C` is overwritten by the desired matrix product. +* - `work` is a double-precision array with dimension `(LDWORK,K)`. +* +* @private +* @param {string} side - specifies whether `H` or `H^T` is applied from the left or right +* @param {string} trans - specifies whether to apply `H` or `H^T` +* @param {string} direct - indicates how `H` is formed from a product of elementary reflectors +* @param {string} storev - indicates how the vectors which define the elementary reflectors are stored +* @param {NonNegativeInteger} M - number of rows of the matrix `C` +* @param {NonNegativeInteger} N - number of columns of the matrix `C` +* @param {NonNegativeInteger} K - order of the matrix `T` +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of `V` +* @param {integer} strideV2 - stride of the second dimension of `V` +* @param {integer} offsetV - index offset for `V` +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of `T` +* @param {integer} strideT2 - stride of the second dimension of `T` +* @param {integer} offsetT - index offset for `T` +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of `C` +* @param {integer} strideC2 - stride of the second dimension of `C` +* @param {integer} offsetC - index offset for `C` +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of `work` +* @param {integer} strideWork2 - stride of the second dimension of `work` +* @param {integer} offsetWork - index offset for `work` +* @returns {Float64Array} updated matrix `C` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* dlarfb( 'left', 'transpose', 'forward', 'columns', 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0 ); +* +* // C => [ -1350.00, -1400.00, -1450.00, -30961.00, -32102.00, -33243.00, -266612.00, -275464.00, -284316.00 ] +*/ +function dlarfb( side, trans, direct, storev, M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork ) { + // Quick return if possible + if ( M <= 0 || N <= 0 ) { + return C; + } + + if ( side === 'left' ) { + if ( storev === 'columns') { + if ( direct === 'forward' ) { + return leftForwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + return leftBackwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + if ( direct === 'forward' ) { + return leftForwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + return leftBackwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + if ( storev === 'columns') { + if ( direct === 'forward' ) { + return rightForwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + return rightBackwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + if ( direct === 'forward' ) { + return rightForwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); + } + return rightBackwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ); +} + + +// EXPORTS // + +module.exports = dlarfb; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarft.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarft.js new file mode 100644 index 000000000000..75afd916fb30 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarft.js @@ -0,0 +1,571 @@ +/** +* @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 dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dlacpy = require( '@stdlib/lapack/base/dlacpy' ).ndarray; +var floor = require( '@stdlib/math/base/special/floor' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Forms the triangular factor T of a real block reflector H of order N, which is defined as a product of K elementary reflectors. +* +* ## Notes +* +* - If `direct` = 'forward', `H = H(1) H(2) . . . H(k)` and `T` is upper triangular. +* - If `direct` = 'backward', `H = H(k) . . . H(2) H(1)` and `T` is lower triangular. +* - If `storev` = 'columns', the vector which defines the elementary reflector `H(i)` is stored in the i-th column of the array `V`, and `H = I - V * T * V**T`. +* - If `storev` = 'rows', the vector which defines the elementary reflector `H(i)` is stored in the i-th row of the array `V`, and `H = I - V**T * T * V`. +* +* ## Method +* +* ### QR Case +* +* - Break \\(V\\) apart into six components +* +* ```tex +* V = \left[ +* \begin{array}{cc} +* V_{1,1} & 0 \\ +* V_{2,1} & V_{2,2} \\ +* V_{3,1} & V_{3,2} +* \end{array} +* \right] +* ``` +* +* where +* +* - \\(V_{1,1} \in \mathbb{R}^{l,l}\\) is unit lower triangular +* - \\(V_{2,1} \in \mathbb{R}^{k-l,l}\\) is rectangular +* - \\(V_{3,1} \in \mathbb{R}^{n-k,l}\\) is rectangular +* - \\(V_{2,2} \in \mathbb{R}^{k-l,k-l}\\) is unit lower triangular +* - \\(V_{3,2} \in \mathbb{R}^{n-k,k-l}\\) is rectangular +* +* - We construct the \\(T\\) matrix +* +* ```tex +* T = \left[ +* \begin{array}{cc} +* T_{1,1} & T_{1,2} \\ +* 0 & T_{2,2} +* \end{array} +* \right] +* ``` +* +* where \\(T\\) is the triangular factor obtained from block reflectors. +* +* - Assume we have already computed \\(T_{1,1}\\) and \\(T_{2,2}\\), and collect the associated reflectors in \\(V_1\\) and \\(V_2\\) +* +* ```tex +* \begin{aligned} +* T_{1,1} &\in \mathbb{R}^{l,l} && \text{upper triangular} \\ +* T_{2,2} &\in \mathbb{R}^{k-l,k-l} && \text{upper triangular} \\ +* T_{1,2} &\in \mathbb{R}^{l,k-l} && \text{rectangular} +* \end{aligned} +* ``` +* +* with \\(l = \lfloor k/2 \rfloor\\). +* +* - Consider the product +* +* ```tex +* \begin{aligned} +* (I - V_1 T_{1,1} V_1^T)(I - V_2 T_{2,2} V_2^T) +* = I - V_1 T_{1,1} V_1^T - V_2 T_{2,2} V_2^T + V_1 T_{1,1} V_1^T V_2 T_{2,2} V_2^T +* \end{aligned} +* ``` +* +* - Define +* +* ```tex +* T_{1,2} = -T_{1,1} V_1^T V_2 T_{2,2} +* ``` +* +* - Define the matrix \\(V\\) as +* +* ```tex +* V = \left[ +* \begin{array}{cc} +* V_1 & V_2 +* \end{array} +* \right] +* ``` +* +* so the product is equivalent to \\(I - V T V^T\\). +* +* This means we can compute \\(T_{1,1}\\) and \\(T_{2,2}\\) recursively, then use this information to compute \\(T_{1,2}\\). +* +* ### LQ Case +* +* - Break \\(V\\) apart into six components +* +* ```tex +* V = \left[ +* \begin{array}{ccc} +* V_{1,1} & V_{1,2} & V_{1,3} \\ +* 0 & V_{2,2} & V_{2,3} +* \end{array} +* \right] +* ``` +* +* where +* +* - \\(V_{1,1} \in \mathbb{R}^{l,l}\\) is unit upper triangular +* - \\(V_{1,2} \in \mathbb{R}^{l,k-l}\\) is rectangular +* - \\(V_{1,3} \in \mathbb{R}^{l,n-k}\\) is rectangular +* - \\(V_{2,2} \in \mathbb{R}^{k-l,k-l}\\) is unit upper triangular +* - \\(V_{2,3} \in \mathbb{R}^{k-l,n-k}\\) is rectangular +* +* with \\(l = \lfloor k/2 \rfloor\\). +* +* - We construct the \\(T\\) matrix +* +* ```tex +* T = \left[ +* \begin{array}{cc} +* T_{1,1} & T_{1,2} \\ +* 0 & T_{2,2} +* \end{array} +* \right] +* ``` +* +* where \\(T\\) is the triangular factor obtained from block reflectors. +* +* - Assume we have already computed \\(T_{1,1}\\) and \\(T_{2,2}\\), and collect the associated reflectors in \\(V_1\\) and \\(V_2\\) +* +* ```tex +* \begin{aligned} +* T_{1,1} &\in \mathbb{R}^{l,l} && \text{upper triangular} \\ +* T_{2,2} &\in \mathbb{R}^{k-l,k-l} && \text{upper triangular} \\ +* T_{1,2} &\in \mathbb{R}^{l,k-l} && \text{rectangular} +* \end{aligned} +* ``` +* +* - Consider the product +* +* ```tex +* \begin{aligned} +* (I - V_1^T T_{1,1} V_1)(I - V_2^T T_{2,2} V_2) +* = I - V_1^T T_{1,1} V_1 - V_2^T T_{2,2} V_2 + V_1^T T_{1,1} V_1 V_2^T T_{2,2} V_2 +* \end{aligned} +* ``` +* +* - Define +* +* ```tex +* T_{1,2} = -T_{1,1} V_1 V_2^T T_{2,2} +* ``` +* +* - Define the matrix \\(V\\) as +* +* ```tex +* V = \left[ +* \begin{array}{c} +* V_1 \\ +* V_2 +* \end{array} +* \right] +* ``` +* +* so the product is equivalent to \\(I - V^T T V\\). +* +* This means we can compute \\(T_{1,1}\\) and \\(T_{2,2}\\) recursively, then use this information to compute \\(T_{1,2}\\). +* +* ### QL Case +* +* - Break \\(V\\) apart into six components +* +* ```tex +* V = \left[ +* \begin{array}{cc} +* V_{1,1} & V_{1,2} \\ +* V_{2,1} & V_{2,2} \\ +* 0 & V_{3,2} +* \end{array} +* \right] +* ``` +* +* where +* +* - \\(V_{1,1} \in \mathbb{R}^{n-k,k-l}\\) is rectangular +* - \\(V_{2,1} \in \mathbb{R}^{k-l,k-l}\\) is unit upper triangular +* - \\(V_{1,2} \in \mathbb{R}^{n-k,l}\\) is rectangular +* - \\(V_{2,2} \in \mathbb{R}^{k-l,l}\\) is rectangular +* - \\(V_{3,2} \in \mathbb{R}^{l,l}\\) is unit upper triangular +* +* - We construct the \\(T\\) matrix +* +* ```tex +* T = \left[ +* \begin{array}{cc} +* T_{1,1} & 0 \\ +* T_{2,1} & T_{2,2} +* \end{array} +* \right] +* ``` +* +* where \\(T\\) is the triangular factor obtained from block reflectors. +* +* - Assume we have already computed \\(T_{1,1}\\) and \\(T_{2,2}\\), and collect the associated reflectors in \\(V_1\\) and \\(V_2\\) +* +* ```tex +* \begin{aligned} +* T_{1,1} &\in \mathbb{R}^{k-l,k-l} && \text{non-unit lower triangular} \\ +* T_{2,2} &\in \mathbb{R}^{l,l} && \text{non-unit lower triangular} \\ +* T_{2,1} &\in \mathbb{R}^{l,k-l} && \text{rectangular} +* \end{aligned} +* ``` +* +* with \\(l = \lfloor k/2 \rfloor\\). +* +* - Consider the product +* +* ```tex +* \begin{aligned} +* (I - V_2 T_{2,2} V_2^T)(I - V_1 T_{1,1} V_1^T) +* = I - V_2 T_{2,2} V_2^T - V_1 T_{1,1} V_1^T + V_2 T_{2,2} V_2^T V_1 T_{1,1} V_1^T +* \end{aligned} +* ``` +* +* - Define +* +* ```tex +* T_{2,1} = -T_{2,2} V_2^T V_1 T_{1,1} +* ``` +* +* - Define the matrix \\(V\\) as +* +* ```tex +* V = \left[ +* \begin{array}{cc} +* V_1 & V_2 +* \end{array} +* \right] +* ``` +* +* so the product is equivalent to \\(I - V T V^T\\). +* +* This means we can compute \\(T_{1,1}\\) and \\(T_{2,2}\\) recursively, then use this information to compute \\(T_{2,1}\\). +* +* ### RQ Case +* +* - Break \\(V\\) apart into six components +* +* ```tex +* V = \left[ +* \begin{array}{ccc} +* V_{1,1} & V_{1,2} & 0 \\ +* V_{2,1} & V_{2,2} & V_{2,3} +* \end{array} +* \right] +* ``` +* +* where +* +* - \\(V_{1,1} \in \mathbb{R}^{k-l,n-k}\\) is rectangular +* - \\(V_{1,2} \in \mathbb{R}^{k-l,k-l}\\) is unit lower triangular +* - \\(V_{2,1} \in \mathbb{R}^{l,n-k}\\) is rectangular +* - \\(V_{2,2} \in \mathbb{R}^{l,k-l}\\) is rectangular +* - \\(V_{2,3} \in \mathbb{R}^{l,l}\\) is unit lower triangular +* +* - We construct the \\(T\\) matrix +* +* ```tex +* T = \left[ +* \begin{array}{cc} +* T_{1,1} & 0 \\ +* T_{2,1} & T_{2,2} +* \end{array} +* \right] +* ``` +* +* where \\(T\\) is the triangular factor obtained from block reflectors. +* +* - Assume we have already computed \\(T_{1,1}\\) and \\(T_{2,2}\\), and collect the associated reflectors in \\(V_1\\) and \\(V_2\\) +* +* ```tex +* \begin{aligned} +* T_{1,1} &\in \mathbb{R}^{k-l,k-l} && \text{non-unit lower triangular} \\ +* T_{2,2} &\in \mathbb{R}^{l,l} && \text{non-unit lower triangular} \\ +* T_{2,1} &\in \mathbb{R}^{l,k-l} && \text{rectangular} +* \end{aligned} +* ``` +* +* with \\(l = \lfloor k/2 \rfloor\\). +* +* - Consider the product +* +* ```tex +* \begin{aligned} +* (I - V_2^T T_{2,2} V_2)(I - V_1^T T_{1,1} V_1) +* = I - V_2^T T_{2,2} V_2 - V_1^T T_{1,1} V_1 + V_2^T T_{2,2} V_2 V_1^T T_{1,1} V_1 +* \end{aligned} +* ``` +* +* - Define +* +* ```tex +* T_{2,1} = -T_{2,2} V_2 V_1^T T_{1,1} +* ``` +* +* - Define the matrix \\(V\\) as +* +* ```tex +* V = \left[ +* \begin{array}{c} +* V_1 \\ +* V_2 +* \end{array} +* \right] +* ``` +* +* so the product is equivalent to \\(I - V^T T V\\). +* +* This means we can compute \\(T_{1,1}\\) and \\(T_{2,2}\\) recursively, then use this information to compute \\(T_{2,1}\\). +* +* @private +* @param {string} direct - specifies the order in which the elementary reflectors are multiplied to form the block reflector `H` +* @param {string} storev - specifies how the vectors which define the elementary reflectors are stored +* @param {NonNegativeInteger} N - order of the block reflector `H` +* @param {NonNegativeInteger} K - order of the triangular factor `T` (the number of elementary reflectors) +* @param {Float64Array} V - matrix of reflector vectors +* @param {integer} strideV1 - stride of first dimension of `V` +* @param {integer} strideV2 - stride of second dimension of `V` +* @param {NonNegativeInteger} offsetV - starting index for `V` +* @param {Float64Array} TAU - array of scalar factors of the elementary reflector `H(i)` +* @param {integer} strideTAU - stride length for `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index for `TAU` +* @param {Float64Array} T - output triangular matrix +* @param {integer} strideT1 - stride of first dimension of `T` +* @param {integer} strideT2 - stride of second dimension of `T` +* @param {NonNegativeInteger} offsetT - starting index for `T` +* @returns {Float64Array} `T` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 1.0, 0.2, 0.3, -0.4, 0.5, 0.0, 1.0, -0.6, 0.7, -0.8, 0.0, 0.0, 1.0, 0.9, 1.1 ] ); +* var TAU = new Float64Array( [ 1.2, 0.7, 1.5 ] ); +* var T = new Float64Array( 9 ); +* +* dlarft( 'forward', 'rows', 5, 3, V, 5, 1, 0, TAU, 1, 0, T, 3, 1, 0 ); +* // T => [ ~1.2, ~0.5544, ~-0.17514, 0.0, 0.7, 0.8925, 0.0, 0.0, 1.5 ] +*/ +function dlarft( direct, storev, N, K, V, strideV1, strideV2, offsetV, TAU, strideTAU, offsetTAU, T, strideT1, strideT2, offsetT ) { + var colv; + var dirf; + var i0; + var i1; + var i2; + var i3; + var lq; + var ql; + var qr; + var i; + var j; + var l; + + if ( N === 0 || K === 0 ) { + return T; + } + + if ( N === 1 || K === 1 ) { + T[ offsetT ] = TAU[ offsetTAU ]; + return T; + } + + l = floor( K / 2 ); + + if ( direct === 'forward' ) { + dirf = true; + } + else { + dirf = false; + } + + if ( storev === 'columns') { + colv = true; + } + else { + colv = false; + } + + // QR happens when we have forward direction in column storage + qr = dirf & colv; + + // LQ happens when we have forward direction in row storage + lq = dirf & ( !colv ); + + // QL happens when we have backward direction in column storage + ql = ( !dirf ) & colv; + + // The last case is RQ. Due to how we structured this, if the above 3 are false, then RQ must be true, so we never store this RQ happens when we have backward direction in row storage `RQ = ( !dirf ) & ( !colv )` + if ( qr ) { + // Compute T_{1,1} recursively + dlarft( direct, storev, N, l, V, strideV1, strideV2, offsetV, TAU, strideTAU, offsetTAU, T, strideT1, strideT2, offsetT ); + + // Compute T_{2,2} recursively + dlarft( direct, storev, N - l, K - l, V, strideV1, strideV2, offsetV + ( ( strideV1 + strideV2 ) * l ), TAU, strideTAU, offsetTAU + ( strideTAU * l ), T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * l ) ); + + // Compute T_{1,2} = V_{2,1} + i0 = offsetT + ( strideT2 * l ); + i1 = offsetV + ( strideV1 * l ); + for ( j = 0; j < l; j++ ) { + i2 = i0; + i3 = i1; + for ( i = 0; i < K - l; i++ ) { + T[ i2 ] = V[ i3 ]; + i2 += strideT2; + i3 += strideV1; + } + i0 += strideT1; + i1 += strideV2; + } + + // T_{1,2} = T_{1,2}*V_{2,2} + dtrmm( 'right', 'lower', 'no-transpose', 'unit', l, K - l, 1, V, strideV1, strideV2, offsetV + ( ( strideV1 + strideV2 ) * l ), T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + // T_{1,2} = V_{3,1}'*V_{3,2} + T_{1,2} + + // Note: We assume K <= N, and GEMM will do nothing if N=K + dgemm( 'transpose', 'no-transpose', l, K - l, N - K, 1, V, strideV1, strideV2, offsetV + ( strideV1 * K ), V, strideV1, strideV2, offsetV + ( strideV1 * K ) + ( strideV2 * l ), 1, T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + /* + At this point, we have that T_{1,2} = V_1'*V_2 + All that is left is to pre and post multiply by -T_{1,1} and T_{2,2} respectively. + + T_{1,2} = -T_{1,1}*T_{1,2} + */ + dtrmm( 'left', 'upper', 'no-transpose', 'non-unit', l, K - l, -1, T, strideT1, strideT2, offsetT, T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + // T_{1,2} = T_{1,2}*T_{2,2} + dtrmm( 'right', 'upper', 'no-transpose', 'non-unit', l, K - l, 1, T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * l ), T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + } else if ( lq ) { + // Compute T_{1,1} recursively + dlarft( direct, storev, N, l, V, strideV1, strideV2, offsetV, TAU, strideTAU, offsetTAU, T, strideT1, strideT2, offsetT ); + + // Compute T_{2,2} recursively + dlarft( direct, storev, N - l, K - l, V, strideV1, strideV2, offsetV + ( ( strideV1 + strideV2 ) * l ), TAU, strideTAU, offsetTAU + ( strideTAU * l ), T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * l ) ); + + // Compute T_{1,2} = V_{1,2} + dlacpy( 'all', l, K - l, V, strideV1, strideV2, offsetV + ( strideV2 * l ), T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + // T_{1,2} = T_{1,2}*V_{2,2} + dtrmm( 'right', 'upper', 'transpose', 'unit', l, K - l, 1, V, strideV1, strideV2, offsetV + ( ( strideV1 + strideV2 ) * l ), T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + // T_{1,2} = V_{1,3}*V_{2,3}' + T_{1,2} + + // Note: We assume K <= N, and GEMM will do nothing if N=K + dgemm( 'no-transpose', 'transpose', l, K - l, N - K, 1, V, strideV1, strideV2, offsetV + ( strideV2 * K ), V, strideV1, strideV2, offsetV + ( strideV1 * l ) + ( strideV2 * K ), 1, T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + /* + At this point, we have that T_{1,2} = V_1*V_2' + All that is left is to pre and post multiply by -T_{1,1} and T_{2,2} respectively. + + T_{1,2} = -T_{1,1}*T_{1,2} + */ + dtrmm( 'left', 'upper', 'no-transpose', 'non-unit', l, K - l, -1, T, strideT1, strideT2, offsetT, T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + + // T_{1,2} = T_{1,2}*T_{2,2} + dtrmm( 'right', 'upper', 'no-transpose', 'non-unit', l, K - l, 1, T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * l ), T, strideT1, strideT2, offsetT + ( strideT2 * l ) ); + } else if ( ql ) { + // Compute T_{1,1} recursively + dlarft( direct, storev, N - l, K - l, V, strideV1, strideV2, offsetV, TAU, strideTAU, offsetTAU, T, strideT1, strideT2, offsetT ); + + // Compute T_{2,2} recursively + dlarft( direct, storev, N - l, K - l, V, strideV1, strideV2, offsetV + ( ( strideV1 + strideV2 ) * l ), TAU, strideTAU, offsetTAU + ( strideTAU * l ), T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * l ) ); + + // Compute T_{2,1} = V_{2,2} + i0 = offsetT + ( strideT1 * ( K - l ) ); + i1 = offsetV + ( strideV1 * ( N - K ) ) + ( strideV2 * ( K - l ) ); + for ( j = 0; j < K - l; j++ ) { + i2 = i0; + i3 = i1; + for ( i = 0; i < l; i++ ) { + T[ i2 ] = V[ i3 ]; + i2 += strideT1; + i3 += strideV2; + } + i0 += strideT2; + i1 += strideV1; + } + + // T_{2,1} = T_{2,1}*V_{2,1} + dtrmm( 'right', 'upper', 'no-transpose', 'unit', l, K - l, 1, V, strideV1, strideV2, offsetV + ( strideV1 * ( N - K ) ), T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + // T_{2,1} = V_{2,2}'*V_{2,1} + T_{2,1} + + // Note: We assume K <= N, and GEMM will do nothing if N=K + dgemm( 'transpose', 'no-transpose', l, K - l, N - K, 1, V, strideV1, strideV2, offsetV + ( strideV2 * ( K - l ) ), V, strideV1, strideV2, offsetV, 1, T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + /* + At this point, we have that T_{2,1} = V_2'*V_1 + All that is left is to pre and post multiply by -T_{2,2} and T_{1,1} respectively. + + T_{2,1} = -T_{2,2}*T_{2,1} + */ + dtrmm( 'left', 'lower', 'no-transpose', 'non-unit', l, K - l, -1, T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * ( K - l ) ), T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + // T_{2,1} = T_{2,1}*T_{1,1} + dtrmm( 'right', 'lower', 'no-transpose', 'non-unit', l, K - l, 1, T, strideT1, strideT2, offsetT, T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + } else { + // Else means RQ case + + // Compute T_{1,1} recursively + dlarft( direct, storev, N - l, K - l, V, strideV1, strideV2, offsetV, TAU, strideTAU, offsetTAU, T, strideT1, strideT2, offsetT ); + + // Compute T_{2,2} recursively + dlarft( direct, storev, N, l, V, strideV1, strideV2, offsetV + ( strideV1 * ( K - l ) ), TAU, strideTAU, offsetTAU + ( strideTAU * ( K - l ) ), T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * ( K - l ) ) ); + + // Compute T_{2,1} = V_{2,2} + dlacpy( 'all', l, K - l, V, strideV1, strideV2, offsetV + ( strideV1 * ( K - l ) ) + ( strideV2 * ( N - K ) ), T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + // T_{2,1} = T_{2,1}*V_{1,2} + dtrmm( 'right', 'lower', 'transpose', 'unit', l, K - l, 1, V, strideV1, strideV2, offsetV + ( strideV2 * ( N - K ) ), T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + // T_{2,1} = V_{2,1}*V_{1,1}' + T_{2,1} + + // Note: We assume K <= N, and GEMM will do nothing if N=K + dgemm('no-transpose', 'transpose', l, K - l, N - K, 1, V, strideV1, strideV2, offsetV + ( strideV1 * ( K - l ) ), V, strideV1, strideV2, offsetV, 1, T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + /* + At this point, we have that T_{2,1} = V_2*V_1' + All that is left is to pre and post multiply by -T_{2,2} and T_{1,1} respectively. + + T_{2,1} = -T_{2,2}*T_{2,1} + */ + dtrmm( 'left', 'lower', 'no-transpose', 'non-unit', l, K - l, -1, T, strideT1, strideT2, offsetT + ( ( strideT1 + strideT2 ) * ( K - l ) ), T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + + // T_{2,1} = T_{2,1}*T_{1,1} + dtrmm( 'right', 'lower', 'no-transpose', 'non-unit', l, K - l, 1, T, strideT1, strideT2, offsetT, T, strideT1, strideT2, offsetT + ( strideT1 * ( K - l ) ) ); + } + return T; +} + + +// EXPORTS // + +module.exports = dlarft; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorg2r.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorg2r.js new file mode 100644 index 000000000000..d4c59f618c27 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorg2r.js @@ -0,0 +1,113 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var dlarf1f = require( './dlarf1f.js' ); +var initUnitColumns = require( './init_unit_columns.js' ); + + +// MAIN // + +/** +* Generates an M-by-N real matrix Q with orthonormal columns. The matrix Q is defined as the first N columns of a product of K elementary reflectors of order M. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`. +* +* @private +* @param {PositiveInteger} M - number of rows in matrix `A` +* @param {PositiveInteger} N - number of columns in matrix `A` +* @param {NonNegativeInteger} K - number of elementary reflectors whose product defines the matrix Q +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset for `A` +* @param {Float64Array} tau - vector of K scalar factors of the elementary reflectors +* @param {integer} strideTau - stride length for `tau` +* @param {NonNegativeInteger} offsetTau - index offset for `tau` +* @param {Float64Array} work - workspace array +* @param {integer} strideWork - stride length for `work` +* @param {NonNegativeInteger} offsetWork - index offset for `work` +* @returns {Float64Array} matrix `A` overwritten with the orthogonal matrix Q +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var tau = new Float64Array( [ 0.0, 0.0 ] ); +* var work = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dorg2r( 3, 2, 2, A, 1, 3, 0, tau, 1, 0, work, 1, 0 ); +* // A => [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] +*/ +function dorg2r( M, N, K, A, strideA1, strideA2, offsetA, tau, strideTau, offsetTau, work, strideWork, offsetWork ) { // eslint-disable-line max-len, max-params + var ia1; + var ia3; + var del; + var ia2; + var it; + var i; + var j; + + if ( N <= 0 ) { + return A; + } + + // Initialize columns k+1:n to columns of the unit matrix + initUnitColumns( M, N, K, A, strideA1, strideA2, offsetA ); + + del = strideA1 + strideA2; + it = offsetTau + ((K-1)*strideTau); + ia1 = offsetA + ((K-1)*(strideA1+strideA2)); + ia2 = offsetA + ((K-1)*strideA2); + + // Apply H(i) to A(i:m,i:n) from the left + for ( i = K-1; i >= 0; i-- ) { + if ( i < N ) { + // Apply H(i) to A(i:m,i+1:n) from the left + dlarf1f( 'left', M-i, N-i-1, A, strideA1, ia1, tau[ it ], A, strideA1, strideA2, ia1 + strideA2, work, strideWork, offsetWork ); + } + if ( i < M ) { + // Scale A(i+1:m,i) by -tau(i) + dscal( M-i-1, -tau[ it ], A, strideA1, ia1 + strideA1 ); + } + + // Set A(i,i) = 1 - tau(i) + A[ ia1 ] = 1.0 - tau[ it ]; + + ia3 = 0; + + // Set A(0:i-1,i) to zero + for ( j = 0; j < i; j++ ) { + A[ ia2 + ia3 ] = 0.0; + ia3 += strideA1; + } + it -= strideTau; + + ia1 -= del; + ia2 -= strideA2; + } + + return A; +} + + +// EXPORTS // + +module.exports = dorg2r; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js new file mode 100644 index 000000000000..bffe3b1ca2be --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js @@ -0,0 +1,107 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var format = require( '@stdlib/string/format' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Generates an `M-by-N` real orthogonal matrix `Q` from the elementary reflectors returned by `DGELQF`. +* +* ## Notes +* +* - On entry, the i-th row must contain the vector which defines the elementary reflector `H(i)`, for `i = 1,2,...,K`, as returned by `DGELQF` in the first `K` rows of its array argument `A`. +* - On exit, the `M-by-N` orthogonal matrix `Q`. +* - `WORK` must have length, `LWORK >= max(1,M)`. For optimum performance `LWORK >= M*NB`. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of rows of `Q` +* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {NonNegativeInteger} K - number of elementary reflectors +* @param {Float64Array} A - input/output matrix +* @param {integer} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Float64Array} TAU - scalar factors of reflectors +* @param {Float64Array} WORK - workspace array +* @param {NonNegativeInteger} LWORK - dimension of the array `WORK` +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} second argument must be a non-negative integer +* @throws {RangeError} third argument must be greater than or equal to `M` +* @throws {RangeError} fourth argument must be a non-negative integer and smaller than or equal to `M` +* @throws {RangeError} sixth argument must be a valid `LDA` value +* @throws {RangeError} ninth argument must be a valid `LWORK` value +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1, 0, 0, -1, -2, 0 ] ); +* var TAU = new Float64Array( [ 1, 1 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorgbr( 'column-major', 2, 3, 2, A, 2, TAU, WORK, 10 ); +* // A => [ 0, 0, 0, 0, 2, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ +function dorgbr( order, M, N, K, A, LDA, TAU, WORK, LWORK ) { + var sa1; + var sa2; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < M ) { + throw new RangeError( format( 'invalid argument. Third argument must be greater than or equal to `M`. Value: `%d`.', N ) ); + } + if ( K < 0 || K > M ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer and smaller than or equal to `M`. Value: `%d`.', K ) ); + } + if ( order === 'column-major' ) { + if ( LDA < max( 1, M ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to `max(1,M)`. Value: `%d`.', LDA ) ); + } + sa1 = 1; + sa2 = LDA; + } else { // row-major + if ( LDA < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to `max(1,N)`. Value: `%d`.', LDA ) ); + } + sa1 = LDA; + sa2 = 1; + } + if ( LWORK < max( 1, N ) && LWORK !== -1 ) { + throw new RangeError( format( 'invalid argument. Ninth argument must be greater than or equal to `max(1,N)` except when equal to -1. Value: `%d`.', LWORK ) ); + } + return base( M, N, K, A, sa1, sa2, 0, TAU, 1, 0, WORK, 1, 0, LWORK ); +} + + +// EXPORTS // + +module.exports = dorgbr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgl2.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgl2.js new file mode 100644 index 000000000000..46d8bcedef9c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgl2.js @@ -0,0 +1,143 @@ +/** +* @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 dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Generate an M-by-N real orthogonal matrix `Q` from the elementary reflectors returned by `DGELQF`/`DGELQ2` (LQ factorization, unblocked). +* +* ## Notes +* +* - On entry, the i-th row of A must contain the vector which defines the elementary reflector H(i), for i = 1, 2, ..., K, as returned by `DGELQF` in the first K rows of its array argument A. +* +* - Q is defined as the product of K elementary reflectors: +* +* - Q = H(K) ... H(2) H(1), where each H(i) has the form `H(i) = I - tau(i)*v*v^T`, and v is stored as row i of the input matrix A. +* +* - On exit, A contains the M-by-N matrix Q. +* +* @private +* @param {NonNegativeInteger} M - number of rows of Q (0 <= M <= N) +* @param {NonNegativeInteger} N - number of columns of Q (N >= 0) +* @param {NonNegativeInteger} K - number of elementary reflectors (0 <= K <= M) +* @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 for A +* @param {Float64Array} TAU - scalar factors of reflectors (length K) +* @param {integer} strideTAU - stride for TAU +* @param {NonNegativeInteger} offsetTAU - starting index for TAU +* @param {Float64Array} WORK - workspace (length >= M) +* @param {integer} strideWORK - stride for WORK +* @param {NonNegativeInteger} offsetWORK - starting index for WORK +* @returns {integer} status code (0 = success) +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( 12 ); +* var TAU = new Float64Array( 2 ); +* var WORK = new Float64Array( 3 ); +* +* var info = dorgl2( 3, 4, 2, A, 4, 1, 0, TAU, 1, 0, WORK, 1, 0 ); +* // returns 0 +* // A => [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ] +* // WORK => [ 0, 0, 0 ] +*/ +function dorgl2( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK ) { + var idx0; + var idx1; + var idx2; + var idx3; + var i; + var j; + var l; + + // Initialize rows K+1..M to rows of the unit matrix + if ( K < M ) { + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + idx1 = offsetA + ( strideA1*K ); + for ( l = K; l < M; l++ ) { + idx2 = idx1; + for ( j = 0; j < N; j++ ) { + A[ idx2 ] = 0; + idx2 += strideA2; + if ( j >= K && j < M ) { + A[ offsetA + ( j*( strideA1 + strideA2 ) ) ] = 1; + } + } + idx1 += strideA1; + } + } else { // column-major + idx1 = offsetA; + for ( j = 0; j < N; j++ ) { + idx2 = idx1 + ( K*strideA1 ); + for ( l = K; l < M; l++ ) { + A[ idx2 ] = 0; + idx2 += strideA1; + } + if ( j >= K && j < M ) { + A[ idx1 + ( j*strideA1 ) ] = 1; + } + idx1 += strideA2; + } + } + } + + idx0 = offsetTAU + ( strideTAU*( K - 1 ) ); // TAU( i ) + idx1 = offsetA + ( ( K - 1 )*( strideA1 + strideA2 ) ); // A( i,i ) + idx2 = offsetA + ( ( K - 1 )*strideA1 ); // A( i,0 ) + for ( i = K - 1; i >= 0; i-- ) { + // Apply H(i) to A(i:m,i:n) from the right + if ( i < N - 1 ) { + if ( i < M - 1 ) { + dlarf1f( 'right', M - i - 1, N - i, A, strideA2, idx1, TAU[ idx0 ], A, strideA1, strideA2, idx1 + strideA1, WORK, strideWORK, offsetWORK ); + } + dscal( N - i - 1, -TAU[ idx0 ], A, strideA2, idx1 + strideA2 ); + } + + A[ idx1 ] = 1 - TAU[ idx0 ]; + + // Set A(i,1:i-1) to zero + idx3 = idx2; // A( i,l ) + for ( l = 0; l < i; l++ ) { + A[ idx3 ] = 0; + idx3 += strideA2; + } + idx0 -= strideTAU; + idx1 -= strideA1 + strideA2; + idx2 -= strideA1; + } + return 0; +} + + +// EXPORTS // + +module.exports = dorgl2; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorglq.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorglq.js new file mode 100644 index 000000000000..019d16c13762 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorglq.js @@ -0,0 +1,176 @@ +/** +* @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 max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var dorgl2 = require( './dorgl2.js' ); +var dlarft = require( './dlarft.js' ); +var dlarfb = require( './dlarfb.js' ); + + +// MAIN // + +/** +* Generates an `M-by-N` real orthogonal matrix `Q` from the elementary reflectors returned by `DGELQF`. +* +* ## Notes +* +* - On entry, the i-th row must contain the vector which defines the elementary reflector `H(i)`, for `i = 1,2,...,K`, as returned by `DGELQF` in the first `K` rows of its array argument `A`. +* - On exit, the `M-by-N` orthogonal matrix `Q`. +* - `WORK` must have length, `LWORK >= max(1,M)`. For optimum performance `LWORK >= M*NB`. +* +* @private +* @param {NonNegativeInteger} M - number of rows of `Q` +* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {NonNegativeInteger} K - number of elementary reflectors +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride length of the first dimension of `A` +* @param {integer} strideA2 - stride length of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float64Array} TAU - scalar factors of reflectors +* @param {integer} strideTAU - stride length of `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index for `TAU` +* @param {Float64Array} WORK - workspace array +* @param {integer} strideWORK - stride length of `WORK` +* @param {NonNegativeInteger} offsetWORK - starting index for `WORK` +* @param {NonNegativeInteger} LWORK - dimension of the array `WORK` +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1, 0, 0, -1, -2, 0 ] ); +* var TAU = new Float64Array( [ 1, 1 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorglq( 2, 3, 2, A, 1, 2, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ 0, 0, 0, 0, 2, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ +function dorglq( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { + var ldwork; + var lquery; + var lwkopt; + var nbmin; + var iws; + var nb; + var nx; + var kk; + var ki; + var ib; + var i; + var j; + var l; + + nb = 32; // Optimal block size derived from the Fortran LAPACK call `ilaenv( 1, 'DORGLQ', ' ', m, n, k, -1 )` + lwkopt = max( 1, M ) * nb; + WORK[ offsetWORK ] = lwkopt; + lquery = ( LWORK === -1 ); + + if ( lquery ) { + return 0; + } + + // Quick return if possible + if ( M === 0 ) { + WORK[ offsetWORK ] = 1; + return 0; + } + + nbmin = 2; + nx = 0; + iws = M; + + if ( ( nb > 1 ) && ( nb < K ) ) { + // Determine when to cross over from blocked to unblocked code. + nx = 128; // The crossover point derived from the Fortran LAPACK call `ilaenv( 3, 'DORGLQ', ' ', m, n, k, -1 )` + + if ( nx < K ) { + // Determine if workspace is large enough for blocked code. + ldwork = M; + iws = ldwork * nb; + if ( LWORK < iws ) { + // Not enough workspace to use optimal NB: reduce NB and determine the minimum value of NB. + nb = floor( LWORK / ldwork ); + nbmin = 2; // The minimum block size derived from the Fortran LAPACK call `ilaenv( 2, 'DORGLQ', ' ', m, n, k, -1 )` + } + } + } + + if ( ( nb >= nbmin ) && ( nb < K ) && ( nx < K ) ) { + // Use blocked code after the last block. + // The first kk rows are handled by the block method. + ki = floor( ( K - nx - 1 ) / nb ) * nb; + kk = min( K, ki + nb ); + + // Set A(kk+1:m,1:kk) to zero. + for ( j = 0; j < kk; j++ ) { + for ( i = kk; i < M; i++ ) { + A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] = 0; + } + } + } else { + kk = 0; + } + + // Use unblocked code for the last or only block. + if ( kk < M ) { + dorgl2( M - kk, N - kk, K - kk, A, strideA1, strideA2, offsetA + ( kk * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( kk * strideTAU ), WORK, strideWORK, offsetWORK ); + } + + if ( kk > 0 ) { + // Use blocked code + for ( i = ki; i >= 0; i -= nb ) { + ib = min( nb, K - i ); + + if ( i + ib < M ) { + // Form the triangular factor of the block reflector, H = H(i) H(i+1) . . . H(i+ib-1) + dlarft( 'forward', 'rows', N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, 1, ldwork, offsetWORK ); + + // Apply H**T to A(i+ib:m,i:n) from the right + dlarfb( 'right', 'transpose', 'forward', 'rows', M - i - ib, N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), WORK, 1, ldwork, offsetWORK, A, strideA1, strideA2, offsetA + ( ( i + ib ) * strideA1 ) + ( i * strideA2 ), WORK, 1, ldwork, offsetWORK + ( ib * strideWORK ) ); + } + + // Apply H**T to columns i:n of current block + dorgl2( ib, N - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, strideWORK, offsetWORK ); + + // Set columns 1:i-1 of current block to zero + for ( j = 0; j < i; j++ ) { + for ( l = i; l < i + ib; l++ ) { + A[ offsetA + ( l * strideA1 ) + ( j * strideA2 ) ] = 0.0; + } + } + } + } + + WORK[ offsetWORK ] = iws; + return 0; +} + + +// EXPORTS // + +module.exports = dorglq; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgqr.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgqr.js new file mode 100644 index 000000000000..82c1830af589 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgqr.js @@ -0,0 +1,176 @@ +/** +* @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. +*/ + +'use strict'; + +/* eslint-disable max-len, max-params */ + +// MODULES // + +var max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); +var dorg2r = require( './dorg2r.js' ); +var dlarfb = require( './dlarfb.js' ); +var dlarft = require( './dlarft.js' ); + + +// MAIN // + +/** +* Generates an `M-by-N` real matrix `Q` with orthonormal columns, which is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`. +* +* ## Notes +* +* - On entry, the i-th column of A must contain the reflector vector for `H(i)`, as returned by DGEQRF. +* - On exit, A contains the M-by-N orthogonal matrix Q. +* - For optimum performance `LWORK >= N*NB`, where `NB` is the optimal blocksize. +* - If `LWORK = -1`, then a workspace query is assumed. +* - The routine only calculates the optimal size of the `WORK` array, returns this value as the first entry of the `WORK` array. +* +* @private +* @param {NonNegativeInteger} M - number of rows of `Q` +* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {NonNegativeInteger} K - number of elementary reflectors whose product defines the matrix `Q` +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index of `A` +* @param {Float64Array} TAU - scalar factors of reflectors +* @param {integer} strideTAU - stride length for `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index of `TAU` +* @param {Float64Array} WORK - workspace array +* @param {integer} strideWORK - stride length for `WORK` +* @param {NonNegativeInteger} offsetWORK - starting index of `WORK` +* @param {NonNegativeInteger} LWORK - dimension of the array `WORK` +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); +* var TAU = new Float64Array( [ 2, 2 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorgqr( 3, 2, 2, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ -1, 0, 0, 0, -1, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ +function dorgqr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { + var ldwork; + var lwkopt; + var lquery; + var nbmin; + var iws; + var nb; + var nx; + var kk; + var ki; + var ib; + var i; + var j; + var l; + + nb = 32; // The optimal blocksize derived from the Fortran LAPACK call `ilaenv( 1, 'DORGQR', ' ', m, n, k, -1 )` + lwkopt = max( 1, N ) * nb; + WORK[ offsetWORK ] = lwkopt; + lquery = ( LWORK === -1 ); + + if ( lquery ) { + return 0; + } + + // Quick return if possible + if ( N === 0 ) { + WORK[ offsetWORK ] = 1; + return 0; + } + + nbmin = 2; + nx = 0; + iws = N; + + if ( nb > 1 && nb < K ) { + // Determine when to cross over from blocked to unblocked code. + nx = 128; // The cross-over point derived from the Fortran LAPACK call `ilaenv( 3, 'DORGQR', ' ', m, n, k, -1 )` + + if ( nx < K ) { + // Determine if workspace is large enough for blocked code + ldwork = N; + iws = ldwork * nb; + if ( LWORK < iws ) { + // Not enough workspace to use optimal NB: reduce NB and determine the minimum value of NB. + nb = LWORK / ldwork; + nbmin = 2; // The minimum block size derived from the Fortran LAPACK call `ilaenv( 2, 'DORGQR', ' ', m, n, k, -1 )` + } + } + } + + if ( nb >= nbmin && nb < K && nx < K ) { + // Use blocked code after the last block. The first kk columns are handled by the block method. + ki = ( ( K - nx - 1 ) / nb ) * nb; + kk = min( K, ki + nb ); + + // Set A(1:kk,kk+1:n) to zero + for ( j = kk; j < N; j++ ) { + for ( i = 0; i < kk; i++ ) { + A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] = 0; + } + } + } else { + kk = 0; + } + + // Use unblocked code for the last or only block + if ( kk < N ) { + dorg2r( M - kk, N - kk, K - kk, A, strideA1, strideA2, offsetA + ( kk * strideA1 ) + ( kk * strideA2 ), TAU, strideTAU, offsetTAU + ( kk * strideTAU ), WORK, strideWORK, offsetWORK ); + } + + if ( kk > 0 ) { + // Use blocked code + for ( i = ki; i >= 0; i -= nb ) { + ib = min( nb, K - i ); + + if ( i + ib < N ) { + // Form the triangular factor T of the block reflector H = H(i) H(i+1) . . . H(i+ib-1) + dlarft( 'forward', 'columns', M - i, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, 1, ldwork, offsetWORK ); + + // Apply H to A(i:M-1, i+ib:N-1) from the left + dlarfb( 'left', 'no-transpose', 'forward', 'columns', M - i, N - i - ib, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), WORK, 1, ldwork, offsetWORK, A, strideA1, strideA2, offsetA + ( i * strideA1 ) + ( ( i + ib ) * strideA2 ), WORK, 1, ldwork, offsetWORK + ( ib * strideWORK ) ); + } + + // Apply H to rows i:m of current block + dorg2r( M - i, ib, ib, A, strideA1, strideA2, offsetA + ( i * ( strideA1 + strideA2 ) ), TAU, strideTAU, offsetTAU + ( i * strideTAU ), WORK, 1, offsetWORK ); + + // Set rows 1:i-1 of current block to zero + for ( j = i; j < i + ib; j++ ) { + for ( l = 0; l < i; l++ ) { + A[ offsetA + ( l * strideA1 ) + ( j * strideA2 ) ] = 0; + } + } + } + } + + WORK[ offsetWORK ] = iws; + return 0; +} + + +// EXPORTS // + +module.exports = dorgqr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dtrmm.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dtrmm.js new file mode 100644 index 000000000000..f360237c6ef3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dtrmm.js @@ -0,0 +1,362 @@ +/** +* @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-statements, max-lines-per-function */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// FUNCTIONS // + +/** +* Fills a matrix with zeros. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {Float64Array} X - matrix to fill +* @param {integer} strideX1 - stride of the first dimension of `X` +* @param {integer} strideX2 - stride of the second dimension of `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @returns {Float64Array} input matrix +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* zeros( 2, 3, X, 3, 1, 0 ); +* // X => [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* zeros( 2, 3, X, 1, 2, 0 ); +* // X => [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] +*/ +function zeros( M, N, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package + var dx0; + var dx1; + var S0; + var S1; + var i0; + var i1; + var ix; + + if ( isRowMajor( [ strideX1, strideX2 ] ) ) { + // For row-major matrices, the last dimension has the fastest changing index... + S0 = N; + S1 = M; + dx0 = strideX2; // offset increment for innermost loop + dx1 = strideX1 - ( S0*strideX2 ); // offset increment for outermost loop + } else { // column-major + // For column-major matrices, the first dimension has the fastest changing index... + S0 = M; + S1 = N; + dx0 = strideX1; // offset increment for innermost loop + dx1 = strideX2 - ( S0*strideX1 ); // offset increment for outermost loop + } + ix = offsetX; + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + X[ ix ] = 0.0; + ix += dx0; + } + ix += dx1; + } + return X; +} + + +// MAIN // + +/** +* Performs one of the matrix-matrix operations `B = α * op(A) * B` or `B = α * B * op(A)` where `α` is a scalar, `B` is an `M` by `N` matrix, `A` is a unit, or non-unit, upper or lower triangular matrix and `op( A )` is one of `op( A ) = A` or `op( A ) = A^T`. +* +* @private +* @param {string} side - specifies whether `op( A )` appears on the left or right side of `B` +* @param {string} uplo - specifies whether the upper or lower triangular part of the matrix `A` should be referenced +* @param {string} transa - specifies whether `A` should be transposed, conjugate-transposed, or not transposed +* @param {string} diag - specifies whether or not `A` is unit triangular +* @param {NonNegativeInteger} M - number of rows in `B` +* @param {NonNegativeInteger} N - number of columns in `B` +* @param {number} alpha - scalar constant +* @param {Float64Array} A - first input 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 for `A` +* @param {Float64Array} B - second input matrix +* @param {integer} strideB1 - stride of the first dimension of `B` +* @param {integer} strideB2 - stride of the second dimension of `B` +* @param {NonNegativeInteger} offsetB - starting index for `B` +* @returns {Float64Array} `B` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] ); +* var B = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); +* +* dtrmm( 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0 ); +* // B => [ 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ] +*/ +function dtrmm( side, uplo, transa, diag, M, N, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { // eslint-disable-line max-params + var nonunit; + var isrma; + var tmp; + var oa2; + var ob2; + var sa0; + var sa1; + var sb0; + var sb1; + var oa; + var ob; + var ia; + var ib; + var i; + var j; + var k; + var t; + + // Note on variable naming convention: sa#, sb# where # corresponds to the loop number, with `0` being the innermost loop... + + nonunit = ( diag === 'non-unit' ); + + if ( M === 0 || N === 0 ) { + return B; + } + + // Handle alpha = 0 before any layout conversion (zeroing uses original layout)... + if ( alpha === 0.0 ) { + if ( isRowMajor( [ strideB1, strideB2 ] ) ) { + sb0 = strideB2; + sb1 = strideB1; + } else { + sb0 = strideB1; + sb1 = strideB2; + } + zeros( M, N, B, sb0, sb1, offsetB ); + return B; + } + + // Detect layout and convert column-major to an equivalent row-major problem... + isrma = isRowMajor( [ strideA1, strideA2 ] ); + if ( !isrma ) { + // Swap strides: effectively view A and B as transposed (row-major)... + t = strideA1; + strideA1 = strideA2; + strideA2 = t; + + t = strideB1; + strideB1 = strideB2; + strideB2 = t; + + side = ( side === 'left' ) ? 'right' : 'left'; + uplo = ( uplo === 'upper' ) ? 'lower' : 'upper'; + t = M; + M = N; + N = t; + } + + // For row-major matrices, the last dimension has the fastest changing index... + sa0 = strideA2; // stride for innermost loop + sa1 = strideA1; // stride for outermost loop + sb0 = strideB2; // stride for innermost loop + sb1 = strideB1; // stride for outermost loop + + if ( side === 'left' && uplo === 'upper' && transa === 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ib = offsetB + ( j*sb0 ); + for ( k = 0; k < M; k++ ) { + ob2 = ib + ( k * sb1 ); + tmp = alpha * B[ ob2 ]; + ia = offsetA + ( k*sa0 ); + for ( i = 0; i < k; i++ ) { + B[ ib + ( i*sb1 ) ] += ( tmp * A[ ia + ( i*sa1 ) ] ); + } + if ( nonunit ) { + tmp *= A[ ia + ( k*sa1 ) ]; + } + B[ ob2 ] = tmp; + } + } + return B; + } + if ( side === 'left' && uplo === 'lower' && transa === 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ib = offsetB + ( j*sb0 ); + for ( k = M - 1; k >= 0; k-- ) { + ob2 = ib + ( k*sb1 ); + tmp = alpha * B[ ob2 ]; + ia = offsetA + ( k*sa0 ); + for ( i = k + 1; i < M; i++ ) { + oa2 = ia + ( i*sa1 ); + B[ ib + ( i*sb1 ) ] += ( tmp * A[ oa2 ] ); + } + if ( nonunit ) { + tmp *= A[ ia + ( k*sa1 ) ]; + } + B[ ob2 ] = tmp; + } + } + return B; + } + if ( side === 'left' && uplo === 'upper' && transa !== 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ib = offsetB + ( j*sb0 ); + for ( i = M - 1; i >= 0; i-- ) { + ob2 = ib + ( i*sb1 ); + tmp = 0.0; + ia = offsetA + ( i*sa0 ); + if ( nonunit ) { + tmp += ( A[ ia + ( i*sa1 ) ] * B[ ob2 ] ); + } else { + tmp += B[ ob2 ]; + } + for ( k = 0; k < i; k++ ) { + oa2 = ia + ( k*sa1 ); + tmp += A[ oa2 ] * B[ ib + ( k*sb1 ) ]; + } + B[ ob2 ] = alpha * tmp; + } + } + return B; + } + if ( side === 'left' && uplo === 'lower' && transa !== 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ib = offsetB + ( j * sb0 ); + for ( i = 0; i < M; i++ ) { + ia = offsetA + ( i * sa0 ); + ob2 = ib + ( i * sb1 ); + tmp = 0.0; + for ( k = i + 1; k < M; k++ ) { + tmp += A[ ia + ( k * sa1 ) ] * B[ ib + ( k * sb1 ) ]; + } + if ( nonunit ) { + tmp += ( A[ ia + ( i * sa1 ) ] * B[ ob2 ] ); + } else { + tmp += B[ ob2 ]; + } + B[ ob2 ] = alpha * tmp; + } + } + return B; + } + if ( side === 'right' && uplo === 'upper' && transa === 'no-transpose' ) { + for ( j = N - 1; j >= 0; j-- ) { + ia = offsetA + ( j*sa0 ); + ib = offsetB + ( j*sb0 ); + for ( i = 0; i < M; i++ ) { + ob = ib + ( i*sb1 ); + B[ ob ] *= alpha; + if ( nonunit ) { + oa2 = ia + ( j*sa1 ); + tmp = A[ oa2 ]; + B[ ob ] *= tmp; + } + for ( k = 0; k < j; k++ ) { + oa2 = ia + ( k*sa1 ); + ob2 = offsetB + ( k*sb0 ); + if ( A[ oa2 ] !== 0.0 ) { + tmp = alpha * A[ oa2 ]; + B[ ob ] += ( tmp * B[ ob2 + ( i*sb1 ) ] ); + } + } + } + } + return B; + } + if ( side === 'right' && uplo === 'lower' && transa === 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ia = offsetA + ( j*sa0 ); + for ( i = 0; i < M; i++ ) { + ib = offsetB + ( i*sb1 ); + ob = ib + ( j*sb0 ); + B[ ob ] *= alpha; + if ( nonunit ) { + oa = ia + ( j*sa1 ); + B[ ob ] *= A[ oa ]; + } + for ( k = j + 1; k < N; k++ ) { + oa2 = ia + ( k*sa1 ); + ob2 = ib + ( k*sb0 ); + if ( A[ oa2 ] !== 0.0 ) { + tmp = alpha * A[ oa2 ]; + B[ ob ] += ( tmp * B[ ob2 ] ); + } + } + } + } + return B; + } + if ( side === 'right' && uplo === 'upper' && transa !== 'no-transpose' ) { + for ( j = 0; j < N; j++ ) { + ia = offsetA + ( j*sa1 ); + for ( i = 0; i < M; i++ ) { + ib = offsetB + ( i*sb1 ); + oa = ia + ( j*sa0 ); + ob = ib + ( j*sb0 ); + if ( nonunit ) { + tmp = B[ ob ] * A[ oa ]; + } else { + tmp = B[ ob ]; + } + for ( k = j + 1; k < N; k++ ) { + oa2 = ia + ( k*sa0 ); + ob2 = ib + ( k*sb0 ); + tmp += ( B[ ob2 ] * A[ oa2 ] ); + } + B[ ob ] = alpha * tmp; + } + } + return B; + } + // side === 'right', uplo === 'lower', transa !== 'no-transpose' + for ( i = 0; i < M; i++ ) { + ib = offsetB + ( i*sb1 ); + for ( j = N - 1; j >= 0; j-- ) { + ia = offsetA + ( j*sa1 ); + oa = ia + ( j*sa0 ); + ob = ib + ( j*sb0 ); + if ( nonunit ) { + tmp = B[ ob ] * A[ oa ]; + } else { + tmp = B[ ob ]; + } + for ( k = 0; k < j; k++ ) { + oa2 = ia + ( k*sa0 ); + ob2 = ib + ( k*sb0 ); + tmp += ( B[ ob2 ] * A[ oa2 ] ); + } + B[ ob ] = alpha * tmp; + } + } + return B; +} + + +// EXPORTS // + +module.exports = dtrmm; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js new file mode 100644 index 000000000000..8b2261c18681 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js @@ -0,0 +1,63 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* LAPACK routine to generate an `M-by-N` real matrix `Q` with orthonormal columns, which is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`. +* +* @module @stdlib/lapack/base/dorgbr +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dorgbr = require( '@stdlib/lapack/base/dorgbr' ); +* +* var A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); +* var TAU = new Float64Array( [ 2, 2 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorgbr( 'column-major', 3, 2, 2, A, 3, TAU, WORK, 10 ); +* // A => [ -1, 0, 0, 0, -1, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dorgbr; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dorgbr = main; +} else { + dorgbr = tmp; +} + + +// EXPORTS // + +module.exports = dorgbr; + +// exports: { "ndarray": "dorgbr.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/init_unit_columns.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/init_unit_columns.js new file mode 100644 index 000000000000..a7aa37422545 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/init_unit_columns.js @@ -0,0 +1,95 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Initializes columns K+1:N of a matrix to columns of the unit matrix. +* +* @private +* @param {PositiveInteger} M - number of rows in matrix `A` +* @param {PositiveInteger} N - number of columns in matrix `A` +* @param {NonNegativeInteger} K - starting column index for initialization +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset for `A` +* @returns {Float64Array} matrix `A` with columns K+1:N initialized as unit matrix columns +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); +* initUnitColumns( 3, 3, 1, A, 1, 3, 0 ); +* // A => [ 1.0, 2.0, 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ] +*/ +function initUnitColumns( M, N, K, A, strideA1, strideA2, offsetA ) { + var ia1; + var ia2; + var del; + var da; + var i; + var j; + + // Initialize columns k+1:n to columns of the unit matrix + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + ia2 = offsetA + (K*strideA2); + da = strideA1 - ((N-K) * strideA2); + + for ( i = 0; i < M; i++ ) { + for ( j = K; j < N; j++ ) { + if ( i === j ) { + A[ ia2 ] = 1.0; + } else { + A[ ia2 ] = 0.0; + } + ia2 += strideA2; + } + ia2 += da; + } + } else { + ia1 = offsetA + (K*strideA1) + (K*strideA2); + ia2 = offsetA + (K*strideA2); + da = strideA2 - (M * strideA1); + del = strideA1 + strideA2; + + for ( i = K; i < N; i++ ) { + for ( j = 0; j < M; j++ ) { + A[ ia2 ] = 0.0; + ia2 += strideA1; + } + A[ ia1 ] = 1.0; + ia2 += da; + ia1 += del; + } + } + + return A; +} + + +// EXPORTS // + +module.exports = initUnitColumns; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_columns.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_columns.js new file mode 100644 index 000000000000..5a71b0c9aec0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_columns.js @@ -0,0 +1,162 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the left, with backward direction and column storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = leftBackwardColumns( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -557890.0, -592880.0, -627870.0, -596341.0, -632662.0, -668983.0, -7412.0, -7864.0, -8316.0 ] +*/ +function leftBackwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var transt; + var da0; + var da1; + var db0; + var db1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var i; + var j; + var o; + + if ( trans === 'no-transpose' ) { + transt = 'transpose'; + } else { + transt = 'no-transpose'; + } + + /* Let V = ( V1 ) + * ( V2 ) (last K rows) + * Where V2 is unit upper triangular. + */ + + /* Form H * C or H^T * C where C = ( C1 ) + * ( C2 ) + * W := C**T * V = (C1**T * V1 + C2**T * V2) (stored in WORK) + * W := C2**T + */ + ic = offsetC + ( (M-K) * strideC1 ); + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + iw = offsetWork + ( j * strideWork2 ); + dcopy( N, C, strideC2, ic, work, strideWork1, iw ); + ic += strideC1; + iw += strideWork2; + } + // W := W * V2 + iv = offsetV + ( (M-K) * strideV1 ); + dtrmm( 'right', 'upper', 'no-transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + if ( M > K ) { + // W := W + C1**T * V1 + dgemm( 'transpose', 'no-transpose', N, K, M-K, 1.0, C, strideC1, strideC2, offsetC, V, strideV1, strideV2, offsetV, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T**T or W * T + dtrmm( 'right', 'lower', transt, 'non-unit', N, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - V * W**T + if ( M > K ) { + // C1 := C1 - V1 * W**T + dgemm( 'no-transpose', 'transpose', M-K, N, K, -1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork, 1.0, C, strideC1, strideC2, offsetC ); + } + // W := W * V2**T + iv = offsetV + ( (M-K) * strideV1 ); + dtrmm( 'right', 'upper', 'transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + + // C2 := C2 - W**T + o = loopOrder( [ K, N ], [ strideC2, strideC1 ], [ strideWork1, strideWork2 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + ia = offsetC + ( (M-K) * strideC1 ); + ib = offsetWork; + + for ( j = 0; j < S1; j++ ) { + for ( i = 0; i < S0; i++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = leftBackwardColumns; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_rows.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_rows.js new file mode 100644 index 000000000000..89bedab3ecee --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_rows.js @@ -0,0 +1,165 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the left, with backward direction and row storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = leftBackwardRows( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -155530.0, -164560.0, -173590.0, -292241.0, -308662.0, -325083.0, -4832.0, -5104.0, -5376.0 ] +*/ +function leftBackwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var transt; + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + if ( trans === 'no-transpose' ) { + transt = 'transpose'; + } else { + transt = 'no-transpose'; + } + + /* Let V = ( V1 V2 ) (V2: last K columns) + * Where V2 is unit lower triangular. + */ + + /* Form H * C or H^T * C where C = ( C1 ) + * ( C2 ) + * W := C**T * V**T = (C1**T * V1**T + C2**T * V2**T) (stored in WORK) + * W := C2**T + */ + ic = offsetC; + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( N, C, strideC2, ic, work, strideWork1, iw ); + ic += strideC1; + iw += strideWork2; + } + // W := W * V2**T + iv = offsetV + ( (M-K) * strideV2 ); + dtrmm( 'right', 'lower', 'transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + if ( M > K ) { + // W := W + C1**T * V1**T + dgemm( 'transpose', 'transpose', N, K, M-K, 1.0, C, strideC1, strideC2, offsetC, V, strideV1, strideV2, offsetV, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T**T or W * T + dtrmm( 'right', 'lower', transt, 'non-unit', N, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - V**T * W**T + if ( M > K ) { + // C1 := C1 - V1**T * W**T + dgemm( 'transpose', 'transpose', M-K, N, K, -1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork, 1.0, C, strideC1, strideC2, offsetC ); + } + // W := W * V2 + iv = offsetV + ( (M-K) * strideV2 ); + dtrmm( 'right', 'lower', 'no-transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + + // C2 := C2 - W**T + o = loopOrder( [ K, N ], [ strideC1, strideC2 ], [ strideWork2, strideWork1 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC + ( (M-K) * strideC1 ); + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = leftBackwardRows; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_columns.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_columns.js new file mode 100644 index 000000000000..e7b134abf652 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_columns.js @@ -0,0 +1,168 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the left, with forward direction and column storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = leftForwardColumns( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -1350.0, -1400.0, -1450.0, -30961.0, -32102.0, -33243.0, -266612.0, -275464.0, -284316.0 ] +*/ +function leftForwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var transt; + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + if ( trans === 'no-transpose' ) { + transt = 'transpose'; + } else { + transt = 'no-transpose'; + } + + /* Let V = ( V1 ) (first K rows) + * ( V2 ) + * Where V1 is unit lower triangular. + */ + + /* Form H * C or H^T * C where C = ( C1 ) + * ( C2 ) + * W := C**T * V = (C1**T * V1 + C2**T * V2) (stored in WORK) + * W := C1**T + */ + ic = offsetC; + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( N, C, strideC2, ic, work, strideWork1, iw ); + ic += strideC1; + iw += strideWork2; + } + // W := W * V1 + dtrmm( 'right', 'lower', 'no-transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + if ( M > K ) { + // W := W + C2**T * V2 + ic = offsetC + ( K * strideC1 ); // C( k+1, 1 ) - 0 based index + iv = offsetV + ( K * strideV1 ); // V( k+1, 1 ) - 0 based index + dgemm( 'transpose', 'no-transpose', N, K, M-K, 1.0, C, strideC1, strideC2, ic, V, strideV1, strideV2, iv, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T**T or W * T + dtrmm( 'right', 'upper', transt, 'non-unit', N, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - V * W**T + if ( M > K ) { + // C2 := C2 - V2 * W**T + ic = offsetC + ( K * strideC1 ); // C( k+1, 1 ) - 0 based index + iv = offsetV + ( K * strideV1 ); // V( k+1, 1 ) - 0 based index + dgemm( 'no-transpose', 'transpose', M-K, N, K, -1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork, 1.0, C, strideC1, strideC2, ic ); + } + // W := W * V1**T + dtrmm( 'right', 'lower', 'transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + + // C1 := C1 - W**T + o = loopOrder( [ K, N ], [ strideC1, strideC2 ], [ strideWork2, strideWork1 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC; + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = leftForwardColumns; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_rows.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_rows.js new file mode 100644 index 000000000000..d62c3646d67f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_rows.js @@ -0,0 +1,167 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the left, with forward direction and row storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = leftForwardRows( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -3010.0, -3120.0, -3230.0, -125821.0, -130422.0, -135023.0, -611692.0, -632424.0, -653156.0 ] +*/ +function leftForwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var transt; + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + if ( trans === 'no-transpose' ) { + transt = 'transpose'; + } else { + transt = 'no-transpose'; + } + + /* Let V = ( V1 V2 ) (V1: first K columns) + * Where V1 is unit upper triangular. + */ + + /* Form H * C or H^T * C where C = ( C1 ) + * ( C2 ) + * W := C**T * V**T = (C1**T * V1**T + C2**T * V2**T) (stored in work) + * W := C1**T + */ + ic = offsetC; + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( N, C, strideC2, ic, work, strideWork1, iw ); + ic += strideC1; + iw += strideWork2; + } + // W := W * V1**T + dtrmm( 'right', 'upper', 'transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + if ( M > K ) { + // W := W + C2**T * V2**T + ic = offsetC + ( K * strideC1 ); + iv = offsetV + ( K * strideV2 ); + dgemm( 'transpose', 'transpose', N, K, M-K, 1.0, C, strideC1, strideC2, ic, V, strideV1, strideV2, iv, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T**T or W * T + dtrmm( 'right', 'upper', transt, 'non-unit', N, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - V**T * W**T + if ( M > K ) { + // C2 := C2 - V2**T * W**T + ic = offsetC + ( K * strideC1 ); + iv = offsetV + ( K * strideV2 ); + dgemm( 'transpose', 'transpose', M-K, N, K, -1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork, 1.0, C, strideC1, strideC2, ic ); + } + // W := W * V1 + dtrmm( 'right', 'upper', 'no-transpose', 'unit', N, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + + // C1 := C1 - W**T + o = loopOrder( [ K, N ], [ strideC1, strideC2 ], [ strideWork2, strideWork1 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC; + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = leftForwardRows; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/main.js new file mode 100644 index 000000000000..e779a74b7b6d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/main.js @@ -0,0 +1,35 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dorgbr = require( './dorgbr.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dorgbr, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dorgbr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js new file mode 100644 index 000000000000..d32c9b1caf1f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js @@ -0,0 +1,94 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Generates an `M-by-N` real matrix `Q` with orthonormal columns, which is defined as the first `N` columns of a product of `K` elementary reflectors of order `M` using alternative indexing semantics. +* +* ## Notes +* +* - On entry, the i-th column of A must contain the reflector vector for `H(i)`, as returned by DGEQRF. +* - On exit, A contains the M-by-N orthogonal matrix Q. +* - For optimum performance `LWORK >= N*NB`, where `NB` is the optimal blocksize. +* - If `LWORK = -1`, then a workspace query is assumed. +* - The routine only calculates the optimal size of the `WORK` array, returns this value as the first entry of the `WORK` array. +* +* @param {NonNegativeInteger} M - number of rows of `Q` +* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {NonNegativeInteger} K - number of elementary reflectors whose product defines the matrix `Q` +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index of `A` +* @param {Float64Array} TAU - scalar factors of reflectors +* @param {integer} strideTAU - stride length for `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index of `TAU` +* @param {Float64Array} WORK - workspace array +* @param {integer} strideWORK - stride length for `WORK` +* @param {NonNegativeInteger} offsetWORK - starting index of `WORK` +* @param {NonNegativeInteger} LWORK - dimension of the array `WORK` +* @throws {RangeError} first argument must be a non-negative integer +* @throws {RangeError} second argument must be a non-negative integer and smaller than `M` +* @throws {RangeError} third argument must be a non-negative integer and smaller than `N` +* @throws {RangeError} fourteenth argument must be a valid `LWORK` value +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); +* var TAU = new Float64Array( [ 2, 2 ] ); +* var WORK = new Float64Array( 10 ); +* +* var info = dorgbr( 3, 2, 2, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ -1, 0, 0, 0, -1, 0 ] +* // info => 0 +* // WORK[ 0 ] => 2 +*/ +function dorgbr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 || N > M ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer and smaller than `M`. Value: `%d`.', N ) ); + } + if ( K < 0 || K > N ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer and smaller than `N`. Value: `%d`.', K ) ); + } + if ( LWORK < max( 1, N ) && LWORK !== -1 ) { + throw new RangeError( format( 'invalid argument. Fourteenth argument must be greater than or equal to `max(1,N)` except when equal to -1. Value: `%d`.', LWORK ) ); + } + return base( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); +} + + +// EXPORTS // + +module.exports = dorgbr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_columns.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_columns.js new file mode 100644 index 000000000000..20f98fd01d52 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_columns.js @@ -0,0 +1,158 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the right, with backward direction and column storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = rightBackwardColumns( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -402190.0, -419212.0, -5216.0, -752090.0, -782422.0, -9736.0, -1101990.0, -1145632.0, -14256.0 ] +*/ +function rightBackwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + /* Let V = ( V1 ) + * ( V2 ) (last K rows) + * Where V2 is unit upper triangular. + */ + + /* Form C * H or C * H^T where C = ( C1 C2 ) + * W := C * V = (C1*V1 + C2*V2) (stored in WORK) + * W := C2 + */ + ic = offsetC + ( (N-K) * strideC2 ); + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( M, C, strideC1, ic, work, strideWork1, iw ); + ic += strideC2; + iw += strideWork2; + } + // W := W * V2 + iv = offsetV + ( (N-K) * strideV1 ); + dtrmm( 'right', 'upper', 'no-transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + if ( N > K ) { + // W := W + C1 * V1 + dgemm( 'no-transpose', 'no-transpose', M, K, N-K, 1.0, C, strideC1, strideC2, offsetC, V, strideV1, strideV2, offsetV, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T or W * T**T + dtrmm( 'right', 'upper', trans, 'non-unit', M, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - W * V**T + if ( N > K ) { + // C1 := C1 - W * V1**T + dgemm( 'no-transpose', 'transpose', M, N-K, K, -1.0, work, strideWork1, strideWork2, offsetWork, V, strideV1, strideV2, offsetV, 1.0, C, strideC1, strideC2, offsetC ); + } + // W := W * V2**T + iv = offsetV + ( (N-K) * strideV1 ); + dtrmm( 'right', 'upper', 'transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + + // C2 := C2 - W + o = loopOrder( [ K, M ], [ strideC1, strideC2 ], [ strideWork1, strideWork2 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC + ( (N-K) * strideC2 ); + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = rightBackwardColumns; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_rows.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_rows.js new file mode 100644 index 000000000000..e10b8b011af6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_rows.js @@ -0,0 +1,157 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the right, with backward direction and row storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = rightBackwardRows( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -104950.0, -191792.0, -3176.0, -195250.0, -356002.0, -5896.0, -285550.0, -520212.0, -8616.0 ] +*/ +function rightBackwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + /* Let V = ( V1 V2 ) (V2: last K columns) + * Where V2 is unit lower triangular. + */ + + /* Form C * H or C * H^T where C = ( C1 C2 ) + * W := C * V**T = (C1*V1**T + C2*V2**T) (stored in WORK) + * W := C2 + */ + ic = offsetC + ( (N-K) * strideC2 ); + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( M, C, strideC1, ic, work, strideWork1, iw ); + iw += strideWork2; + ic += strideC2; + } + // W := W * V2**T + iv = offsetV + ( (N-K) * strideV2 ); + dtrmm( 'right', 'lower', 'transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + if ( N > K ) { + // W := W + C1 * V1**T + dgemm( 'no-transpose', 'transpose', M, K, N-K, 1.0, C, strideC1, strideC2, offsetC, V, strideV1, strideV2, offsetV, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T or W * T**T + dtrmm( 'right', 'lower', trans, 'non-unit', M, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - W * V + if ( N > K ) { + // C1 := C1 - W * V1 + dgemm( 'no-transpose', 'no-transpose', M, N-K, K, -1.0, work, strideWork1, strideWork2, offsetWork, V, strideV1, strideV2, offsetV, 1.0, C, strideC1, strideC2, offsetC ); + } + // W := W * V2 + iv = offsetV + ( (N-K) * strideV2 ); + dtrmm( 'right', 'lower', 'no-transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, iv, work, strideWork1, strideWork2, offsetWork ); + + // C1 := C1 - W + o = loopOrder( [ K, M ], [ strideC1, strideC2 ], [ strideWork1, strideWork2 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC; + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = rightBackwardRows; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_columns.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_columns.js new file mode 100644 index 000000000000..0c7574a3b7b9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_columns.js @@ -0,0 +1,160 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the right, with forward direction and column storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = rightForwardColumns( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -630.0, -14392.0, -114296.0, -1130.0, -25802.0, -202816.0, -1630.0, -37212.0, -291336.0 ] +*/ +function rightForwardColumns( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + /* Let V = ( V1 ) (first K rows) + * ( V2 ) + * Where V1 is unit lower triangular. + */ + + /* Form C * H or C * H^T where C = ( C1 C2 ) + * W := C * V = (C1*V1 + C2*V2) (stored in WORK) + * W := C1 + */ + ic = offsetC; + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( M, C, strideC1, ic, work, strideWork1, iw ); + ic += strideC2; + iw += strideWork2; + } + // W := W * V1 + dtrmm( 'right', 'lower', 'no-transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + if ( N > K ) { + // W := W + C2 * V2 + ic = offsetC + ( K * strideC2 ); + iv = offsetV + ( K * strideV1 ); + dgemm( 'no-transpose', 'no-transpose', M, K, N-K, 1.0, C, strideC1, strideC2, ic, V, strideV1, strideV2, iv, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T or W * T**T + dtrmm( 'right', 'upper', trans, 'non-unit', M, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - W * V**T + if ( N > K ) { + // C2 := C2 - W * V2**T + ic = offsetC + ( K * strideC2 ); + iv = offsetV + ( K * strideV1 ); + dgemm( 'no-transpose', 'transpose', M, N-K, K, -1.0, work, strideWork1, strideWork2, offsetWork, V, strideV1, strideV2, iv, 1.0, C, strideC1, strideC2, ic ); + } + // W := W * V1**T + dtrmm( 'right', 'lower', 'transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + + // C1 := C1 - W + o = loopOrder( [ K, M ], [ strideC2, strideC1 ], [ strideWork2, strideWork1 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC; + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = rightForwardColumns; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_rows.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_rows.js new file mode 100644 index 000000000000..830e208c4700 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_rows.js @@ -0,0 +1,159 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray; +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' ); +var dtrmm = require( './dtrmm.js' ); + + +// MAIN // + +/** +* Applies a real block reflector H or its transpose H^T to a real M by N matrix C from the right, with forward direction and row storage. +* +* @private +* @param {NonNegativeInteger} M - number of rows of the matrix C +* @param {NonNegativeInteger} N - number of columns of the matrix C +* @param {NonNegativeInteger} K - order of the matrix T +* @param {Float64Array} V - input matrix +* @param {integer} strideV1 - stride of the first dimension of V +* @param {integer} strideV2 - stride of the second dimension of V +* @param {integer} offsetV - index offset for V +* @param {Float64Array} T - input matrix +* @param {integer} strideT1 - stride of the first dimension of T +* @param {integer} strideT2 - stride of the second dimension of T +* @param {integer} offsetT - index offset for T +* @param {Float64Array} C - input matrix +* @param {integer} strideC1 - stride of the first dimension of C +* @param {integer} strideC2 - stride of the second dimension of C +* @param {integer} offsetC - index offset for C +* @param {Float64Array} work - work array +* @param {integer} strideWork1 - stride of the first dimension of work +* @param {integer} strideWork2 - stride of the second dimension of work +* @param {integer} offsetWork - index offset for work +* @param {string} trans - specifies whether to apply H or H^T +* @returns {Float64Array} updated matrix C +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); +* var work = new Float64Array( 9 ); +* +* var result = rightForwardRows( 3, 3, 3, V, 3, 1, 0, T, 3, 1, 0, C, 3, 1, 0, work, 3, 1, 0, 'no-transpose' ); +* // returns [ -1390.0, -58132.0, -266416.0, -2490.0, -104142.0, -473736.0, -3590.0, -150152.0, -681056.0 ] +*/ +function rightForwardRows( M, N, K, V, strideV1, strideV2, offsetV, T, strideT1, strideT2, offsetT, C, strideC1, strideC2, offsetC, work, strideWork1, strideWork2, offsetWork, trans ) { // eslint-disable-line max-params, max-len + var da0; + var da1; + var db0; + var db1; + var i0; + var i1; + var sh; + var sa; + var sb; + var S0; + var S1; + var ia; + var ib; + var ic; + var iv; + var iw; + var j; + var o; + + /* Let V = ( V1 V2 ) (V1: first K columns) + * Where V1 is unit upper triangular. + */ + + /* Form C * H or C * H^T where C = ( C1 C2 ) + * W := C * V**T = (C1*V1**T + C2*V2**T) (stored in WORK) + * W := C1 + */ + ic = offsetC; + iw = offsetWork; + for ( j = 0; j < K; j++ ) { + dcopy( M, C, strideC1, ic, work, strideWork1, iw ); + ic += strideC2; + iw += strideWork2; + } + // W := W * V1**T + dtrmm( 'right', 'upper', 'transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + if ( N > K ) { + // W := W + C2 * V2**T + ic = offsetC + ( K * strideC2 ); + iv = offsetV + ( K * strideV2 ); + dgemm( 'no-transpose', 'transpose', M, K, N-K, 1.0, C, strideC1, strideC2, ic, V, strideV1, strideV2, iv, 1.0, work, strideWork1, strideWork2, offsetWork ); + } + // W := W * T or W * T**T + dtrmm( 'right', 'upper', trans, 'non-unit', M, K, 1.0, T, strideT1, strideT2, offsetT, work, strideWork1, strideWork2, offsetWork ); + + // C := C - W * V + if ( N > K ) { + // C2 := C2 - W * V2 + ic = offsetC + ( K * strideC2 ); + iv = offsetV + ( K * strideV2 ); + dgemm( 'no-transpose', 'no-transpose', M, N-K, K, -1.0, work, strideWork1, strideWork2, offsetWork, V, strideV1, strideV2, iv, 1.0, C, strideC1, strideC2, ic ); + } + // W := W * V1 + dtrmm( 'right', 'upper', 'no-transpose', 'unit', M, K, 1.0, V, strideV1, strideV2, offsetV, work, strideWork1, strideWork2, offsetWork ); + + // C1 := C1 - W + o = loopOrder( [ K, M ], [ strideC1, strideC2 ], [ strideWork1, strideWork2 ] ); // eslint-disable-line max-len + sh = o.sh; + sa = o.sx; + sb = o.sy; + + // Extract loop variables for loop interchange + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + da0 = sa[ 0 ]; + da1 = sa[ 1 ] - ( S0 * sa[ 0 ] ); + db0 = sb[ 0 ]; + db1 = sb[ 1 ] - ( S0 * sb[ 0 ] ); + + // Set pointers to first indexed elements + ia = offsetC; + ib = offsetWork; + + // Iterate over matrix dimensions with optimized loop order + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + C[ ia ] -= work[ ib ]; + ia += da0; + ib += db0; + } + ia += da1; + ib += db1; + } + + return C; +} + + +// EXPORTS // + +module.exports = rightForwardRows; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json new file mode 100644 index 000000000000..27afec0ff8b4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dorgbr", + "version": "0.0.0", + "description": "LAPACK routine to generate an `M-by-N` real orthogonal matrix `Q` from the elementary reflectors returned by `DGELQF`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "lapack", + "dorgbr", + "reflector", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "matrix", + "float64", + "double", + "float64array" + ] +}