All files / blas/base/dtpmv/lib base.js

100% Statements 163/163
100% Branches 32/32
100% Functions 1/1
100% Lines 163/163

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 1643x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 48x 52x 12x 12x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 12x 12x 36x 36x 36x 36x 12x 12x 40x 52x 35x 52x 15x 15x 15x 15x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 15x 15x 45x 45x 45x 45x 15x 15x 25x 52x 17x 52x 13x 13x 13x 39x 39x 39x 39x 15x 15x 39x 39x 39x 39x 39x 39x 39x 39x 39x 13x 13x 12x 12x 52x 36x 36x 36x 36x 12x 12x 36x 36x 36x 36x 36x 36x 36x 36x 36x 12x 52x 3x 3x 3x 3x 3x  
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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';
 
// MAIN //
 
/**
* Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix, supplied in packed form.
*
* @private
* @param {string} order - storage layout
* @param {string} uplo - specifies whether `A` is an upper or lower triangular matrix
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
* @param {string} diag - specifies whether `A` has a unit diagonal
* @param {NonNegativeInteger} N - number of elements along each dimension of `A`
* @param {Float64Array} AP - packed form of a symmetric matrix `A`
* @param {integer} strideAP - `AP` stride length
* @param {NonNegativeInteger} offsetAP - starting index for `AP`
* @param {Float64Array} x - input vector
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @returns {Float64Array} `x`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ]
* var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
*
* dtpmv( 'row-major', 'upper', 'no-transpose', 'unit', 3, AP, 1, 0, x, 1, 0 );
* // x => <Float64Array>[ 14.0, 8.0, 3.0 ]
*/
function dtpmv( order, uplo, trans, diag, N, AP, strideAP, offsetAP, x, strideX, offsetX ) { // eslint-disable-line max-params, max-len
	var nonunit;
	var isrm;
	var tmp;
	var iap;
	var ix0;
	var ix1;
	var i0;
	var i1;
	var kk;
	var ox;
 
	isrm = ( order === 'row-major' );
	nonunit = ( diag === 'non-unit' );
	kk = offsetAP;
	ox = offsetX;
	if (
		( !isrm && uplo === 'upper' && trans === 'no-transpose' ) ||
		( isrm && uplo === 'lower' && trans !== 'no-transpose' )
	) {
		ix1 = ox;
		for ( i1 = 0; i1 < N; i1++ ) {
			if ( x[ ix1 ] !== 0.0 ) {
				tmp = x[ ix1 ];
				iap = kk;
				ix0 = ox;
				for ( i0 = 0; i0 < i1; i0++ ) {
					x[ ix0 ] += AP[ iap ] * tmp;
					iap += strideAP;
					ix0 += strideX;
				}
				if ( nonunit ) {
					x[ix0] *= AP[ iap ];
				}
			}
			ix1 += strideX;
			kk += ( i1 + 1 ) * strideAP;
		}
		return x;
	}
	if (
		( !isrm && uplo === 'lower' && trans === 'no-transpose' ) ||
		( isrm && uplo === 'upper' && trans !== 'no-transpose' )
	) {
		kk += ( ( N * ( N + 1 ) / 2 ) - 1 ) * strideAP;
		ox += ( N - 1 ) * strideX;
		ix1 = ox;
		for ( i1 = N-1; i1 >=0; i1-- ) {
			if ( x[ ix1 ] !== 0.0 ) {
				tmp = x[ ix1 ];
				iap = kk;
				ix0 = ox;
				for ( i0 = N-1; i0 > i1; i0-- ) {
					x[ ix0 ] += AP[ iap ] * tmp;
					iap -= strideAP;
					ix0 -= strideX;
				}
				if ( nonunit ) {
					x[ ix0 ] *= AP[ iap ];
				}
			}
			ix1 -= strideX;
			kk -= ( N - i1 ) * strideAP;
		}
		return x;
	}
	if (
		( !isrm && uplo === 'upper' && trans !== 'no-transpose' ) ||
		( isrm && uplo === 'lower' && trans === 'no-transpose' )
	) {
		kk += ( ( N * ( N + 1 ) / 2 ) - 1 ) * strideAP;
		ix1 = ox + ( ( N - 1 ) * strideX );
		for ( i1 = N-1; i1 >= 0; i1-- ) {
			tmp = x[ ix1 ];
			iap = kk;
			ix0 = ix1;
			if ( nonunit ) {
				tmp *= AP[ iap ];
			}
			for ( i0 = i1-1; i0 >= 0; i0-- ) {
				ix0 -= strideX;
				iap -= strideAP;
				tmp += AP[ iap ] * x[ ix0 ];
			}
			x[ ix1 ] = tmp;
			ix1 -= strideX;
			kk -= ( i1 + 1 ) * strideAP;
		}
		return x;
	}
	// ( !isrm && uplo === 'lower' && trans !== 'no-transpose' ) || ( isrm && uplo === 'upper' && trans === 'no-transpose' )
	ix1 = ox;
	for ( i1 = 0; i1 < N; i1++ ) {
		tmp = x[ ix1 ];
		iap = kk;
		ix0 = ix1;
		if ( nonunit ) {
			tmp *= AP[ iap ];
		}
		for ( i0 = i1+1; i0 < N; i0++ ) {
			ix0 += strideX;
			iap += strideAP;
			tmp += AP[ iap ] * x[ ix0 ];
		}
		x[ ix1 ] = tmp;
		ix1 += strideX;
		kk += ( N - i1 ) * strideAP;
	}
	return x;
}
 
 
// EXPORTS //
 
module.exports = dtpmv;