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 210 211 212 213 | 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 3x 100x 100x 100x 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 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 8x 8x 52x 44x 44x 44x 52x 52x 52x 48x 48x 52x 4x 4x 48x 48x 52x 28x 52x 24x 4x 4x 4x 24x 20x 20x 20x 20x 24x 24x 24x 56x 56x 8x 56x 48x 48x 160x 160x 160x 160x 160x 48x 56x 56x 56x 24x 24x 24x 24x 24x 52x 20x 20x 20x 52x 4x 4x 4x 4x 24x 24x 52x 88x 88x 88x 192x 192x 192x 192x 88x 88x 88x 88x 88x 24x 52x 3x 3x 3x 3x 3x | /**
* @license Apache-2.0
*
* Copyright (c) 2025 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' );
var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray;
var gscal = require( '@stdlib/blas/base/gscal' ).ndarray;
// FUNCTIONS //
/**
* Tests whether a provided string indicates to transpose a matrix.
*
* @private
* @param {string} str - input string
* @returns {boolean} boolean indicating whether to transpose a matrix
*
* @example
* var bool = isTransposed( 'transpose' );
* // returns true
*
* @example
* var bool = isTransposed( 'conjugate-transpose' );
* // returns true
*
* @example
* var bool = isTransposed( 'no-transpose' );
* // returns false
*/
function isTransposed( str ) { // TODO: consider moving to a separate helper utility package
return ( str !== 'no-transpose' );
}
// MAIN //
/**
* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
*
* @private
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
* @param {NonNegativeInteger} M - number of rows in the matrix `A`
* @param {NonNegativeInteger} N - number of columns in the matrix `A`
* @param {number} alpha - scalar constant
* @param {Object} A - output matrix object
* @param {Collection} A.data - input matrix data
* @param {Array<Function>} A.accessors - array element accessors
* @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 {Object} x - first input vector object
* @param {Collection} x.data - first input vector data
* @param {Array<Function>} x.accessors - array element accessors
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {number} beta - scalar constant
* @param {Object} y - second input vector object
* @param {Collection} y.data - second input vector data
* @param {Array<Function>} y.accessors - array element accessors
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @returns {Object} second input vector object
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
* var x = [ 1.0, 1.0, 1.0 ];
* var y = [ 1.0, 1.0 ];
*
* ggemv( 'no-transpose', 2, 3, 1.0, arraylike2object( toAccessorArray( A ) ), 3, 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0, 1.0, arraylike2object( toAccessorArray( y ) ), 1, 0 );
* // y => [ 7.0, 16.0 ]
*/
function ggemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
var isrm;
var getX;
var getY;
var getA;
var setY;
var xbuf;
var ybuf;
var Abuf;
var xlen;
var ylen;
var tmp;
var da0;
var da1;
var ix;
var iy;
var ia;
var i1;
var i0;
var v;
// Cache references to array data:
xbuf = x.data;
ybuf = y.data;
Abuf = A.data;
// Cache references to element accessors:
getX = x.accessors[ 0 ];
getY = y.accessors[ 0 ];
getA = A.accessors[ 0 ];
setY = y.accessors[ 1 ];
// Note on variable naming convention: da#, i# where # corresponds to the loop number, with `0` being the innermost loop...
isrm = isRowMajor( [ strideA1, strideA2 ] );
if ( isTransposed( trans ) ) {
xlen = M;
ylen = N;
} else {
xlen = N;
ylen = M;
}
// y = beta*y
if ( beta === 0.0 ) {
gfill( ylen, 0.0, ybuf, strideY, offsetY );
} else if ( beta !== 1.0 ) {
gscal( ylen, beta, ybuf, strideY, offsetY );
}
if ( alpha === 0.0 ) {
return y;
}
// Form: y = α*A*x + y
if (
( !isrm && !isTransposed( trans ) ) ||
( isrm && isTransposed( trans ) )
) {
if ( isrm ) {
// For row-major matrices, the last dimension has the fastest changing index...
da0 = strideA2; // offset increment for innermost loop
da1 = strideA1 - ( ylen*strideA2 ); // offset increment for outermost loop
} else { // isColMajor
// For column-major matrices, the first dimension has the fastest changing index...
da0 = strideA1; // offset increment for innermost loop
da1 = strideA2 - ( ylen*strideA1 ); // offset increment for outermost loop
}
ia = offsetA;
ix = offsetX;
for ( i1 = 0; i1 < xlen; i1++ ) {
tmp = alpha * getX( xbuf, ix );
if ( tmp === 0.0 ) {
ia += da0 * ylen;
} else {
iy = offsetY;
for ( i0 = 0; i0 < ylen; i0++ ) {
v = getA( Abuf, ia ) * tmp;
setY( ybuf, iy, getY( ybuf, iy ) + v );
iy += strideY;
ia += da0;
}
}
ix += strideX;
ia += da1;
}
return y;
}
// Form: y = α*A^T*x + y
// ( !isrm && isTransposed( trans ) ) || ( isrm && !isTransposed( trans ) )
if ( isrm ) {
// For row-major matrices, the last dimension has the fastest changing index...
da0 = strideA2; // offset increment for innermost loop
da1 = strideA1 - ( xlen*strideA2 ); // offset increment for outermost loop
} else { // isColMajor
// For column-major matrices, the first dimension has the fastest changing index...
da0 = strideA1; // offset increment for innermost loop
da1 = strideA2 - ( xlen*strideA1 ); // offset increment for outermost loop
}
ia = offsetA;
iy = offsetY;
for ( i1 = 0; i1 < ylen; i1++ ) {
tmp = 0.0;
ix = offsetX;
for ( i0 = 0; i0 < xlen; i0++ ) {
tmp += getA( Abuf, ia ) * getX( xbuf, ix );
ix += strideX;
ia += da0;
}
v = alpha * tmp;
setY( ybuf, iy, getY( ybuf, iy ) + v );
iy += strideY;
ia += da1;
}
return y;
}
// EXPORTS //
module.exports = ggemv;
|