From 93aaf610947596699bf233854707a2b90a94a807 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 22 Jun 2026 22:49:50 +0530 Subject: [PATCH] feat: add blas/base/ndarray/strmv --- 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/strmv/README.md | 118 +++++++++++ .../base/ndarray/strmv/benchmark/benchmark.js | 108 ++++++++++ .../blas/base/ndarray/strmv/docs/repl.txt | 34 +++ .../base/ndarray/strmv/docs/types/index.d.ts | 57 +++++ .../base/ndarray/strmv/docs/types/test.ts | 63 ++++++ .../blas/base/ndarray/strmv/examples/index.js | 36 ++++ .../blas/base/ndarray/strmv/lib/index.js | 49 +++++ .../blas/base/ndarray/strmv/lib/main.js | 69 ++++++ .../blas/base/ndarray/strmv/package.json | 72 +++++++ .../blas/base/ndarray/strmv/test/test.js | 198 ++++++++++++++++++ 10 files changed, 804 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strmv/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/README.md new file mode 100644 index 000000000000..542754789977 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/README.md @@ -0,0 +1,118 @@ + + +# strmv + +> Perform one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var strmv = require( '@stdlib/blas/base/ndarray/strmv' ); +``` + +#### strmv( arrays ) + +Perform one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. + +```javascript +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strmv( [ x, A ] ); +// x => [ 14.0, 8.0, 3.0 ] + +var bool = ( out === x ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional input ndarray. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var strmv = require( '@stdlib/blas/base/ndarray/strmv' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strmv( [ x, A ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/benchmark/benchmark.js new file mode 100644 index 000000000000..5c6c26d6e936 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @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 ones = require( '@stdlib/ndarray/ones' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var strmv = 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 x; + var A; + + x = ones( [ len ], options ); + A = ones( [ len, len ], 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 = strmv( [ x, A ] ); + 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/strmv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/repl.txt new file mode 100644 index 000000000000..ee71b50b60ef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( arrays ) + Perform one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where + `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, + upper or lower triangular matrix. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional input ndarray. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float32}}( [ 1.0, 2.0 ] ); + > var buf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 0.0, 1.0 ] ); + > var sh = [ 2, 2 ]; + > var st = [ 2, 1 ]; + > var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'float32', buf, sh, st, 0, 'row-major' ); + + > {{alias}}( [ x, A ] ); + > x + [ 5.0, 2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/index.d.ts new file mode 100644 index 000000000000..f99cb5e59545 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional input ndarray. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strmv( [ x, A ] ); +* // returns [ 14.0, 8.0, 3.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +declare function strmv( arrays: [ float32ndarray, float32ndarray ] ): float32ndarray; + + +// EXPORTS // + +export = strmv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/test.ts new file mode 100644 index 000000000000..276b9ec2a5c8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/docs/types/test.ts @@ -0,0 +1,63 @@ +/* +* @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 strmv = require( '@stdlib/blas/base/ndarray/strmv' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const A = zeros( [ 3, 3 ], { + 'dtype': 'float32' + }); + + strmv( [ x, A ] ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + strmv( '10' ); // $ExpectError + strmv( 10 ); // $ExpectError + strmv( true ); // $ExpectError + strmv( false ); // $ExpectError + strmv( null ); // $ExpectError + strmv( undefined ); // $ExpectError + strmv( [] ); // $ExpectError + strmv( {} ); // $ExpectError + strmv( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const A = zeros( [ 3, 3 ], { + 'dtype': 'float32' + }); + + strmv(); // $ExpectError + strmv( [ x, A ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/examples/index.js new file mode 100644 index 000000000000..c27ba14ae694 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var strmv = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strmv( [ x, A ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/index.js new file mode 100644 index 000000000000..82cae5d294b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 2 routine to perform one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* +* @module @stdlib/blas/base/ndarray/strmv +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* var strmv = require( '@stdlib/blas/base/ndarray/strmv' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strmv( [ x, A ] ); +* // returns [ 14.0, 8.0, 3.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/main.js new file mode 100644 index 000000000000..6437c189ff0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/lib/main.js @@ -0,0 +1,69 @@ +/** +* @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 strided = require( '@stdlib/blas/base/strmv' ).ndarray; + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional input ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strmv( [ x, A ] ); +* // returns [ 14.0, 8.0, 3.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +function strmv( arrays ) { + var x = arrays[ 0 ]; + var A = arrays[ 1 ]; + strided( 'upper', 'no-transpose', 'non-unit', numelDimension( A, 0 ), getData( A ), getStride( A, 0 ), getStride( A, 1 ), getOffset( A ), getData( x ), getStride( x, 0 ), getOffset( x ) ); + return x; +} + + +// EXPORTS // + +module.exports = strmv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/package.json new file mode 100644 index 000000000000..810fb0bcad88 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/strmv", + "version": "0.0.0", + "description": "Perform one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element ndarray and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.", + "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", + "strmv", + "linear", + "algebra", + "subroutines", + "triangular", + "multiplication", + "vector", + "matrix", + "array", + "ndarray", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strmv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/test/test.js new file mode 100644 index 000000000000..203e67ade4bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strmv/test/test.js @@ -0,0 +1,198 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var strmv = 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} N - number of rows and 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, N, stride0, stride1, offset ) { + return new ndarray( 'float32', buffer, [ N, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof strmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( strmv.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `x = A*x`', function test( t ) { + var expected; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strmv( [ x, A ] ); + + expected = new Float32Array( [ 14.0, 28.0, 27.0 ] ); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-unit strides', function test( t ) { + var expected; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strmv( [ x, A ] ); + + expected = new Float32Array( [ 14.0, 0.0, 28.0, 0.0, 27.0 ] ); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides', function test( t ) { + var expected; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array([ + 3.0, // 2 + 2.0, // 1 + 1.0 // 0 + ]); + x = vector( xbuf, 3, -1, 2 ); + + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strmv( [ x, A ] ); + + expected = new Float32Array( [ 27.0, 28.0, 14.0 ] ); + t.strictEqual( v, x, '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 xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array([ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + x = vector( xbuf, 3, 2, 1 ); + + Abuf = new Float32Array([ + 999.0, + 999.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0 + ]); + A = matrix( Abuf, 3, 3, 1, 2 ); + + v = strmv( [ x, A ] ); + + expected = new Float32Array([ + 0.0, + 14.0, + 0.0, + 28.0, + 0.0, + 27.0 + ]); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});