From 45c9679c09677858740707b3d182ddce8bf0a47b Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 26 Jun 2026 15:55:21 +0530 Subject: [PATCH 1/2] feat: add blas/base/ndarray/cgemv --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/ndarray/cgemv/README.md | 141 ++++++ .../base/ndarray/cgemv/benchmark/benchmark.js | 135 ++++++ .../blas/base/ndarray/cgemv/docs/repl.txt | 43 ++ .../base/ndarray/cgemv/docs/types/index.d.ts | 70 +++ .../base/ndarray/cgemv/docs/types/test.ts | 81 ++++ .../blas/base/ndarray/cgemv/examples/index.js | 46 ++ .../blas/base/ndarray/cgemv/lib/index.js | 59 +++ .../blas/base/ndarray/cgemv/lib/main.js | 86 ++++ .../blas/base/ndarray/cgemv/package.json | 72 +++ .../blas/base/ndarray/cgemv/test/test.js | 434 ++++++++++++++++++ 10 files changed, 1167 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js 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..4313766e95a0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md @@ -0,0 +1,141 @@ + + +# cgemv + +> Perform the matrix-vector operation `y = alpha*A*x + beta*y`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); +``` + +#### cgemv( arrays ) + +Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. + +```javascript +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); + +var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +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 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, 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. + - first one-dimensional input ndarray. + - second one-dimensional input/output ndarray. + - first zero-dimensional ndarray containing a scalar constant. + - second zero-dimensional ndarray containing a scalar constant. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new ndarray( 'complex64', new Complex64Array( discreteUniform( 24, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +var x = new Complex64Vector( discreteUniform( 8, 0, 10, opts ) ); +var y = new Complex64Vector( discreteUniform( 6, 0, 10, opts ) ); + +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, 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..64c3f6071ec9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js @@ -0,0 +1,135 @@ +/** +* @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 Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ndarray = require( '@stdlib/ndarray/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 xbuf; + var ybuf; + var Abuf; + var A; + var x; + var y; + + Abuf = uniform( len*len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + A = new ndarray( 'complex64', new Complex64Array( Abuf.buffer ), [ len, len ], [ len, 1 ], 0, 'row-major' ); + + 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 ); + + 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, 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..3abd3bac3459 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( arrays ) + Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where + `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is + an `M` by `N` matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a two-dimensional input ndarray. + - first one-dimensional input ndarray. + - second one-dimensional input/output ndarray. + - first zero-dimensional ndarray containing a scalar constant. + - second zero-dimensional ndarray containing a scalar constant. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + > var buf = new {{alias:@stdlib/array/complex64}}( arr ); + > var sh = [ 2, 2 ]; + > var st = [ 2, 1 ]; + > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'complex64', buf, sh, st, 0, 'row-major' ); + > 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' }); + + > {{alias}}( [ A, x, y, 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..a4b186ee4911 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/index.d.ts @@ -0,0 +1,70 @@ +/* +* @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 } from '@stdlib/types/ndarray'; + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray. +* - first one-dimensional input ndarray. +* - second one-dimensional input/output ndarray. +* - first zero-dimensional ndarray containing a scalar constant. +* - second zero-dimensional ndarray containing a scalar constant. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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 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, alpha, beta ] ); +* // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] +* +* var bool = ( z === y ); +* // returns true +*/ +declare function cgemv( arrays: [ complex64ndarray, complex64ndarray, complex64ndarray, 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..fe7d677c7937 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/types/test.ts @@ -0,0 +1,81 @@ +/* +* @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 alpha = zeros( [], { + 'dtype': 'complex64' + }); + const beta = zeros( [], { + 'dtype': 'complex64' + }); + + cgemv( [ A, x, y, 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 alpha = zeros( [], { + 'dtype': 'complex64' + }); + const beta = zeros( [], { + 'dtype': 'complex64' + }); + + cgemv(); // $ExpectError + cgemv( [ A, x, y, 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..edf5ba3a4cf5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cgemv = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new ndarray( 'complex64', new Complex64Array( discreteUniform( 24, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +var x = new Complex64Vector( discreteUniform( 8, 0, 10, opts ) ); +var y = new Complex64Vector( discreteUniform( 6, 0, 10, opts ) ); + +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, 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..38ec0d5499fc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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 the matrix-vector operation `y = alpha*A*x + beta*y`. +* +* @module @stdlib/blas/base/ndarray/cgemv +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); +* +* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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 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, 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..1ffafff3257a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js @@ -0,0 +1,86 @@ +/** +* @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 the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray. +* - first one-dimensional input ndarray. +* - second one-dimensional input/output ndarray. +* - first zero-dimensional ndarray containing a scalar constant. +* - second zero-dimensional ndarray containing a scalar constant. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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 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, alpha, beta ] ); +* // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] +* +* var bool = ( z === y ); +* // returns true +*/ +function cgemv( arrays ) { + var alpha = ndarraylike2scalar( arrays[ 3 ] ); + var beta = ndarraylike2scalar( arrays[ 4 ] ); + var A = arrays[ 0 ]; + var x = arrays[ 1 ]; + var y = arrays[ 2 ]; + strided( 'no-transpose', 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..2aa7b92276b0 --- /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 the matrix-vector operation `y = alpha*A*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..4c6ebaad24d4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js @@ -0,0 +1,434 @@ +/** +* @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 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 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' + }); + + v = cgemv( [ A, x, y, 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' + }); + + v = cgemv( [ A, x, y, 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 with complex scalars', function test( t ) { + var expected; + var alpha; + var beta; + 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' + }); + + v = cgemv( [ A, x, y, 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 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' + }); + + v = cgemv( [ A, x, y, 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', function test( t ) { + var expected; + var alpha; + var beta; + 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 + 0.0, + 0.0, + 5.0, + 6.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + + ybuf = new Complex64Array([ + 1.0, + 2.0, // 0 + 0.0, + 0.0, + 3.0, + 4.0 // 1 + ]); + y = vector( ybuf, 2, 2, 0 ); + + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + v = cgemv( [ A, x, y, alpha, beta ] ); + + expected = new Complex64Array( [ -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(); +}); + +tape( 'the function supports ndarrays having negative strides', function test( t ) { + var expected; + var alpha; + var beta; + 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([ + 5.0, + 6.0, // 2 + 0.0, + 0.0, + 3.0, + 4.0, // 1 + 0.0, + 0.0, + 1.0, + 2.0 // 0 + ]); + x = vector( xbuf, 3, -2, 4 ); + + ybuf = new Complex64Array([ + 3.0, + 4.0, // 1 + 0.0, + 0.0, + 1.0, + 2.0 // 0 + ]); + y = vector( ybuf, 2, -2, 2 ); + + alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + v = cgemv( [ A, x, y, alpha, beta ] ); + + expected = new Complex64Array( [ -72.0, 436.0, 0.0, 0.0, -40.0, 180.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 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' + }); + + v = cgemv( [ A, x, y, 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(); +}); From 110d93e9de2d37cf62229f7d7e33ecbef69326a2 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sat, 27 Jun 2026 11:32:38 +0530 Subject: [PATCH 2/2] apply suggestions from the code review --- .../@stdlib/blas/base/ndarray/cgemv/README.md | 39 ++-- .../base/ndarray/cgemv/benchmark/benchmark.js | 12 +- .../blas/base/ndarray/cgemv/docs/repl.txt | 28 +-- .../base/ndarray/cgemv/docs/types/index.d.ts | 28 +-- .../base/ndarray/cgemv/docs/types/test.ts | 10 +- .../blas/base/ndarray/cgemv/examples/index.js | 11 +- .../blas/base/ndarray/cgemv/lib/index.js | 13 +- .../blas/base/ndarray/cgemv/lib/main.js | 31 +-- .../blas/base/ndarray/cgemv/package.json | 2 +- .../blas/base/ndarray/cgemv/test/test.js | 183 +++++++++++++++--- 10 files changed, 262 insertions(+), 95 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md index 4313766e95a0..bb686235cdb2 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/README.md @@ -20,7 +20,7 @@ limitations under the License. # cgemv -> Perform the matrix-vector operation `y = alpha*A*x + beta*y`. +> 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`.
@@ -38,19 +38,23 @@ var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); #### cgemv( arrays ) -Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. +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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Complex64Array = require( '@stdlib/array/complex64' ); +var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); -var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +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' }); @@ -58,7 +62,7 @@ var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { 'dtype': 'complex64' }); -var out = cgemv( [ A, x, y, alpha, beta ] ); +var out = cgemv( [ A, x, y, trans, alpha, beta ] ); // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] var bool = ( out === y ); @@ -69,11 +73,12 @@ The function has the following parameters: - **arrays**: array-like object containing the following ndarrays: - - a two-dimensional input ndarray. - - first one-dimensional input ndarray. - - second one-dimensional input/output ndarray. - - first zero-dimensional ndarray containing a scalar constant. - - second zero-dimensional ndarray containing a scalar constant. + - 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`.
@@ -92,12 +97,13 @@ The function has the following parameters: ```javascript +/* eslint-disable max-len */ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Complex64Array = require( '@stdlib/array/complex64' ); +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' ); @@ -105,10 +111,13 @@ var opts = { 'dtype': 'float32' }; -var A = new ndarray( 'complex64', new Complex64Array( discreteUniform( 24, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +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' }); @@ -116,7 +125,7 @@ var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { 'dtype': 'complex64' }); -var out = cgemv( [ A, x, y, alpha, beta ] ); +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 index 64c3f6071ec9..3bb7f2f197c3 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/benchmark/benchmark.js @@ -26,10 +26,10 @@ 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64Matrix = require( '@stdlib/ndarray/matrix/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var cgemv = require( './../lib' ); @@ -54,6 +54,7 @@ var options = { function createBenchmark( len ) { var alpha; var beta; + var trans; var xbuf; var ybuf; var Abuf; @@ -64,7 +65,7 @@ function createBenchmark( len ) { Abuf = uniform( len*len*2, -100.0, 100.0, { 'dtype': 'float32' }); - A = new ndarray( 'complex64', new Complex64Array( Abuf.buffer ), [ len, len ], [ len, 1 ], 0, 'row-major' ); + A = new Complex64Matrix( Abuf.buffer, 0, [ len, len ] ); xbuf = uniform( len*2, -100.0, 100.0, { 'dtype': 'float32' @@ -78,6 +79,9 @@ function createBenchmark( len ) { 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; @@ -93,7 +97,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - z = cgemv( [ A, x, y, alpha, beta ] ); + z = cgemv( [ A, x, y, trans, alpha, beta ] ); if ( typeof z !== 'object' ) { b.fail( 'should return an ndarray' ); } 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 index 3abd3bac3459..88eebc30943f 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/docs/repl.txt @@ -1,19 +1,21 @@ {{alias}}( arrays ) - Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where - `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is - an `M` by `N` matrix. + 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. - - first one-dimensional input ndarray. - - second one-dimensional input/output ndarray. - - first zero-dimensional ndarray containing a scalar constant. - - second zero-dimensional ndarray containing a scalar constant. + - 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 ------- @@ -22,19 +24,17 @@ Examples -------- - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - > var buf = new {{alias:@stdlib/array/complex64}}( arr ); - > var sh = [ 2, 2 ]; - > var st = [ 2, 1 ]; - > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'complex64', buf, sh, st, 0, 'row-major' ); + > 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, alpha, beta ] ); + > {{alias}}( [ A, x, y, trans, alpha, beta ] ); > y [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] 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 index a4b186ee4911..77d0d2860490 100644 --- 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 @@ -20,35 +20,39 @@ /// -import { complex64ndarray } from '@stdlib/types/ndarray'; +import { complex64ndarray, int8ndarray } from '@stdlib/types/ndarray'; /** -* Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. +* 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. -* - first one-dimensional input ndarray. -* - second one-dimensional input/output ndarray. -* - first zero-dimensional ndarray containing a scalar constant. -* - second zero-dimensional ndarray containing a scalar constant. +* - 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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Complex64Array = require( '@stdlib/array/complex64' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); * -* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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' * }); @@ -56,13 +60,13 @@ import { complex64ndarray } from '@stdlib/types/ndarray'; * 'dtype': 'complex64' * }); * -* var z = cgemv( [ A, x, y, alpha, beta ] ); +* 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, complex64ndarray, complex64ndarray ] ): complex64ndarray; +declare function cgemv( arrays: [ complex64ndarray, complex64ndarray, complex64ndarray, int8ndarray, complex64ndarray, complex64ndarray ] ): complex64ndarray; // EXPORTS // 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 index fe7d677c7937..1e452d275cef 100644 --- 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 @@ -35,6 +35,9 @@ import cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); const y = zeros( [ 2 ], { 'dtype': 'complex64' }); + const trans = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'complex64' }); @@ -42,7 +45,7 @@ import cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); 'dtype': 'complex64' }); - cgemv( [ A, x, y, alpha, beta ] ); // $ExpectType complex64ndarray + 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... @@ -69,6 +72,9 @@ import cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); const y = zeros( [ 2 ], { 'dtype': 'complex64' }); + const trans = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'complex64' }); @@ -77,5 +83,5 @@ import cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); }); cgemv(); // $ExpectError - cgemv( [ A, x, y, alpha, beta ], {} ); // $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 index edf5ba3a4cf5..eac195228217 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/examples/index.js @@ -19,11 +19,11 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Complex64Array = require( '@stdlib/array/complex64' ); +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' ); @@ -31,10 +31,13 @@ var opts = { 'dtype': 'float32' }; -var A = new ndarray( 'complex64', new Complex64Array( discreteUniform( 24, 0, 10, opts ) ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +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' }); @@ -42,5 +45,5 @@ var beta = scalar2ndarray( new Complex64( 1.0, 0.0 ), { 'dtype': 'complex64' }); -var out = cgemv( [ A, x, y, alpha, beta ] ); +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 index 38ec0d5499fc..45014283a105 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/index.js @@ -19,22 +19,25 @@ 'use strict'; /** -* BLAS level 2 routine to perform the matrix-vector operation `y = alpha*A*x + beta*y`. +* 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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Complex64Array = require( '@stdlib/array/complex64' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); * var cgemv = require( '@stdlib/blas/base/ndarray/cgemv' ); * -* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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' * }); @@ -42,7 +45,7 @@ * 'dtype': 'complex64' * }); * -* var out = cgemv( [ A, x, y, alpha, beta ] ); +* var out = cgemv( [ A, x, y, trans, alpha, beta ] ); * // returns [ [ -9.0, 30.0 ], [ -15.0, 72.0 ] ] * * var bool = ( out === y ); 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 index 1ffafff3257a..a70295565f47 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/lib/main.js @@ -31,32 +31,36 @@ var strided = require( '@stdlib/blas/base/cgemv' ).ndarray; // MAIN // /** -* Performs the matrix-vector operation `y = alpha*A*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are ndarrays, and `A` is an `M` by `N` matrix. +* 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. -* - first one-dimensional input ndarray. -* - second one-dimensional input/output ndarray. -* - first zero-dimensional ndarray containing a scalar constant. -* - second zero-dimensional ndarray containing a scalar constant. +* - 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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Complex64Array = require( '@stdlib/array/complex64' ); +* var str2enum = require( '@stdlib/blas/base/transpose-operation-str2enum' ); * -* var A = new ndarray( 'complex64', new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); +* 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' * }); @@ -64,19 +68,20 @@ var strided = require( '@stdlib/blas/base/cgemv' ).ndarray; * 'dtype': 'complex64' * }); * -* var z = cgemv( [ A, x, y, alpha, beta ] ); +* 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 alpha = ndarraylike2scalar( arrays[ 3 ] ); - var beta = ndarraylike2scalar( arrays[ 4 ] ); + 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( 'no-transpose', 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 ) ); + 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; } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json index 2aa7b92276b0..8fb04277dfc7 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/ndarray/cgemv", "version": "0.0.0", - "description": "Perform the matrix-vector operation `y = alpha*A*x + beta*y`.", + "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", 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 index 4c6ebaad24d4..100906fdb256 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/cgemv/test/test.js @@ -25,6 +25,7 @@ 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' ); @@ -80,6 +81,7 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y var expected; var alpha; var beta; + var trans; var xbuf; var ybuf; var Abuf; @@ -113,7 +115,11 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + 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' ); @@ -144,7 +150,11 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + 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' ); @@ -153,10 +163,109 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y 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; @@ -188,7 +297,11 @@ tape( 'the function performs the matrix-vector operation with complex scalars', 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + 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' ); @@ -201,6 +314,7 @@ 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; @@ -234,7 +348,11 @@ tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + 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' ); @@ -243,10 +361,11 @@ tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { t.end(); }); -tape( 'the function supports ndarrays having non-unit strides', function test( t ) { +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; @@ -264,13 +383,9 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 0.0, 0.0, 3.0, - 4.0, // 1 - 0.0, - 0.0, - 5.0, - 6.0 // 2 + 4.0 // 1 ]); - x = vector( xbuf, 3, 2, 0 ); + x = vector( xbuf, 2, 2, 0 ); ybuf = new Complex64Array([ 1.0, @@ -278,9 +393,13 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 0.0, 0.0, 3.0, - 4.0 // 1 + 4.0, // 1 + 0.0, + 0.0, + 5.0, + 6.0 // 2 ]); - y = vector( ybuf, 2, 2, 0 ); + y = vector( ybuf, 3, 2, 0 ); alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { 'dtype': 'complex64' @@ -289,18 +408,23 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( str2enum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); - expected = new Complex64Array( [ -40.0, 180.0, 0.0, 0.0, -72.0, 436.0 ] ); + 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', function test( t ) { +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; @@ -313,10 +437,6 @@ tape( 'the function supports ndarrays having negative strides', function test( t A = matrix( Abuf, 2, 3, 3, 1, 0 ); xbuf = new Complex64Array([ - 5.0, - 6.0, // 2 - 0.0, - 0.0, 3.0, 4.0, // 1 0.0, @@ -324,9 +444,13 @@ tape( 'the function supports ndarrays having negative strides', function test( t 1.0, 2.0 // 0 ]); - x = vector( xbuf, 3, -2, 4 ); + 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, @@ -334,7 +458,7 @@ tape( 'the function supports ndarrays having negative strides', function test( t 1.0, 2.0 // 0 ]); - y = vector( ybuf, 2, -2, 2 ); + y = vector( ybuf, 3, -2, 4 ); alpha = scalar2ndarray( new Complex64( 2.0, 0.0 ), { 'dtype': 'complex64' @@ -343,9 +467,13 @@ tape( 'the function supports ndarrays having negative strides', function test( t 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( str2enum( 'conjugate-transpose' ), { + 'dtype': 'int8' + }); - expected = new Complex64Array( [ -72.0, 436.0, 0.0, 0.0, -40.0, 180.0 ] ); + 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(); @@ -355,6 +483,7 @@ 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; @@ -416,7 +545,11 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t 'dtype': 'complex64' }); - v = cgemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( str2enum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = cgemv( [ A, x, y, trans, alpha, beta ] ); expected = new Complex64Array([ 0.0,