Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
198 changes: 198 additions & 0 deletions lib/node_modules/@stdlib/blas/base/cgemv/lib/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var scabs1 = require( '@stdlib/blas/base/scabs1' );
var cmulf = require( '@stdlib/complex/float32/base/mul' );
var caddf = require( '@stdlib/complex/float32/base/add' );
var conjf = require( '@stdlib/complex/float32/conj' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var cfill = require( '@stdlib/blas/ext/base/cfill' ).ndarray;
var cscal = require( '@stdlib/blas/base/cscal' ).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 ) { // NOTE: 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 complex scalars, `x` and `y` are complex vectors, and `A` is an `M` by `N` complex 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 {Complex64} alpha - scalar constant
* @param {Complex64Array} A - input matrix
* @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 {Complex64Array} x - first input vector
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Complex64} beta - scalar constant
* @param {Complex64Array} y - second input vector
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @returns {Complex64Array} `y`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var x = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
* var y = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0 ] );
* var alpha = new Complex64( 1.0, 0.0 );
* var beta = new Complex64( 1.0, 0.0 );
*
* cgemv( 'no-transpose', 2, 3, alpha, A, 3, 1, 0, x, 1, 0, beta, y, 1, 0 );
* // y => <Complex64Array>[ 10.0, 12.0, 28.0, 30.0 ]
*/
function cgemv( 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 xlen;
var ylen;
var tmp;
var da0;
var da1;
var aij;
var ix;
var iy;
var ia;
var i1;
var i0;

isrm = isRowMajor( [ strideA1, strideA2 ] );
if ( isTransposed( trans ) ) {
xlen = M;
ylen = N;
} else {
xlen = N;
ylen = M;
}
// y = beta*y
if ( scabs1( beta ) === 0.0 ) {
cfill( ylen, 0.0, y, strideY, offsetY );
} else if ( scabs1( beta ) !== 1.0 ) {
cscal( ylen, beta, y, strideY, offsetY );
}
if ( scabs1( 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 = cmulf( alpha, x.get( ix ) );
if ( scabs1( tmp ) === 0.0 ) {
ia += da0 * ylen;
} else {
iy = offsetY;
for ( i0 = 0; i0 < ylen; i0++ ) {
aij = A.get( ia );
if ( trans === 'conjugate-transpose' ) {
aij = conjf( aij );
}
y.set( caddf( y.get( iy ), cmulf( aij, tmp ) ), iy );
iy += strideY;
ia += da0;
}
}
ix += strideX;
ia += da1;
}
return y;
}
// Form: y = α*A^T*x + y

// ( !isrm && isTransposed( trans ) ) || ( isrm && !isTransposed( trans ) )

Check warning on line 165 in lib/node_modules/@stdlib/blas/base/cgemv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"

Check warning on line 165 in lib/node_modules/@stdlib/blas/base/cgemv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"
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
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++ ) {
ix = offsetX;
tmp = new Complex64( 0.0, 0.0 );
for ( i0 = 0; i0 < xlen; i0++ ) {
aij = A.get( ia );
if ( trans === 'conjugate-transpose' ) {
aij = conjf( aij );
}
tmp = caddf( tmp, cmulf( aij, x.get( ix ) ) );
ix += strideX;
ia += da0;
}
y.set( caddf( y.get( iy ), cmulf( alpha, tmp ) ), iy );
iy += strideY;
ia += da1;
}
return y;
}


// EXPORTS //

module.exports = cgemv;
71 changes: 71 additions & 0 deletions lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @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' );

Check failure on line 23 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'isLayout' is assigned a value but never used
var isMatrixTranspose = require( '@stdlib/blas/base/assert/is-transpose-operation' );

Check failure on line 24 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'isMatrixTranspose' is assigned a value but never used
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );

Check failure on line 25 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'isColumnMajor' is assigned a value but never used
var stride2offset = require( '@stdlib/strided/base/stride2offset' );

Check failure on line 26 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'stride2offset' is assigned a value but never used
var max = require( '@stdlib/math/base/special/fast/max' );

Check failure on line 27 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'max' is assigned a value but never used
var scabs1 = require( '@stdlib/blas/base/scabs1' );

Check failure on line 28 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'scabs1' is assigned a value but never used
var format = require( '@stdlib/string/format' );

Check failure on line 29 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'format' is assigned a value but never used
var base = require( './base.js' );

Check failure on line 30 in lib/node_modules/@stdlib/blas/base/cgemv/lib/cgemv.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'base' is assigned a value but never used


// MAIN //

/**
* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are complex scalars, `x` and `y` are complex vectors, and `A` is an `M` by `N` complex matrix.
*
* @param {string} order - storage layout
* @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 {Complex64} alpha - scalar constant
* @param {Complex64Array} A - input matrix
* @param {PositiveInteger} LDA - stride of the first dimension of `A`
* @param {Complex64Array} x - first input vector
* @param {integer} strideX - `x` stride length
* @param {Complex64} beta - scalar constant
* @param {Complex64Array} y - second input vector
* @param {integer} strideY - `y` stride length
* @throws {TypeError} first argument must be a valid order
* @throws {TypeError} second argument must be a valid transpose operation
* @throws {RangeError} third argument must be a nonnegative integer
* @throws {RangeError} fourth argument must be a nonnegative integer
* @throws {RangeError} seventh argument must be a valid stride
* @throws {RangeError} ninth argument must be non-zero
* @throws {RangeError} twelfth argument must be non-zero
* @returns {Complex64Array} `y`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var x = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
* var y = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0 ] );
* var alpha = new Complex64( 1.0, 0.0 );
* var beta = new Complex64( 1.0, 0.0 );
*
* cgemv( 'no-transpose', 2, 3, alpha, A, 3, 1, 0, x, 1, 0, beta, y, 1, 0 );
* // y => <Complex64Array>[ 10.0, 12.0, 28.0, 30.0 ]
*/
Empty file.
Empty file.
92 changes: 92 additions & 0 deletions lib/node_modules/@stdlib/blas/base/cgemv/lib/ndarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @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 isMatrixTranspose = require( '@stdlib/blas/base/assert/is-transpose-operation' );
var format = require( '@stdlib/string/format' );
var base = require( './base.js' );

/**
* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are complex scalars, `x` and `y` are complex vectors, and `A` is an `M` by `N` complex matrix.
*
* @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 {Complex64} alpha - scalar constant
* @param {Complex64Array} A - input matrix
* @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 {Complex64Array} x - first input vector
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Complex64} beta - scalar constant
* @param {Complex64Array} y - second input vector
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @throws {TypeError} first argument must be a valid transpose operation
* @throws {RangeError} second argument must be a nonnegative integer
* @throws {RangeError} third argument must be a nonnegative integer
* @throws {RangeError} tenth argument must be non-zero
* @throws {RangeError} fourteenth argument must be non-zero
* @returns {Complex64Array} `y`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var x = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
* var y = new Complex64Array( [ 1.0, 0.0, 1.0, 0.0 ] );
* var alpha = new Complex64( 1.0, 0.0 );
* var beta = new Complex64( 1.0, 0.0 );
*
* cgemv( 'no-transpose', 2, 3, alpha, A, 3, 1, 0, x, 1, 0, beta, y, 1, 0 );
* // y => <Complex64Array>[ 10.0, 12.0, 28.0, 30.0 ]
*/
function cgemv(trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY) { // eslint-disable-line max-params, max-len
if (!isMatrixTranspose(trans)) {
throw new TypeError( format( 'invalid argument. First argument must be a valid transpose operation. Value: `%s`.', trans ) );
}
if (M < 0) {
throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) );
}
if (N < 0) {
throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) );
}
if (strideX === 0) {
throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) );
}
if (strideY === 0) {
throw new RangeError( format( 'invalid argument. Fourteenth argument must be non-zero. Value: `%d`.', strideY ) );
}
// Check if we can early return...
if (M === 0 || N === 0) {
return y;
}

return base( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len
}


// EXPORTS //

module.exports = cgemv;
Loading