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
251 changes: 251 additions & 0 deletions lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/**
* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
var max = require( '@stdlib/math/base/special/max' );
var min = require( '@stdlib/math/base/special/min' );


// MAIN //

/**
* Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x` or `x = A^H*x` where `x` is an `N` element complex vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular band matrix, with (`K` + 1) diagonals.
*
* @private
* @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 {NonNegativeInteger} K - number of super-diagonals or sub-diagonals of the matrix `A`
* @param {Complex64Array} A - input complex 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 - input complex vector
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @returns {Complex64Array} `x`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var A = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0 ] );
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
*
* ctbmv( 'lower', 'no-transpose', 'non-unit', 3, 1, A, 2, 1, 0, x, 1, 0 );
* // x => <Complex64Array>[ 0.0, 2.0, 0.0, 16.0, 0.0, 46.0 ]
*/
function ctbmv( uplo, trans, diag, N, K, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) { // eslint-disable-line max-params, max-len

Check warning on line 60 in lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Function 'ctbmv' has too many statements (138). Maximum allowed is 100
var nonunit;
var viewA;
var viewX;
var retmp;
var imtmp;
var isrm;
var sign;
var rex0;
var imx0;
var rex1;
var imx1;
var rea;
var ima;
var ix0;
var ix1;
var sa0;
var sa1;
var oa2;
var ox;
var sx;
var oa;
var i0;
var i1;
var ia;

// Layout
isrm = isRowMajor( [ strideA1, strideA2 ] );
nonunit = ( diag === 'non-unit' );

// Reinterpret arrays to raw numeric views
viewA = reinterpret( A, 0 );
viewX = reinterpret( x, 0 );

// Set sign to handle conjugation: flip the imaginary part for conjugate-transpose
if ( trans === 'conjugate-transpose' ) {
sign = -1;
} else {
sign = 1;
}

if ( isrm ) {
// For row-major matrices, the last dimension has the fastest changing index...
sa0 = strideA2 * 2; // offset increment for innermost loop
sa1 = strideA1 * 2; // offset increment for outermost loop
} else { // isColMajor
// For column-major matrices, the first dimension has the fastest changing index...
sa0 = strideA1 * 2; // offset increment for innermost loop
sa1 = strideA2 * 2; // offset increment for outermost loop
}

// Vector indexing base
oa = offsetA * 2;
ox = offsetX * 2;

// Vector strides
sx = strideX * 2;

if (
( !isrm && trans === 'no-transpose' && uplo === 'upper' ) ||
( isrm && trans !== 'no-transpose' && uplo === 'lower' )
) {
for ( i1 = 0; i1 < N; i1++ ) {
oa2 = oa + ( i1 * sa1 ) + ( K * sa0 );
ix1 = ox + ( i1 * sx );
rex1 = viewX[ ix1 ];
imx1 = viewX[ ix1 + 1 ];
if ( nonunit ) {
rea = viewA[ oa2 ];
ima = sign * viewA[ oa2 + 1 ];
retmp = f32( ( rea * rex1 ) - ( ima * imx1 ) );
imtmp = f32( ( rea * imx1 ) + ( ima * rex1 ) );
} else {
retmp = rex1;
imtmp = imx1;
}
for ( i0 = i1 + 1; i0 <= min( N - 1, i1 + K ); i0++ ) {
ix0 = ox + ( i0 * sx );
ia = oa2 + ( (i0 - i1) * ( sa1 - sa0 ) );
rea = viewA[ ia ];
ima = sign * viewA[ ia + 1 ];
rex0 = viewX[ ix0 ];
imx0 = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex0 ) - ( ima * imx0 ) );
imtmp += f32( ( rea * imx0 ) + ( ima * rex0 ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
}
return x;
}
if (
( !isrm && trans === 'no-transpose' && uplo === 'lower' ) ||
( isrm && trans !== 'no-transpose' && uplo === 'upper' )
) {
for ( i1 = N - 1; i1 >= 0; i1-- ) {
oa2 = oa + ( i1 * sa1 );
ix1 = ox + ( i1 * sx );
rex1 = viewX[ ix1 ];
imx1 = viewX[ ix1 + 1 ];
if ( nonunit ) {
rea = viewA[ oa2 ];
ima = sign * viewA[ oa2 + 1 ];
retmp = f32( ( rea * rex1 ) - ( ima * imx1 ) );
imtmp = f32( ( rea * imx1 ) + ( ima * rex1 ) );
} else {
retmp = rex1;
imtmp = imx1;
}
for ( i0 = max( 0, i1 - K ); i0 < i1; i0++ ) {
ix0 = ox + ( i0 * sx );
ia = oa2 + ( ( i0 - i1 ) * ( sa1 - sa0 ) );
rea = viewA[ ia ];
ima = sign * viewA[ ia + 1 ];
rex0 = viewX[ ix0 ];
imx0 = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex0 ) - ( ima * imx0 ) );
imtmp += f32( ( rea * imx0 ) + ( ima * rex0 ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
}
return x;
}
if (
( !isrm && trans !== 'no-transpose' && uplo === 'upper' ) ||
( isrm && trans === 'no-transpose' && uplo === 'lower' )
) {
for ( i1 = N - 1; i1 >= 0; i1-- ) {
oa2 = oa + ( i1 * sa1 ) + ( K * sa0 );
ix1 = ox + ( i1 * sx );
rex1 = viewX[ ix1 ];
imx1 = viewX[ ix1 + 1 ];
if ( nonunit ) {
rea = viewA[ oa2 ];
ima = sign * viewA[ oa2 + 1 ];
retmp = f32( ( rea * rex1 ) - ( ima * imx1 ) );
imtmp = f32( ( rea * imx1 ) + ( ima * rex1 ) );
} else {
retmp = rex1;
imtmp = imx1;
}
for ( i0 = max( 0, i1 - K ); i0 < i1; i0++ ) {
ix0 = ox + ( i0 * sx );
ia = oa2 + ( ( i0 - i1 ) * sa0 );
rea = viewA[ ia ];
ima = sign * viewA[ ia + 1 ];
rex0 = viewX[ ix0 ];
imx0 = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex0 ) - ( ima * imx0 ) );
imtmp += f32( ( rea * imx0 ) + ( ima * rex0 ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
}
return x;
}
// ( !isrm && trans !== 'no-transpose' && uplo === 'lower' ) || ( isrm && trans === 'no-transpose' && uplo === 'upper' )

Check warning on line 217 in lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "uplo"

Check warning on line 217 in lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"

Check warning on line 217 in lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "uplo"

Check warning on line 217 in lib/node_modules/@stdlib/blas/base/ctbmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"
for ( i1 = 0; i1 < N; i1++ ) {
oa2 = oa + ( i1 * sa1 );
ix1 = ox + ( i1 * sx );
rex1 = viewX[ ix1 ];
imx1 = viewX[ ix1 + 1 ];
if ( nonunit ) {
rea = viewA[ oa2 ];
ima = sign * viewA[ oa2 + 1 ];
retmp = f32( ( rea * rex1 ) - ( ima * imx1 ) );
imtmp = f32( ( rea * imx1 ) + ( ima * rex1 ) );
} else {
retmp = rex1;
imtmp = imx1;
}
for ( i0 = i1 + 1; i0 <= min( N - 1, i1 + K ); i0++ ) {
ix0 = ox + ( i0 * sx );
ia = oa2 + ( ( i0 - i1 ) * sa0 );
rea = viewA[ ia ];
ima = sign * viewA[ ia + 1 ];
rex0 = viewX[ ix0 ];
imx0 = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex0 ) - ( ima * imx0 ) );
imtmp += f32( ( rea * imx0 ) + ( ima * rex0 ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
}
return x;
}


// EXPORTS //

module.exports = ctbmv;
113 changes: 113 additions & 0 deletions lib/node_modules/@stdlib/blas/base/ctbmv/lib/ctbmv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* @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 max = require( '@stdlib/math/base/special/fast/max' );
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' );
var isDiagonal = require( '@stdlib/blas/base/assert/is-diagonal-type' );
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var format = require( '@stdlib/string/format' );
var base = require( './base.js' );


// MAIN //

/**
* Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x` or `x = A^H*x` where `x` is an `N` element complex vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular band matrix, with (`K` + 1) diagonals.
*
* @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 {NonNegativeInteger} K - number of super-diagonals or sub-diagonals of the matrix `A`
* @param {Complex64Array} A - input matrix
* @param {integer} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
* @param {Complex64Array} x - input vector
* @param {integer} strideX - stride length for `x`
* @throws {TypeError} first argument must be a valid order
* @throws {TypeError} second argument must specify whether a lower or upper triangular matrix is supplied
* @throws {TypeError} third argument must be a valid transpose operation
* @throws {TypeError} fourth argument must be a valid diagonal type
* @throws {RangeError} fifth argument must be a nonnegative integer
* @throws {RangeError} sixth argument must be a nonnegative integer
* @throws {RangeError} eighth argument must be greater than or equal to max(1,N)
* @throws {RangeError} tenth argument must be non-zero
* @returns {Complex64Array} `x`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var A = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0 ] );
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
*
* ctbmv( 'row-major', 'lower', 'no-transpose', 'non-unit', 3, 1, A, 2, x, 1 );
* // x => <Complex64Array>[ 0.0, 2.0, 0.0, 16.0, 0.0, 46.0 ]
*/
function ctbmv( order, uplo, trans, diag, N, K, A, LDA, x, strideX ) {
var sa1;
var sa2;
var ox;

if ( !isLayout( order ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
}
if ( !isMatrixTriangle( uplo ) ) {
throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) );
}
if ( !isTransposeOperation( trans ) ) {
throw new TypeError( format( 'invalid argument. Third argument must be a valid transpose operation. Value: `%s`.', trans ) );
}
if ( !isDiagonal( diag ) ) {
throw new TypeError( format( 'invalid argument. Fourth argument must be a valid diagonal type. Value: `%s`.', diag ) );
}
if ( N < 0 ) {
throw new RangeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%d`.', N ) );
}
if ( K < 0 ) {
throw new RangeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%d`.', K ) );
}
if ( LDA < max( 1, K + 1 ) ) {
throw new RangeError( 'invalid argument. Eighth argument must be greater than or equal to ( K + 1 ). Value: `%d`.', LDA );
}
if ( strideX === 0 ) {
throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) );
}
if ( N === 0 ) {
return x;
}
if ( order === 'column-major' ) {
sa1 = 1;
sa2 = LDA;
} else { // order === 'row-major'
sa1 = LDA;
sa2 = 1;
}
ox = stride2offset( N, strideX );
return base( uplo, trans, diag, N, K, A, sa1, sa2, 0, x, strideX, ox );
}


// EXPORTS //

module.exports = ctbmv;
Loading
Loading