From c36a7b7626d163e930ec89f66815b77e0eedc860 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 23 Jun 2026 00:04:28 +0530 Subject: [PATCH 1/2] feat: add blas/base/ndarray/strsv --- 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/strsv/README.md | 118 +++++++++++ .../base/ndarray/strsv/benchmark/benchmark.js | 109 ++++++++++ .../blas/base/ndarray/strsv/docs/repl.txt | 34 +++ .../base/ndarray/strsv/docs/types/index.d.ts | 57 +++++ .../base/ndarray/strsv/docs/types/test.ts | 63 ++++++ .../blas/base/ndarray/strsv/examples/index.js | 36 ++++ .../blas/base/ndarray/strsv/lib/index.js | 49 +++++ .../blas/base/ndarray/strsv/lib/main.js | 69 ++++++ .../blas/base/ndarray/strsv/package.json | 72 +++++++ .../blas/base/ndarray/strsv/test/test.js | 198 ++++++++++++++++++ 10 files changed, 805 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md new file mode 100644 index 000000000000..24a15fdb5915 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md @@ -0,0 +1,118 @@ + + +# strsv + +> Solve one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var strsv = require( '@stdlib/blas/base/ndarray/strsv' ); +``` + +#### strsv( arrays ) + +Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strsv( [ x, A ] ); +// x => [ -0.25, -0.125, 0.5 ] + +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 strsv = require( '@stdlib/blas/base/ndarray/strsv' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 1, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strsv( [ x, A ] ); +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js new file mode 100644 index 000000000000..d665d1abc705 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @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 zeros = require( '@stdlib/ndarray/zeros' ); +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 strsv = 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 = zeros( [ len ], options ); + A = uniform( [ len, len ], -100.0, 100.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 = strsv( [ 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/strsv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt new file mode 100644 index 000000000000..1854fe779ec6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( arrays ) + Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` + and `x` are `N` element ndarrays 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 + [ -3.0, 2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts new file mode 100644 index 000000000000..e420de8b7732 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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'; + +/** +* Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strsv( [ x, A ] ); +* // returns [ -0.25, -0.125, 0.5 ] +* +* var bool = ( out === x ); +* // returns true +*/ +declare function strsv( arrays: [ float32ndarray, float32ndarray ] ): float32ndarray; + + +// EXPORTS // + +export = strsv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts new file mode 100644 index 000000000000..5e2c50478a00 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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 strsv = require( '@stdlib/blas/base/ndarray/strsv' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 3 ], { + 'dtype': 'float32' + }); + const A = zeros( [ 3, 3 ], { + 'dtype': 'float32' + }); + + strsv( [ x, A ] ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + strsv( '10' ); // $ExpectError + strsv( 10 ); // $ExpectError + strsv( true ); // $ExpectError + strsv( false ); // $ExpectError + strsv( null ); // $ExpectError + strsv( undefined ); // $ExpectError + strsv( [] ); // $ExpectError + strsv( {} ); // $ExpectError + strsv( ( 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' + }); + + strsv(); // $ExpectError + strsv( [ x, A ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js new file mode 100644 index 000000000000..c96fb516d08d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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 strsv = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); +var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 1, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); + +var out = strsv( [ x, A ] ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js new file mode 100644 index 000000000000..9681afbb9d70 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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 solve one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* +* @module @stdlib/blas/base/ndarray/strsv +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var Float32Array = require( '@stdlib/array/float32' ); +* var strsv = require( '@stdlib/blas/base/ndarray/strsv' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); +* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strsv( [ x, A ] ); +* // returns [ -0.25, -0.125, 0.5 ] +* +* 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/strsv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js new file mode 100644 index 000000000000..394fd02fcd6b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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/strsv' ).ndarray; + + +// MAIN // + +/** +* Solves one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* +* var out = strsv( [ x, A ] ); +* // returns [ -0.25, -0.125, 0.5 ] +* +* var bool = ( out === x ); +* // returns true +*/ +function strsv( 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 = strsv; diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json new file mode 100644 index 000000000000..c13d82af745b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/base/ndarray/strsv", + "version": "0.0.0", + "description": "Solve one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays 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", + "strsv", + "linear", + "algebra", + "subroutines", + "triangular", + "solve", + "vector", + "matrix", + "array", + "ndarray", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js new file mode 100644 index 000000000000..87a0eafb8e0a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/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 strsv = 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 strsv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( strsv.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function solves the system of equations `A*x = b`', 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strsv( [ x, A ] ); + + expected = new Float32Array( [ -0.25, -0.125, 0.5 ] ); + 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strsv( [ x, A ] ); + + expected = new Float32Array( [ -0.25, 0.0, -0.125, 0.0, 0.5 ] ); + 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + v = strsv( [ x, A ] ); + + expected = new Float32Array( [ 0.5, -0.125, -0.25 ] ); + 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, + 0.0, + 4.0, + 5.0, + 0.0, + 0.0, + 6.0 + ]); + A = matrix( Abuf, 3, 3, 1, 2 ); + + v = strsv( [ x, A ] ); + + expected = new Float32Array([ + 0.0, + -0.25, + 0.0, + -0.125, + 0.0, + 0.5 + ]); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); From 14c9a1c7826476af0c7435d71e41a42a7ab1a54c Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sat, 18 Jul 2026 11:14:22 +0530 Subject: [PATCH 2/2] feat: add float32Matrix 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/strsv/README.md | 60 ++++-- .../base/ndarray/strsv/benchmark/benchmark.js | 16 +- .../blas/base/ndarray/strsv/docs/repl.txt | 30 ++- .../base/ndarray/strsv/docs/types/index.d.ts | 34 +++- .../base/ndarray/strsv/docs/types/test.ts | 22 ++- .../blas/base/ndarray/strsv/examples/index.js | 22 ++- .../blas/base/ndarray/strsv/lib/index.js | 25 ++- .../blas/base/ndarray/strsv/lib/main.js | 60 ++++-- .../blas/base/ndarray/strsv/package.json | 2 +- .../blas/base/ndarray/strsv/test/test.js | 171 +++++++++++++++++- 10 files changed, 374 insertions(+), 68 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md index 24a15fdb5915..d9cb6367cb23 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/README.md @@ -20,7 +20,7 @@ limitations under the License. # strsv -> Solve one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +> Solve one of the systems of equations `A*x = b` or `A^T*x = b` for a triangular matrix `A`.
@@ -38,17 +38,32 @@ var strsv = require( '@stdlib/blas/base/ndarray/strsv' ); #### strsv( arrays ) -Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are one-dimensional ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. + + ```javascript +var Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); -var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); - -var out = strsv( [ x, A ] ); +var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 0.0, 4.0, 5.0 ], [ 0.0, 0.0, 6.0 ] ] ); + +var uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' +}); +var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' +}); +var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' +}); + +var out = strsv( [ x, A, uplo, trans, diag ] ); // x => [ -0.25, -0.125, 0.5 ] var bool = ( out === x ); @@ -59,8 +74,11 @@ The function has the following parameters: - **arrays**: array-like object containing the following ndarrays: - - a one-dimensional input ndarray. - - a two-dimensional input ndarray. + - a one-dimensional input/output ndarray corresponding to `x`. + - a two-dimensional input ndarray corresponding to `A`. + - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. + - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. + - a zero-dimensional ndarray specifying whether `A` has a unit or non-unit diagonal.
@@ -76,24 +94,34 @@ The function has the following parameters: ## 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 discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var strsv = require( '@stdlib/blas/base/ndarray/strsv' ); var opts = { 'dtype': 'float32' }; +var eopts = { + 'dtype': 'int32' +}; + +var x = discreteUniform( [ 3 ], 0, 10, opts ); +var A = discreteUniform( [ 3, 3 ], 0, 10, opts ); -var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); -var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 1, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +var uplo = scalar2ndarray( resolveTriangle( 'upper' ), eopts ); +var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), eopts ); +var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), eopts ); -var out = strsv( [ x, A ] ); +var out = strsv( [ x, A, uplo, trans, diag ] ); console.log( ndarray2array( out ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js index d665d1abc705..7b850517c7ce 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/benchmark/benchmark.js @@ -25,6 +25,10 @@ var uniform = require( '@stdlib/random/uniform' ); var zeros = require( '@stdlib/ndarray/zeros' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var strsv = require( './../lib' ); @@ -35,6 +39,9 @@ var strsv = require( './../lib' ); var options = { 'dtype': 'float32' }; +var eopts = { + 'dtype': 'int32' +}; // FUNCTIONS // @@ -47,12 +54,19 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { + var trans; + var diag; + var uplo; var x; var A; x = zeros( [ len ], options ); A = uniform( [ len, len ], -100.0, 100.0, options ); + uplo = scalar2ndarray( resolveTriangle( 'upper' ), eopts ); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), eopts ); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), eopts ); + return benchmark; /** @@ -67,7 +81,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - z = strsv( [ x, A ] ); + z = strsv( [ x, A, uplo, trans, diag ] ); if ( typeof z !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt index 1854fe779ec6..cfc27520574d 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` - and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or + and `x` are one-dimensional ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. Parameters @@ -9,8 +9,14 @@ arrays: ArrayLikeObject Array-like object containing the following ndarrays: - - a one-dimensional input ndarray. - - a two-dimensional input ndarray. + - a one-dimensional input/output ndarray corresponding to `x`. + - a two-dimensional input ndarray corresponding to `A`. + - a zero-dimensional ndarray specifying whether the upper or lower + triangular part of `A` should be referenced. + - a zero-dimensional ndarray specifying whether `A` should be + transposed, conjugate-transposed, or not transposed. + - a zero-dimensional ndarray specifying whether `A` has a unit or non- + unit diagonal. Returns ------- @@ -19,15 +25,19 @@ 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' ); + > var xbuf = [ 1.0, 2.0, 3.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/float32}}( xbuf ); - > {{alias}}( [ x, A ] ); + > var abuf = [ [ 1.0, 2.0, 3.0 ], [ 0.0, 4.0, 5.0 ], [ 0.0, 0.0, 6.0 ] ]; + > var A = new {{alias:@stdlib/ndarray/matrix/float32}}( abuf ); + + > var uplo = {{alias:@stdlib/ndarray/from-scalar}}( 'upper' ); + > var trans = {{alias:@stdlib/ndarray/from-scalar}}( 'no-transpose' ); + > var diag = {{alias:@stdlib/ndarray/from-scalar}}( 'non-unit' ); + + > {{alias}}( [ x, A, uplo, trans, diag ] ); > x - [ -3.0, 2.0 ] + [ -0.25, -0.125, 0.5 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts index e420de8b7732..48582a4b98ca 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/index.d.ts @@ -20,36 +20,52 @@ /// -import { float32ndarray } from '@stdlib/types/ndarray'; +import { float32ndarray, ndarray } from '@stdlib/types/ndarray'; /** -* Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are one-dimensional ndarrays 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. +* - a one-dimensional input/output ndarray corresponding to `x`. +* - a two-dimensional input ndarray corresponding to `A`. +* - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. +* - a zero-dimensional ndarray specifying whether `A` has a unit or non-unit diagonal. * * @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float32Array = require( '@stdlib/array/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +* var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); * * var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 0.0, 4.0, 5.0 ], [ 0.0, 0.0, 6.0 ] ] ); * -* var out = strsv( [ x, A ] ); +* var uplo = scalar2ndarray( resolveTriangle( 'upper' ), { +* 'dtype': 'int32' +* }); +* var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { +* 'dtype': 'int32' +* }); +* var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { +* 'dtype': 'int32' +* }); +* +* var out = strsv( [ x, A, uplo, trans, diag ] ); * // returns [ -0.25, -0.125, 0.5 ] * * var bool = ( out === x ); * // returns true */ -declare function strsv( arrays: [ float32ndarray, float32ndarray ] ): float32ndarray; +declare function strsv( arrays: [ float32ndarray, float32ndarray, ndarray, ndarray, ndarray ] ): float32ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts index 5e2c50478a00..f8768ae29fe1 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/docs/types/test.ts @@ -32,8 +32,17 @@ import strsv = require( '@stdlib/blas/base/ndarray/strsv' ); const A = zeros( [ 3, 3 ], { 'dtype': 'float32' }); + const uplo = zeros( [], { + 'dtype': 'int32' + }); + const trans = zeros( [], { + 'dtype': 'int32' + }); + const diag = zeros( [], { + 'dtype': 'int32' + }); - strsv( [ x, A ] ); // $ExpectType float32ndarray + strsv( [ x, A, uplo, trans, diag ] ); // $ExpectType float32ndarray } // The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... @@ -57,7 +66,16 @@ import strsv = require( '@stdlib/blas/base/ndarray/strsv' ); const A = zeros( [ 3, 3 ], { 'dtype': 'float32' }); + const uplo = zeros( [], { + 'dtype': 'int32' + }); + const trans = zeros( [], { + 'dtype': 'int32' + }); + const diag = zeros( [], { + 'dtype': 'int32' + }); strsv(); // $ExpectError - strsv( [ x, A ], {} ); // $ExpectError + strsv( [ x, A, uplo, trans, diag ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js index c96fb516d08d..5ef8cc153f02 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/examples/index.js @@ -18,19 +18,27 @@ '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 discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var strsv = require( './../lib' ); var opts = { 'dtype': 'float32' }; +var eopts = { + 'dtype': 'int32' +}; + +var x = discreteUniform( [ 3 ], 0, 10, opts ); +var A = discreteUniform( [ 3, 3 ], 0, 10, opts ); -var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) ); -var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 1, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +var uplo = scalar2ndarray( resolveTriangle( 'upper' ), eopts ); +var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), eopts ); +var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), eopts ); -var out = strsv( [ x, A ] ); +var out = strsv( [ x, A, uplo, trans, diag ] ); console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js index 9681afbb9d70..63bb15c22d17 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/index.js @@ -19,20 +19,33 @@ 'use strict'; /** -* BLAS level 2 routine to solve one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* BLAS level 2 routine to solve one of the systems of equations `A*x = b` or `A^T*x = b` for a triangular matrix `A`. * * @module @stdlib/blas/base/ndarray/strsv * * @example +* var Float32Matrix = require( '@stdlib/ndarray/matrix/float32' ); * var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float32Array = require( '@stdlib/array/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +* var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); * var strsv = require( '@stdlib/blas/base/ndarray/strsv' ); * * var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); -* -* var out = strsv( [ x, A ] ); +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 0.0, 4.0, 5.0 ], [ 0.0, 0.0, 6.0 ] ] ); +* +* var uplo = scalar2ndarray( resolveTriangle( 'upper' ), { +* 'dtype': 'int32' +* }); +* var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { +* 'dtype': 'int32' +* }); +* var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { +* 'dtype': 'int32' +* }); +* +* var out = strsv( [ x, A, uplo, trans, diag ] ); * // returns [ -0.25, -0.125, 0.5 ] * * var bool = ( out === x ); diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js index 394fd02fcd6b..c0606cc728e6 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/lib/main.js @@ -20,46 +20,84 @@ // 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' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var resolveTriangleStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +var resolveTransposeStr = require( '@stdlib/blas/base/transpose-operation-resolve-str' ); +var resolveDiagonalStr = require( '@stdlib/blas/base/diagonal-type-resolve-str' ); var strided = require( '@stdlib/blas/base/strsv' ).ndarray; // MAIN // /** -* Solves one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix. +* Solves one of the systems of equations `A*x = b` or `A^T*x = b`, where `b` and `x` are one-dimensional ndarrays 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. +* - a one-dimensional input/output ndarray corresponding to `x`. +* - a two-dimensional input ndarray corresponding to `A`. +* - a zero-dimensional ndarray specifying whether the upper or lower triangular part of `A` should be referenced. +* - a zero-dimensional ndarray specifying whether `A` should be transposed, conjugate-transposed, or not transposed. +* - a zero-dimensional ndarray specifying whether `A` has a unit or non-unit diagonal. * * @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var Float32Array = require( '@stdlib/array/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +* var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +* var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); * * var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] ); -* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' ); +* var A = new Float32Matrix( [ [ 1.0, 2.0, 3.0 ], [ 0.0, 4.0, 5.0 ], [ 0.0, 0.0, 6.0 ] ] ); * -* var out = strsv( [ x, A ] ); +* var uplo = scalar2ndarray( resolveTriangle( 'upper' ), { +* 'dtype': 'int32' +* }); +* var trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { +* 'dtype': 'int32' +* }); +* var diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { +* 'dtype': 'int32' +* }); +* +* var out = strsv( [ x, A, uplo, trans, diag ] ); * // returns [ -0.25, -0.125, 0.5 ] * * var bool = ( out === x ); * // returns true */ function strsv( 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 ) ); + var trans; + var diag; + var uplo; + var sh; + var st; + var x; + var A; + + x = arrays[ 0 ]; + A = arrays[ 1 ]; + + uplo = resolveTriangleStr( ndarraylike2scalar( arrays[ 2 ] ) ); + trans = resolveTransposeStr( ndarraylike2scalar( arrays[ 3 ] ) ); + diag = resolveDiagonalStr( ndarraylike2scalar( arrays[ 4 ] ) ); + + sh = getShape( A, false ); + st = getStrides( A, false ); + + strided( uplo, trans, diag, sh[ 0 ], getData( A ), st[ 0 ], st[ 1 ], getOffset( A ), getData( x ), getStride( x, 0 ), getOffset( x ) ); + return x; } diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json index c13d82af745b..1cf7ee95accf 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/ndarray/strsv", "version": "0.0.0", - "description": "Solve one of the systems of equations `A*x = b` or `A^T*x = b` where `b` and `x` are `N` element ndarrays and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.", + "description": "Solve one of the systems of equations `A*x = b` or `A^T*x = b` for a triangular matrix `A`.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js index 87a0eafb8e0a..89e7e69db09a 100644 --- a/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/ndarray/strsv/test/test.js @@ -23,6 +23,10 @@ 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 resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveTranspose = require( '@stdlib/blas/base/transpose-operation-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var getData = require( '@stdlib/ndarray/data-buffer' ); var strsv = require( './../lib' ); @@ -73,8 +77,11 @@ tape( 'the function has an arity of 1', function test( t ) { t.end(); }); -tape( 'the function solves the system of equations `A*x = b`', function test( t ) { +tape( 'the function solves the system of equations `A*x = b` (upper, no-transpose, non-unit)', function test( t ) { var expected; + var trans; + var diag; + var uplo; var xbuf; var Abuf; var x; @@ -86,7 +93,17 @@ tape( 'the function solves the system of equations `A*x = b`', function test( t x = vector( xbuf, 3, 1, 0 ); A = matrix( Abuf, 3, 3, 1, 0 ); - v = strsv( [ x, A ] ); + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); expected = new Float32Array( [ -0.25, -0.125, 0.5 ] ); t.strictEqual( v, x, 'returns expected value' ); @@ -95,8 +112,116 @@ tape( 'the function solves the system of equations `A*x = b`', function test( t t.end(); }); +tape( 'the function solves the system of equations `A*x = b` (lower, no-transpose, non-unit)', function test( t ) { + var expected; + var trans; + var diag; + var uplo; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array( [ 1.0, 3.0, 5.0 ] ); + Abuf = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0, 3.0, 5.0, 6.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + uplo = scalar2ndarray( resolveTriangle( 'lower' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); + + expected = new Float32Array( [ 1.0, 0.25, 0.125 ] ); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function solves the system of equations `A^T*x = b` (upper, transpose, non-unit)', function test( t ) { + var expected; + var trans; + var diag; + var uplo; + var xbuf; + var Abuf; + var x; + var A; + var v; + + xbuf = new Float32Array( [ 1.0, 3.0, 5.0 ] ); + Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); + + expected = new Float32Array( [ 1.0, 0.25, 0.125 ] ); + t.strictEqual( v, x, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a unit diagonal (upper, no-transpose, unit)', function test( t ) { + var expected; + var trans; + var diag; + var uplo; + 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, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + A = matrix( Abuf, 3, 3, 1, 0 ); + + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); + + expected = new Float32Array( [ 18.0, -13.0, 3.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 trans; + var diag; + var uplo; var xbuf; var Abuf; var x; @@ -115,7 +240,17 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); A = matrix( Abuf, 3, 3, 1, 0 ); - v = strsv( [ x, A ] ); + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); expected = new Float32Array( [ -0.25, 0.0, -0.125, 0.0, 0.5 ] ); t.strictEqual( v, x, 'returns expected value' ); @@ -125,6 +260,9 @@ tape( 'the function supports ndarrays having non-unit strides', function test( t tape( 'the function supports ndarrays having negative strides', function test( t ) { var expected; + var trans; + var diag; + var uplo; var xbuf; var Abuf; var x; @@ -141,7 +279,17 @@ tape( 'the function supports ndarrays having negative strides', function test( t Abuf = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); A = matrix( Abuf, 3, 3, 1, 0 ); - v = strsv( [ x, A ] ); + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); expected = new Float32Array( [ 0.5, -0.125, -0.25 ] ); t.strictEqual( v, x, 'returns expected value' ); @@ -151,6 +299,9 @@ 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 diag; + var uplo; var xbuf; var Abuf; var x; @@ -182,7 +333,17 @@ tape( 'the function supports ndarrays having non-zero offsets', function test( t ]); A = matrix( Abuf, 3, 3, 1, 2 ); - v = strsv( [ x, A ] ); + uplo = scalar2ndarray( resolveTriangle( 'upper' ), { + 'dtype': 'int32' + }); + trans = scalar2ndarray( resolveTranspose( 'no-transpose' ), { + 'dtype': 'int32' + }); + diag = scalar2ndarray( resolveDiagonal( 'non-unit' ), { + 'dtype': 'int32' + }); + + v = strsv( [ x, A, uplo, trans, diag ] ); expected = new Float32Array([ 0.0,