diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/README.md b/lib/node_modules/@stdlib/blas/base/dspmv/README.md new file mode 100644 index 000000000000..7d8149aa8e93 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/README.md @@ -0,0 +1,261 @@ + + +# dspmv + +> 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 dspmv = require( '@stdlib/blas/base/dspmv' ); +``` + +#### dspmv( 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 Float64Array = require( '@stdlib/array/float64' ); + +var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + +dspmv( '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**: specifies the order of the matrix `A`. +- **α**: scalar constant. +- **AP**: packed form of a symmetric matrix `A` stored in linear memory as a [`Float64Array`][mdn-float64array]. +- **x**: input [`Float64Array`][mdn-float64array]. +- **sx**: index increment for `x`. +- **β**: scalar constant. +- **y**: output [`Float64Array`][mdn-float64array]. +- **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 Float64Array = require( '@stdlib/array/float64' ); + +var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + +dspmv( '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( [ 1.0, 1.0 ] ); +var y0 = new Float64Array( [ 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*0 ); // start at 1st element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*0 ); // start at 1st element + +dspmv( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 ); +// y0 => [ 6.0, 4.0 ] +``` + +#### dspmv.ndarray( order, uplo, N, α, AP, 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 Float64Array = require( '@stdlib/array/float64' ); + +var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + +dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 ); +// y => [ 7.0, 12.0, 15.0 ] +``` + +The function has the following additional parameters: + +- **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 Float64Array = require( '@stdlib/array/float64' ); + +var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + +dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, -1, 2 ); +// y => [ 15.0, 12.0, 7.0 ] +``` + +
+ + + +
+ +## Notes + +- `dspmv()` corresponds to the [BLAS][blas] level 2 function [`dspmv`][dspmv]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dspmv = require( '@stdlib/blas/base/dspmv' ); + +var opts = { + 'dtype': 'float64' +}; + +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 ); + +dspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 ); +console.log( y ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.js new file mode 100644 index 000000000000..7a27e9cbf7ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 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 dspmv = require( './../lib/dspmv.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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 = dspmv( '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( pkg+':size='+( len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..10433a29453e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 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 dspmv = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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 = dspmv( 'row-major', 'upper', len, 1.0, AP, 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( pkg+':ndarray:size='+( len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dspmv/docs/repl.txt new file mode 100644 index 000000000000..9cd3209ff839 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/docs/repl.txt @@ -0,0 +1,154 @@ + +{{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: Float64Array + Matrix in packed form. + + x: Float64Array + Input vector `x`. + + sx: integer + Index increment for `x`. + + β: number + Scalar constant. + + y: Float64Array + Input/output vector `y`. + + sy: integer + Index increment for `y`. + + Returns + ------- + y: Float64Array + Output array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var AP = new {{alias:@stdlib/array/float64}}( [ 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 = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > AP = new {{alias:@stdlib/array/float64}}( [ 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 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > AP = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*0 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*0 ); + > {{alias}}( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 ); + > y0 + [ ~6.0, ~4.0 ] + + +{{alias}}.ndarray( ord, uplo, N, α, AP, 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. + + AP: Float64Array + Matrix in packed form. + + x: Float64Array + Input vector `x`. + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + β: number + Scalar. + + y: Float64Array + Input/output vector `y`. + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + y: Float64Array + Output array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var AP = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ord = 'row-major'; + > var uplo = 'upper'; + > {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 ) + [ ~4.0, ~6.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > AP = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, x, -1, 1, 1.0, y, -1, 1 ) + [ ~6.0, ~4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/index.d.ts new file mode 100644 index 000000000000..37627586c98f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/index.d.ts @@ -0,0 +1,126 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { Layout, MatrixTriangle } from '@stdlib/types/blas'; + +/** +* Interface describing `dspmv`. +*/ +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 columns in the matrix `A` + * @param alpha - scalar constant + * @param AP - packed form of a symmetric matrix `A` + * @param x - first input array + * @param strideX - `x` stride length + * @param beta - scalar constant + * @param y - second input array + * @param strideY - `y` stride length + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * + * dspmv( '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: Float64Array, x: Float64Array, strideX: number, beta: number, y: Float64Array, strideY: number ): Float64Array; + + /** + * 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 columns in the matrix `A` + * @param alpha - scalar constant + * @param AP - packed form of a symmetric matrix `A` + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting `x` index + * @param beta - scalar constant + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting `y` index + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * + * dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 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: Float64Array, x: Float64Array, strideX: number, offsetX: number, beta: number, y: Float64Array, strideY: number, offsetY: number ): Float64Array; +} + +/** +* 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 columns in the matrix `A` +* @param alpha - scalar constant +* @param AP - packed form of a symmetric matrix `A` +* @param x - first input array +* @param strideX - `x` stride length +* @param beta - scalar constant +* @param y - second input array +* @param strideY - `y` stride length +* @returns `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, -1 ); +* // y => [ 15.0, 12.0, 7.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, -1, 2 ); +* // y => [ 15.0, 12.0, 7.0 ] +*/ +declare var dspmv: Routine; + + +// EXPORTS // + +export = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/test.ts new file mode 100644 index 000000000000..1aefcc3f2dff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/docs/types/test.ts @@ -0,0 +1,432 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dspmv = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 10, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( true, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( false, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( null, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( void 0, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( [], 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( {}, 'upper', 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( ( x: number ): number => x, 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 10, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', true, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', false, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', null, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', void 0, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', [ '1' ], 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', {}, 10, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', ( x: number ): number => x, 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', '10', 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', true, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', false, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', null, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', void 0, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', [], 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', {}, 1.0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', ( x: number ): number => x, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, '10', A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, true, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, false, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, null, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, void 0, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, [], A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, {}, A, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, ( x: number ): number => x, A, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dspmv( 'row-major', 'upper', 10, 1.0, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, '10', x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, true, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, false, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, null, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, void 0, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, [ '1' ], x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, {}, x, 1, 1.0, y, 1 ); // $ExpectError + dspmv( '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 a Float64Array... +{ + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, 10, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, '10', 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, true, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, false, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, null, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, void 0, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, [ '1' ], 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, {}, 1, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, ( 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, x, '10', 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, true, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, false, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, null, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, void 0, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, [], 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, {}, 1.0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, '10', y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, true, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, false, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, null, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, void 0, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, [], y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, {}, y, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, 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 a Float64Array... +{ + const x = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, 10, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, '10', 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, true, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, false, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, null, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, void 0, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, [ '1' ], 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, {}, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, '10' ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, true ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, false ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, null ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, void 0 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, [] ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, {} ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv(); // $ExpectError + dspmv( 'row-major' ); // $ExpectError + dspmv( 'row-major', 'upper' ); // $ExpectError + dspmv( 'row-major', 'upper', 10 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0 ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y ); // $ExpectError + dspmv( 'row-major', 'upper', 10, 1.0, A, x, 1, 1.0, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $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 A = new Float64Array( 55 ); + + dspmv.ndarray( 10, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( true, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( false, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( null, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( void 0, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( [], 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( {}, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( ( x: number ): number => x, 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $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 A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 10, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', true, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', false, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', null, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', void 0, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', [ '1' ], 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', {}, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', ( x: number ): number => x, 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $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 A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', '10', 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', true, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', false, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', null, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', void 0, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', [], 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', {}, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', ( x: number ): number => x, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); // $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 A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, '10', A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, true, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, false, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, null, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, void 0, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, [], A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, {}, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, ( x: number ): number => x, A, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, 10, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, '10', x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, true, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, false, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, null, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, void 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, [ '1' ], x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, {}, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, ( x: number ): number => x, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, 10, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, '10', 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, true, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, false, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, null, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, void 0, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, [ '1' ], 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, {}, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, ( x: number ): number => x, 1, 0, 1.0, y, 1, 0 ); // $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 A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, '10', 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, true, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, false, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, null, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, void 0, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, [], 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, {}, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, ( x: number ): number => x, 0, 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 A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, '10', 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, true, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, false, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, null, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, void 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, [], 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, {}, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, ( x: number ): number => x, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, '10', y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, true, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, false, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, null, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, void 0, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, [], y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, {}, y, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, 10, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, '10', 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, true, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, false, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, null, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, void 0, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, [ '1' ], 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, {}, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, '10', 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, true, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, false, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, null, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, void 0, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, [], 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, {}, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 55 ); + + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, '10' ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, true ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, false ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, null ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, void 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, [] ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, {} ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, 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 A = new Float64Array( 55 ); + + dspmv.ndarray(); // $ExpectError + dspmv.ndarray( 'row-major' ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper' ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1 ); // $ExpectError + dspmv.ndarray( 'row-major', 'upper', 10, 1.0, A, x, 1, 0, 1.0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/examples/index.js b/lib/node_modules/@stdlib/blas/base/dspmv/examples/index.js new file mode 100644 index 000000000000..6ea87c251684 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dspmv = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +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 ); + +dspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/dspmv.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/dspmv.js new file mode 100644 index 000000000000..1d1cdf420058 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/dspmv.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dfill = require( '@stdlib/blas/ext/base/dfill' ); +var dscal = require( '@stdlib/blas/base/dscal' ); +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); + + +// 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 {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 {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {number} beta - scalar constant +* @param {Float64Array} y - second input array +* @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 {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +* // y => [ ~7.0, ~12.0, ~15.0 ] +*/ +function dspmv( order, uplo, N, alpha, AP, x, strideX, beta, y, strideY ) { + var temp1; + var temp2; + var ix; + var iy; + var jx; + var jy; + var kk; + var kx; + var ky; + var sy; + var j; + var k; + + if ( !isLayout( order ) ) { + throw new TypeError( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ); + } + if ( N < 0 ) { + throw new RangeError( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ); + } + if ( strideX === 0 ) { + throw new RangeError( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideX ); + } + if ( strideY === 0 ) { + throw new RangeError( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideY ); + } + if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) { + return y; + } + // Form: y = beta*y + sy = strideY; + if ( beta !== 1.0 ) { + if ( beta === 0.0 ) { + dfill( N, 0.0, y, strideY ); + } else { + if ( strideY < 0 ) { + sy = -sy; + } + dscal( N, beta, y, sy ); + } + } + if ( alpha === 0.0 ) { + return y; + } + if ( strideX > 0 ) { + kx = 0; + } else { + kx = ( 1 - N ) * strideX; + } + if ( strideY > 0 ) { + ky = 0; + } else { + ky = ( 1 - N ) * strideY; + } + // Form: y = alpha*A*x + y + kk = 0; + if ( + ( order === 'row-major' && uplo === 'upper' ) || + ( order === 'column-major' && uplo === 'lower' ) + ) { + jx = kx; + jy = ky; + 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; + } + // ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' ) + jx = kx; + jy = ky; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * x[ jx ]; + temp2 = 0.0; + ix = kx; + iy = ky; + 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 = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/index.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/index.js new file mode 100644 index 000000000000..98196e098333 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/index.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/dspmv +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dspmv = require( '@stdlib/blas/base/dspmv' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 ); +* // y => [ ~7.0, ~12.0, ~15.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dspmv = require( '@stdlib/blas/base/dspmv' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ ~7.0, ~12.0, ~15.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dspmv; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dspmv = main; +} else { + dspmv = tmp; +} + + +// EXPORTS // + +module.exports = dspmv; + +// exports: { "ndarray": "dspmv.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/main.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/main.js new file mode 100644 index 000000000000..19a9d9e22979 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dspmv = require( './dspmv.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dspmv, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.js new file mode 100644 index 000000000000..c77c91a27dc3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.js @@ -0,0 +1,159 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dfill = require( '@stdlib/blas/ext/base/dfill' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); + + +// 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 {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 {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {number} beta - scalar constant +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @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} eleventh argument must be non-zero +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv( 'column-major', 'lower', 3, 1.0, A, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ ~7.0, ~12.0, ~15.0 ] +*/ +function dspmv( order, uplo, N, alpha, AP, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len + var temp1; + var temp2; + var ix; + var iy; + var jx; + var jy; + var kk; + var kx; + var ky; + var j; + var k; + + if ( !isLayout( order ) ) { + throw new TypeError( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ); + } + if ( N < 0 ) { + throw new RangeError( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ); + } + if ( strideX === 0 ) { + throw new RangeError( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideX ); + } + if ( strideY === 0 ) { + throw new RangeError( 'invalid argument. Eleventh argument must be non-zero. Value: `%d`.', strideY ); + } + if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) { + return y; + } + // Form: y = beta*y + if ( beta !== 1.0 ) { + if ( beta === 0.0 ) { + dfill( N, 0.0, y, strideY, offsetY ); + } else { + dscal( N, beta, y, strideY, offsetY ); + } + } + if ( alpha === 0.0 ) { + return y; + } + // Form: y = alpha*A*x + y + kx = offsetX; + ky = offsetY; + kk = 0; + if ( + ( order === 'row-major' && uplo === 'upper' ) || + ( order === 'column-major' && uplo === 'lower' ) + ) { + jx = kx; + jy = ky; + 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; + } + // ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' ) + jx = kx; + jy = ky; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * x[ jx ]; + temp2 = 0.0; + ix = kx; + iy = ky; + 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 = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/package.json b/lib/node_modules/@stdlib/blas/base/dspmv/package.json new file mode 100644 index 000000000000..a3796aeb02c6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/base/dspmv", + "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", + "dspmv", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xnyn.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xnyn.json new file mode 100644 index 000000000000..dd535606e057 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xnyn.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "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/dspmv/test/fixtures/column_major_xnyp.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xnyp.json new file mode 100644 index 000000000000..88b876d94788 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xnyp.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": 1, + "offsetY": 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/dspmv/test/fixtures/column_major_xoyt.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xoyt.json new file mode 100644 index 000000000000..7ce888f02a01 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xoyt.json @@ -0,0 +1,15 @@ +{ + "uplo": "lower", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 2, + "offsetY": 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/dspmv/test/fixtures/column_major_xpyn.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xpyn.json new file mode 100644 index 000000000000..8fedbd443972 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xpyn.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 2, + "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/dspmv/test/fixtures/column_major_xpyp.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xpyp.json new file mode 100644 index 000000000000..0e57578aba8e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/column_major_xpyp.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "column-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 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/dspmv/test/fixtures/row_major_xnyn.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xnyn.json new file mode 100644 index 000000000000..4763913667f8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xnyn.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "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/dspmv/test/fixtures/row_major_xnyp.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xnyp.json new file mode 100644 index 000000000000..fc5df6d7ce93 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xnyp.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": -1, + "offsetX": 2, + "strideY": 1, + "offsetY": 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/dspmv/test/fixtures/row_major_xoyt.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xoyt.json new file mode 100644 index 000000000000..f77e7da3427f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xoyt.json @@ -0,0 +1,15 @@ +{ + "uplo": "lower", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 2, + "offsetY": 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/dspmv/test/fixtures/row_major_xpyn.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xpyn.json new file mode 100644 index 000000000000..82387497ca33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xpyn.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 2, + "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/dspmv/test/fixtures/row_major_xpyp.json b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xpyp.json new file mode 100644 index 000000000000..d4deab60a3fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/fixtures/row_major_xpyp.json @@ -0,0 +1,15 @@ +{ + "uplo": "upper", + "order": "row-major", + "N": 3, + "alpha": 1.0, + "beta": 1.0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 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/dspmv/test/test.dspmv.js b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.js new file mode 100644 index 000000000000..22282eee40c5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.js @@ -0,0 +1,564 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ones = require( '@stdlib/array/ones' ); +var dspmv = require( './../lib/dspmv.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' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( dspmv.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 i; + + 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() { + dspmv( value, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, value, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, value, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), value, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y_out ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y_out ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.beta, y, cxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxoyt.AP ); + x = new Float64Array( rxoyt.x ); + y = new Float64Array( rxoyt.y ); + + expected = new Float64Array( rxoyt.y_out ); + + out = dspmv( rxoyt.order, rxoyt.uplo, rxoyt.N, rxoyt.alpha, ap, x, rxoyt.strideX, rxoyt.beta, y, rxoyt.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxoyt.AP ); + x = new Float64Array( cxoyt.x ); + y = new Float64Array( cxoyt.y ); + + expected = new Float64Array( cxoyt.y_out ); + + out = dspmv( cxoyt.order, cxoyt.uplo, cxoyt.N, cxoyt.alpha, ap, x, cxoyt.strideX, cxoyt.beta, y, cxoyt.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyn.AP ); + x = new Float64Array( rxpyn.x ); + y = new Float64Array( rxpyn.y ); + + expected = new Float64Array( rxpyn.y_out ); + + out = dspmv( rxpyn.order, rxpyn.uplo, rxpyn.N, rxpyn.alpha, ap, x, rxpyn.strideX, rxpyn.beta, y, rxpyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyn.AP ); + x = new Float64Array( cxpyn.x ); + y = new Float64Array( cxpyn.y ); + + expected = new Float64Array( cxpyn.y_out ); + + out = dspmv( cxpyn.order, cxpyn.uplo, cxpyn.N, cxpyn.alpha, ap, x, cxpyn.strideX, cxpyn.beta, y, cxpyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyp.AP ); + x = new Float64Array( rxnyp.x ); + y = new Float64Array( rxnyp.y ); + + expected = new Float64Array( rxnyp.y_out ); + + out = dspmv( rxnyp.order, rxnyp.uplo, rxnyp.N, rxnyp.alpha, ap, x, rxnyp.strideX, rxnyp.beta, y, rxnyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyp.AP ); + x = new Float64Array( cxnyp.x ); + y = new Float64Array( cxnyp.y ); + + expected = new Float64Array( cxnyp.y_out ); + + out = dspmv( cxnyp.order, cxnyp.uplo, cxnyp.N, cxnyp.alpha, ap, x, cxnyp.strideX, cxnyp.beta, y, cxnyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', function test( t ) { + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, 0, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, 0.0, ap, x, rxpyp.strideX, 1.0, y, rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y ); + + out = dspmv( cxpyp.order, cxpyp.uplo, 0, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.beta, y, cxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, 0.0, ap, x, cxpyp.strideX, 1.0, y, cxpyp.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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( '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 = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( '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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( '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 = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( '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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( '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 = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( '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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( '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 = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( '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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyn.AP ); + x = new Float64Array( rxnyn.x ); + y = new Float64Array( rxnyn.y ); + + expected = new Float64Array( rxnyn.y_out ); + + out = dspmv( rxnyn.order, rxnyn.uplo, rxnyn.N, rxnyn.alpha, ap, x, rxnyn.strideX, rxnyn.beta, y, rxnyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyn.AP ); + x = new Float64Array( cxnyn.x ); + y = new Float64Array( cxnyn.y ); + + expected = new Float64Array( cxnyn.y_out ); + + out = dspmv( cxnyn.order, cxnyn.uplo, cxnyn.N, cxnyn.alpha, ap, x, cxnyn.strideX, cxnyn.beta, y, cxnyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/test/test.js b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.js new file mode 100644 index 000000000000..8c3bd0120733 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dspmv = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dspmv, '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 dspmv.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dspmv = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dspmv, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dspmv; + var main; + + main = require( './../lib/dspmv.js' ); + + dspmv = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dspmv, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.js new file mode 100644 index 000000000000..2f446b3d536c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.js @@ -0,0 +1,564 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ones = require( '@stdlib/array/ones' ); +var dspmv = 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' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( dspmv.length, 12, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( value, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, value, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, value, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), value, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eleventh argument', function test( t ) { + var values; + var i; + + 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() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), value, rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y_out ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y_out ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.offsetX, cxpyp.beta, y, cxpyp.strideY, cxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxoyt.AP ); + x = new Float64Array( rxoyt.x ); + y = new Float64Array( rxoyt.y ); + + expected = new Float64Array( rxoyt.y_out ); + + out = dspmv( rxoyt.order, rxoyt.uplo, rxoyt.N, rxoyt.alpha, ap, x, rxoyt.strideX, rxoyt.offsetX, rxoyt.beta, y, rxoyt.strideY, rxoyt.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxoyt.AP ); + x = new Float64Array( cxoyt.x ); + y = new Float64Array( cxoyt.y ); + + expected = new Float64Array( cxoyt.y_out ); + + out = dspmv( cxoyt.order, cxoyt.uplo, cxoyt.N, cxoyt.alpha, ap, x, cxoyt.strideX, cxoyt.offsetX, cxoyt.beta, y, cxoyt.strideY, cxoyt.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyn.AP ); + x = new Float64Array( rxpyn.x ); + y = new Float64Array( rxpyn.y ); + + expected = new Float64Array( rxpyn.y_out ); + + out = dspmv( rxpyn.order, rxpyn.uplo, rxpyn.N, rxpyn.alpha, ap, x, rxpyn.strideX, rxpyn.offsetX, rxpyn.beta, y, rxpyn.strideY, rxpyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyn.AP ); + x = new Float64Array( cxpyn.x ); + y = new Float64Array( cxpyn.y ); + + expected = new Float64Array( cxpyn.y_out ); + + out = dspmv( cxpyn.order, cxpyn.uplo, cxpyn.N, cxpyn.alpha, ap, x, cxpyn.strideX, cxpyn.offsetX, cxpyn.beta, y, cxpyn.strideY, cxpyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyp.AP ); + x = new Float64Array( rxnyp.x ); + y = new Float64Array( rxnyp.y ); + + expected = new Float64Array( rxnyp.y_out ); + + out = dspmv( rxnyp.order, rxnyp.uplo, rxnyp.N, rxnyp.alpha, ap, x, rxnyp.strideX, rxnyp.offsetX, rxnyp.beta, y, rxnyp.strideY, rxnyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyp.AP ); + x = new Float64Array( cxnyp.x ); + y = new Float64Array( cxnyp.y ); + + expected = new Float64Array( cxnyp.y_out ); + + out = dspmv( cxnyp.order, cxnyp.uplo, cxnyp.N, cxnyp.alpha, ap, x, cxnyp.strideX, cxnyp.offsetX, cxnyp.beta, y, cxnyp.strideY, cxnyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', function test( t ) { + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, 0, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, 0.0, ap, x, rxpyp.strideX, rxpyp.offsetX, 1.0, y, rxpyp.strideY, rxpyp.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 out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y ); + + out = dspmv( cxpyp.order, cxpyp.uplo, 0, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.offsetX, cxpyp.beta, y, cxpyp.strideY, cxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, 0.0, ap, x, cxpyp.strideX, cxpyp.offsetX, 1.0, y, cxpyp.strideY, cxpyp.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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, 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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, 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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, 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 = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, 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 out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyn.AP ); + x = new Float64Array( rxnyn.x ); + y = new Float64Array( rxnyn.y ); + + expected = new Float64Array( rxnyn.y_out ); + + out = dspmv( rxnyn.order, rxnyn.uplo, rxnyn.N, rxnyn.alpha, ap, x, rxnyn.strideX, rxnyn.offsetX, rxnyn.beta, y, rxnyn.strideY, rxnyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyn.AP ); + x = new Float64Array( cxnyn.x ); + y = new Float64Array( cxnyn.y ); + + expected = new Float64Array( cxnyn.y_out ); + + out = dspmv( cxnyn.order, cxnyn.uplo, cxnyn.N, cxnyn.alpha, ap, x, cxnyn.strideX, cxnyn.offsetX, cxnyn.beta, y, cxnyn.strideY, cxnyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +});