All files dlarft.js

100% Statements 113/113
100% Branches 19/19
100% Functions 1/1
100% Lines 113/113

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 1142x 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 58x 58x 58x 58x 58x 58x 58x 13x 13x 58x 13x 13x 58x 13x 13x 58x 12x 4x 4x 12x 3x 3x 5x 5x 5x 5x 58x 7x 7x 7x 7x 7x 58x 3x 3x 9x 9x 58x 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.
*/
 
'use strict';
 
// MODULES //
 
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
var max = require( '@stdlib/math/base/special/max' );
var format = require( '@stdlib/string/format' );
var isStorage = require( './is_storage.js' );
var isDirection = require( './is_direction.js' );
var base = require( './base.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` = 'columnwise', 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` = 'rowwise', 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`.
*
* @param {string} order - storage layout
* @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 {PositiveInteger} LDV - leading dimension of `V`
* @param {Float64Array} TAU - array of scalar factors of the elementary reflector `H(i)`y
* @param {Float64Array} T - output triangular matrix
* @param {PositiveInteger} LDT - leading dimension of `T`
* @throws {TypeError} first argument must be a valid order
* @throws {TypeError} second argument must be a valid direction
* @throws {TypeError} third argument must be a valid storage layout
* @throws {RangeError} seventh argument must be a valid `LDV`
* @throws {RangeError} tenth argument must be a valid `LDT`
* @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( 'row-major', 'forward', 'rowwise', 5, 3, V, 5, TAU, T, 3 );
* // T => <Float64Array>[ ~1.2, ~0.5544, ~-0.17514, 0.0, 0.7, 0.8925, 0.0, 0.0, 1.5 ]
*/
function dlarft( order, direct, storev, N, K, V, LDV, TAU, T, LDT ) {
	var strideV1;
	var strideV2;
	var strideT1;
	var strideT2;
 
	if ( !isLayout( order ) ) {
		throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
	}
	if ( !isDirection( direct ) ) {
		throw new TypeError( format( 'invalid argument. Second argument must be a direction. Value: `%s`.', direct ) );
	}
	if ( !isStorage( storev ) ) {
		throw new TypeError( format( 'invalid argument. Third argument must be a valid storage layout. Value: `%s`.', storev ) );
	}
	if ( isColumnMajor( order ) ) {
		if ( storev === 'columnwise' && LDV < max( 1, N ) ) {
			throw new RangeError( format( 'invalid argument. Seventh argument must be at least max(1,%d). Value: `%d`.', N, LDV ) );
		}
		if ( storev === 'rowwise' && LDV < K ) {
			throw new RangeError( format( 'invalid argument. Seventh argument must be at least %d. Value: `%d`.', K, LDV ) );
		}
		strideV1 = 1;
		strideV2 = LDV;
		strideT1 = 1;
		strideT2 = LDT;
	} else { // order === 'row-major'
		strideV1 = LDV;
		strideV2 = 1;
		strideT1 = LDT;
		strideT2 = 1;
	}
	if ( LDT < K ) {
		throw new RangeError( format( 'invalid argument. Tenth argument must be at least %d. Value: `%d`.', K, LDT ) );
	}
	base( direct, storev, N, K, V, strideV1, strideV2, 0, TAU, 1, 0, T, strideT1, strideT2, 0 );
	return T;
}
 
 
// EXPORTS //
 
module.exports = dlarft;