diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md new file mode 100644 index 000000000000..bb686235cdb2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md @@ -0,0 +1,150 @@ + + +# cgemv + +> Perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); +``` + +#### cgemv( arrays ) + +Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. + +```javascript +/* eslint-disable max-len */ +var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); + +var A = new Complex64Matrix( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); +var x = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); +var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); + +var out = cgemv( [ A, x, y, trans, alpha, beta ] ); +// returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] + +var bool = ( out === y ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a two-dimensional input ndarray corresponding to `A`. + - a one-dimensional input ndarray corresponding to `x`. + - a one-dimensional input/output ndarray corresponding to `y`. + - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed corresponding to `trans`. + - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. + - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +/* eslint-disable max-len */ +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new Complex64Matrix( discreteUniform( 24, 0, 10, opts ).buffer, 0, [ 3, 4 ] ); +var x = new Complex64Vector( discreteUniform( 8, 0, 10, opts ) ); +var y = new Complex64Vector( discreteUniform( 6, 0, 10, opts ) ); + +var trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); +var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); + +var out = cgemv( [ A, x, y, trans, alpha, beta ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js new file mode 100644 index 000000000000..3bb7f2f197c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js @@ -0,0 +1,139 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var realf = require( '@stdlib/complex/float32/real' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var cgemv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'complex64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var A; + var x; + var y; + + Abuf = uniform( len*len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + A = new Complex64Matrix( Abuf.buffer, 0, [ len, len ] ); + + xbuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + x = new Complex64Vector( xbuf.buffer ); + + ybuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + y = new Complex64Vector( ybuf.buffer ); + + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), options ); + beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), options ); + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = cgemv( [ A, x, y, trans, alpha, beta ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnanf( realf( z.get( i%len ) ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt new file mode 100644 index 000000000000..88eebc30943f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( arrays ) + Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, + `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` + and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` + is an `M` by `N` matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a two-dimensional input ndarray corresponding to `A`. + - a one-dimensional input ndarray corresponding to `x`. + - a one-dimensional input/output ndarray corresponding to `y`. + - a zero-dimensional ndarray Specifies whether `A` should be transposed, conjugate-transposed, or not transposed. + - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. + - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var A = new {{alias:@stdlib/ndarray/matrix/complex64}}( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); + > var x = new {{alias:@stdlib/ndarray/vector/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = new {{alias:@stdlib/ndarray/vector/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 0.0 ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( ca, { 'dtype': 'complex64' }); + > var cb = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 0.0 ); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( cb, { 'dtype': 'complex64' }); + > var t = {{alias:@stdlib/blas/base/transpose-operation-str2enum}}( 'no-transpose' ); + > var trans = {{alias:@stdlib/ndarray/from-scalar}}( t, { 'dtype': 'int8' }); + + > {{alias}}( [ A, x, y, trans, alpha, beta ] ); + > y + [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/index.d.ts new file mode 100644 index 000000000000..77d0d2860490 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { complex64ndarray, int8ndarray } from '@stdlib/types/ndarray'; + +/** +* Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray corresponding to `A`. +* - a one-dimensional input ndarray corresponding to `x`. +* - a one-dimensional input/output ndarray corresponding to `y`. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed corresponding to `trans`. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +* +* var A = new Complex64Matrix( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); +* var x = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var trans = scalar2ndarray( str2enum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var z = cgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] +* +* var bool = ( z === y ); +* // returns true +*/ +declare function cgemv( arrays: [ complex64ndarray, complex64ndarray, complex64ndarray, int8ndarray, complex64ndarray, complex64ndarray ] ): complex64ndarray; + + +// EXPORTS // + +export = cgemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/test.ts new file mode 100644 index 000000000000..1e452d275cef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/test.ts @@ -0,0 +1,87 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const A = zeros( [ 2, 3 ], { + 'dtype': 'complex64' + }); + const x = zeros( [ 3 ], { + 'dtype': 'complex64' + }); + const y = zeros( [ 2 ], { + 'dtype': 'complex64' + }); + const trans = zeros( [], { + 'dtype': 'int8' + }); + const alpha = zeros( [], { + 'dtype': 'complex64' + }); + const beta = zeros( [], { + 'dtype': 'complex64' + }); + + cgemv( [ A, x, y, trans, alpha, beta ] ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + cgemv( '10' ); // $ExpectError + cgemv( 10 ); // $ExpectError + cgemv( true ); // $ExpectError + cgemv( false ); // $ExpectError + cgemv( null ); // $ExpectError + cgemv( undefined ); // $ExpectError + cgemv( [] ); // $ExpectError + cgemv( {} ); // $ExpectError + cgemv( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = zeros( [ 2, 3 ], { + 'dtype': 'complex64' + }); + const x = zeros( [ 3 ], { + 'dtype': 'complex64' + }); + const y = zeros( [ 2 ], { + 'dtype': 'complex64' + }); + const trans = zeros( [], { + 'dtype': 'int8' + }); + const alpha = zeros( [], { + 'dtype': 'complex64' + }); + const beta = zeros( [], { + 'dtype': 'complex64' + }); + + cgemv(); // $ExpectError + cgemv( [ A, x, y, trans, alpha, beta ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js new file mode 100644 index 000000000000..eac195228217 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js @@ -0,0 +1,49 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cgemv = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new Complex64Matrix( discreteUniform( 24, 0, 10, opts ).buffer, 0, [ 3, 4 ] ); +var x = new Complex64Vector( discreteUniform( 8, 0, 10, opts ) ); +var y = new Complex64Vector( discreteUniform( 6, 0, 10, opts ) ); + +var trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); +var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' +}); + +var out = cgemv( [ A, x, y, trans, alpha, beta ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js new file mode 100644 index 000000000000..45014283a105 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js @@ -0,0 +1,62 @@ +/** +* @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'; + +/** +* BLAS level 2 routine to perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`. +* +* @module @stdlib/blas/base/ndarray/cgemv +* +* @example +* var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +* var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); +* +* var A = new Complex64Matrix( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); +* var x = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var trans = scalar2ndarray( str2enum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] +* +* var bool = ( out === y ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js new file mode 100644 index 000000000000..a70295565f47 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/base/cgemv' ).ndarray; + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray corresponding to `A`. +* - a one-dimensional input ndarray corresponding to `x`. +* - a one-dimensional input/output ndarray corresponding to `y`. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed corresponding to `trans`. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. +* - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +* +* var A = new Complex64Matrix( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); +* var x = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var trans = scalar2ndarray( str2enum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var z = cgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] +* +* var bool = ( z === y ); +* // returns true +*/ +function cgemv( arrays ) { + var trans = ndarraylike2scalar( arrays[ 3 ] ); + var alpha = ndarraylike2scalar( arrays[ 4 ] ); + var beta = ndarraylike2scalar( arrays[ 5 ] ); + var A = arrays[ 0 ]; + var x = arrays[ 1 ]; + var y = arrays[ 2 ]; + strided( trans, numelDimension( A, 0 ), numelDimension( A, 1 ), alpha, getData( A ), getStride( A, 0 ), getStride( A, 1 ), getOffset( A ), getData( x ), getStride( x, 0 ), getOffset( x ), beta, getData( y ), getStride( y, 0 ), getOffset( y ) ); + return y; +} + + +// EXPORTS // + +module.exports = cgemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json new file mode 100644 index 000000000000..8fb04277dfc7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/cgemv", + "version": "0.0.0", + "description": "Perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 2", + "cgemv", + "linear", + "algebra", + "subroutines", + "matrix-vector", + "multiply", + "vector", + "matrix", + "array", + "ndarray", + "complex64", + "complex", + "complex64array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js new file mode 100644 index 000000000000..100906fdb256 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js @@ -0,0 +1,567 @@ +/** +* @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 tape = require( 'tape' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cgemv = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'complex64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'complex64', buffer, [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( cgemv.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y`', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, // 3 + 6.0 // 3 + ]); + Abuf = 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 ] ); + A = matrix( Abuf, 3, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ -9.0, 30.0, -15.0, 72.0, -21.0, 114.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, // 3 + 6.0 // 3 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + Abuf = 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 ] ); + A = matrix( Abuf, 2, 3, 1, 2, 0 ); + x = vector( xbuf, 3, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ -52.0, 296.0, -60.0, 384.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A^T*x + beta*y`', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + Abuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + A = matrix( Abuf, 2, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ -11.0, 44.0, -13.0, 66.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A^H*x + beta*y`', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + Abuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + A = matrix( Abuf, 2, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'conjugate-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ 45.0, 4.0, 67.0, 10.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation with complex scalars', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + Abuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + A = matrix( Abuf, 2, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 0.5, 0.5 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 0.5, -0.5 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ -17.5, 9.5, -39.5, 25.5 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0 // 2 + ]); + ybuf = new Complex64Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, // 3 + 6.0 // 3 + ]); + Abuf = 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 ] ); + A = matrix( Abuf, 3, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 0.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-unit strides (transpose)', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + Abuf = 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 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = new Complex64Array([ + 1.0, + 2.0, // 0 + 0.0, + 0.0, + 3.0, + 4.0 // 1 + ]); + x = vector( xbuf, 2, 2, 0 ); + + ybuf = new Complex64Array([ + 1.0, + 2.0, // 0 + 0.0, + 0.0, + 3.0, + 4.0, // 1 + 0.0, + 0.0, + 5.0, + 6.0 // 2 + ]); + y = vector( ybuf, 3, 2, 0 ); + + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ -26.0, 116.0, 0.0, 0.0, -30.0, 160.0, 0.0, 0.0, -34.0, 204.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides (conjugate-transpose)', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + Abuf = 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 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = new Complex64Array([ + 3.0, + 4.0, // 1 + 0.0, + 0.0, + 1.0, + 2.0 // 0 + ]); + x = vector( xbuf, 2, -2, 2 ); + + ybuf = new Complex64Array([ + 5.0, + 6.0, // 2 + 0.0, + 0.0, + 3.0, + 4.0, // 1 + 0.0, + 0.0, + 1.0, + 2.0 // 0 + ]); + y = vector( ybuf, 3, -2, 4 ); + + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'conjugate-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array( [ 206.0, 36.0, 0.0, 0.0, 162.0, 24.0, 0.0, 0.0, 118.0, 12.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var alpha; + var beta; + var trans; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + Abuf = new Complex64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 11.0, + 12.0 + ]); + A = matrix( Abuf, 2, 3, 3, 1, 2 ); + + xbuf = new Complex64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + x = vector( xbuf, 3, 1, 2 ); + + ybuf = new Complex64Array([ + 0.0, + 0.0, + 1.0, + 2.0, // 0 + 0.0, + 0.0, + 3.0, + 4.0 // 1 + ]); + y = vector( ybuf, 2, 2, 1 ); + + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Complex64Array([ + 0.0, + 0.0, + -40.0, + 180.0, + 0.0, + 0.0, + -72.0, + 436.0 + ]); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});