From dfa355dc2241326ca55bfd09134a4a6ea23a625d Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 15 Jun 2026 22:10:56 +0530 Subject: [PATCH 1/6] 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(); +}); From 9b5085650802e30d13d7f14e11b0f0b34cb284ad Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sun, 12 Jul 2026 21:52:56 +0530 Subject: [PATCH 2/6] feat: add ndarray/matrix/ctor and cleanup --- 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 | 58 +++--- .../base/ndarray/ggemv/benchmark/benchmark.js | 13 +- .../blas/base/ndarray/ggemv/docs/repl.txt | 48 +++-- .../base/ndarray/ggemv/docs/types/index.d.ts | 33 ++-- .../base/ndarray/ggemv/docs/types/test.ts | 10 +- .../blas/base/ndarray/ggemv/examples/index.js | 23 ++- .../blas/base/ndarray/ggemv/lib/index.js | 18 +- .../blas/base/ndarray/ggemv/lib/main.js | 60 ++++-- .../blas/base/ndarray/ggemv/package.json | 2 +- .../blas/base/ndarray/ggemv/test/test.js | 175 ++++++++++++++---- 10 files changed, 298 insertions(+), 142 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md index bb035beb1301..d6718bf4b74d 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md @@ -20,7 +20,7 @@ limitations under the License. # ggemv -> Perform the matrix-vector operation `y = alpha*A*x + beta*y`. +> Perform one of the matrix-vector operations `y = alpha*A*x + beta*y` or `y = alpha*A^T*x + beta*y`.
@@ -38,26 +38,31 @@ 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. +Performs one of the matrix-vector operations `y = alpha*A*x + beta*y` or `y = alpha*A^T*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 matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); -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 A = matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ], 'generic' ); var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); var y = vector( [ 4.0, 5.0 ], 'generic' ); -var alpha = scalar2ndarray( 3.0, { +var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, { 'dtype': 'generic' }); -var beta = scalar2ndarray( 2.0, { +var beta = scalar2ndarray( 1.0, { 'dtype': 'generic' }); -var out = ggemv( [ A, x, y, alpha, beta ] ); -// returns [ 50.0, 106.0 ] +var out = ggemv( [ A, x, y, trans, alpha, beta ] ); +// returns [ 18.0, 37.0 ] var bool = ( out === y ); // returns true @@ -67,11 +72,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. + - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. + - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`.
@@ -90,10 +96,12 @@ The function has the following parameters: ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +/* eslint-disable max-len */ +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); @@ -101,19 +109,17 @@ 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 A = matrix( ndarray2array( discreteUniform( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); +var x = vector( ndarray2array( discreteUniform( [ 4 ], 0, 10, opts ) ), 'generic' ); +var y = vector( ndarray2array( discreteUniform( [ 3 ], 0, 10, opts ) ), 'generic' ); -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 trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, opts ); +var beta = scalar2ndarray( 1.0, opts ); -var out = ggemv( [ A, x, y, alpha, beta ] ); +var out = ggemv( [ A, x, y, trans, 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 index 3bf4b5d0e2ba..1e25a8cf12b4 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/benchmark/benchmark.js @@ -25,6 +25,7 @@ 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 resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var ggemv = require( './../lib' ); @@ -47,18 +48,22 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { + var trans; var alpha; var beta; + var A; 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 ); + alpha = scalar2ndarray( 1.0, options ); + beta = scalar2ndarray( 1.0, options ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); return benchmark; @@ -74,7 +79,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - z = ggemv( [ A, x, y, alpha, beta ] ); + z = ggemv( [ 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/ggemv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt index 4e1f83b2cf7d..50d08645d0da 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt @@ -1,19 +1,23 @@ {{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` or + `y = alpha*A^T*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 specifying 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,18 +26,24 @@ 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 ] ); + > var abuf = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + > var A = {{alias:@stdlib/ndarray/matrix/ctor}}( abuf, 'generic' ); + + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var x = {{alias:@stdlib/ndarray/vector/ctor}}( xbuf, 'generic' ); + + > var ybuf = [ 4.0, 5.0 ]; + > var y = {{alias:@stdlib/ndarray/vector/ctor}}( ybuf, 'generic' ); + + > var opts = { 'dtype': 'generic' }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + + > var trans = {{alias:@stdlib/ndarray/from-scalar}}( 'no-transpose' ); + + > {{alias}}( [ A, x, y, trans, alpha, beta ] ); > y - [ 50.0, 106.0 ] + [ 18.0, 37.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 index b538b5f1beb6..4f424e48ff4e 100644 --- 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 @@ -20,47 +20,52 @@ /// -import { typedndarray } from '@stdlib/types/ndarray'; +import { typedndarray, ndarray } 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` or `y = alpha*A^T*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. +* - 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 matrix = require( '@stdlib/ndarray/matrix/ctor' ); * var vector = require( '@stdlib/ndarray/vector/ctor' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); * -* 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 A = matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ], 'generic' ); * var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var y = vector( [ 4.0, 5.0 ], 'generic' ); * -* var alpha = scalar2ndarray( 3.0, { +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); -* var beta = scalar2ndarray( 2.0, { +* var beta = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); * -* var z = ggemv( [ A, x, y, alpha, beta ] ); -* // returns [ 50.0, 106.0 ] +* var z = ggemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.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; +declare function ggemv = typedndarray, U extends typedndarray = typedndarray, V extends typedndarray = typedndarray>( arrays: [ T, U, V, ndarray, typedndarray, typedndarray ] ): V; // EXPORTS // 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 index 9ae79b687535..d9ef68af4f94 100644 --- 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 @@ -35,6 +35,9 @@ import ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); const y = zeros( [ 2 ], { 'dtype': 'generic' }); + const trans = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'generic' }); @@ -42,7 +45,7 @@ import ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); 'dtype': 'generic' }); - ggemv( [ A, x, y, alpha, beta ] ); // $ExpectType genericndarray + ggemv( [ A, x, y, trans, alpha, beta ] ); // $ExpectType genericndarray } // 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 ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); const y = zeros( [ 2 ], { 'dtype': 'generic' }); + const trans = zeros( [], { + 'dtype': 'int8' + }); const alpha = zeros( [], { 'dtype': 'generic' }); @@ -77,5 +83,5 @@ import ggemv = require( '@stdlib/blas/base/ndarray/ggemv' ); }); ggemv(); // $ExpectError - ggemv( [ A, x, y, alpha, beta ], {} ); // $ExpectError + ggemv( [ A, x, y, trans, 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 index f0c0c2d7b282..23b0c63698e4 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -19,9 +19,10 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ggemv = require( './../lib' ); @@ -29,17 +30,15 @@ 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 A = matrix( ndarray2array( discreteUniform( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); +var x = vector( ndarray2array( discreteUniform( [ 4 ], 0, 10, opts ) ), 'generic' ); +var y = vector( ndarray2array( discreteUniform( [ 3 ], 0, 10, opts ) ), 'generic' ); -var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); -console.log( ndarray2array( x ) ); +var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, opts ); +var beta = scalar2ndarray( 1.0, opts ); -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 ] ); +var out = ggemv( [ A, x, y, trans, 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 index ecae5858cd6d..0d9cb255269f 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/index.js @@ -19,29 +19,33 @@ '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` or `y = alpha*A^T*x + beta*y`. * * @module @stdlib/blas/base/ndarray/ggemv * * @example +* var matrix = require( '@stdlib/ndarray/matrix/ctor' ); * var vector = require( '@stdlib/ndarray/vector/ctor' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); * 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 A = matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ], 'generic' ); * var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var y = vector( [ 4.0, 5.0 ], 'generic' ); * -* var alpha = scalar2ndarray( 3.0, { +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); -* var beta = scalar2ndarray( 2.0, { +* var beta = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); * -* var out = ggemv( [ A, x, y, alpha, beta ] ); -* // returns [ 50.0, 106.0 ] +* var out = ggemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.0 ] * * var bool = ( out === y ); * // returns true 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 index 4f9837d9faae..7ecd6466efa7 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/lib/main.js @@ -20,7 +20,8 @@ // MODULES // -var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); var getStride = require( '@stdlib/ndarray/base/stride' ); var getOffset = require( '@stdlib/ndarray/base/offset' ); var getData = require( '@stdlib/ndarray/base/data-buffer' ); @@ -31,50 +32,71 @@ 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. +* Performs one of the matrix-vector operations `y = alpha*A*x + beta*y` or `y = alpha*A^T*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. +* - 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 matrix = require( '@stdlib/ndarray/matrix/ctor' ); * var vector = require( '@stdlib/ndarray/vector/ctor' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); * -* 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 A = matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ], 'generic' ); * var x = vector( [ 1.0, 2.0, 3.0 ], 'generic' ); * var y = vector( [ 4.0, 5.0 ], 'generic' ); * -* var alpha = scalar2ndarray( 3.0, { +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); -* var beta = scalar2ndarray( 2.0, { +* var beta = scalar2ndarray( 1.0, { * 'dtype': 'generic' * }); * -* var z = ggemv( [ A, x, y, alpha, beta ] ); -* // returns [ 50.0, 106.0 ] +* var z = ggemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.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 ) ); + var trans; + var alpha; + var beta; + var sh; + var st; + var A; + var x; + var y; + + A = arrays[ 0 ]; + x = arrays[ 1 ]; + y = arrays[ 2 ]; + + trans = ndarraylike2scalar( arrays[ 3 ] ); + alpha = ndarraylike2scalar( arrays[ 4 ] ); + beta = ndarraylike2scalar( arrays[ 5 ] ); + + sh = getShape( A, false ); + st = getStrides( A, false ); + + strided( trans, sh[ 0 ], sh[ 1 ], alpha, getData( A ), st[ 0 ], st[ 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/ggemv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json index 9db1a803f313..28c61878e34d 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/ndarray/ggemv", "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` or `y = alpha*A^T*x + beta*y`.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", 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 index b8ae5ad1e53b..c83d432671ba 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var isSameArray = require( '@stdlib/assert/is-same-array' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var getData = require( '@stdlib/ndarray/data-buffer' ); var ggemv = require( './../lib' ); @@ -76,6 +77,7 @@ tape( 'the function has an arity of 1', function test( t ) { tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y`', function test( t ) { var expected; + var trans; var alpha; var beta; var xbuf; @@ -86,8 +88,15 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y var A; var v; - xbuf = [ 1.0, 2.0 ]; - ybuf = [ 1.0, 2.0, 3.0 ]; + xbuf = [ + 1.0, // 0 + 2.0 // 1 + ]; + ybuf = [ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; 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 ); @@ -99,15 +108,26 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, 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 ]; + xbuf = [ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + ybuf = [ + 1.0, // 0 + 2.0 // 1 + ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; A = matrix( Abuf, 2, 3, 1, 2, 0 ); x = vector( xbuf, 3, 1, 0 ); y = vector( ybuf, 2, 1, 0 ); @@ -118,9 +138,58 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); - expected = [ 14.0, 32.0 ]; + expected = [ 46.0, 60.0 ]; + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A^T*x + beta*y`', function test( t ) { + var expected; + var trans; + var alpha; + var beta; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = [ + 1.0, // 0 + 2.0 // 1 + ]; + ybuf = [ + 1.0, // 0 + 2.0 // 1 + ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0 ]; + A = matrix( Abuf, 2, 2, 2, 1, 0 ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + alpha = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + beta = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); + + expected = [ 8.0, 12.0 ]; t.strictEqual( v, y, 'returns expected value' ); t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); @@ -129,6 +198,7 @@ tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { var expected; + var trans; var alpha; var beta; var xbuf; @@ -139,8 +209,15 @@ tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { var A; var v; - xbuf = [ 1.0, 2.0 ]; - ybuf = [ 3.0, 4.0, 5.0 ]; + xbuf = [ + 1.0, // 0 + 2.0 // 1 + ]; + ybuf = [ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; 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 ); @@ -152,17 +229,22 @@ tape( 'if `alpha` is `0`, the function returns `beta*y`', function test( t ) { 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); - expected = [ 6.0, 8.0, 10.0 ]; + expected = [ 2.0, 4.0, 6.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 ) { +tape( 'the function supports ndarrays having non-unit strides (transpose)', function test( t ) { var expected; + var trans; var alpha; var beta; var xbuf; @@ -173,24 +255,24 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t var A; var v; - Abuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; A = matrix( Abuf, 2, 3, 3, 1, 0 ); xbuf = [ 1.0, // 0 0.0, - 2.0, // 1 - 0.0, - 3.0 // 2 + 2.0 // 1 ]; - x = vector( xbuf, 3, 2, 0 ); + x = vector( xbuf, 2, 2, 0 ); ybuf = [ 1.0, // 0 0.0, - 2.0 // 1 + 2.0, // 1 + 0.0, + 3.0 // 2 ]; - y = vector( ybuf, 2, 2, 0 ); + y = vector( ybuf, 3, 2, 0 ); alpha = scalar2ndarray( 2.0, { 'dtype': 'generic' @@ -199,16 +281,21 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); - expected = [ 2.0, 0.0, 4.0 ]; + expected = [ 20.0, 0.0, 28.0, 0.0, 36.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 ) { +tape( 'the function supports ndarrays having negative strides (transpose)', function test( t ) { var expected; + var trans; var alpha; var beta; var xbuf; @@ -219,21 +306,24 @@ tape( 'the function supports ndarrays having negative strides', function test( t var A; var v; - Abuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + Abuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; A = matrix( Abuf, 2, 3, 3, 1, 0 ); xbuf = [ - 3.0, // 2 2.0, // 1 + 0.0, 1.0 // 0 ]; - x = vector( xbuf, 3, -1, 2 ); + x = vector( xbuf, 2, -2, 2 ); ybuf = [ + 3.0, // 2 + 0.0, 2.0, // 1 + 0.0, 1.0 // 0 ]; - y = vector( ybuf, 2, -1, 1 ); + y = vector( ybuf, 3, -2, 4 ); alpha = scalar2ndarray( 2.0, { 'dtype': 'generic' @@ -242,9 +332,13 @@ tape( 'the function supports ndarrays having negative strides', function test( t 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); - expected = [ 4.0, 2.0 ]; + expected = [ 36.0, 0.0, 28.0, 0.0, 20.0 ]; t.strictEqual( v, y, 'returns expected value' ); t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); t.end(); @@ -252,6 +346,7 @@ tape( 'the function supports ndarrays having negative strides', function test( t tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { var expected; + var trans; var alpha; var beta; var xbuf; @@ -263,14 +358,14 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t var v; Abuf = [ - 999.0, - 999.0, - 0.0, 0.0, 0.0, - 0.0, - 0.0, - 0.0 + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0 ]; A = matrix( Abuf, 2, 3, 3, 1, 2 ); @@ -298,13 +393,17 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t 'dtype': 'generic' }); - v = ggemv( [ A, x, y, alpha, beta ] ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = ggemv( [ A, x, y, trans, alpha, beta ] ); expected = [ 0.0, - 2.0, + 30.0, 0.0, - 4.0 + 68.0 ]; t.strictEqual( v, y, 'returns expected value' ); t.strictEqual( isSameArray( getData( v ), expected ), true, 'returns expected value' ); From babd34de98ecd3a5487c10a407a27cc2d6da108e Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sun, 12 Jul 2026 22:05:15 +0530 Subject: [PATCH 3/6] fix: import utility --- 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: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/ndarray/ggemv/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 23b0c63698e4..171cb130a326 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -18,7 +18,7 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); From b2407d69c79861c03ea3486d6d626f276a77b592 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 13 Jul 2026 16:10:42 +0530 Subject: [PATCH 4/6] fix: examples --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/ndarray/ggemv/README.md | 9 +++++---- .../@stdlib/blas/base/ndarray/ggemv/docs/repl.txt | 2 +- .../@stdlib/blas/base/ndarray/ggemv/examples/index.js | 9 +++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md index d6718bf4b74d..e82d216add35 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/README.md @@ -97,7 +97,8 @@ The function has the following parameters: ```javascript /* eslint-disable max-len */ -var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniformNd = require( '@stdlib/random/discrete-uniform' ); var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); @@ -109,9 +110,9 @@ var opts = { 'dtype': 'generic' }; -var A = matrix( ndarray2array( discreteUniform( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); -var x = vector( ndarray2array( discreteUniform( [ 4 ], 0, 10, opts ) ), 'generic' ); -var y = vector( ndarray2array( discreteUniform( [ 3 ], 0, 10, opts ) ), 'generic' ); +var A = matrix( ndarray2array( discreteUniformNd( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); +var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); +var y = vector( discreteUniform( 3, 0, 10, opts ), 'generic' ); var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { 'dtype': 'int8' 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 index 50d08645d0da..dedc96905fdf 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/docs/repl.txt @@ -13,7 +13,7 @@ - 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. + 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 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 index 171cb130a326..e865ef58fefe 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -18,7 +18,8 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniformNd = require( '@stdlib/random/discrete-uniform' ); var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); @@ -30,9 +31,9 @@ var opts = { 'dtype': 'generic' }; -var A = matrix( ndarray2array( discreteUniform( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); -var x = vector( ndarray2array( discreteUniform( [ 4 ], 0, 10, opts ) ), 'generic' ); -var y = vector( ndarray2array( discreteUniform( [ 3 ], 0, 10, opts ) ), 'generic' ); +var A = matrix( ndarray2array( discreteUniformNd( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); +var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); +var y = vector( discreteUniform( 3, 0, 10, opts ), 'generic' ); var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { 'dtype': 'int8' From 7c50676fcd78672b8d84bf626f26601c86780660 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 13 Jul 2026 16:23:05 +0530 Subject: [PATCH 5/6] Update lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js Signed-off-by: Kaustubh Patange --- .../@stdlib/blas/base/ndarray/ggemv/examples/index.js | 1 - 1 file changed, 1 deletion(-) 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 index e865ef58fefe..43c11c637f80 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -19,7 +19,6 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var discreteUniformNd = require( '@stdlib/random/discrete-uniform' ); var matrix = require( '@stdlib/ndarray/matrix/ctor' ); var vector = require( '@stdlib/ndarray/vector/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); From 6095160159e85dc45c0f595edf424ba21be632c6 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 13 Jul 2026 16:23:13 +0530 Subject: [PATCH 6/6] Update lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js Signed-off-by: Kaustubh Patange --- .../@stdlib/blas/base/ndarray/ggemv/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 43c11c637f80..7038217e29e1 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/ggemv/examples/index.js @@ -30,7 +30,7 @@ var opts = { 'dtype': 'generic' }; -var A = matrix( ndarray2array( discreteUniformNd( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); +var A = matrix( ndarray2array( discreteUniform( [ 3, 4 ], 0, 10, opts ) ), 'generic' ); var x = vector( discreteUniform( 4, 0, 10, opts ), 'generic' ); var y = vector( discreteUniform( 3, 0, 10, opts ), 'generic' );