From dfa355dc2241326ca55bfd09134a4a6ea23a625d Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 15 Jun 2026 22:10:56 +0530 Subject: [PATCH] feat: add blas/base/ndarray/gemv --- 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/ggemv/README.md | 138 ++++++++ .../base/ndarray/ggemv/benchmark/benchmark.js | 116 +++++++ .../blas/base/ndarray/ggemv/docs/repl.txt | 40 +++ .../base/ndarray/ggemv/docs/types/index.d.ts | 68 ++++ .../base/ndarray/ggemv/docs/types/test.ts | 81 +++++ .../blas/base/ndarray/ggemv/examples/index.js | 45 +++ .../blas/base/ndarray/ggemv/lib/index.js | 57 ++++ .../blas/base/ndarray/ggemv/lib/main.js | 84 +++++ .../blas/base/ndarray/ggemv/package.json | 72 ++++ .../blas/base/ndarray/ggemv/test/test.js | 312 ++++++++++++++++++ 10 files changed, 1013 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md new file mode 100644 index 000000000000..bb035beb1301 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md @@ -0,0 +1,138 @@ + + +# ggemv + +> Perform the matrix-vector operation `y = alpha*A*x + beta*y`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); +``` + +#### ggemv( 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 vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var A = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); +var y = vector( [ 4.0, 5.0 ], 'generic' ); + +var alpha = scalar2ndarray( 3.0, { + 'dtype': 'generic' +}); +var beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' +}); + +var out = ggemv( [ A, x, y, alpha, beta ] ); +// returns [ 50.0, 106.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 vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); + +var opts = { + 'dtype': 'generic' +}; + +var A = new ndarray( 'generic', discreteUniform( 12, 0, 10, opts ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +console.log( ndarray2array( A ) ); + +var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); +console.log( ndarray2array( x ) ); + +var y = vector( discreteUniform( 3, 0, 10, opts ), 'generic' ); +console.log( ndarray2array( y ) ); + +var alpha = scalar2ndarray( 3.0, opts ); +var beta = scalar2ndarray( 2.0, opts ); + +var out = ggemv( [ A, x, y, alpha, beta ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js new file mode 100644 index 000000000000..3bf4b5d0e2ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js @@ -0,0 +1,116 @@ +/** +* @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/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ggemv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var beta; + var x; + var y; + var A; + + A = uniform( [ len, len ], -100.0, 100.0, options ); + x = uniform( [ len ], -100.0, 100.0, options ); + y = uniform( [ len ], -100.0, 100.0, options ); + + alpha = scalar2ndarray( 3.0, options ); + beta = scalar2ndarray( 2.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 = ggemv( [ A, x, y, alpha, beta ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( 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/ggemv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt new file mode 100644 index 000000000000..4e1f83b2cf7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt @@ -0,0 +1,40 @@ + +{{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 buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var sh = [ 2, 3 ]; + > var st = [ 3, 1 ]; + > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'generic', buf, sh, st, 0, 'row-major' ); + > var x = {{alias:@stdlib/ndarray/vector/ctor}}( [ 1.0, 2.0, 3.0 ], 'generic' ); + > var y = {{alias:@stdlib/ndarray/vector/ctor}}( [ 4.0, 5.0 ], 'generic' ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 3.0, { 'dtype': 'generic' }); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'generic' }); + + > {{alias}}( [ A, x, y, alpha, beta ] ); + > y + [ 50.0, 106.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/index.d.ts new file mode 100644 index 000000000000..b538b5f1beb6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/index.d.ts @@ -0,0 +1,68 @@ +/* +* @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 { typedndarray } 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 vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var A = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); +* var y = vector( [ 4.0, 5.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 3.0, { +* 'dtype': 'generic' +* }); +* var beta = scalar2ndarray( 2.0, { +* 'dtype': 'generic' +* }); +* +* var z = ggemv( [ A, x, y, alpha, beta ] ); +* // returns [ 50.0, 106.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +declare function ggemv = typedndarray, U extends typedndarray = typedndarray, V extends typedndarray = typedndarray>( arrays: [ T, U, V, typedndarray, typedndarray ] ): V; + + +// EXPORTS // + +export = ggemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/types/test.ts new file mode 100644 index 000000000000..9ae79b687535 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/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 ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const A = zeros( [ 2, 3 ], { + 'dtype': 'generic' + }); + const x = zeros( [ 3 ], { + 'dtype': 'generic' + }); + const y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + const alpha = zeros( [], { + 'dtype': 'generic' + }); + const beta = zeros( [], { + 'dtype': 'generic' + }); + + ggemv( [ A, x, y, alpha, beta ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + ggemv( '10' ); // $ExpectError + ggemv( 10 ); // $ExpectError + ggemv( true ); // $ExpectError + ggemv( false ); // $ExpectError + ggemv( null ); // $ExpectError + ggemv( undefined ); // $ExpectError + ggemv( [] ); // $ExpectError + ggemv( {} ); // $ExpectError + ggemv( ( 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': 'generic' + }); + const x = zeros( [ 3 ], { + 'dtype': 'generic' + }); + const y = zeros( [ 2 ], { + 'dtype': 'generic' + }); + const alpha = zeros( [], { + 'dtype': 'generic' + }); + const beta = zeros( [], { + 'dtype': 'generic' + }); + + ggemv(); // $ExpectError + ggemv( [ A, x, y, alpha, beta ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js new file mode 100644 index 000000000000..f0c0c2d7b282 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -0,0 +1,45 @@ +/** +* @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 vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ggemv = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var A = new ndarray( 'generic', discreteUniform( 12, 0, 10, opts ), [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); +console.log( ndarray2array( A ) ); + +var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); +console.log( ndarray2array( x ) ); + +var y = vector( discreteUniform( 3, 0, 10, opts ), 'generic' ); +console.log( ndarray2array( y ) ); + +var alpha = scalar2ndarray( 3.0, opts ); +var beta = scalar2ndarray( 2.0, opts ); + +var out = ggemv( [ A, x, y, alpha, beta ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js new file mode 100644 index 000000000000..ecae5858cd6d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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/ggemv +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); +* +* var A = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); +* var y = vector( [ 4.0, 5.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 3.0, { +* 'dtype': 'generic' +* }); +* var beta = scalar2ndarray( 2.0, { +* 'dtype': 'generic' +* }); +* +* var out = ggemv( [ A, x, y, alpha, beta ] ); +* // returns [ 50.0, 106.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/ggemv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/main.js new file mode 100644 index 000000000000..4f9837d9faae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/main.js @@ -0,0 +1,84 @@ +/** +* @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/ggemv' ).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 vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var A = new ndarray( 'generic', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); +* var y = vector( [ 4.0, 5.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 3.0, { +* 'dtype': 'generic' +* }); +* var beta = scalar2ndarray( 2.0, { +* 'dtype': 'generic' +* }); +* +* var z = ggemv( [ A, x, y, alpha, beta ] ); +* // returns [ 50.0, 106.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +function ggemv( 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 = ggemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json new file mode 100644 index 000000000000..9db1a803f313 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/ggemv", + "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", + "ggemv", + "linear", + "algebra", + "subroutines", + "matrix-vector", + "multiply", + "vector", + "matrix", + "array", + "ndarray", + "typedndarray", + "generic", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js new file mode 100644 index 000000000000..b8ae5ad1e53b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js @@ -0,0 +1,312 @@ +/** +* @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 isSameArray = require( '@stdlib/assert/is-same-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ggemv = 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( 'generic', 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( 'generic', 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 ggemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( ggemv.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 = [ 1.0, 2.0 ]; + ybuf = [ 1.0, 2.0, 3.0 ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + A = matrix( Abuf, 3, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ 6.0, 13.0, 20.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 1.0, 1.0 ]; + ybuf = [ 1.0, 1.0 ]; + Abuf = [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ]; + A = matrix( Abuf, 2, 3, 1, 2, 0 ); + x = vector( xbuf, 3, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ 14.0, 32.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( 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 = [ 1.0, 2.0 ]; + ybuf = [ 3.0, 4.0, 5.0 ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + A = matrix( Abuf, 3, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ 6.0, 8.0, 10.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( 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 = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]; + x = vector( xbuf, 3, 2, 0 ); + + ybuf = [ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + y = vector( ybuf, 2, 2, 0 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ 2.0, 0.0, 4.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( 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 = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = [ + 3.0, // 2 + 2.0, // 1 + 1.0 // 0 + ]; + x = vector( xbuf, 3, -1, 2 ); + + ybuf = [ + 2.0, // 1 + 1.0 // 0 + ]; + y = vector( ybuf, 2, -1, 1 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ 4.0, 2.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( 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 = [ + 999.0, + 999.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + A = matrix( Abuf, 2, 3, 3, 1, 2 ); + + xbuf = [ + 0.0, + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + x = vector( xbuf, 3, 1, 2 ); + + ybuf = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + y = vector( ybuf, 2, 2, 1 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'generic' + }); + + v = ggemv( [ A, x, y, alpha, beta ] ); + + expected = [ + 0.0, + 2.0, + 0.0, + 4.0 + ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});