All files base.js

100% Statements 209/209
100% Branches 23/23
100% Functions 2/2
100% Lines 209/209

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 2102x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 12x 12x 12x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 10x 10x 12x 2x 2x 2x 12x 12x 12x 12x 12x 12x 1x 1x 11x 11x 11x 12x 2x 2x 9x 12x 4x 4x 1x 1x 4x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 12x 5x 5x 2x 5x 3x 3x 5x 2x 2x 5x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 5x 9x 9x 9x 12x 2x 2x 2x 2x 2x  
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
/* eslint-disable max-len, max-params */
 
'use strict';
 
// MODULES //
 
var max = require( '@stdlib/math/base/special/max' );
var dormlq = require( './dormlq.js' );
var dormqr = require( './dormqr.js' );
 
 
// 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 //
 
/**
* Multiply a general matrix by the orthogonal matrix from a bi-diagonal reduction determined by `DGEBRD`.
*
* ## Notes
*
* -   `Q` and `P^T` are the orthogonal matrices determined by `DGEBRD` when reducing a real matrix `A` to bi-diagonal form, `A = Q * B * P^T`.
*
* -   If VECT = 'Q', `DORMBR` overwrites the general real `M` by `N` matrix `C` with,
*
*     -   `Q * C`  if SIDE = 'left' and TRANS = 'no-transpose', or
*     -   `Q^T * C`  if SIDE = 'left' and TRANS = 'transpose', or
*     -   `C * Q`  if SIDE = 'right' and TRANS = 'no-transpose', or
*     -   `C * Q^T`  if SIDE = 'right' and TRANS = 'transpose'.
*
* -   If VECT = 'P', `DORMBR` overwrites the general real `M` by `N` matrix `C` with,
*
*     -   `P * C`  if SIDE = 'left' and TRANS = 'no-transpose', or
*     -   `P^T * C`  if SIDE = 'left' and TRANS = 'transpose', or
*     -   `C * P`  if SIDE = 'right' and TRANS = 'no-transpose', or
*     -   `C * P^T`  if SIDE = 'right' and TRANS = 'transpose'.
*
* -   If SIDE = 'left', `LWORK >= max(1,N)`.
*
* -   If SIDE = 'right', `LWORK >= max(1,M)`.
*
* -   For optimum performance, `LWORK >= N*NB` if SIDE = 'left', and `LWORK >= M*NB` if SIDE = 'right', 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 and returns this value as the first entry of the `WORK` array.
*
* @private
* @param {string} vect - specifies whether the matrix `Q` or the matrix `P` is applied
* @param {string} side - specifies the side of multiplication with `C`
* @param {string} trans - `'no-transpose'` for `Q`, `'transpose'` for `Q^T`
* @param {NonNegativeInteger} M - number of rows of `C`
* @param {NonNegativeInteger} N - number of columns of `C`
* @param {NonNegativeInteger} K - number of elementary reflectors
* @param {Float64Array} A - reflector vectors from `DGEBRD`
* @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
* @param {integer} strideTAU - stride for TAU
* @param {NonNegativeInteger} offsetTAU - starting index for TAU
* @param {Float64Array} C - input/output 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 for `WORK`
* @param {NonNegativeInteger} offsetWORK - starting index for `WORK`
* @param {NonNegativeInteger} LWORK - dimension of the array `WORK`
* @returns {integer} status code (0 if successful)
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1, 0, 0 ] );
* var TAU = new Float64Array( [ 2 ] );
* var C = new Float64Array( [ 1, 3, 5, 2, 4, 6 ] );
* var WORK = new Float64Array( 3 );
*
* var info = dormbr( 'Q', 'left', 'no-transpose', 2, 3, 1, A, 2, 1, 0, TAU, 1, 0, C, 3, 1, 0, WORK, 1, 0, 3 );
* // returns 0
* // C => <Float64Array>[ -1, -3, -5, 2, 4, 6 ]
* // WORK => <Float64Array>[ 96, 0, 0 ]
*/
function dormbr( vect, side, trans, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, C, strideC1, strideC2, offsetC, WORK, strideWORK, offsetWORK, LWORK ) {
	var isTrans;
	var applyq;
	var isLeft;
	var lquery;
	var transt;
	var lwkopt;
	var mi;
	var ni;
	var i1;
	var i2;
	var nb;
	var nq;
	var nw;
 
	applyq = ( vect === 'Q' );
	isLeft = isLeftSide( side );
	isTrans = ( trans === 'transpose' );
	lquery = ( LWORK === -1 );
 
	// NQ is the order of Q or P and NW is the minimum dimension of WORK...
	if ( isLeft ) {
		nq = M;
		nw = max( 1, N );
	} else {
		nq = N;
		nw = max( 1, M );
	}
 
	nb = 32;
	lwkopt = nw*nb;
	WORK[ offsetWORK ] = lwkopt;
 
	if ( lquery ) {
		return 0;
	}
 
	// Quick return:
	WORK[ offsetWORK ] = 1;
	if ( M === 0 || N === 0 ) {
		return 0;
	}
 
	if ( applyq ) {
		// Apply Q...
		if ( nq >= K ) {
			// Q was determined by a call to DGEBRD with NQ >= K
			dormqr( side, trans, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, C, strideC1, strideC2, offsetC, WORK, strideWORK, offsetWORK, LWORK );
		} else if ( nq > 1 ) {
			// Q was determined by a call to DGEBRD with NQ < K
			if ( isLeft ) {
				mi = M - 1;
				ni = N;
				i1 = 1;
				i2 = 0;
			} else {
				mi = M;
				ni = N - 1;
				i1 = 0;
				i2 = 1;
			}
			dormqr( side, trans, mi, ni, nq - 1, A, strideA1, strideA2, offsetA + strideA1, TAU, strideTAU, offsetTAU, C, strideC1, strideC2, offsetC + ( i1 * strideC1 ) + ( i2 * strideC2 ), WORK, strideWORK, offsetWORK, LWORK );
		}
	} else {
		// Apply P...
		if ( isTrans ) {
			transt = 'no-transpose';
		} else {
			transt = 'transpose';
		}
		if ( nq > K ) {
			// P was determined by a call to DGEBRD with NQ > K
			dormlq( side, transt, M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, C, strideC1, strideC2, offsetC, WORK, strideWORK, offsetWORK, LWORK );
		} else if ( nq > 1 ) {
			// P was determined by a call to DGEBRD with NQ <= K
			if ( isLeft ) {
				mi = M - 1;
				ni = N;
				i1 = 1;
				i2 = 0;
			} else {
				mi = M;
				ni = N - 1;
				i1 = 0;
				i2 = 1;
			}
			dormlq( side, transt, mi, ni, nq - 1, A, strideA1, strideA2, offsetA + strideA2, TAU, strideTAU, offsetTAU, C, strideC1, strideC2, offsetC + ( i1 * strideC1 ) + ( i2 * strideC2 ), WORK, strideWORK, offsetWORK, LWORK );
		}
	}
 
	WORK[ offsetWORK ] = lwkopt;
	return 0;
}
 
 
// EXPORTS //
 
module.exports = dormbr;