Skip to content
248 changes: 248 additions & 0 deletions lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
* @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-string' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var muladd = require( '@stdlib/complex/float32/base/mul-add' ).assign;


// 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 complex 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 {Complex64Array} AP - packed form of a symmetric matrix `A`
* @param {integer} strideAP - `AP` stride length
* @param {NonNegativeInteger} offsetAP - starting index for `AP`
* @param {Complex64Array} x - input vector
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @returns {Complex64Array} `x`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
*
* var AP = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 4.0, 4.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0 ] );
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
*
* ctpmv( 'row-major', 'lower', 'no-transpose', 'non-unit', 3, AP, 1, 0, x, 1, 0 );
* // x => <Complex64Array>[ 0.0, 2.0, 0.0, 20.0, 0.0, 62.0 ]
*/
function ctpmv( order, uplo, trans, diag, N, AP, strideAP, offsetAP, x, strideX, offsetX ) { // eslint-disable-line max-params, max-len

Check warning on line 57 in lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Function 'ctpmv' has too many statements (141). Maximum allowed is 100
var nonunit;
var viewAP;
var viewX;
var retmp;
var imtmp;
var isrm;
var sign;
var rex;
var imx;
var rea;
var ima;
var iap;
var ix0;
var ix1;
var sap;
var kk;
var ox;
var sx;
var i1;
var i0;

// Layout
isrm = isRowMajor( order );

// Diagonal
nonunit = ( diag === 'non-unit' );

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

// Adjust sign to account for conjugation
if ( trans === 'conjugate-transpose' ) {
sign = -1;
} else {
sign = 1;
}

// Vector indexing base
ox = offsetX * 2;
kk = offsetAP * 2;

// Vector strides
sx = strideX * 2;
sap = strideAP * 2;

if (
( !isrm && uplo === 'upper' && trans === 'no-transpose' ) ||
( isrm && uplo === 'lower' && trans !== 'no-transpose' )
) {
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
retmp = viewX[ ix1 ];
imtmp = viewX[ ix1 + 1 ];
if (retmp !== 0.0 || imtmp !== 0.0) {
iap = kk;
ix0 = ox;
for ( i0 = 0; i0 < i1; i0++ ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
muladd( rea, ima, retmp, imtmp, rex, imx, viewX, 1, ix0 );
iap += sap;
ix0 += sx;
}
if ( nonunit ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
viewX[ ix0 ] = f32( ( rea * rex ) - ( ima * imx ) );
viewX[ ix0 + 1 ] = f32( ( rea * imx ) + ( ima * rex ) );
}
}
ix1 += sx;
kk += ( i1 + 1 ) * sap;
}
return x;
}
if (
( !isrm && uplo === 'lower' && trans === 'no-transpose' ) ||
( isrm && uplo === 'upper' && trans !== 'no-transpose' )
) {
kk += ( ( N * ( N + 1 ) / 2 ) - 1 ) * sap;
ox += ( N - 1 ) * sx;
ix1 = ox;
for ( i1 = N - 1; i1 >= 0; i1-- ) {
retmp = viewX[ ix1 ];
imtmp = viewX[ ix1 + 1 ];
if ( retmp !== 0.0 || imtmp !== 0.0 ) {
iap = kk;
ix0 = ox;
for ( i0 = N - 1; i0 > i1; i0-- ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
muladd( rea, ima, retmp, imtmp, rex, imx, viewX, 1, ix0 );
iap -= sap;
ix0 -= sx;
}
if ( nonunit ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
viewX[ ix0 ] = f32( ( rea * rex ) - ( ima * imx ) );
viewX[ ix0 + 1 ] = f32( ( rea * imx ) + ( ima * rex ) );
}
}
ix1 -= sx;
kk -= ( N - i1 ) * sap;
}
return x;
}
if (
( !isrm && uplo === 'upper' && trans !== 'no-transpose' ) ||
( isrm && uplo === 'lower' && trans === 'no-transpose' )
) {
kk += ( ( N * ( N + 1 ) / 2 ) - 1 ) * sap;
ix1 = ox + ( ( N - 1 ) * sx );
for ( i1 = N - 1; i1 >= 0; i1-- ) {
rex = viewX[ ix1 ];
imx = viewX[ ix1 + 1 ];
iap = kk;
ix0 = ix1;
if ( nonunit ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
retmp = f32( ( rea * rex ) - ( ima * imx ) );
imtmp = f32( ( rea * imx ) + ( ima * rex ) );
} else {
retmp = rex;
imtmp = imx;
}
for ( i0 = i1 - 1; i0 >= 0; i0-- ) {
ix0 -= sx;
iap -= sap;
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex ) - ( ima * imx ) );
imtmp += f32( ( rea * imx ) + ( ima * rex ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
ix1 -= sx;
kk -= ( i1 + 1 ) * sap;
}
return x;
}
// ( !isrm && uplo === 'lower' && trans !== 'no-transpose' ) || ( isrm && uplo === 'upper' && trans === 'no-transpose' )

Check warning on line 211 in lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "uplo"

Check warning on line 211 in lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"

Check warning on line 211 in lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "uplo"

Check warning on line 211 in lib/node_modules/@stdlib/blas/base/ctpmv/lib/base.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "isrm"
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
rex = viewX[ ix1 ];
imx = viewX[ ix1 + 1 ];
iap = kk;
ix0 = ix1;
if ( nonunit ) {
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
retmp = f32( ( rea * rex ) - ( ima * imx ) );
imtmp = f32( ( rea * imx ) + ( ima * rex ) );
} else {
retmp = rex;
imtmp = imx;
}
for ( i0 = i1+1; i0 < N; i0++ ) {
ix0 += sx;
iap += sap;
rea = viewAP[ iap ];
ima = sign * viewAP[ iap + 1 ];
rex = viewX[ ix0 ];
imx = viewX[ ix0 + 1 ];
retmp += f32( ( rea * rex ) - ( ima * imx ) );
imtmp += f32( ( rea * imx ) + ( ima * rex ) );
}
viewX[ ix1 ] = retmp;
viewX[ ix1 + 1 ] = imtmp;
ix1 += sx;
kk += ( N - i1 ) * sap;
}
return x;
}


// EXPORTS //

module.exports = ctpmv;
93 changes: 93 additions & 0 deletions lib/node_modules/@stdlib/blas/base/ctpmv/lib/ctpmv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* @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 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 complex matrix, supplied in packed form.
*
* @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 {Complex64Array} AP - packed form of a symmetric matrix `A`
* @param {Complex64Array} x - input vector
* @param {integer} strideX - `x` stride length
* @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} eighth argument must be non-zero
* @returns {Complex64Array} `x`
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
*
* var AP = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 4.0, 4.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0 ] );
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
*
* ctpmv( 'row-major', 'lower', 'no-transpose', 'non-unit', 3, AP, x, 1 );
* // x => <Complex64Array>[ 0.0, 2.0, 0.0, 20.0, 0.0, 62.0 ]
*/
function ctpmv( order, uplo, trans, diag, N, AP, x, strideX ) {
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 ( strideX === 0 ) {
throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideX ) );
}
if ( N === 0 ) {
return x;
}
ox = stride2offset( N, strideX );
return base( order, uplo, trans, diag, N, AP, 1, 0, x, strideX, ox );
}


// EXPORTS //

module.exports = ctpmv;
Loading
Loading