From 736e726cc5070e5e22cad747bdb3346b8b0351a3 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 17 Aug 2026 12:32:54 +0530 Subject: [PATCH] feat: add blas/base/gspmv --- 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/gspmv/README.md | 189 ++++++ .../blas/base/gspmv/benchmark/benchmark.js | 106 +++ .../base/gspmv/benchmark/benchmark.ndarray.js | 106 +++ .../@stdlib/blas/base/gspmv/docs/repl.txt | 147 +++++ .../blas/base/gspmv/docs/types/index.d.ts | 125 ++++ .../blas/base/gspmv/docs/types/test.ts | 443 +++++++++++++ .../@stdlib/blas/base/gspmv/examples/index.js | 37 ++ .../@stdlib/blas/base/gspmv/lib/accessors.js | 153 +++++ .../@stdlib/blas/base/gspmv/lib/base.js | 147 +++++ .../@stdlib/blas/base/gspmv/lib/index.js | 63 ++ .../@stdlib/blas/base/gspmv/lib/main.js | 89 +++ .../@stdlib/blas/base/gspmv/lib/ndarray.js | 87 +++ .../@stdlib/blas/base/gspmv/package.json | 69 ++ .../test/fixtures/column_major_xnyn.json | 16 + .../test/fixtures/column_major_xnyp.json | 16 + .../test/fixtures/column_major_xoyt.json | 16 + .../test/fixtures/column_major_xpyn.json | 16 + .../test/fixtures/column_major_xpyp.json | 16 + .../gspmv/test/fixtures/row_major_xnyn.json | 16 + .../gspmv/test/fixtures/row_major_xnyp.json | 16 + .../gspmv/test/fixtures/row_major_xoyt.json | 16 + .../gspmv/test/fixtures/row_major_xpyn.json | 16 + .../gspmv/test/fixtures/row_major_xpyp.json | 16 + .../@stdlib/blas/base/gspmv/test/test.js | 38 ++ .../@stdlib/blas/base/gspmv/test/test.main.js | 613 ++++++++++++++++++ .../blas/base/gspmv/test/test.ndarray.js | 613 ++++++++++++++++++ 26 files changed, 3185 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xoyt.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xoyt.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspmv/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/README.md b/lib/node_modules/@stdlib/blas/base/gspmv/README.md new file mode 100644 index 000000000000..40c703fd8620 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/README.md @@ -0,0 +1,189 @@ + + +# gspmv + +> Perform the matrix-vector operation `y = α*A*x + β*y` where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + +
+ +## Usage + +```javascript +var gspmv = require( '@stdlib/blas/base/gspmv' ); +``` + +#### gspmv( order, uplo, N, α, AP, x, sx, β, y, sy ) + +Performs the matrix-vector operation `y = α*A*x + β*y` where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form `AP`. + +```javascript +var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var x = [ 1.0, 1.0, 1.0 ]; +var y = [ 1.0, 1.0, 1.0 ]; + +gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +// y => [ 7.0, 12.0, 15.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. +- **N**: number of elements along each dimension of `A`. +- **α**: scalar constant. +- **AP**: packed form of a symmetric matrix `A`. +- **x**: input vector. +- **sx**: index increment for `x`. +- **β**: scalar constant. +- **y**: output vector. +- **sy**: index increment for `y`. + +The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `y` in reverse order, + +```javascript +var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var x = [ 1.0, 1.0, 1.0 ]; +var y = [ 1.0, 1.0, 1.0 ]; + +gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, -1 ); +// y => [ 15.0, 12.0, 7.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); +var y0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); +var AP = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +gspmv( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 ); +// y0 => [ 0.0, 6.0, 4.0 ] +``` + +#### gspmv.ndarray( order, uplo, N, α, AP, oa, x, sx, ox, β, y, sy, oy ) + +Performs the matrix-vector operation `y = α*A*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form `AP`. + +```javascript +var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var x = [ 1.0, 1.0, 1.0 ]; +var y = [ 1.0, 1.0, 1.0 ]; + +gspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +// y => [ 7.0, 12.0, 15.0 ] +``` + +The function has the following additional parameters: + +- **oa**: starting index for `AP`. +- **ox**: starting index for `x`. +- **oy**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + +```javascript +var AP = [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var x = [ 1.0, 1.0, 1.0 ]; +var y = [ 1.0, 1.0, 1.0 ]; + +gspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 2, x, 1, 0, 1.0, y, -1, 2 ); +// y => [ 15.0, 12.0, 7.0 ] +``` + +
+ + + +
+ +## Notes + +- `gspmv()` corresponds to the [BLAS][blas] level 2 function [`dspmv`][dspmv] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, typed versions such as [`dspmv`][@stdlib/blas/base/dspmv] and [`sspmv`][@stdlib/blas/base/sspmv] are likely to be significantly more performant. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gspmv = require( '@stdlib/blas/base/gspmv' ); + +var opts = { + 'dtype': 'generic' +}; + +var N = 3; + +var AP = discreteUniform( N * ( N + 1 ) / 2, -10, 10, opts ); +var x = discreteUniform( N, -10, 10, opts ); +var y = discreteUniform( N, -10, 10, opts ); + +gspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.js new file mode 100644 index 000000000000..ca728c798385 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var gspmv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = gspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 1.0, y, 1 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + 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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s:size=%d', pkg, len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..eae6783f205e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/benchmark/benchmark.ndarray.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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var gspmv = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = gspmv( 'row-major', 'upper', len, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + 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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:size=%d', pkg, len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/gspmv/docs/repl.txt new file mode 100644 index 000000000000..6f05bf5664dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/docs/repl.txt @@ -0,0 +1,147 @@ + +{{alias}}( ord, uplo, N, α, AP, x, sx, β, y, sy ) + Performs the matrix-vector operation `y = α*A*x + β*y` where `α` and `β` are + scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` + symmetric matrix supplied in packed form. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N` is equal to `0`, the function returns `y` unchanged. + + If `α` equals `0` and `β` equals `1`, the function returns `y` unchanged. + + Parameters + ---------- + ord: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + uplo: string + Specifies whether the upper or lower triangular matrix of `A` is + supplied. Must be either 'upper' or 'lower'. + + N: integer + Number of elements along each dimension of `A`. + + α: number + Scalar constant. + + AP: Array|TypedArray + Matrix in packed form. + + x: Array|TypedArray + Input vector `x`. + + sx: integer + Index increment for `x`. + + β: number + Scalar constant. + + y: Array|TypedArray + Input/output vector `y`. + + sy: integer + Index increment for `y`. + + Returns + ------- + y: Array|TypedArray + Output vector `y`. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, 1.0 ]; + > var y = [ 1.0, 1.0 ]; + > var AP = [ 1.0, 2.0, 3.0, 4.0 ]; + > {{alias}}( 'row-major', 'upper', 2, 1.0, AP, x, 1, 1.0, y, 1 ) + [ 4.0, 6.0 ] + + // Advanced indexing: + > x = [ 1.0, 1.0 ]; + > y = [ 1.0, 1.0 ]; + > AP = [ 1.0, 2.0, 3.0, 4.0 ]; + > {{alias}}( 'row-major', 'upper', 2, 1.0, AP, x, -1, 1.0, y, -1 ) + [ 6.0, 4.0 ] + + +{{alias}}.ndarray( ord, uplo, N, α, AP, oa, x, sx, ox, β, y, sy, oy ) + Performs the matrix-vector operation `y = α*A*x + β*y` using alternative + indexing semantics and where `α` and `β` are scalars, `x` and `y` are `N` + element vectors, and `A` is an `N` by `N` symmetric matrix supplied in + packed form. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + ord: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + uplo: string + Specifies whether the upper or lower triangular matrix of `A` is + supplied. Must be either 'upper' or 'lower'. + + N: integer + Number of elements along each dimension of `A`. + + α: number + Scalar constant. + + AP: Array|TypedArray + Matrix in packed form. + + oa: integer + Starting index for `AP`. + + x: Array|TypedArray + Input vector `x`. + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + β: number + Scalar constant. + + y: Array|TypedArray + Input/output vector `y`. + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + y: Array|TypedArray + Output vector `y`. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, 1.0 ]; + > var y = [ 1.0, 1.0 ]; + > var AP = [ 1.0, 2.0, 3.0, 4.0 ]; + > var ord = 'row-major'; + > var uplo = 'upper'; + > {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ) + [ 4.0, 6.0 ] + + // Advanced indexing: + > x = [ 1.0, 1.0 ]; + > y = [ 1.0, 1.0 ]; + > AP = [ 1.0, 2.0, 3.0, 4.0 ]; + > {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, 0, x, -1, 1, 1.0, y, -1, 1 ) + [ 6.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/index.d.ts new file mode 100644 index 000000000000..c04419065562 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/index.d.ts @@ -0,0 +1,125 @@ +/* +* @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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout, MatrixTriangle } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gspmv`. +*/ +interface Routine { + /** + * Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied + * @param N - number of elements along each dimension of `A` + * @param alpha - scalar constant + * @param AP - packed form of a symmetric matrix `A` + * @param x - first input vector + * @param strideX - `x` stride length + * @param beta - scalar constant + * @param y - second input vector + * @param strideY - `y` stride length + * @returns `y` + * + * @example + * var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var x = [ 1.0, 1.0, 1.0 ]; + * var y = [ 1.0, 1.0, 1.0 ]; + * + * gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); + * // y => [ 7.0, 12.0, 15.0 ] + */ + ( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: InputArray, x: InputArray, strideX: number, beta: number, y: T, strideY: number ): T; + + /** + * Performs the matrix-vector operation `y = alpha*A*x + beta*y`, using alternative indexing semantics and where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied + * @param N - number of elements along each dimension of `A` + * @param alpha - scalar constant + * @param AP - packed form of a symmetric matrix `A` + * @param offsetAP - starting index for `AP` + * @param x - first input vector + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param beta - scalar constant + * @param y - second input vector + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns `y` + * + * @example + * var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var x = [ 1.0, 1.0, 1.0 ]; + * var y = [ 1.0, 1.0, 1.0 ]; + * + * gspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + * // y => [ 7.0, 12.0, 15.0 ] + */ + ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: InputArray, offsetAP: number, x: InputArray, strideX: number, offsetX: number, beta: number, y: T, strideY: number, offsetY: number ): T; +} + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param order - storage layout +* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied +* @param N - number of elements along each dimension of `A` +* @param alpha - scalar constant +* @param AP - packed form of a symmetric matrix `A` +* @param x - first input vector +* @param strideX - `x` stride length +* @param beta - scalar constant +* @param y - second input vector +* @param strideY - `y` stride length +* @returns `y` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 12.0, 15.0 ] +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 12.0, 15.0 ] +*/ +declare var gspmv: Routine; + + +// EXPORTS // + +export = gspmv; diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/test.ts new file mode 100644 index 000000000000..0f23f8d4811b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/docs/types/test.ts @@ -0,0 +1,443 @@ +/* +* @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. +*/ + +import gspmv = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 10, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( true, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( false, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( null, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( void 0, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( [], 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( {}, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( ( x: number ): number => x, 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 10, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', true, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', false, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', null, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', void 0, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', [ '1' ], 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', {}, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', ( x: number ): number => x, 10, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', '10', 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', true, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', false, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', null, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', void 0, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', [], 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', {}, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', ( x: number ): number => x, 1.0, AP, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, '10', AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, true, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, false, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, null, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, void 0, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, [], AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, {}, AP, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, ( x: number ): number => x, AP, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + gspmv( 'row-major', 'upper', 10, 1.0, 10, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, '10', x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, true, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, false, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, null, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, void 0, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, {}, x, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, ( x: number ): number => x, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not an array... +{ + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, 10, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, '10', 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, true, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, false, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, null, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, void 0, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, {}, 1, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, ( x: number ): number => x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, '10', 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, true, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, false, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, null, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, void 0, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, [], 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, {}, 1.0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, ( x: number ): number => x, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, '10', y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, true, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, false, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, null, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, void 0, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, [], y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, {}, y, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not an array... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, 10, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, '10', 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, true, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, false, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, null, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, void 0, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, {}, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, '10' ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, true ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, false ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, null ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, void 0 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, [] ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, {} ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv(); // $ExpectError + gspmv( 'row-major' ); // $ExpectError + gspmv( 'row-major', 'upper' ); // $ExpectError + gspmv( 'row-major', 'upper', 10 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0 ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y ); // $ExpectError + gspmv( 'row-major', 'upper', 10, 1.0, AP, x, 1, 1.0, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 10, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( true, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( false, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( null, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( void 0, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( [], 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( {}, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( ( x: number ): number => x, 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 10, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', true, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', false, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', null, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', void 0, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', [ '1' ], 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', {}, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', ( x: number ): number => x, 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', '10', 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', true, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', false, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', null, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', void 0, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', [], 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', {}, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', ( x: number ): number => x, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, '10', AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, true, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, false, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, null, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, void 0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, [], AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, {}, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, ( x: number ): number => x, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, 10, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, '10', 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, true, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, false, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, null, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, void 0, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, {}, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, ( x: number ): number => x, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, '10', x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, true, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, false, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, null, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, void 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, [], x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, {}, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, ( x: number ): number => x, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not an array... +{ + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, 10, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, '10', 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, true, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, false, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, null, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, void 0, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, {}, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, ( x: number ): number => x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, '10', 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, true, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, false, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, null, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, void 0, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, [], 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, {}, 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, ( x: number ): number => x, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, '10', 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, true, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, false, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, null, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, void 0, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, [], 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, {}, 1.0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, ( x: number ): number => x, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, '10', y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, true, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, false, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, null, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, void 0, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, [], y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, {}, y, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not an array... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, 10, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, '10', 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, true, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, false, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, null, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, void 0, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, {}, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, '10', 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, true, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, false, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, null, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, void 0, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, [], 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, {}, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, '10' ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, true ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, false ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, null ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, void 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, [] ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, {} ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspmv.ndarray(); // $ExpectError + gspmv.ndarray( 'row-major' ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper' ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1 ); // $ExpectError + gspmv.ndarray( 'row-major', 'upper', 10, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/examples/index.js b/lib/node_modules/@stdlib/blas/base/gspmv/examples/index.js new file mode 100644 index 000000000000..06d192813814 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 gspmv = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var N = 3; +var AP = discreteUniform( N * ( N + 1 ) / 2, -10, 10, opts ); +var x = discreteUniform( N, -10, 10, opts ); +var y = discreteUniform( N, -10, 10, opts ); + +gspmv( 'row-major', 'upper', N, 1.0, AP, x, 1, 1.0, y, 1 ); +console.log( y ); + +gspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/gspmv/lib/accessors.js new file mode 100644 index 000000000000..4c2a9d64a6d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/lib/accessors.js @@ -0,0 +1,153 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); + + +// MAIN // + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {Object} AP - packed matrix object +* @param {Collection} AP.data - packed matrix data +* @param {Array} AP.accessors - array element accessors +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @param {Object} x - first input vector object +* @param {Collection} x.data - first input vector data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {number} beta - scalar constant +* @param {Object} y - second input vector object +* @param {Collection} y.data - second input vector data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {Object} second input vector object +*/ +function gspmv( order, uplo, N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len + var APbuf; + var getAP; + var temp1; + var temp2; + var setY; + var getY; + var getX; + var xbuf; + var ybuf; + var ix; + var iy; + var jx; + var jy; + var kk; + var j; + var k; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + APbuf = AP.data; + + // Cache references to element accessors: + getX = x.accessors[ 0 ]; + getY = y.accessors[ 0 ]; + setY = y.accessors[ 1 ]; + getAP = AP.accessors[ 0 ]; + + // Form: y = beta*y + if ( beta !== 1.0 ) { + iy = offsetY; + if ( beta === 0.0 ) { + for ( k = 0; k < N; k++ ) { + setY( ybuf, iy, 0.0 ); + iy += strideY; + } + } else { + for ( k = 0; k < N; k++ ) { + setY( ybuf, iy, beta * getY( ybuf, iy ) ); + iy += strideY; + } + } + } + if ( alpha === 0.0 ) { + return y; + } + // Form: y = alpha*A*x + y + kk = offsetAP; + if ( + ( isRowMajor( order ) && uplo === 'upper' ) || + ( isColumnMajor( order ) && uplo === 'lower' ) + ) { + jx = offsetX; + jy = offsetY; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * getX( xbuf, jx ); + temp2 = 0.0; + setY( ybuf, jy, getY( ybuf, jy ) + ( temp1 * getAP( APbuf, kk ) ) ); + ix = jx; + iy = jy; + for ( k = kk+1; k < kk+N-j; k++ ) { + ix += strideX; + iy += strideY; + setY( ybuf, iy, getY( ybuf, iy ) + ( temp1 * getAP( APbuf, k ) ) ); + temp2 += getAP( APbuf, k ) * getX( xbuf, ix ); + } + setY( ybuf, jy, getY( ybuf, jy ) + ( alpha * temp2 ) ); + jx += strideX; + jy += strideY; + kk += N - j; + } + return y; + } + // ( isRowMajor( order ) && uplo === 'lower' ) || ( isColumnMajor( order ) && uplo === 'upper' ) + jx = offsetX; + jy = offsetY; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * getX( xbuf, jx ); + temp2 = 0.0; + ix = offsetX; + iy = offsetY; + for ( k = kk; k < kk+j; k++ ) { + setY( ybuf, iy, getY( ybuf, iy ) + ( temp1 * getAP( APbuf, k ) ) ); + temp2 += getAP( APbuf, k ) * getX( xbuf, ix ); + ix += strideX; + iy += strideY; + } + setY( ybuf, jy, getY( ybuf, jy ) + ( temp1 * getAP( APbuf, kk+j ) ) + ( alpha * temp2 ) ); // eslint-disable-line max-len + jx += strideX; + jy += strideY; + kk += j + 1; + } + return y; +} + + +// EXPORTS // + +module.exports = gspmv; diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/lib/base.js b/lib/node_modules/@stdlib/blas/base/gspmv/lib/base.js new file mode 100644 index 000000000000..2299e3b062c1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/lib/base.js @@ -0,0 +1,147 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var gscal = require( '@stdlib/blas/base/gscal' ).ndarray; +var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @param {NumericArray} x - first input vector +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {number} beta - scalar constant +* @param {NumericArray} y - second input vector +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {NumericArray} `y` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 12.0, 15.0 ] +*/ +function gspmv( order, uplo, N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len + var temp1; + var temp2; + var apo; + var ix; + var iy; + var jx; + var jy; + var kk; + var xo; + var yo; + var j; + var k; + + if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) { + return y; + } + xo = arraylike2object( x ); + yo = arraylike2object( y ); + apo = arraylike2object( AP ); + if ( xo.accessorProtocol || yo.accessorProtocol || apo.accessorProtocol ) { + accessors( order, uplo, N, alpha, apo, offsetAP, xo, strideX, offsetX, beta, yo, strideY, offsetY ); // eslint-disable-line max-len + return y; + } + // Form: y = beta*y + if ( beta !== 1.0 ) { + if ( beta === 0.0 ) { + gfill( N, 0.0, y, strideY, offsetY ); + } else { + gscal( N, beta, y, strideY, offsetY ); + } + } + if ( alpha === 0.0 ) { + return y; + } + // Form: y = alpha*A*x + y + kk = offsetAP; + if ( + ( isRowMajor( order ) && uplo === 'upper' ) || + ( isColumnMajor( order ) && uplo === 'lower' ) + ) { + jx = offsetX; + jy = offsetY; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * x[ jx ]; + temp2 = 0.0; + y[ jy ] += temp1 * AP[ kk ]; + ix = jx; + iy = jy; + for ( k = kk+1; k < kk+N-j; k++ ) { + ix += strideX; + iy += strideY; + y[ iy ] += temp1 * AP[ k ]; + temp2 += AP[ k ] * x[ ix ]; + } + y[ jy ] += alpha * temp2; + jx += strideX; + jy += strideY; + kk += N - j; + } + return y; + } + // ( isRowMajor( order ) && uplo === 'lower' ) || ( isColumnMajor( order ) && uplo === 'upper' ) + jx = offsetX; + jy = offsetY; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * x[ jx ]; + temp2 = 0.0; + ix = offsetX; + iy = offsetY; + for ( k = kk; k < kk+j; k++ ) { + y[ iy ] += temp1 * AP[ k ]; + temp2 += AP[ k ] * x[ ix ]; + ix += strideX; + iy += strideY; + } + y[ jy ] += ( temp1 * AP[ kk+j ] ) + ( alpha * temp2 ); + jx += strideX; + jy += strideY; + kk += j + 1; + } + return y; +} + + +// EXPORTS // + +module.exports = gspmv; diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/lib/index.js b/lib/node_modules/@stdlib/blas/base/gspmv/lib/index.js new file mode 100644 index 000000000000..7de319313411 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* BLAS level 2 routine to perform the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @module @stdlib/blas/base/gspmv +* +* @example +* var gspmv = require( '@stdlib/blas/base/gspmv' ); +* +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 12.0, 15.0 ] +* +* @example +* var gspmv = require( '@stdlib/blas/base/gspmv' ); +* +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 12.0, 15.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/lib/main.js b/lib/node_modules/@stdlib/blas/base/gspmv/lib/main.js new file mode 100644 index 000000000000..165fd7427de2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/lib/main.js @@ -0,0 +1,89 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param {string} order - storage layout +* @param {(integer|string)} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @param {NumericArray} x - first input vector +* @param {integer} strideX - `x` stride length +* @param {number} beta - scalar constant +* @param {NumericArray} y - second input vector +* @param {integer} strideY - `y` stride length +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} second argument must specify whether the lower or upper triangular matrix is supplied +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} seventh argument must be non-zero +* @throws {RangeError} tenth argument must be non-zero +* @returns {NumericArray} `y` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 12.0, 15.0 ] +*/ +function gspmv( order, uplo, N, alpha, AP, x, strideX, beta, y, strideY ) { + var ox; + var oy; + var u; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + u = resolveStr( uplo ); + if ( u === null ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideY ) ); + } + ox = stride2offset( N, strideX ); + oy = stride2offset( N, strideY ); + return base( order, u, N, alpha, AP, 0, x, strideX, ox, beta, y, strideY, oy ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gspmv; diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/gspmv/lib/ndarray.js new file mode 100644 index 000000000000..46b6b7b74dd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/lib/ndarray.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form, using alternative indexing semantics. +* +* @param {string} order - storage layout +* @param {(integer|string)} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @param {NumericArray} x - first input vector +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {number} beta - scalar constant +* @param {NumericArray} y - second input vector +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} second argument must specify whether the lower or upper triangular matrix is supplied +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} eighth argument must be non-zero +* @throws {RangeError} twelfth argument must be non-zero +* @returns {NumericArray} `y` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var x = [ 1.0, 1.0, 1.0 ]; +* var y = [ 1.0, 1.0, 1.0 ]; +* +* gspmv( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 12.0, 15.0 ] +*/ +function gspmv( order, uplo, N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len + var u; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + u = resolveStr( uplo ); + if ( u === null ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + return base( order, u, N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gspmv; diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/package.json b/lib/node_modules/@stdlib/blas/base/gspmv/package.json new file mode 100644 index 000000000000..1d52624ef032 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/base/gspmv", + "version": "0.0.0", + "description": "Perform the matrix-vector operation `y = α*A*x + β*y` where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.", + "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", + "gspmv", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "generic", + "typed-array", + "matrix", + "vector" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyn.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyn.json new file mode 100644 index 000000000000..06b6850679f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyn.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "offsetAP": 2, + "AP": [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 16.0, 11.0, 8.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyp.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyp.json new file mode 100644 index 000000000000..c2d83166074e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xnyp.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": 1, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 8.0, 11.0, 16.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xoyt.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xoyt.json new file mode 100644 index 000000000000..b05e6fe81a66 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xoyt.json @@ -0,0 +1,16 @@ +{ + "uplo": "lower", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 2, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ], + "y_out": [ 7.0, 0.0, 12.0, 0.0, 15.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyn.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyn.json new file mode 100644 index 000000000000..f4aad6d8b842 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyn.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 2, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 16.0, 11.0, 8.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyp.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyp.json new file mode 100644 index 000000000000..b3123f8e2f1a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/column_major_xpyp.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 8.0, 11.0, 16.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyn.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyn.json new file mode 100644 index 000000000000..f1631104ae57 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyn.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "offsetAP": 2, + "AP": [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 15.0, 12.0, 7.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyp.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyp.json new file mode 100644 index 000000000000..475ee4d49195 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xnyp.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": 1, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 7.0, 12.0, 15.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xoyt.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xoyt.json new file mode 100644 index 000000000000..211518d861c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xoyt.json @@ -0,0 +1,16 @@ +{ + "uplo": "lower", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 2, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ], + "y_out": [ 8.0, 0.0, 11.0, 0.0, 16.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyn.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyn.json new file mode 100644 index 000000000000..2a6711742d6d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyn.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 2, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 15.0, 12.0, 7.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyp.json b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyp.json new file mode 100644 index 000000000000..ddee2b156243 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/fixtures/row_major_xpyp.json @@ -0,0 +1,16 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "offsetAP": 0, + "AP": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], + "x": [ 1.0, 1.0, 1.0 ], + "y": [ 1.0, 1.0, 1.0 ], + "y_out": [ 7.0, 12.0, 15.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/test.js b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.js new file mode 100644 index 000000000000..6045225800c1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gspmv = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gspmv.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/test.main.js b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.main.js new file mode 100644 index 000000000000..720952d531db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.main.js @@ -0,0 +1,613 @@ +/** +* @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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var gspmv = require( './../lib/main.js' ); + + +// FIXTURES // + +var rxoyt = require( './fixtures/row_major_xoyt.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var cxoyt = require( './fixtures/column_major_xoyt.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gspmv.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( value, data.uplo, data.N, data.alpha, copy( data.AP ), copy( data.x ), data.strideX, data.beta, copy( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, value, data.N, data.alpha, copy( data.AP ), copy( data.x ), data.strideX, data.beta, copy( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, value, data.alpha, copy( data.AP ), copy( data.x ), data.strideX, data.beta, copy( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, data.N, data.alpha, copy( data.AP ), copy( data.x ), value, data.beta, copy( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, data.N, data.alpha, copy( data.AP ), copy( data.x ), data.strideX, data.beta, copy( data.y ), value ); + }; + } +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=2)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxoyt; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=2)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxoyt; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=-1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=-1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=-1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxnyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=-1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxnyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', function test( t ) { + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y ); + + out = gspmv( data.order, data.uplo, 0, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = gspmv( data.order, data.uplo, data.N, 0.0, ap, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y ); + + out = gspmv( data.order, data.uplo, 0, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = gspmv( data.order, data.uplo, data.N, 0.0, ap, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, upper)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'row-major', 'upper', 3, 0.0, ap, x, 1, 5.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'row-major', 'upper', 3, 0.0, ap, x, 1, 0.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, lower)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'row-major', 'lower', 3, 0.0, ap, x, 1, 5.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'row-major', 'lower', 3, 0.0, ap, x, 1, 0.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, upper)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'column-major', 'upper', 3, 0.0, ap, x, 1, 5.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'column-major', 'upper', 3, 0.0, ap, x, 1, 0.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, lower)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'column-major', 'lower', 3, 0.0, ap, x, 1, 5.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'column-major', 'lower', 3, 0.0, ap, x, 1, 0.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxnyn; + + ap = copy( data.AP ).slice( data.offsetAP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxnyn; + + ap = copy( data.AP ).slice( data.offsetAP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var fixtures; + var expected; + var ybuf; + var data; + var out; + var ap; + var x; + var y; + var i; + + fixtures = [ rxpyp, cxpyp, rxoyt, cxoyt, rxpyn, cxpyn, rxnyp, cxnyp, rxnyn, cxnyn ]; + for ( i = 0; i < fixtures.length; i++ ) { + data = fixtures[ i ]; + ap = toAccessorArray( copy( data.AP ).slice( data.offsetAP ) ); + x = toAccessorArray( copy( data.x ) ); + ybuf = copy( data.y ); + y = toAccessorArray( ybuf ); + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns the accessor array' ); + t.deepEqual( ybuf, expected, 'returns expected values for fixture '+i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/gspmv/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.ndarray.js new file mode 100644 index 000000000000..22e927f0ba42 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspmv/test/test.ndarray.js @@ -0,0 +1,613 @@ +/** +* @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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var gspmv = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var rxoyt = require( './fixtures/row_major_xoyt.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var cxoyt = require( './fixtures/column_major_xoyt.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 13', function test( t ) { + t.strictEqual( gspmv.length, 13, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( value, data.uplo, data.N, data.alpha, copy( data.AP ), data.offsetAP, copy( data.x ), data.strideX, data.offsetX, data.beta, copy( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, value, data.N, data.alpha, copy( data.AP ), data.offsetAP, copy( data.x ), data.strideX, data.offsetX, data.beta, copy( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, value, data.alpha, copy( data.AP ), data.offsetAP, copy( data.x ), data.strideX, data.offsetX, data.beta, copy( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, data.N, data.alpha, copy( data.AP ), data.offsetAP, copy( data.x ), value, data.offsetX, data.beta, copy( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid twelfth argument', function test( t ) { + var values; + var data; + var i; + + data = rxpyp; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gspmv( data.order, data.uplo, data.N, data.alpha, copy( data.AP ), data.offsetAP, copy( data.x ), data.strideX, data.offsetX, data.beta, copy( data.y ), value, data.offsetY ); + }; + } +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=2)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxoyt; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=2)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxoyt; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=-1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=-1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=-1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxnyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=-1, sy=1)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxnyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', function test( t ) { + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y ); + + out = gspmv( data.order, data.uplo, 0, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = gspmv( data.order, data.uplo, data.N, 0.0, ap, data.offsetAP, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxpyp; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y ); + + out = gspmv( data.order, data.uplo, 0, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = gspmv( data.order, data.uplo, data.N, 0.0, ap, data.offsetAP, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, upper)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'row-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'row-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, lower)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'row-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'row-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, upper)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'column-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'column-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, lower)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + x = [ 1.0, 1.0, 1.0 ]; + y = [ 1.0, 1.0, 1.0 ]; + + expected = [ 5.0, 5.0, 5.0 ]; + + out = gspmv( 'column-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = [ 0.0, 0.0, 0.0 ]; + + out = gspmv( 'column-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = rxnyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + var y; + + data = cxnyn; + + ap = copy( data.AP ); + x = copy( data.x ); + y = copy( data.y ); + + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var fixtures; + var expected; + var ybuf; + var data; + var out; + var ap; + var x; + var y; + var i; + + fixtures = [ rxpyp, cxpyp, rxoyt, cxoyt, rxpyn, cxpyn, rxnyp, cxnyp, rxnyn, cxnyn ]; + for ( i = 0; i < fixtures.length; i++ ) { + data = fixtures[ i ]; + ap = toAccessorArray( copy( data.AP ) ); + x = toAccessorArray( copy( data.x ) ); + ybuf = copy( data.y ); + y = toAccessorArray( ybuf ); + expected = copy( data.y_out ); + + out = gspmv( data.order, data.uplo, data.N, data.alpha, ap, data.offsetAP, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns the accessor array' ); + t.deepEqual( ybuf, expected, 'returns expected values for fixture '+i ); + } + t.end(); +});