diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/README.md new file mode 100644 index 000000000000..e171a4ed596a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/README.md @@ -0,0 +1,144 @@ + + +# sgemv + +> Perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`. + +
+ +
+ + + +
+ +## Usage + +```javascript +var sgemv = require( '@stdlib/blas/base/ndarray/sgemv' ); +``` + +#### sgemv( arrays ) + +Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. + +```javascript +/* eslint-disable max-len */ +var Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); + +var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] ); +var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +var y = new Float32Vector( [ 4.0, 5.0 ] ); + +var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, { + 'dtype': 'float32' +}); +var beta = scalar2ndarray( 1.0, { + 'dtype': 'float32' +}); + +var out = sgemv( [ A, x, y, trans, alpha, beta ] ); +// returns [ 18.0, 37.0 ] + +var bool = ( out === y ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a two-dimensional input ndarray corresponding to `A`. + - a one-dimensional input ndarray corresponding to `x`. + - a one-dimensional input/output ndarray corresponding to `y`. + - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. + - a zero-dimensional ndarray containing a scalar constant corresponding to `alpha`. + - a zero-dimensional ndarray containing a scalar constant corresponding to `beta`. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +/* eslint-disable max-len */ +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +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 sgemv = require( '@stdlib/blas/base/ndarray/sgemv' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new Float32Matrix( discreteUniform( 12, 0, 10, opts ).buffer, 0, [ 3, 4 ] ); +var x = new Float32Vector( discreteUniform( 4, 0, 10, opts ) ); +var y = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); + +var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, opts ); +var beta = scalar2ndarray( 1.0, opts ); + +var out = sgemv( [ A, x, y, trans, alpha, beta ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/benchmark/benchmark.js new file mode 100644 index 000000000000..951bfa6f02f8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/benchmark/benchmark.js @@ -0,0 +1,121 @@ +/** +* @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 isnanf = 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 sgemv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var trans; + var alpha; + var beta; + var A; + var x; + var y; + + 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( 1.0, options ); + beta = scalar2ndarray( 1.0, options ); + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = sgemv( [ A, x, y, trans, alpha, beta ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnanf( 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/sgemv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/repl.txt new file mode 100644 index 000000000000..d39d313bfa82 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( arrays ) + Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, + `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` + and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` + is an `M` by `N` matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a two-dimensional input ndarray corresponding to `A`. + - a one-dimensional input ndarray corresponding to `x`. + - a one-dimensional input/output ndarray corresponding to `y`. + - a zero-dimensional ndarray 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 + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var abuf = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + > var A = new {{alias:@stdlib/ndarray/matrix/float32}}( abuf ); + + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/float32}}( xbuf ); + + > var ybuf = [ 4.0, 5.0 ]; + > var y = new {{alias:@stdlib/ndarray/vector/float32}}( ybuf ); + + > var opts = { 'dtype': 'float32' }; + > 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 + [ 18.0, 37.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/index.d.ts new file mode 100644 index 000000000000..9b958758c722 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/index.d.ts @@ -0,0 +1,73 @@ +/* +* @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 { float32ndarray, ndarray } from '@stdlib/types/ndarray'; + +/** +* Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray corresponding to `A`. +* - a one-dimensional input ndarray corresponding to `x`. +* - a one-dimensional input/output ndarray corresponding to `y`. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. +* - 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 Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] ); +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Vector( [ 4.0, 5.0 ] ); +* +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* var beta = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* +* var z = sgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +declare function sgemv( arrays: [ float32ndarray, float32ndarray, float32ndarray, ndarray, float32ndarray, float32ndarray ] ): float32ndarray; + + +// EXPORTS // + +export = sgemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/test.ts new file mode 100644 index 000000000000..9ccf9c531ed9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/docs/types/test.ts @@ -0,0 +1,87 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import sgemv = require( '@stdlib/blas/base/ndarray/sgemv' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const A = zeros( [ 2, 3 ], { + 'dtype': 'float32' + }); + const x = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const y = zeros( [ 2 ], { + 'dtype': 'float32' + }); + const trans = zeros( [], { + 'dtype': 'int8' + }); + const alpha = zeros( [], { + 'dtype': 'float32' + }); + const beta = zeros( [], { + 'dtype': 'float32' + }); + + sgemv( [ A, x, y, trans, alpha, beta ] ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + sgemv( '10' ); // $ExpectError + sgemv( 10 ); // $ExpectError + sgemv( true ); // $ExpectError + sgemv( false ); // $ExpectError + sgemv( null ); // $ExpectError + sgemv( undefined ); // $ExpectError + sgemv( [] ); // $ExpectError + sgemv( {} ); // $ExpectError + sgemv( ( 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': 'float32' + }); + const x = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const y = zeros( [ 2 ], { + 'dtype': 'float32' + }); + const trans = zeros( [], { + 'dtype': 'int8' + }); + const alpha = zeros( [], { + 'dtype': 'float32' + }); + const beta = zeros( [], { + 'dtype': 'float32' + }); + + sgemv(); // $ExpectError + sgemv( [ A, x, y, trans, alpha, beta ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/examples/index.js new file mode 100644 index 000000000000..dbebec8ce589 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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 Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +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 sgemv = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var A = new Float32Matrix( discreteUniform( 12, 0, 10, opts ).buffer, 0, [ 3, 4 ] ); +var x = new Float32Vector( discreteUniform( 4, 0, 10, opts ) ); +var y = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); + +var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' +}); +var alpha = scalar2ndarray( 1.0, opts ); +var beta = scalar2ndarray( 1.0, opts ); + +var out = sgemv( [ A, x, y, trans, alpha, beta ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/lib/index.js new file mode 100644 index 000000000000..6d6b71043b27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 2 routine to perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`. +* +* @module @stdlib/blas/base/ndarray/sgemv +* +* @example +* var Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* var sgemv = require( '@stdlib/blas/base/ndarray/sgemv' ); +* +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] ); +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Vector( [ 4.0, 5.0 ] ); +* +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* var beta = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* +* var out = sgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.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/sgemv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/lib/main.js new file mode 100644 index 000000000000..987fe09b0d81 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/lib/main.js @@ -0,0 +1,106 @@ +/** +* @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 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' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/base/sgemv' ).ndarray; + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`, where `alpha` and `beta` are scalars, `x` and `y` are one-dimensional ndarrays, and `A` is an `M` by `N` matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a two-dimensional input ndarray corresponding to `A`. +* - a one-dimensional input ndarray corresponding to `x`. +* - a one-dimensional input/output ndarray corresponding to `y`. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. +* - 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 Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveEnum = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] ); +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Vector( [ 4.0, 5.0 ] ); +* +* var trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { +* 'dtype': 'int8' +* }); +* var alpha = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* var beta = scalar2ndarray( 1.0, { +* 'dtype': 'float32' +* }); +* +* var z = sgemv( [ A, x, y, trans, alpha, beta ] ); +* // returns [ 18.0, 37.0 ] +* +* var bool = ( z === y ); +* // returns true +*/ +function sgemv( arrays ) { + 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; +} + + +// EXPORTS // + +module.exports = sgemv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/package.json new file mode 100644 index 000000000000..bb620c8ab2eb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/sgemv", + "version": "0.0.0", + "description": "Perform one of the matrix-vector operations `y = alpha*A*x + beta*y`, `y = alpha*A^T*x + beta*y`, or `y = alpha*A^H*x + beta*y`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 2", + "sgemv", + "linear", + "algebra", + "subroutines", + "matrix-vector", + "multiply", + "vector", + "matrix", + "array", + "ndarray", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/test/test.js new file mode 100644 index 000000000000..fe81627296d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/sgemv/test/test.js @@ -0,0 +1,457 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float32Array = require( '@stdlib/array/float32' ); +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 sgemv = 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( 'float32', 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( 'float32', 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 sgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( sgemv.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 trans; + var alpha; + var beta; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + ybuf = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]); + Abuf = new Float32Array( [ 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': 'float32' + }); + beta = scalar2ndarray( 1.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 6.0, 13.0, 20.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + xbuf = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]); + ybuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + Abuf = new Float32Array( [ 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 ); + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 46.0, 60.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( 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 = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + ybuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + Abuf = new Float32Array( [ 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': 'float32' + }); + beta = scalar2ndarray( 1.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 8.0, 12.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A^H*x + beta*y`', function test( t ) { + var expected; + var trans; + var alpha; + var beta; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + ybuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + Abuf = new Float32Array( [ 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': 'float32' + }); + beta = scalar2ndarray( 1.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'conjugate-transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 8.0, 12.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( 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 trans; + var alpha; + var beta; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + xbuf = new Float32Array([ + 1.0, // 0 + 2.0 // 1 + ]); + ybuf = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]); + Abuf = new Float32Array( [ 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': 'float32' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-unit strides (transpose)', function test( t ) { + var expected; + var trans; + var alpha; + var beta; + var xbuf; + var ybuf; + var Abuf; + var x; + var y; + var A; + var v; + + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]); + x = vector( xbuf, 2, 2, 0 ); + + ybuf = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + y = vector( ybuf, 3, 2, 0 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 20.0, 0.0, 28.0, 0.0, 36.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides (transpose)', 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; + + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + A = matrix( Abuf, 2, 3, 3, 1, 0 ); + + xbuf = new Float32Array([ + 2.0, // 1 + 0.0, + 1.0 // 0 + ]); + x = vector( xbuf, 2, -2, 2 ); + + ybuf = new Float32Array([ + 3.0, // 2 + 0.0, + 2.0, // 1 + 0.0, + 1.0 // 0 + ]); + y = vector( ybuf, 3, -2, 4 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array( [ 36.0, 0.0, 28.0, 0.0, 20.0 ] ); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', 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; + + Abuf = new Float32Array([ + 0.0, + 0.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0 + ]); + A = matrix( Abuf, 2, 3, 3, 1, 2 ); + + xbuf = new Float32Array([ + 0.0, + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]); + x = vector( xbuf, 3, 1, 2 ); + + ybuf = new Float32Array([ + 0.0, + 1.0, // 0 + 0.0, + 2.0 // 1 + ]); + y = vector( ybuf, 2, 2, 1 ); + + alpha = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + beta = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + + trans = scalar2ndarray( resolveEnum( 'no-transpose' ), { + 'dtype': 'int8' + }); + + v = sgemv( [ A, x, y, trans, alpha, beta ] ); + + expected = new Float32Array([ + 0.0, + 30.0, + 0.0, + 68.0 + ]); + t.strictEqual( v, y, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});