|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2025 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +// MODULES // |
| 22 | + |
| 23 | +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); |
| 24 | +var isOperationSide = require( '@stdlib/blas/base/assert/is-operation-side' ); |
| 25 | +var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' ); |
| 26 | +var isMatrixOrientation = require( '@stdlib/blas/base/assert/is-matrix-orientation' ); |
| 27 | +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); |
| 28 | +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); |
| 29 | +var max = require( '@stdlib/math/base/special/max' ); |
| 30 | +var format = require( '@stdlib/string/format' ); |
| 31 | +var base = require( './base.js' ); |
| 32 | + |
| 33 | + |
| 34 | +// MAIN // |
| 35 | + |
| 36 | +/** |
| 37 | +* 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. |
| 38 | +* |
| 39 | +* @param {string} order - storage layout |
| 40 | +* @param {string} side - specifies whether `H` or `H ^ T` is applied from the left or right |
| 41 | +* @param {string} trans - specifies whether to apply `H` or `H ^ T` (`'no-transpose'` or `'transpose'`) |
| 42 | +* @param {string} direct - indicates how `H` is formed from a product of elementary reflectors (`'forward'` or `'backward'`) |
| 43 | +* @param {string} storev - indicates how the vectors which define the elementary reflectors are stored (`'column-major'` or `'row-major'`) |
| 44 | +* @param {NonNegativeInteger} M - number of rows of the matrix `C` |
| 45 | +* @param {NonNegativeInteger} N - number of columns of the matrix `C` |
| 46 | +* @param {NonNegativeInteger} K - order of the matrix `T` |
| 47 | +* @param {Float64Array} V - input matrix |
| 48 | +* @param {PositiveInteger} LDV - leading dimension of `V` |
| 49 | +* @param {Float64Array} T - input matrix (upper/lower triangular as dictated by `direct`/`storev`) |
| 50 | +* @param {PositiveInteger} LDT - leading dimension of `T` (must be ≥ max(1,K)) |
| 51 | +* @param {Float64Array} C - input/output matrix |
| 52 | +* @param {PositiveInteger} LDC - leading dimension of `C` |
| 53 | +* @param {Float64Array} work - work array |
| 54 | +* @param {PositiveInteger} LDWORK - leading dimension of `work` |
| 55 | +* @throws {TypeError} first argument must be a valid order |
| 56 | +* @throws {TypeError} invalid `side` |
| 57 | +* @throws {TypeError} invalid `trans` |
| 58 | +* @throws {TypeError} invalid `direct` |
| 59 | +* @throws {TypeError} invalid `storev` |
| 60 | +* @throws {RangeError} invalid leading dimension(s) |
| 61 | +* @returns {Float64Array} updated matrix `C` |
| 62 | +* |
| 63 | +* @example |
| 64 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 65 | +* |
| 66 | +* var V = new Float64Array( [ 10.0, 40.0, 70.0, 20.0, 50.0, 80.0, 30.0, 60.0, 90.0 ] ); |
| 67 | +* var T = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] ); |
| 68 | +* var C = new Float64Array( [ 11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0 ] ); |
| 69 | +* var work = new Float64Array( 9 ); |
| 70 | +* |
| 71 | +* dlarfb( 'row-major', 'left', 'transpose', 'forward', 'columns', 3, 3, 3, V, 3, T, 3, C, 3, work, 3 ); |
| 72 | +* |
| 73 | +* // C => <Float64Array>[ -1350.00, -1400.00, -1450.00, -30961.00, -32102.00, -33243.00, -266612.00, -275464.00, -284316.00 ] |
| 74 | +*/ |
| 75 | +function dlarfb( order, side, trans, direct, storev, M, N, K, V, LDV, T, LDT, C, LDC, work, LDWORK ) { // eslint-disable-line max-params, max-len |
| 76 | + var requiredLdwork; |
| 77 | + var sv1; |
| 78 | + var sv2; |
| 79 | + var st1; |
| 80 | + var st2; |
| 81 | + var sc1; |
| 82 | + var sc2; |
| 83 | + var sw1; |
| 84 | + var sw2; |
| 85 | + |
| 86 | + if ( !isLayout( order ) ) { |
| 87 | + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); |
| 88 | + } |
| 89 | + if ( !isOperationSide( side ) ) { |
| 90 | + throw new TypeError( format( 'invalid argument. Second argument must be a valid BLAS operation side. Value: `%s`.', side ) ); |
| 91 | + } |
| 92 | + if ( !isTransposeOperation( trans ) ) { |
| 93 | + throw new TypeError( format( 'invalid argument. Third argument must be a valid BLAS transpose operation. Value: `%s`.', trans ) ); |
| 94 | + } |
| 95 | + if ( direct !== 'forward' && direct !== 'backward' ) { |
| 96 | + throw new TypeError( format( 'invalid argument. Fourth argument must be either `forward` or `backward`. Value: `%s`.', direct ) ); |
| 97 | + } |
| 98 | + if ( !isMatrixOrientation( storev ) ) { |
| 99 | + throw new TypeError( format( 'invalid argument. Fifth argument must be a valid matrix orientation. Value: `%s`.', storev ) ); |
| 100 | + } |
| 101 | + |
| 102 | + if ( isRowMajor( order ) ) { |
| 103 | + if ( LDC < max( 1, N ) ) { |
| 104 | + throw new RangeError( format( 'invalid argument. Thirteenth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDC ) ); |
| 105 | + } |
| 106 | + if ( LDT < max( 1, K ) ) { |
| 107 | + throw new RangeError( format( 'invalid argument. Twelfth argument must be greater than or equal to max(1,%d). Value: `%d`.', K, LDT ) ); |
| 108 | + } |
| 109 | + if ( storev === 'columns' ) { |
| 110 | + if ( LDV < max( 1, K ) ) { |
| 111 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', K, LDV ) ); |
| 112 | + } |
| 113 | + } else if ( storev === 'rows' ) { |
| 114 | + if ( side === 'left' ) { |
| 115 | + if ( LDV < max( 1, M ) ) { |
| 116 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', M, LDV ) ); |
| 117 | + } |
| 118 | + } else if ( side === 'right' ) { |
| 119 | + if ( LDV < max( 1, N ) ) { |
| 120 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDV ) ); |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + if ( LDWORK < max( 1, K ) ) { |
| 125 | + throw new RangeError( format( 'invalid argument. Fifteenth argument must be greater than or equal to max(1,%d). Value: `%d`.', K, LDWORK ) ); |
| 126 | + } |
| 127 | + } else if ( isColumnMajor( order ) ) { |
| 128 | + if ( LDC < max( 1, M ) ) { |
| 129 | + throw new RangeError( format( 'invalid argument. Thirteenth argument must be greater than or equal to max(1,%d). Value: `%d`.', M, LDC ) ); |
| 130 | + } |
| 131 | + if ( LDT < max( 1, K ) ) { |
| 132 | + throw new RangeError( format( 'invalid argument. Twelfth argument must be greater than or equal to max(1,%d). Value: `%d`.', K, LDT ) ); |
| 133 | + } |
| 134 | + if ( storev === 'columns' ) { |
| 135 | + if ( side === 'left' ) { |
| 136 | + if ( LDV < max( 1, M ) ) { |
| 137 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', M, LDV ) ); |
| 138 | + } |
| 139 | + } else if ( side === 'right' ) { |
| 140 | + if ( LDV < max( 1, N ) ) { |
| 141 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDV ) ); |
| 142 | + } |
| 143 | + } |
| 144 | + } else if ( storev === 'rows' ) { |
| 145 | + if ( LDV < max( 1, K ) ) { |
| 146 | + throw new RangeError( format( 'invalid argument. Eleventh argument must be greater than or equal to max(1,%d). Value: `%d`.', K, LDV ) ); |
| 147 | + } |
| 148 | + } |
| 149 | + if ( side === 'left' ) { |
| 150 | + requiredLdwork = N; |
| 151 | + } else { |
| 152 | + requiredLdwork = M; |
| 153 | + } |
| 154 | + if ( LDWORK < max( 1, requiredLdwork ) ) { |
| 155 | + throw new RangeError( format( 'invalid argument. Fifteenth argument must be greater than or equal to max(1,%d). Value: `%d`.', requiredLdwork, LDWORK ) ); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + if ( isColumnMajor( order ) ) { |
| 160 | + sv1 = 1; |
| 161 | + sv2 = LDV; |
| 162 | + st1 = 1; |
| 163 | + st2 = LDT; |
| 164 | + sc1 = 1; |
| 165 | + sc2 = LDC; |
| 166 | + sw1 = 1; |
| 167 | + sw2 = LDWORK; |
| 168 | + } else { |
| 169 | + sv1 = LDV; |
| 170 | + sv2 = 1; |
| 171 | + st1 = LDT; |
| 172 | + st2 = 1; |
| 173 | + sc1 = LDC; |
| 174 | + sc2 = 1; |
| 175 | + sw1 = LDWORK; |
| 176 | + sw2 = 1; |
| 177 | + } |
| 178 | + |
| 179 | + return base( side, trans, direct, storev, M, N, K, V, sv1, sv2, 0, T, st1, st2, 0, C, sc1, sc2, 0, work, sw1, sw2, 0 ); // eslint-disable-line max-len |
| 180 | +} |
| 181 | + |
| 182 | + |
| 183 | +// EXPORTS // |
| 184 | + |
| 185 | +module.exports = dlarfb; |
0 commit comments