From 88ebc2451b8bf3a0b56496861b71859709cd8080 Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Mon, 10 Aug 2026 23:21:48 +0530 Subject: [PATCH 1/2] feat: add `lapack/base/dorgbr` --- .../@stdlib/lapack/base/dorgbr/lib/base.js | 171 ++++++ .../@stdlib/lapack/base/dorgbr/lib/dlarf1f.js | 184 ++++++ .../@stdlib/lapack/base/dorgbr/lib/dlarfb.js | 118 ++++ .../@stdlib/lapack/base/dorgbr/lib/dlarft.js | 571 ++++++++++++++++++ .../@stdlib/lapack/base/dorgbr/lib/dorg2r.js | 113 ++++ .../@stdlib/lapack/base/dorgbr/lib/dorgbr.js | 107 ++++ .../@stdlib/lapack/base/dorgbr/lib/dorgl2.js | 143 +++++ .../@stdlib/lapack/base/dorgbr/lib/dorglq.js | 176 ++++++ .../@stdlib/lapack/base/dorgbr/lib/dorgqr.js | 176 ++++++ .../@stdlib/lapack/base/dorgbr/lib/dtrmm.js | 362 +++++++++++ .../@stdlib/lapack/base/dorgbr/lib/index.js | 63 ++ .../base/dorgbr/lib/init_unit_columns.js | 95 +++ .../base/dorgbr/lib/left_backward_columns.js | 162 +++++ .../base/dorgbr/lib/left_backward_rows.js | 165 +++++ .../base/dorgbr/lib/left_forward_columns.js | 168 ++++++ .../base/dorgbr/lib/left_forward_rows.js | 167 +++++ .../@stdlib/lapack/base/dorgbr/lib/main.js | 35 ++ .../@stdlib/lapack/base/dorgbr/lib/ndarray.js | 94 +++ .../base/dorgbr/lib/right_backward_columns.js | 158 +++++ .../base/dorgbr/lib/right_backward_rows.js | 157 +++++ .../base/dorgbr/lib/right_forward_columns.js | 160 +++++ .../base/dorgbr/lib/right_forward_rows.js | 159 +++++ .../@stdlib/lapack/base/dorgbr/package.json | 69 +++ 23 files changed, 3773 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarf1f.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarfb.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dlarft.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorg2r.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgl2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorglq.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgqr.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dtrmm.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/init_unit_columns.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_columns.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_backward_rows.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_columns.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/left_forward_rows.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_columns.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_backward_rows.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_columns.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/lib/right_forward_rows.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/package.json 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" + ] +} From dba5837b219c2e729258336e67d4556493be2329 Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Fri, 14 Aug 2026 22:30:30 +0530 Subject: [PATCH 2/2] chore: add tests, bencmarks and docs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/lapack/base/dorgbr/README.md | 318 ++++++++++ .../lapack/base/dorgbr/benchmark/benchmark.js | 126 ++++ .../dorgbr/benchmark/benchmark.ndarray.js | 140 +++++ .../@stdlib/lapack/base/dorgbr/docs/repl.txt | 168 ++++++ .../lapack/base/dorgbr/docs/types/index.d.ts | 154 +++++ .../lapack/base/dorgbr/docs/types/test.ts | 330 ++++++++++ .../lapack/base/dorgbr/examples/index.js | 69 +++ .../@stdlib/lapack/base/dorgbr/lib/base.js | 167 +++--- .../@stdlib/lapack/base/dorgbr/lib/dorgbr.js | 82 ++- .../@stdlib/lapack/base/dorgbr/lib/index.js | 12 +- .../@stdlib/lapack/base/dorgbr/lib/ndarray.js | 85 ++- .../@stdlib/lapack/base/dorgbr/package.json | 2 +- .../test/fixtures/p_k_ge_n_col_maj.json | 123 ++++ .../test/fixtures/p_k_lt_n_col_maj.json | 69 +++ .../test/fixtures/q_m_ge_k_col_maj.json | 104 ++++ .../test/fixtures/q_m_lt_k_col_maj.json | 88 +++ .../lapack/base/dorgbr/test/test.dorgbr.js | 566 ++++++++++++++++++ .../@stdlib/lapack/base/dorgbr/test/test.js | 82 +++ 18 files changed, 2540 insertions(+), 145 deletions(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/README.md create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_ge_n_col_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_lt_n_col_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_ge_k_col_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_lt_k_col_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.dorgbr.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.js diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/README.md b/lib/node_modules/@stdlib/lapack/base/dorgbr/README.md new file mode 100644 index 000000000000..22288aeec958 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/README.md @@ -0,0 +1,318 @@ + + +# dorgbr + +> Generate one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form. + +
+ +The `dorgbr` routine generates one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`. `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. + + + +```math +A = Q B P^{T} +``` + + + +If `vect = 'Q'`, `A` is assumed to have been an `M-by-K` matrix, and `Q` is of order `M`: + + + +```math +Q = H(1) H(2) \ldots H(k) +``` + + + +If `vect = 'P'`, `A` is assumed to have been a `K-by-N` matrix, and `P^T` is of order `N`: + + + +```math +P^{T} = G(k) \ldots G(2) G(1) +``` + + + +
+ + + +
+ +## Usage + +```javascript +var dorgbr = require( '@stdlib/lapack/base/dorgbr' ); +``` + +#### dorgbr( order, vect, M, N, K, A, LDA, TAU, WORK, LWORK ) + +Generates one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +var WORK = new Float64Array( 10 ); + +dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); +// A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +// WORK[ 0 ] => 96.0 +``` + +The function has the following parameters: + +- **order**: storage layout. Must be `'row-major'` or `'column-major'`. +- **vect**: specifies whether the matrix `Q` or the matrix `P^T` is returned in `A`. Must be `'Q'` or `'P'`. +- **M**: number of rows of `Q` or `P^T`. +- **N**: number of columns of `Q` or `P^T`. If `vect` is `'Q'`, must be greater than or equal to `min(M,K)` and smaller than or equal to `M`. If `vect` is `'P'`, must be greater than or equal to `M`, and `M` must be greater than or equal to `min(N,K)`. +- **K**: if `vect` is `'Q'`, the number of columns in the original `M-by-K` matrix reduced by `dgebrd`; if `vect` is `'P'`, the number of rows in the original `K-by-N` matrix reduced by `dgebrd`. +- **A**: input/output matrix of size `M×N` stored in linear memory as a [`Float64Array`][@stdlib/array/float64]. On entry, `A` contains the vectors which define the elementary reflectors, as returned by `dgebrd`. On exit, `A` is overwritten by the `M-by-N` matrix `Q` or `P^T`. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). Must be at least `max(1,M)` when `order` is `'column-major'` and at least `max(1,N)` when `order` is `'row-major'`. +- **TAU**: scalar factors of the elementary reflectors as a [`Float64Array`][@stdlib/array/float64]. Must have length `min(M,K)` if `vect` is `'Q'` and length `min(N,K)` if `vect` is `'P'`. +- **WORK**: workspace array as a [`Float64Array`][@stdlib/array/float64]. +- **LWORK**: dimension of the array `WORK`. Must be at least `max(1,min(M,N))`, unless equal to `-1`, in which case a workspace query is performed and the optimal size of `WORK` is returned in `WORK[0]`. + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var A0 = new Float64Array( [ 0.0, 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +var TAU0 = new Float64Array( [ 0.0, 1.3, 0.9, 1.1 ] ); +var WORK0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views... +var A = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var TAU = new Float64Array( TAU0.buffer, TAU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var WORK = new Float64Array( WORK0.buffer, WORK0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); +// A0 => [ 0.0, -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +// WORK0[ 1 ] => 96.0 +``` + + + +#### dorgbr.ndarray( vect, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) + +Generates one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +var WORK = new Float64Array( 10 ); + +dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +// A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +// WORK[ 0 ] => 96.0 +``` + +The function has the following additional parameters: + +- **strideA1**: stride length for the first dimension of `A`. +- **strideA2**: stride length for the second dimension of `A`. +- **offsetA**: starting index for `A`. +- **strideTAU**: stride length for `TAU`. +- **offsetTAU**: starting index for `TAU`. +- **strideWORK**: stride length for `WORK`. +- **offsetWORK**: starting index for `WORK`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 0.0, 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +var TAU = new Float64Array( [ 0.0, 1.3, 0.9, 1.1 ] ); +var WORK = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 1, TAU, 1, 1, WORK, 1, 1, 10 ); +// A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +// WORK[ 1 ] => 96.0 +``` + +
+ + + +
+ +## Notes + +- Both functions mutate the input arrays `A` and `WORK`. + +- Both functions return a status code indicating success (`0`) or failure. + +- `dorgbr()` corresponds to the [LAPACK][LAPACK] routine [`dorgbr`][lapack-dorgbr]. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var dorgbr = require( '@stdlib/lapack/base/dorgbr' ); + +// Define matrix dimensions: +var M = 4; +var N = 3; +var K = 3; +var shape = [ M, N ]; +var order = 'column-major'; +var strides = shape2strides( shape, order ); + +// Create the matrix A containing the elementary reflector vectors returned by dgebrd: +var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +// Define the scalar factors and workspace array: +var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +var WORK = new Float64Array( 10 ); + +// Generate the orthogonal matrix Q: +var info = dorgbr( order, 'Q', M, N, K, A, strides[ 1 ], TAU, WORK, WORK.length ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); +console.log( info ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.js new file mode 100644 index 000000000000..dfda928f9b34 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.js @@ -0,0 +1,126 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dorgbr = require( './../lib/dorgbr.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; +var VECTORS = [ + 'Q', + 'P' +]; +var opts = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {string} vect - specifies whether to generate the matrix `Q` or the matrix `P^T` +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, vect, N ) { + var WORK = new Float64Array( N * 32 ); + var TAU = discreteUniform( N, 0.0, 10.0, opts ); + var A = discreteUniform( N*N, 0.0, 10.0, opts ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var z; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dorgbr( order, vect, N, N, N, A, N, TAU, WORK, WORK.length ); + if ( z < 0 ) { + b.fail( 'should return a success status code' ); + } + } + b.toc(); + if ( z < 0 ) { + b.fail( 'should return a success status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var vect; + var min; + var max; + var ord; + var N; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < LAYOUTS.length; j++ ) { + ord = LAYOUTS[ j ]; + for ( k = 0; k < VECTORS.length; k++ ) { + vect = VECTORS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/3.0 ) ); + f = createBenchmark( ord, vect, N ); + bench( format( '%s::square_matrix:order=%s,vect=%s,size=%d', pkg, ord, vect, N*N ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..2b860df48e5a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/benchmark/benchmark.ndarray.js @@ -0,0 +1,140 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dorgbr = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; +var VECTORS = [ + 'Q', + 'P' +]; +var opts = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {string} vect - specifies whether to generate the matrix `Q` or the matrix `P^T` +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, vect, N ) { + var WORK; + var sa1; + var sa2; + var TAU; + var A; + + WORK = new Float64Array( N * 32 ); + TAU = discreteUniform( N, 0.0, 10.0, opts ); + A = discreteUniform( N*N, 0.0, 10.0, opts ); + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = N; + } else { // order === 'row-major' + sa1 = N; + sa2 = 1; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var z; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dorgbr( vect, N, N, N, A, sa1, sa2, 0, TAU, 1, 0, WORK, 1, 0, WORK.length ); // eslint-disable-line max-len + if ( z < 0 ) { + b.fail( 'should return a success status code' ); + } + } + b.toc(); + if ( z < 0 ) { + b.fail( 'should return a success status code' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var vect; + var min; + var max; + var ord; + var N; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < LAYOUTS.length; j++ ) { + ord = LAYOUTS[ j ]; + for ( k = 0; k < VECTORS.length; k++ ) { + vect = VECTORS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/23.0 ) ); + f = createBenchmark( ord, vect, N ); + bench( format( '%s::square_matrix:ndarray:order=%s,vect=%s,size=%d', pkg, ord, vect, N*N ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/repl.txt new file mode 100644 index 000000000000..ce66a3303519 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/repl.txt @@ -0,0 +1,168 @@ +{{alias}}( order, vect, M, N, K, A, LDA, TAU, WORK, LWORK ) + Generates one of the real orthogonal matrices `Q` or `P**T` determined + by `DGEBRD` when reducing a real matrix `A` to bidiagonal form: + `A = Q * B * P**T`. + + `Q` and `P**T` are defined as products of elementary reflectors `H(i)` + or `G(i)` respectively. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + The function mutates `A` and `WORK`. + + Parameters + ---------- + order: string + Storage layout. Must be either 'row-major' or 'column-major'. + + vect: string + Specifies whether the matrix `Q` or the matrix `P**T` is returned in + `A`. Must be either 'Q' or 'P'. + + M: integer + Number of rows of `Q` or `P**T`. + + N: integer + Number of columns of `Q` or `P**T`. + + If `vect` is 'Q', `N` must be greater than or equal to `min(M,K)` and + smaller than or equal to `M`. If `vect` is 'P', `N` must be greater + than or equal to `M`, and `M` must be greater than or equal to + `min(N,K)`. + + K: integer + If `vect` is 'Q', the number of columns in the original `M-by-K` + matrix reduced by `DGEBRD`. If `vect` is 'P', the number of rows in + the original `K-by-N` matrix reduced by `DGEBRD`. + + A: Float64Array + Input/output matrix. On entry, `A` contains the vectors which define + the elementary reflectors, as returned by `DGEBRD`. On exit, `A` is + overwritten by the `M-by-N` matrix `Q` or `P**T`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). Must be at least `max(1,M)` when `order` is + `'column-major'` and at least `max(1,N)` when `order` is `'row-major'`. + + TAU: Float64Array + Scalar factors of the elementary reflectors. Must have length + `min(M,K)` if `vect` is 'Q' and length `min(N,K)` if `vect` is 'P'. + + WORK: Float64Array + Workspace array. + + LWORK: integer + Dimension of the array `WORK`. Must be at least `max(1,min(M,N))`, + unless equal to `-1`, in which case a workspace query is performed and + the optimal size of `WORK` is returned in `WORK[0]`. + + Returns + ------- + info: integer + Status code. A status code of `0` indicates success. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}([ 1,0,0,-1,-2,0 ]); + > var TAU = new {{alias:@stdlib/array/float64}}( [ 1, 1 ] ); + > var WORK = new {{alias:@stdlib/array/float64}}( 10 ); + > {{alias}}( 'column-major', 'P', 2, 3, 2, A, 2, TAU, WORK, 10 ) + 0 + > A + [ 0, 0, 0, 0, 2, 0 ] + > WORK[ 0 ] + 64 + + +{{alias}}.ndarray(vect,M,N,K,A,sA1,sA2,oA,TAU,sTAU,oTAU, WORK,sWORK,oWORK,LWORK) + Generates one of the real orthogonal matrices `Q` or `P**T` determined + by `DGEBRD` when reducing a real matrix `A` to bidiagonal form using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + The function mutates `A` and `WORK`. + + Parameters + ---------- + vect: string + Specifies whether the matrix `Q` or the matrix `P**T` is returned in + `A`. Must be either 'Q' or 'P'. + + M: integer + Number of rows of `Q` or `P**T`. + + N: integer + Number of columns of `Q` or `P**T`. + + If `vect` is 'Q', `N` must be greater than or equal to `min(M,K)` and + smaller than or equal to `M`. If `vect` is 'P', `N` must be greater + than or equal to `M`, and `M` must be greater than or equal to + `min(N,K)`. + + K: integer + If `vect` is 'Q', the number of columns in the original `M-by-K` + matrix reduced by `DGEBRD`. If `vect` is 'P', the number of rows in + the original `K-by-N` matrix reduced by `DGEBRD`. + + A: Float64Array + Input/output matrix. On entry, `A` contains the vectors which define + the elementary reflectors, as returned by `DGEBRD`. On exit, `A` is + overwritten by the `M-by-N` matrix `Q` or `P**T`. + + sA1: integer + Stride length for the first dimension of `A`. + + sA2: integer + Stride length for the second dimension of `A`. + + oA: integer + Starting index for `A`. + + TAU: Float64Array + Scalar factors of the elementary reflectors. Must have length + `min(M,K)` if `vect` is 'Q' and length `min(N,K)` if `vect` is 'P'. + + sTAU: integer + Stride length for `TAU`. + + oTAU: integer + Starting index for `TAU`. + + WORK: Float64Array + Workspace array. + + sWORK: integer + Stride length for `WORK`. + + oWORK: integer + Starting index for `WORK`. + + LWORK: integer + Dimension of the array `WORK`. Must be at least `max(1,min(M,N))`, + unless equal to `-1`, in which case a workspace query is performed and + the optimal size of `WORK` is returned in `WORK[0]`. + + Returns + ------- + info: integer + Status code. A status code of `0` indicates success. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float64}}([ 1,0,0,-1,-2,0 ]); + > var TAU = new {{alias:@stdlib/array/float64}}( [ 1, 1 ] ); + > var WORK = new {{alias:@stdlib/array/float64}}( 10 ); + > {{alias}}.ndarray( `P`, 2, 3, 2, A, 1, 2, 0, TAU, 1, 0, WORK, 1, 0, 10 ) + 0 + > A + [ 0, 0, 0, 0, 2, 0 ] + > WORK[ 0 ] + 64 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/index.d.ts new file mode 100644 index 000000000000..5f35dde2ec96 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/index.d.ts @@ -0,0 +1,154 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Layout } from '@stdlib/types/blas'; + +/** +* Interface describing `dorgbr`. +*/ +interface Routine { + /** + * Generates one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`. + * + * ## Notes + * + * - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. + * - On exit, `A` is overwritten by the `M-by-N` matrix `Q` or `P^T`. + * - `WORK` must have length, `LWORK >= max(1,min(M,N))`. For optimum performance `LWORK >= min(M,N)*NB`, where `NB` is the optimal blocksize. + * - If `LWORK = -1`, then a workspace query is assumed. + * + * @param order - storage layout + * @param vect - specifies whether the matrix `Q` or the matrix `P^T` is returned in `A` + * @param M - number of rows of `Q` or `P^T` + * @param N - number of columns of `Q` or `P^T` + * @param K - number of elementary reflectors + * @param A - input/output matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param TAU - scalar factors of the elementary reflectors + * @param WORK - workspace array + * @param LWORK - dimension of the array `WORK` + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + * var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + * var WORK = new Float64Array( 10 ); + * + * dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); + * // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] + * // WORK[ 0 ] => 96.0 + */ + ( order: Layout, vect: 'Q' | 'P', M: number, N: number, K: number, A: Float64Array, LDA: number, TAU: Float64Array, WORK: Float64Array, LWORK: number ): number; + + /** + * Generates one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form using alternative indexing semantics. + * + * ## Notes + * + * - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. + * - On exit, `A` is overwritten by the `M-by-N` matrix `Q` or `P^T`. + * - `WORK` must have length, `LWORK >= max(1,min(M,N))`. For optimum performance `LWORK >= min(M,N)*NB`, where `NB` is the optimal blocksize. + * - If `LWORK = -1`, then a workspace query is assumed. + * + * @param vect - specifies whether the matrix `Q` or the matrix `P^T` is returned in `A` + * @param M - number of rows of `Q` or `P^T` + * @param N - number of columns of `Q` or `P^T` + * @param K - number of elementary reflectors + * @param A - input/output matrix + * @param strideA1 - stride length for the first dimension of `A` + * @param strideA2 - stride length for the second dimension of `A` + * @param offsetA - starting index of `A` + * @param TAU - scalar factors of the elementary reflectors + * @param strideTAU - stride length for `TAU` + * @param offsetTAU - starting index of `TAU` + * @param WORK - workspace array + * @param strideWORK - stride length for `WORK` + * @param offsetWORK - starting index of `WORK` + * @param LWORK - dimension of the array `WORK` + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + * var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + * var WORK = new Float64Array( 10 ); + * + * dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); + * // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] + * // WORK[ 0 ] => 96.0 + */ + ndarray( vect: 'Q' | 'P', M: number, N: number, K: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number, TAU: Float64Array, strideTAU: number, offsetTAU: number, WORK: Float64Array, strideWORK: number, offsetWORK: number, LWORK: number ): number; +} + +/** +* LAPACK routine to generate one of the real orthogonal matrices `Q` or `P^T` determined by `dgebrd` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`. +* +* ## Notes +* +* - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. +* - On exit, `A` is overwritten by the `M-by-N` matrix `Q` or `P^T`. +* - `WORK` must have length, `LWORK >= max(1,min(M,N))`. For optimum performance `LWORK >= min(M,N)*NB`, where `NB` is the optimal blocksize. +* - If `LWORK = -1`, then a workspace query is assumed. +* +* @param order - storage layout +* @param vect - specifies whether the matrix `Q` or the matrix `P^T` is returned in `A` +* @param M - number of rows of `Q` or `P^T` +* @param N - number of columns of `Q` or `P^T` +* @param K - number of elementary reflectors +* @param A - input/output matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param TAU - scalar factors of the elementary reflectors +* @param WORK - workspace array +* @param LWORK - dimension of the array `WORK` +* @returns status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +* var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +* var WORK = new Float64Array( 10 ); +* +* dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); +* // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +* // WORK[ 0 ] => 96.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +* var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +* var WORK = new Float64Array( 10 ); +* +* dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] +* // WORK[ 0 ] => 96.0 +*/ +declare var dorgbr: Routine; + + +// EXPORTS // + +export = dorgbr; diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/test.ts new file mode 100644 index 000000000000..c0568be930c3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/docs/types/test.ts @@ -0,0 +1,330 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +import dorgbr = require( './index' ); + +// TESTS // + +// The function returns a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectType number + dorgbr( 'column-major', 'P', 4, 4, 5, A, 4, TAU, WORK, 10 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'foo', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 5, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( true, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( false, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( null, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( undefined, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( [], 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( {}, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( ( x: number ): number => x, 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is neither 'Q' nor 'P'... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'foo', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'q', 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 5, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', true, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', false, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', null, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', undefined, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', [], 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', {}, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', ( x: number ): number => x, 4, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', '5', 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', true, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', false, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', null, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', undefined, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', [], 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', {}, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', ( x: number ): number => x, 3, 3, A, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, '5', 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, true, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, false, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, null, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, undefined, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, [], 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, {}, 3, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, ( x: number ): number => x, 3, A, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, '5', A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, true, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, false, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, null, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, undefined, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, [], A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, {}, A, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, ( x: number ): number => x, A, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, '5', 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, 5, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, true, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, false, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, null, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, undefined, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, [], 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, {}, 4, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, ( x: number ): number => x, 4, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, A, '5', TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, true, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, false, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, null, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, undefined, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, [], TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, {}, TAU, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, ( x: number ): number => x, TAU, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, '5', WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, 5, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, true, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, false, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, null, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, undefined, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, [], WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, {}, WORK, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, ( x: number ): number => x, WORK, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, '5', 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, 5, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, true, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, false, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, null, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, undefined, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, [], 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, {}, 10 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, ( x: number ): number => x, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, '5' ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, true ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, false ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, null ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, undefined ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, [] ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, {} ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr(); // $ExpectError + dorgbr( 'column-major' ); // $ExpectError + dorgbr( 'column-major', 'Q' ); // $ExpectError + dorgbr( 'column-major', 'Q', 4 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4 ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK ); // $ExpectError + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectType number + dorgbr.ndarray( 'P', 4, 4, 5, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is neither 'Q' nor 'P'... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray( 'foo', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 5, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( true, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( false, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( null, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( undefined, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( [], 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( {}, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( ( x: number ): number => x, 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray( 'Q', '5', 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', true, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', false, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', null, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', undefined, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', [], 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', {}, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', ( x: number ): number => x, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Float64Array... +{ + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray( 'Q', 4, 3, 3, '5', 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, 5, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, true, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, false, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, null, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, undefined, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, [], 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, {}, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, ( x: number ): number => x, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, '5', 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, 5, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, true, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, false, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, null, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, undefined, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, [], 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, {}, 1, 0, WORK, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, ( x: number ): number => x, 1, 0, WORK, 1, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a Float64Array... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, '5', 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, 5, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, true, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, false, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, null, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, undefined, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, [], 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, {}, 1, 0, 10 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, ( x: number ): number => x, 1, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); + const TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + const WORK = new Float64Array( 10 ); + + dorgbr.ndarray(); // $ExpectError + dorgbr.ndarray( 'Q' ); // $ExpectError + dorgbr.ndarray( 'Q', 4 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dorgbr.ndarray( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/examples/index.js new file mode 100644 index 000000000000..7395c45ab154 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/examples/index.js @@ -0,0 +1,69 @@ +/** +* @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'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var dorgbr = require( './../lib' ); + +// Generate the orthogonal matrix `Q` determined by `dgebrd` when reducing a real `M-by-K` matrix, where `m >= k`: + +// Define matrix dimensions: +var M = 4; +var N = 3; +var K = 3; +var shape = [ M, N ]; +var order = 'column-major'; +var strides = shape2strides( shape, order ); + +// Create the matrix `A` containing the elementary reflector vectors returned by `dgebrd`: +var A = new Float64Array( [ 1.0, 0.2, -0.1, 0.3, 0.0, 1.0, 0.4, -0.2, 0.0, 0.0, 1.0, 0.5 ] ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +// Define the scalar factors and workspace array: +var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); +var WORK = new Float64Array( 10 ); + +// Generate the orthogonal matrix `Q`: +var info = dorgbr( order, 'Q', M, N, K, A, strides[ 1 ], TAU, WORK, WORK.length ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); +console.log( info ); + +// Generate the matrix `P^T` determined by `dgebrd` when reducing a real `K-by-N` matrix, where `k >= n`: + +// Define matrix dimensions: +M = 4; +N = 4; +K = 5; +shape = [ M, N ]; +strides = shape2strides( shape, order ); + +// Create the matrix `A` containing the elementary reflector vectors returned by `dgebrd`: +A = new Float64Array( [ 1.0, 0.5, 0.8, 1.1, 0.2, 2.0, 0.9, 1.2, 0.3, 0.6, 3.0, 1.3, 0.4, 0.7, 1.0, 4.0 ] ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +// Define the scalar factors and workspace array: +TAU = new Float64Array( [ 1.5, 0.9, 1.3, 0.0 ] ); +WORK = new Float64Array( 10 ); + +// Generate the matrix `P^T`: +info = dorgbr( order, 'P', M, N, K, A, strides[ 1 ], TAU, WORK, WORK.length ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); +console.log( info ); diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js index d96c696575f8..0436d8d35d33 100644 --- a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/base.js @@ -32,19 +32,38 @@ 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. +* 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`. * +* ## Notes +* +* - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. +* +* - If `vect = 'Q'`, +* +* - A is assumed to have been an M-by-K matrix, and Q is of order M. +* - if m >= k, Q = H(1) H(2) . . . H(k) and DORGBR returns the first n columns of Q, where m >= n >= k; +* - if m < k, Q = H(1) H(2) . . . H(m-1) and DORGBR returns Q as an M-by-M matrix. +* +* - If `vect = 'P'`, +* +* - A is assumed to have been a K-by-N matrix, and P**T is of order N +* - if k < n, P**T = G(k) . . . G(2) G(1) and DORGBR returns the first m rows of P**T, where n >= m >= k +* - if k >= n, P**T = G(n-1) . . . G(2) G(1) and DORGBR returns P**T as an N-by-N matrix. +* +* - LWORK >= max(1,min(M,N)). For optimum performance LWORK >= min(M,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 {string} vect - specifies whether the matrix Q or the matrix P**T is returned in `A` +* @param {NonNegativeInteger} M - number of rows of `Q` or `P^T` +* @param {NonNegativeInteger} N - number of columns of `Q` or `P^T` * @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 {Float64Array} TAU - scalar factors of elementary reflectors * @param {integer} strideTAU - stride length of `TAU` * @param {NonNegativeInteger} offsetTAU - starting index for `TAU` * @param {Float64Array} WORK - workspace array @@ -60,108 +79,96 @@ var dorgqr = require( './dorgqr.js' ); * 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 ); +* var info = dorgbr( `P`, 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 +* // WORK[ 0 ] => 96 */ -function dorgbr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { - var ldwork; +function dorgbr( vect, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { var lquery; var lwkopt; - var nbmin; - var iws; - var nb; - var nx; - var kk; - var ki; - var ib; + var wantq; + var mn; 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; + wantq = ( vect === 'Q' ); + mn = min( M, N ); lquery = ( LWORK === -1 ); + WORK[ offsetWORK ] = 1; + if ( wantq ) { + if ( M >= K ) { + dorgqr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, -1 ); + } else if ( M > 1 ) { + dorgqr( M - 1, M - 1, M - 1, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, -1 ); + } + } else if ( K < N ) { + dorglq( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, -1 ); + } else if ( N > 1 ) { + dorglq( N - 1, N - 1, N - 1, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, -1 ); + } + + lwkopt = floor( WORK[ offsetWORK ] ); + lwkopt = max( lwkopt, mn ); + if ( lquery ) { + WORK[ offsetWORK ] = lwkopt; return 0; } - - // Quick return if possible - if ( M === 0 ) { + if ( M === 0 || N === 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 ( wantq ) { + // Form Q, determined by a call to DGEBRD to reduce an `M-by-K` matrix... - 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 ); + if ( M >= K ) { + // If M >= K, assume M >= N >= K: + dorgqr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); + } else { + // If M < K, assume M = N; Shift the vectors which define the elementary reflectors one column to the right, and set the first row and column of Q to those of the unit matrix... + for ( j = M - 1; j >= 1; j-- ) { + A[ offsetA + ( j * strideA2 ) ] = 0.0; - // 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; + for ( i = j + 1; i < M; i++ ) { + A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] = A[ offsetA + ( i * strideA1 ) + ( ( j - 1 ) * strideA2 ) ]; + } + } + A[ offsetA ] = 1.0; + for ( i = 1; i < M; i++ ) { + A[ offsetA + ( i * strideA1 ) ] = 0.0; + } + if ( M > 1 ) { + // Form Q(2:m,2:m): + dorgqr( M - 1, M - 1, M - 1, A, strideA1, strideA2, offsetA + strideA1 + strideA2, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); } } + } else if ( K < N ) { + // If k < n, assume k <= m <= n: + dorglq( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); } 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 ) ); + // If k >= n, assume m = n; Shift the vectors which define the elementary reflectors one row downward, and set the first row and column of P**T to those of the unit matrix... + A[ offsetA ] = 1.0; + for ( i = 1; i < N; i++ ) { + A[ offsetA + ( i * strideA1 ) ] = 0.0; + } + for ( j = 1; j < N; j++ ) { + for ( i = j - 1; i >= 1; i-- ) { + A[ offsetA + ( i * strideA1 ) + ( j * strideA2 ) ] = A[ offsetA + ( ( i - 1 ) * strideA1 ) + ( j * strideA2 ) ]; } + // A(0, j) = 0 + A[ offsetA + ( j * strideA2 ) ] = 0.0; + } - // 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; - } - } + if ( N > 1 ) { + // Form P**T(2:n,2:n) + dorglq( N - 1, N - 1, N - 1, A, strideA1, strideA2, offsetA + strideA1 + strideA2, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); } } + WORK[ offsetWORK ] = lwkopt; - WORK[ offsetWORK ] = iws; return 0; } diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js index bffe3b1ca2be..3ac51945fb44 100644 --- a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/dorgbr.js @@ -23,82 +23,108 @@ 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 min = require( '@stdlib/math/base/special/min' ); var base = require( './base.js' ); // MAIN // /** -* Generates an `M-by-N` real orthogonal matrix `Q` from the elementary reflectors returned by `DGELQF`. +* Generates one of the real orthogonal matrices `Q` or `P^T` determined by `DGEBRD` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`. * * ## 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`. +* - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. +* +* - If `vect = 'Q'`, +* +* - `A` is assumed to have been an `M-by-K` matrix, and `Q` is of order `M`. +* - if `m >= k`, `Q = H(1) H(2) . . . H(k)` and `dorgbr` returns the first `n` columns of `Q`, where `m >= n >= k`. +* - if `m < k`, `Q = H(1) H(2) . . . H(m-1)` and `dorgbr` returns `Q` as an `M-by-M` matrix. +* +* - If `vect = 'P'`, +* +* - `A` is assumed to have been a `K-by-N` matrix, and `P^T` is of order `N`. +* - if `k < n`, `P^T = G(k) . . . G(2) G(1)` and `dorgbr` returns the first `m` rows of `P^T`, where `n >= m >= k`. +* - if `k >= n`, `P^T = G(n-1) . . . G(2) G(1)` and `dorgbr` returns `P^T` as an `N-by-N` matrix. +* +* - `WORK` must have length, `LWORK >= max(1,min(M,N))`. For optimum performance `LWORK >= min(M,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, and no error message related to `LWORK` is issued. * * @param {string} order - storage layout -* @param {NonNegativeInteger} M - number of rows of `Q` -* @param {NonNegativeInteger} N - number of columns of `Q` +* @param {string} vect - specifies whether the matrix `Q` or the matrix `P^T` is returned in `A` +* @param {NonNegativeInteger} M - number of rows of `Q` or `P^T` +* @param {NonNegativeInteger} N - number of columns of `Q` or `P^T` * @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} TAU - scalar factors of elementary 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 +* @throws {TypeError} second argument must be either `'Q'` or `'P'` +* @throws {RangeError} third argument must be a non-negative integer +* @throws {RangeError} fourth argument must be a non-negative integer satisfying the constraints for the given `vect` argument +* @throws {RangeError} fifth argument must be a non-negative integer +* @throws {RangeError} seventh argument must be a valid `LDA` value +* @throws {RangeError} tenth 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 A = new Float64Array( [ 1, 0.2, -0.1, 0.3, 0, 1, 0.4, -0.2, 0, 0, 1, 0.5 ] ); +* var TAU = new Float64Array( [ 1.3, 0.9, 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 ] +* var info = dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); +* // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] * // info => 0 -* // WORK[ 0 ] => 2 +* // WORK[ 0 ] => 64 */ -function dorgbr( order, M, N, K, A, LDA, TAU, WORK, LWORK ) { +function dorgbr( order, vect, M, N, K, A, LDA, TAU, WORK, LWORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + var wantq; var sa1; var sa2; if ( !isLayout( order ) ) { throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); } + if ( vect !== 'Q' && vect !== 'P' ) { + throw new TypeError( format( 'invalid argument. Second argument must be either `\'Q\'` or `\'P\'`. Value: `%s`.', vect ) ); + } + wantq = ( vect === 'Q' ); if ( M < 0 ) { - throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + throw new RangeError( format( 'invalid argument. Third 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 ( wantq ) { + if ( N < min( M, K ) || N > M ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to `min(M,K)` and smaller than or equal to `M`. Value: `%d`.', N ) ); + } + } else if ( N < M || M < min( N, K ) ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to `M`, and `M` must be greater than or equal to `min(N,K)`. 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 ( K < 0 ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. 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 ) ); + throw new RangeError( format( 'invalid argument. Seventh 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 ) ); + throw new RangeError( format( 'invalid argument. Seventh 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 ) ); + if ( LWORK < max( 1, min( M, N ) ) && LWORK !== -1 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be greater than or equal to `max(1,min(M,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 ); + return base( vect, M, N, K, A, sa1, sa2, 0, TAU, 1, 0, WORK, 1, 0, LWORK ); } diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js index 8b2261c18681..1c936e72bd7f 100644 --- a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/index.js @@ -19,7 +19,7 @@ '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`. +* LAPACK routine to generate one of the real orthogonal matrices `Q` or `P^T` determined by `DGEBRD` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`. * * @module @stdlib/lapack/base/dorgbr * @@ -27,14 +27,14 @@ * 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 A = new Float64Array( [ 1, 0.2, -0.1, 0.3, 0, 1, 0.4, -0.2, 0, 0, 1, 0.5 ] ); +* var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); * 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 ] +* var info = dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, 10 ); +* // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] * // info => 0 -* // WORK[ 0 ] => 2 +* // WORK[ 0 ] => 96 */ // MODULES // diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js index d32c9b1caf1f..958e9bb34a1d 100644 --- a/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/lib/ndarray.js @@ -24,68 +24,93 @@ var format = require( '@stdlib/string/format' ); var max = require( '@stdlib/math/base/special/fast/max' ); +var min = require( '@stdlib/math/base/special/min' ); 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. +* Generates one of the real orthogonal matrices `Q` or `P^T` determined by `DGEBRD` when reducing a real matrix `A` to bidiagonal form: `A = Q * B * P^T`, 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. +* - `Q` and `P^T` are defined as products of elementary reflectors `H(i)` or `G(i)` respectively. * -* @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` +* - If `vect = 'Q'`, +* +* - `A` is assumed to have been an `M-by-K` matrix, and `Q` is of order `M`. +* - if `m >= k`, `Q = H(1) H(2) . . . H(k)` and `dorgbr` returns the first `n` columns of `Q`, where `m >= n >= k`. +* - if `m < k`, `Q = H(1) H(2) . . . H(m-1)` and `dorgbr` returns `Q` as an `M-by-M` matrix. +* +* - If `vect = 'P'`, +* +* - `A` is assumed to have been a `K-by-N` matrix, and `P^T` is of order `N`. +* - if `k < n`, `P^T = G(k) . . . G(2) G(1)` and `dorgbr` returns the first `m` rows of `P^T`, where `n >= m >= k`. +* - if `k >= n`, `P^T = G(n-1) . . . G(2) G(1)` and `dorgbr` returns `P^T` as an `N-by-N` matrix. +* +* - `WORK` must have length, `LWORK >= max(1,min(M,N))`. For optimum performance `LWORK >= min(M,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, and no error message related to `LWORK` is issued. +* +* @param {string} vect - specifies whether the matrix `Q` or the matrix `P^T` is returned in `A` +* @param {NonNegativeInteger} M - number of rows of `Q` or `P^T` +* @param {NonNegativeInteger} N - number of columns of `Q` or `P^T` +* @param {NonNegativeInteger} K - number of elementary reflectors * @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 {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float64Array} TAU - scalar factors of elementary reflectors * @param {integer} strideTAU - stride length for `TAU` -* @param {NonNegativeInteger} offsetTAU - starting index of `TAU` +* @param {NonNegativeInteger} offsetTAU - starting index for `TAU` * @param {Float64Array} WORK - workspace array * @param {integer} strideWORK - stride length for `WORK` -* @param {NonNegativeInteger} offsetWORK - starting index of `WORK` +* @param {NonNegativeInteger} offsetWORK - starting index for `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 {TypeError} first argument must be either `'Q'` or `'P'` +* @throws {RangeError} second argument must be a non-negative integer +* @throws {RangeError} third argument must be a non-negative integer satisfying the constraints for the given `vect` argument +* @throws {RangeError} fourth argument must be a non-negative integer * @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 A = new Float64Array( [ 1, 0.2, -0.1, 0.3, 0, 1, 0.4, -0.2, 0, 0, 1, 0.5 ] ); +* var TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); * 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 ] +* var info = dorgbr( 'Q', 4, 3, 3, A, 1, 4, 0, TAU, 1, 0, WORK, 1, 0, 10 ); +* // A => [ -0.3, -0.26, 0.13, -0.39, -0.143, 0.0714, -0.3457, 0.1371, ~0.21, ~-0.021, ~-0.146, ~-0.474 ] * // info => 0 -* // WORK[ 0 ] => 2 +* // WORK[ 0 ] => 96 */ -function dorgbr( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { +function dorgbr( vect, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + var wantq; + + if ( vect !== 'Q' && vect !== 'P' ) { + throw new TypeError( format( 'invalid argument. First argument must be either `\'Q\'` or `\'P\'`. Value: `%s`.', vect ) ); + } + wantq = ( vect === 'Q' ); if ( M < 0 ) { - throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', M ) ); + throw new RangeError( format( 'invalid argument. Second 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 ( wantq ) { + if ( N < min( M, K ) || N > M ) { + throw new RangeError( format( 'invalid argument. Third argument must be greater than or equal to `min(M,K)` and smaller than or equal to `M`. Value: `%d`.', N ) ); + } + } else if ( N < M || M < min( N, K ) ) { + throw new RangeError( format( 'invalid argument. Third argument must be greater than or equal to `M`, and `M` must be greater than or equal to `min(N,K)`. 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 ( K < 0 ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. 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 ) ); + if ( LWORK < max( 1, min( M, N ) ) && LWORK !== -1 ) { + throw new RangeError( format( 'invalid argument. Fourteenth argument must be greater than or equal to `max(1,min(M,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 ); + return base( vect, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK ); } diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json index 27afec0ff8b4..e31f2533ee92 100644 --- a/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/package.json @@ -1,7 +1,7 @@ { "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`.", + "description": "LAPACK routine to generate one of the real orthogonal matrices `Q` or `P^T` determined by `DGEBRD` when reducing a real matrix `A` to bidiagonal form: `A = Q*B*P^T`.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_ge_n_col_maj.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_ge_n_col_maj.json new file mode 100644 index 000000000000..b1f863345727 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_ge_n_col_maj.json @@ -0,0 +1,123 @@ +{ + "order": "column-major", + "vect": "P", + "M": 4, + "N": 4, + "K": 5, + "A": [ + 1, + 0.5, + 0.8, + 1.1, + 0.2, + 2, + 0.9, + 1.2, + 0.3, + 0.6, + 3, + 1.3, + 0.4, + 0.7, + 1, + 4 + ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ + 1, + 0.2, + 0.3, + 0.4 + ], + [ + 0.5, + 2, + 0.6, + 0.7 + ], + [ + 0.8, + 0.9, + 3, + 1 + ], + [ + 1.1, + 1.2, + 1.3, + 4 + ] + ], + "TAU": [ + 1.5, + 0.9, + 1.3, + 0 + ], + "strideTAU": 1, + "offsetTAU": 0, + "WORK": [ + 0, + 0, + 0, + 0 + ], + "strideWORK": 1, + "offsetWORK": 0, + "LWORK": 4, + "A_out": [ + 1, + 0, + 0, + 0, + 0, + -0.5, + 0.333, + 0.015570000000000011, + 0, + -0.44999999999999996, + 0.19989999999999997, + 0.19367100000000004, + 0, + -0.6000000000000001, + -0.4968, + -0.16147200000000003 + ], + "A_out_mat": [ + [ + 1, + 0, + 0, + 0 + ], + [ + 0, + -0.5, + -0.44999999999999996, + -0.6000000000000001 + ], + [ + 0, + 0.333, + 0.19989999999999997, + -0.4968 + ], + [ + 0, + 0.015570000000000011, + 0.19367100000000004, + -0.16147200000000003 + ] + ], + "WORK_out": [ + 96, + -0.010380000000000007, + 0, + 0 + ], + "info": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_lt_n_col_maj.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_lt_n_col_maj.json new file mode 100644 index 000000000000..038039002069 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/p_k_lt_n_col_maj.json @@ -0,0 +1,69 @@ +{ + "order": "column-major", + "vect": "P", + "M": 2, + "N": 3, + "K": 2, + "A": [ + 1, + -1, + 0, + -2, + 0, + 0 + ], + "strideA1": 1, + "strideA2": 2, + "offsetA": 0, + "LDA": 2, + "A_mat": [ + [ + 1, + 0, + 0 + ], + [ + -1, + -2, + 0 + ] + ], + "TAU": [ + 1, + 1 + ], + "strideTAU": 1, + "offsetTAU": 0, + "WORK": [ + 0, + 0 + ], + "strideWORK": 1, + "offsetWORK": 0, + "LWORK": 2, + "A_out": [ + 0, + 0, + 0, + 0, + 0, + 0 + ], + "A_out_mat": [ + [ + 0, + 0, + 0 + ], + [ + 0, + 0, + 0 + ] + ], + "WORK_out": [ + 64, + 0 + ], + "info": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_ge_k_col_maj.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_ge_k_col_maj.json new file mode 100644 index 000000000000..fbd6706aed17 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_ge_k_col_maj.json @@ -0,0 +1,104 @@ +{ + "order": "column-major", + "vect": "Q", + "M": 4, + "N": 3, + "K": 3, + "A": [ + 1, + 0.2, + -0.1, + 0.3, + 0, + 1, + 0.4, + -0.2, + 0, + 0, + 1, + 0.5 + ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [ + 1, + 0, + 0 + ], + [ + 0.2, + 1, + 0 + ], + [ + -0.1, + 0.4, + 1 + ], + [ + 0.3, + -0.2, + 0.5 + ] + ], + "TAU": [ + 1.3, + 0.9, + 1.1 + ], + "strideTAU": 1, + "offsetTAU": 0, + "WORK": [ + 0, + 0, + 0 + ], + "strideWORK": 1, + "offsetWORK": 0, + "LWORK": 3, + "A_out": [ + -0.30000000000000004, + -0.26, + 0.13, + -0.39, + -0.14300000000000002, + 0.07139999999999998, + -0.34570000000000006, + 0.13710000000000003, + 0.20969000000000004, + -0.021061999999999977, + -0.1461690000000001, + -0.4744930000000001 + ], + "A_out_mat": [ + [ + -0.30000000000000004, + -0.14300000000000002, + 0.20969000000000004 + ], + [ + -0.26, + 0.07139999999999998, + -0.021061999999999977 + ], + [ + 0.13, + -0.34570000000000006, + -0.1461690000000001 + ], + [ + -0.39, + 0.13710000000000003, + -0.4744930000000001 + ] + ], + "WORK_out": [ + 96, + -0.16130000000000003, + 0 + ], + "info": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_lt_k_col_maj.json b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_lt_k_col_maj.json new file mode 100644 index 000000000000..502f6e7c0503 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/fixtures/q_m_lt_k_col_maj.json @@ -0,0 +1,88 @@ +{ + "order": "column-major", + "vect": "Q", + "M": 3, + "N": 3, + "K": 5, + "A": [ + 2, + 0.1, + 0.2, + 0.3, + 3, + 0.4, + 0.5, + 0.6, + 4 + ], + "strideA1": 1, + "strideA2": 3, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [ + 2, + 0.3, + 0.5 + ], + [ + 0.1, + 3, + 0.6 + ], + [ + 0.2, + 0.4, + 4 + ] + ], + "TAU": [ + 1.5, + 0.8, + 0 + ], + "strideTAU": 1, + "offsetTAU": 0, + "WORK": [ + 0, + 0, + 0 + ], + "strideWORK": 1, + "offsetWORK": 0, + "LWORK": 3, + "A_out": [ + 1, + 0, + 0, + 0, + -0.5, + -0.30000000000000004, + 0, + -0.05999999999999999, + 0.18799999999999994 + ], + "A_out_mat": [ + [ + 1, + 0, + 0 + ], + [ + 0, + -0.5, + -0.05999999999999999 + ], + [ + 0, + -0.30000000000000004, + 0.18799999999999994 + ] + ], + "WORK_out": [ + 64, + 0, + 0 + ], + "info": 0 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.dorgbr.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.dorgbr.js new file mode 100644 index 000000000000..d0e8a644ae72 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.dorgbr.js @@ -0,0 +1,566 @@ +/** +* @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 tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostEqual = require( '@stdlib/assert/is-almost-equal-float64array' ); +var dorgbr = require( './../lib/dorgbr.js' ); + + +// FIXTURES // + +var Q_M_GE_K_COL_MAJ = require( './fixtures/q_m_ge_k_col_maj.json' ); +var Q_M_LT_K_COL_MAJ = require( './fixtures/q_m_lt_k_col_maj.json' ); +var P_K_LT_N_COL_MAJ = require( './fixtures/p_k_lt_n_col_maj.json' ); +var P_K_GE_N_COL_MAJ = require( './fixtures/p_k_ge_n_col_maj.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dorgbr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( dorgbr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a valid order', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( value, 'Q', 3, 2, 2, A, 3, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is neither `\'Q\'` nor `\'P\'`', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 'q', + 'p', + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', value, 3, 2, 2, A, 3, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is smaller than 0', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'Q', value, 2, 2, A, 3, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument when `vect` is `\'Q\'`', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 5, + 2, + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'Q', 4, value, 3, A, 4, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument when `vect` is `\'P\'`', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 1, + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'P', 2, value, 2, A, 2, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if `M` is smaller than `min(N,K)` when `vect` is `\'P\'`', function test( t ) { + var WORK; + var TAU; + var A; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ] ); + TAU = new Float64Array( [ 2, 2, 2, 2 ] ); + WORK = new Float64Array( 10 ); + + t.throws( badValue, RangeError, 'throws an error when `M` is smaller than `min(N,K)`' ); + t.end(); + + function badValue() { + dorgbr( 'column-major', 'P', 2, 3, 4, A, 2, TAU, WORK, 10 ); + } +}); + +tape( 'the function throws an error if provided a fifth argument which is smaller than 0', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'Q', 3, 2, value, A, 3, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided a seventh argument which is not a valid `LDA` (column-major)', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 2, + 1, + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'Q', 3, 2, 2, A, value, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error if provided a seventh argument which is not a valid `LDA` (row-major)', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 1, + 0, + -1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'row-major', 'Q', 3, 2, 2, A, value, TAU, WORK, 10 ); + }; + } +}); + +tape( 'the function throws an error when `LWORK` is smaller than `max(1,min(M,N))`', function test( t ) { + var values; + var WORK; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 0, 0, 0, 1, 0 ] ); + TAU = new Float64Array( [ 2, 2 ] ); + WORK = new Float64Array( 10 ); + + values = [ + 2, + 1, + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, value ); + }; + } +}); + +tape( 'the function quick returns when `LWORK` is equal to -1', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var WORK; + var TAU; + var A; + + A = new Float64Array( [ 1, 0.2, -0.1, 0.3, 0, 1, 0.4, -0.2, 0, 0, 1, 0.5 ] ); + TAU = new Float64Array( [ 1.3, 0.9, 1.1 ] ); + WORK = new Float64Array( 10 ); + + expectedA = A; + expectedWORK = WORK; + expectedWORK[ 0 ] = 96; + + info = dorgbr( 'column-major', 'Q', 4, 3, 3, A, 4, TAU, WORK, -1 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.strictEqual( A, expectedA, 'returns expected value' ); + t.strictEqual( WORK, expectedWORK, 'returns expected value' ); + t.end(); +}); + +tape( 'the function quick returns when `M` is equal to 0', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var WORK; + var TAU; + var A; + + A = new Float64Array( 0 ); + TAU = new Float64Array( 0 ); + WORK = new Float64Array( 10 ); + + expectedA = A; + expectedWORK = WORK; + expectedWORK[ 0 ] = 1; + + info = dorgbr( 'column-major', 'Q', 0, 0, 0, A, 1, TAU, WORK, 10 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.strictEqual( A, expectedA, 'returns expected value' ); + t.strictEqual( WORK, expectedWORK, 'returns expected value' ); + t.end(); +}); + +tape( 'the function quick returns when `N` is equal to 0', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var WORK; + var TAU; + var A; + + A = new Float64Array( 0 ); + TAU = new Float64Array( 0 ); + WORK = new Float64Array( 10 ); + + expectedA = A; + expectedWORK = WORK; + expectedWORK[ 0 ] = 1; + + info = dorgbr( 'column-major', 'Q', 3, 0, 0, A, 3, TAU, WORK, 10 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.strictEqual( A, expectedA, 'returns expected value' ); + t.strictEqual( WORK, expectedWORK, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates the orthogonal matrix `Q` (`m >= k`, column-major)', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var data; + var WORK; + var TAU; + var A; + + data = Q_M_GE_K_COL_MAJ; + + A = new Float64Array( data.A ); + TAU = new Float64Array( data.TAU ); + WORK = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedWORK = new Float64Array( data.WORK_out ); + + info = dorgbr( data.order, data.vect, data.M, data.N, data.K, A, data.LDA, TAU, WORK, data.LWORK ); + t.strictEqual( info, data.info, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( WORK, expectedWORK, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates the orthogonal matrix `Q` (`m < k`, column-major)', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var data; + var WORK; + var TAU; + var A; + + data = Q_M_LT_K_COL_MAJ; + + A = new Float64Array( data.A ); + TAU = new Float64Array( data.TAU ); + WORK = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedWORK = new Float64Array( data.WORK_out ); + + info = dorgbr( data.order, data.vect, data.M, data.N, data.K, A, data.LDA, TAU, WORK, data.LWORK ); + t.strictEqual( info, data.info, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( WORK, expectedWORK, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates the matrix `P^T` (`k < n`, column-major)', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var data; + var WORK; + var TAU; + var A; + + data = P_K_LT_N_COL_MAJ; + + A = new Float64Array( data.A ); + TAU = new Float64Array( data.TAU ); + WORK = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedWORK = new Float64Array( data.WORK_out ); + + info = dorgbr( data.order, data.vect, data.M, data.N, data.K, A, data.LDA, TAU, WORK, data.LWORK ); + t.strictEqual( info, data.info, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( WORK, expectedWORK, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates the matrix `P^T` (`k >= n`, column-major)', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var data; + var WORK; + var TAU; + var A; + + data = P_K_GE_N_COL_MAJ; + + A = new Float64Array( data.A ); + TAU = new Float64Array( data.TAU ); + WORK = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedWORK = new Float64Array( data.WORK_out ); + + info = dorgbr( data.order, data.vect, data.M, data.N, data.K, A, data.LDA, TAU, WORK, data.LWORK ); + t.strictEqual( info, data.info, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( WORK, expectedWORK, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles the case where `m < k` and `m <= 1` when `vect` is `\'Q\'`', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var WORK; + var TAU; + var A; + + A = new Float64Array( [ 0.0 ] ); + TAU = new Float64Array( [ 2.0 ] ); + WORK = new Float64Array( 10 ); + + expectedA = new Float64Array( [ 1.0 ] ); + expectedWORK = WORK; + expectedWORK[ 0 ] = 1; + + info = dorgbr( 'column-major', 'Q', 1, 1, 2, A, 1, TAU, WORK, 10 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( WORK, expectedWORK, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles the case where `k >= n` and `n <= 1` when `vect` is `\'P\'`', function test( t ) { + var expectedWORK; + var expectedA; + var info; + var WORK; + var TAU; + var A; + + A = new Float64Array( [ 0.0 ] ); + TAU = new Float64Array( [ 2.0 ] ); + WORK = new Float64Array( 10 ); + + expectedA = new Float64Array( [ 1.0 ] ); + expectedWORK = WORK; + expectedWORK[ 0 ] = 1; + + info = dorgbr( 'column-major', 'P', 1, 1, 2, A, 1, TAU, WORK, 10 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( WORK, expectedWORK, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.js b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.js new file mode 100644 index 000000000000..e083a2e6c82f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dorgbr/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dorgbr = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dorgbr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dorgbr.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dorgbr = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dorgbr, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dorgbr; + var main; + + main = require( './../lib/dorgbr.js' ); + + dorgbr = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dorgbr, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +});