From ae7730fa99d5365dae7084ef83fb9f00a40effe8 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Sun, 16 Aug 2026 20:03:55 +0530 Subject: [PATCH] feat: add blas/base/gspr --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/gspr/README.md | 172 +++++ .../blas/base/gspr/benchmark/benchmark.js | 105 +++ .../base/gspr/benchmark/benchmark.ndarray.js | 105 +++ .../@stdlib/blas/base/gspr/docs/repl.txt | 109 +++ .../blas/base/gspr/docs/types/index.d.ts | 112 +++ .../@stdlib/blas/base/gspr/docs/types/test.ts | 326 +++++++++ .../@stdlib/blas/base/gspr/examples/index.js | 37 + .../@stdlib/blas/base/gspr/lib/accessors.js | 120 ++++ .../@stdlib/blas/base/gspr/lib/base.js | 115 +++ .../@stdlib/blas/base/gspr/lib/index.js | 61 ++ .../@stdlib/blas/base/gspr/lib/main.js | 82 +++ .../@stdlib/blas/base/gspr/lib/ndarray.js | 85 +++ .../@stdlib/blas/base/gspr/package.json | 68 ++ .../column_major_complex_access_pattern.json | 13 + .../gspr/test/fixtures/column_major_l.json | 13 + .../gspr/test/fixtures/column_major_oap.json | 13 + .../gspr/test/fixtures/column_major_ox.json | 13 + .../gspr/test/fixtures/column_major_sap.json | 13 + .../gspr/test/fixtures/column_major_sapn.json | 13 + .../gspr/test/fixtures/column_major_u.json | 13 + .../gspr/test/fixtures/column_major_xn.json | 13 + .../gspr/test/fixtures/column_major_xp.json | 13 + .../row_major_complex_access_pattern.json | 13 + .../base/gspr/test/fixtures/row_major_l.json | 13 + .../gspr/test/fixtures/row_major_oap.json | 13 + .../base/gspr/test/fixtures/row_major_ox.json | 13 + .../gspr/test/fixtures/row_major_sap.json | 13 + .../gspr/test/fixtures/row_major_sapn.json | 13 + .../base/gspr/test/fixtures/row_major_u.json | 13 + .../base/gspr/test/fixtures/row_major_xn.json | 13 + .../base/gspr/test/fixtures/row_major_xp.json | 13 + .../@stdlib/blas/base/gspr/test/test.js | 38 + .../@stdlib/blas/base/gspr/test/test.main.js | 414 +++++++++++ .../blas/base/gspr/test/test.ndarray.js | 676 ++++++++++++++++++ 34 files changed, 2859 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_complex_access_pattern.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_l.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_oap.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_ox.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sap.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sapn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_u.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_complex_access_pattern.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_l.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_oap.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_ox.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sap.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sapn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_u.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xn.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xp.json create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/gspr/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/base/gspr/README.md b/lib/node_modules/@stdlib/blas/base/gspr/README.md new file mode 100644 index 000000000000..4bc9a94c6c52 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/README.md @@ -0,0 +1,172 @@ + + +# gspr + +> Perform the symmetric rank 1 operation `A = α*x*x^T + A`. + +
+ +## Usage + +```javascript +var gspr = require( '@stdlib/blas/base/gspr' ); +``` + +#### gspr( order, uplo, N, α, x, sx, AP ) + +Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + +```javascript +var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; +var x = [ 1.0, 2.0, 3.0 ]; + +gspr( 'row-major', 'upper', 3, 1.0, x, 1, AP ); +// AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. +- **N**: number of elements along each dimension of `A`. +- **α**: scalar constant. +- **x**: input array. +- **sx**: index increment for `x`. +- **AP**: packed form of a symmetric matrix `A`. + +The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `x` in reverse order, + +```javascript +var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; +var x = [ 3.0, 2.0, 1.0 ]; + +gspr( 'row-major', 'upper', 3, 1.0, x, -1, AP ); +// AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 0.0, 3.0, 2.0, 1.0 ] ); +var AP = new Float64Array( [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +gspr( 'row-major', 'upper', 3, 1.0, x1, -1, AP ); +// AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +``` + +#### gspr.ndarray( order, uplo, N, α, x, sx, ox, AP, sap, oap ) + +Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + +```javascript +var AP = [ 1.0, 1.0, 2.0, 1.0, 2.0, 3.0 ]; +var x = [ 1.0, 2.0, 3.0 ]; + +gspr.ndarray( 'row-major', 'lower', 3, 1.0, x, 1, 0, AP, 1, 0 ); +// AP => [ 2.0, 3.0, 6.0, 4.0, 8.0, 12.0 ] +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. +- **sap**: `AP` stride length. +- **oap**: starting index for `AP`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + +```javascript +var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; +var x = [ 3.0, 2.0, 1.0 ]; + +gspr.ndarray( 'row-major', 'upper', 3, 1.0, x, -1, 2, AP, 1, 0 ); +// AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +``` + +
+ + + +
+ +## Notes + +- `gspr()` corresponds to the BLAS level 2 function `dspr` with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, typed versions such as `dspr` and `sspr` are likely to be significantly more performant. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., `@stdlib/array/base/accessor`). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gspr = require( '@stdlib/blas/base/gspr' ); + +var opts = { + 'dtype': 'generic' +}; + +var N = 5; + +var AP = discreteUniform( N * ( N + 1 ) / 2, -10.0, 10.0, opts ); +var x = discreteUniform( N, -10.0, 10.0, opts ); + +gspr( 'column-major', 'upper', N, 1.0, x, 1, AP ); +console.log( AP ); + +gspr.ndarray( 'column-major', 'upper', N, 1.0, x, 1, 0, AP, 1, 0 ); +console.log( AP ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.js new file mode 100644 index 000000000000..fc6d35c3f231 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var gspr = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( N, -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 = gspr( 'row-major', 'upper', N, 1.0, x, 1, AP ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s:size=%d', pkg, len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..af448cbc676f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var gspr = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( N, -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 = gspr( 'row-major', 'upper', N, 1.0, x, 1, 0, AP, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:size=%d', pkg, len * ( len + 1 ) / 2 ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/gspr/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/gspr/docs/repl.txt new file mode 100644 index 000000000000..b1bfa892349c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/docs/repl.txt @@ -0,0 +1,109 @@ + +{{alias}}( ord, uplo, N, α, x, sx, AP ) + Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a + scalar, `x` is an `N` element vector, 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` or `α` is equal to `0`, the function returns `AP` + 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. + + x: Array|TypedArray + Input vector `x`. + + sx: integer + Index increment for `x`. + + AP: Array|TypedArray + Matrix in packed form. + + Returns + ------- + AP: Array|TypedArray + Matrix in packed form. + + Examples + -------- + > var x = [ 1.0, 1.0 ]; + > var AP = [ 1.0, 2.0, 3.0 ]; + > {{alias}}( 'row-major', 'upper', 2, 1.0, x, 1, AP ) + [ 2.0, 3.0, 4.0 ] + + +{{alias}}.ndarray( ord, uplo, N, α, x, sx, ox, AP, sap, oap ) + Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative + indexing semantics and where `α` is a scalar, `x` is an `N` element vector, + 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. + + x: Array|TypedArray + Input vector `x`. + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + AP: Array|TypedArray + Matrix in packed form. + + sap: integer + Index increment for `AP`. + + oap: integer + Starting index for `AP`. + + Returns + ------- + AP: Array|TypedArray + Matrix in packed form. + + Examples + -------- + > var x = [ 1.0, 1.0 ]; + > var AP = [ 1.0, 2.0, 3.0 ]; + > var ord = 'row-major'; + > var uplo = 'upper'; + > {{alias}}.ndarray( ord, uplo, 2, 1.0, x, 1, 0, AP, 1, 0 ) + [ 2.0, 3.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/gspr/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/gspr/docs/types/index.d.ts new file mode 100644 index 000000000000..3f4b85b2464a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/docs/types/index.d.ts @@ -0,0 +1,112 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout, MatrixTriangle } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gspr`. +*/ +interface Routine { + /** + * Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied + * @param N - number of elements along each dimension of `A` + * @param alpha - scalar constant + * @param x - input vector + * @param strideX - `x` stride length + * @param AP - packed form of a symmetric matrix `A` + * @returns `AP` + * + * @example + * var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] + * var x = [ 1.0, 2.0, 3.0 ]; + * + * gspr( 'row-major', 'upper', 3, 1.0, x, 1, AP ); + * // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] + */ + ( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, x: InputArray, strideX: number, AP: T ): T; + + /** + * Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied + * @param N - number of elements along each dimension of `A` + * @param alpha - scalar constant + * @param x - input vector + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param AP - packed form of a symmetric matrix `A` + * @param strideAP - `AP` stride length + * @param offsetAP - starting index for `AP` + * @returns `AP` + * + * @example + * var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] + * var x = [ 1.0, 2.0, 3.0 ]; + * + * gspr.ndarray( 'row-major', 'upper', 3, 1.0, x, 1, 0, AP, 1, 0 ); + * // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] + */ + ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, x: InputArray, strideX: number, offsetX: number, AP: T, strideAP: number, offsetAP: number ): T; +} + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param order - storage layout +* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied +* @param N - number of elements along each dimension of `A` +* @param alpha - scalar constant +* @param x - input vector +* @param strideX - `x` stride length +* @param AP - packed form of a symmetric matrix `A` +* @returns `AP` +* +* @example +* var AP = [ 1.0, 1.0, 2.0, 1.0, 2.0, 3.0 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr( 'row-major', 'lower', 3, 1.0, x, 1, AP ); +* // AP => [ 2.0, 3.0, 6.0, 4.0, 8.0, 12.0 ] +* +* @example +* var AP = [ 1.0, 1.0, 2.0, 1.0, 2.0, 3.0 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr.ndarray( 'row-major', 'lower', 3, 1.0, x, 1, 0, AP, 1, 0 ); +* // AP => [ 2.0, 3.0, 6.0, 4.0, 8.0, 12.0 ] +*/ +declare var gspr: Routine; + + +// EXPORTS // + +export = gspr; diff --git a/lib/node_modules/@stdlib/blas/base/gspr/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/gspr/docs/types/test.ts new file mode 100644 index 000000000000..8ac6bca3de61 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/docs/types/test.ts @@ -0,0 +1,326 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import gspr = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspr( 'row-major', 'upper', 10, 1.0, x, 1, AP ); // $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 AP = new Float64Array( 55 ); + + gspr( 10, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( true, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( false, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( null, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( void 0, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( [], 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( {}, 'upper', 10, 1.0, x, 1, AP ); // $ExpectError + gspr( ( x: number ): number => x, 'upper', 10, 1.0, x, 1, AP ); // $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 AP = new Float64Array( 55 ); + + gspr( 'row-major', 10, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', true, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', false, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', null, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', void 0, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', [ '1' ], 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', {}, 10, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', ( x: number ): number => x, 10, 1.0, x, 1, AP ); // $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 AP = new Float64Array( 55 ); + + gspr( 'row-major', 'upper', '10', 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', true, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', false, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', null, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', void 0, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', [], 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', {}, 1.0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', ( x: number ): number => x, 1.0, x, 1, AP ); // $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 AP = new Float64Array( 55 ); + + gspr( 'row-major', 'upper', 10, '10', x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, true, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, false, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, null, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, void 0, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, [], x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, {}, x, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, ( x: number ): number => x, x, 1, AP ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not an array... +{ + const AP = new Float64Array( 55 ); + + gspr( 'row-major', 'upper', 10, 1.0, 10, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, '10', 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, true, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, false, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, null, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, void 0, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, [ '1' ], 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, {}, 1, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, ( x: number ): number => x, 1, AP ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspr( 'row-major', 'upper', 10, 1.0, x, '10', AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, true, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, false, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, null, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, void 0, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, [], AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, {}, AP ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, ( x: number ): number => x, AP ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not an array... +{ + const x = new Float64Array( 10 ); + + gspr( 'row-major', 'upper', 10, 1.0, x, 1, 10 ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, '10' ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, true ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, false ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, null ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, void 0 ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, [ '1' ] ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, {} ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, ( 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 AP = new Float64Array( 55 ); + + gspr(); // $ExpectError + gspr( 'row-major' ); // $ExpectError + gspr( 'row-major', 'upper' ); // $ExpectError + gspr( 'row-major', 'upper', 10 ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1 ); // $ExpectError + gspr( 'row-major', 'upper', 10, 1.0, x, 1, AP, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns an array... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray( 10, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( true, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( false, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( null, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( void 0, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( [], 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( {}, 'upper', 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( ( x: number ): number => x, 'upper', 10, 1.0, x, 1, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 10, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', true, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', false, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', null, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', void 0, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', [ '1' ], 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', {}, 10, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', ( x: number ): number => x, 10, 1.0, x, 1, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', '10', 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', true, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', false, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', null, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', void 0, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', [], 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', {}, 1.0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', ( x: number ): number => x, 1.0, x, 1, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, '10', x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, true, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, false, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, null, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, void 0, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, [], x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, {}, x, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, ( x: number ): number => x, x, 1, 0, AP, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not an array... +{ + const AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, 10, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, '10', 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, true, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, false, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, null, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, void 0, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, [ '1' ], 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, {}, 1, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, ( x: number ): number => x, 1, 0, AP, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, '10', 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, true, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, false, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, null, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, void 0, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, [], 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, {}, 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, ( x: number ): number => x, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, '10', AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, true, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, false, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, null, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, void 0, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, [], AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, {}, AP, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, ( x: number ): number => x, AP, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not an array... +{ + const x = new Float64Array( 10 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, 10, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, '10', 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, true, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, false, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, null, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, void 0, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, {}, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, '10', 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, true, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, false, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, null, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, void 0, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, [], 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, {}, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, ( x: number ): number => x, 0 ); // $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 AP = new Float64Array( 55 ); + + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, '10' ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, true ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, false ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, null ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, void 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, [] ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, {} ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 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 AP = new Float64Array( 55 ); + + gspr.ndarray(); // $ExpectError + gspr.ndarray( 'row-major' ); // $ExpectError + gspr.ndarray( 'row-major', 'upper' ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1 ); // $ExpectError + gspr.ndarray( 'row-major', 'upper', 10, 1.0, x, 1, 0, AP, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/examples/index.js b/lib/node_modules/@stdlib/blas/base/gspr/examples/index.js new file mode 100644 index 000000000000..2e3660be3e64 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gspr = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var N = 5; + +var AP = discreteUniform( N * ( N + 1 ) / 2, -10.0, 10.0, opts ); +var x = discreteUniform( N, -10.0, 10.0, opts ); + +gspr( 'column-major', 'upper', N, 1.0, x, 1, AP ); +console.log( AP ); + +gspr.ndarray( 'column-major', 'upper', N, 1.0, x, 1, 0, AP, 1, 0 ); +console.log( AP ); diff --git a/lib/node_modules/@stdlib/blas/base/gspr/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/gspr/lib/accessors.js new file mode 100644 index 000000000000..82dc95e977e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/lib/accessors.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); + + +// MAIN // + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {Object} x - input vector object +* @param {Collection} x.data - input vector data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} AP - packed matrix object +* @param {Collection} AP.data - packed matrix data +* @param {Array} AP.accessors - array element accessors +* @param {integer} strideAP - `AP` stride length +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @returns {Object} packed matrix object +*/ +function gspr( order, uplo, N, alpha, x, strideX, offsetX, AP, strideAP, offsetAP ) { // eslint-disable-line max-len + var setAP; + var getAP; + var APbuf; + var xbuf; + var getX; + var tmp; + var iap; + var ix0; + var ix1; + var i0; + var i1; + var kk; + var v; + + // Cache references to array data: + xbuf = x.data; + APbuf = AP.data; + + // Cache references to element accessors: + getX = x.accessors[ 0 ]; + getAP = AP.accessors[ 0 ]; + setAP = AP.accessors[ 1 ]; + + kk = offsetAP; + if ( + ( isColumnMajor( order ) && uplo === 'upper' ) || + ( isRowMajor( order ) && uplo === 'lower' ) + ) { + ix1 = offsetX; + for ( i1 = 0; i1 < N; i1++ ) { + v = getX( xbuf, ix1 ); + if ( v !== 0.0 ) { + tmp = alpha * v; + ix0 = offsetX; + iap = kk; + for ( i0 = 0; i0 <= i1; i0++ ) { + v = getX( xbuf, ix0 ) * tmp; + setAP( APbuf, iap, getAP( APbuf, iap ) + v ); + ix0 += strideX; + iap += strideAP; + } + } + ix1 += strideX; + kk += ( i1 + 1 ) * strideAP; + } + return AP; + } + ix1 = offsetX; + for ( i1 = 0; i1 < N; i1++ ) { + v = getX( xbuf, ix1 ); + if ( v !== 0.0 ) { + tmp = alpha * v; + ix0 = ix1; + iap = kk; + for ( i0 = 0; i0 < N-i1; i0++ ) { + v = getX( xbuf, ix0 ) * tmp; + setAP( APbuf, iap, getAP( APbuf, iap ) + v ); + ix0 += strideX; + iap += strideAP; + } + } + ix1 += strideX; + kk += ( N - i1 ) * strideAP; + } + return AP; +} + + +// EXPORTS // + +module.exports = gspr; diff --git a/lib/node_modules/@stdlib/blas/base/gspr/lib/base.js b/lib/node_modules/@stdlib/blas/base/gspr/lib/base.js new file mode 100644 index 000000000000..858b2ff1c278 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/lib/base.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @private +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} x - input vector +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @param {integer} strideAP - `AP` stride length +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @returns {NumericArray} `AP` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr( 'row-major', 'upper', 3, 1.0, x, 1, 0, AP, 1, 0 ); +* // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +*/ +function gspr( order, uplo, N, alpha, x, strideX, offsetX, AP, strideAP, offsetAP ) { // eslint-disable-line max-len + var apo; + var tmp; + var iap; + var ix0; + var ix1; + var i0; + var i1; + var kk; + var xo; + + xo = arraylike2object( x ); + apo = arraylike2object( AP ); + if ( xo.accessorProtocol || apo.accessorProtocol ) { + accessors( order, uplo, N, alpha, xo, strideX, offsetX, apo, strideAP, offsetAP ); // eslint-disable-line max-len + return AP; + } + kk = offsetAP; + if ( + ( isColumnMajor( order ) && uplo === 'upper' ) || + ( isRowMajor( order ) && uplo === 'lower' ) + ) { + ix1 = offsetX; + for ( i1 = 0; i1 < N; i1++ ) { + if ( x[ ix1 ] !== 0.0 ) { + tmp = alpha * x[ ix1 ]; + ix0 = offsetX; + iap = kk; + for ( i0 = 0; i0 <= i1; i0++ ) { + AP[ iap ] += x[ ix0 ] * tmp; + ix0 += strideX; + iap += strideAP; + } + } + ix1 += strideX; + kk += ( i1 + 1 ) * strideAP; + } + return AP; + } + // Handle the remaining storage layout and triangle combinations: + ix1 = offsetX; + for ( i1 = 0; i1 < N; i1++ ) { + if ( x[ ix1 ] !== 0.0 ) { + tmp = alpha * x[ ix1 ]; + ix0 = ix1; + iap = kk; + for ( i0 = 0; i0 < N - i1; i0++ ) { + AP[ iap ] += x[ ix0 ] * tmp; + ix0 += strideX; + iap += strideAP; + } + } + ix1 += strideX; + kk += ( N - i1 ) * strideAP; + } + return AP; +} + + +// EXPORTS // + +module.exports = gspr; diff --git a/lib/node_modules/@stdlib/blas/base/gspr/lib/index.js b/lib/node_modules/@stdlib/blas/base/gspr/lib/index.js new file mode 100644 index 000000000000..31308f0e03c8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 2 routine to perform the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @module @stdlib/blas/base/gspr +* +* @example +* var gspr = require( '@stdlib/blas/base/gspr' ); +* +* var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr( 'row-major', 'upper', 3, 1.0, x, 1, AP ); +* // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +* +* @example +* var gspr = require( '@stdlib/blas/base/gspr' ); +* +* var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr.ndarray( 'row-major', 'upper', 3, 1.0, x, 1, 0, AP, 1, 0 ); +* // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/gspr/lib/main.js b/lib/node_modules/@stdlib/blas/base/gspr/lib/main.js new file mode 100644 index 000000000000..87717f6d1140 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param {string} order - storage layout +* @param {(integer|string)} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} x - input vector +* @param {integer} strideX - `x` stride length +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @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} sixth argument must be non-zero +* @returns {NumericArray} `AP` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr( 'row-major', 'upper', 3, 1.0, x, 1, AP ); +* // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +*/ +function gspr( order, uplo, N, alpha, x, strideX, AP ) { + var ox; + var u; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + u = resolveStr( uplo ); + if ( u === null ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( N === 0 || alpha === 0.0 ) { + return AP; + } + ox = stride2offset( N, strideX ); + return base( order, u, N, alpha, x, strideX, ox, AP, 1, 0 ); +} + + +// EXPORTS // + +module.exports = gspr; diff --git a/lib/node_modules/@stdlib/blas/base/gspr/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/gspr/lib/ndarray.js new file mode 100644 index 000000000000..02a1e58b9e75 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/lib/ndarray.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var resolveStr = require( '@stdlib/blas/base/matrix-triangle-resolve-str' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param {string} order - storage layout +* @param {(integer|string)} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {NumericArray} x - input vector +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} AP - packed form of a symmetric matrix `A` +* @param {integer} strideAP - `AP` stride length +* @param {NonNegativeInteger} offsetAP - starting index for `AP` +* @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} sixth argument must be non-zero +* @throws {RangeError} ninth argument must be non-zero +* @returns {NumericArray} `AP` +* +* @example +* var AP = [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ]; // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var x = [ 1.0, 2.0, 3.0 ]; +* +* gspr( 'row-major', 'upper', 3, 1.0, x, 1, 0, AP, 1, 0 ); +* // AP => [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +*/ +function gspr( order, uplo, N, alpha, x, strideX, offsetX, AP, strideAP, offsetAP ) { // eslint-disable-line max-len + var u; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + u = resolveStr( uplo ); + if ( u === null ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideAP === 0 ) { + throw new RangeError( format( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideAP ) ); + } + if ( N === 0 || alpha === 0.0 ) { + return AP; + } + return base( order, u, N, alpha, x, strideX, offsetX, AP, strideAP, offsetAP ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gspr; diff --git a/lib/node_modules/@stdlib/blas/base/gspr/package.json b/lib/node_modules/@stdlib/blas/base/gspr/package.json new file mode 100644 index 000000000000..b8aa8460c994 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/base/gspr", + "version": "0.0.0", + "description": "Perform the symmetric rank 1 operation `A = α*x*x^T + A`.", + "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", + "gspr", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "generic", + "typed-array", + "matrix" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_complex_access_pattern.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_complex_access_pattern.json new file mode 100644 index 000000000000..569d0efa057b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_complex_access_pattern.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 3.0, 2.0, 1.0 ], + "strideX": -1, + "offsetX": 2, + "AP": [ 0.0, 3.0, 0.0, 2.0, 0.0, 2.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ], + "strideAP": -2, + "offsetAP": 11, + "AP_out": [ 0.0, 12.0, 0.0, 8.0, 0.0, 6.0, 0.0, 4.0, 0.0, 3.0, 0.0, 2.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_l.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_l.json new file mode 100644 index 000000000000..4a46b878117e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_l.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 1.0, 1.0, 1.0, 2.0, 2.0, 3.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 3.0, 4.0, 6.0, 8.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_oap.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_oap.json new file mode 100644 index 000000000000..ad4d762d0fec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_oap.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0 ], + "strideAP": 1, + "offsetAP": 1, + "AP_out": [ 0.0, 2.0, 3.0, 4.0, 6.0, 8.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_ox.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_ox.json new file mode 100644 index 000000000000..37578600f8db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_ox.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 0.0, 0.0, 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 2, + "AP": [ 1.0, 1.0, 1.0, 2.0, 2.0, 3.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 3.0, 4.0, 6.0, 8.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sap.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sap.json new file mode 100644 index 000000000000..0c6baacf0db1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sap.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 2.0, 0.0, 2.0, 0.0, 3.0, 0.0 ], + "strideAP": 2, + "offsetAP": 1, + "AP_out": [ 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 6.0, 0.0, 8.0, 0.0, 12.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sapn.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sapn.json new file mode 100644 index 000000000000..c23bc068535b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_sapn.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 0.0, 3.0, 0.0, 2.0, 0.0, 2.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ], + "strideAP": -2, + "offsetAP": 11, + "AP_out": [ 0.0, 12.0, 0.0, 8.0, 0.0, 6.0, 0.0, 4.0, 0.0, 3.0, 0.0, 2.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_u.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_u.json new file mode 100644 index 000000000000..738969690150 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_u.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 1.0, 2.0, 1.0, 3.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 5.0, 6.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xn.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xn.json new file mode 100644 index 000000000000..d3ef596ca516 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xn.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 3.0, 2.0, 1.0 ], + "strideX": -1, + "offsetX": 2, + "AP": [ 1.0, 2.0, 1.0, 3.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 5.0, 6.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xp.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xp.json new file mode 100644 index 000000000000..6d6f60b1b8a4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/column_major_xp.json @@ -0,0 +1,13 @@ +{ + "order": "column-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 0.0, 2.0, 0.0, 3.0 ], + "strideX": 2, + "offsetX": 0, + "AP": [ 1.0, 2.0, 1.0, 3.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 5.0, 6.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_complex_access_pattern.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_complex_access_pattern.json new file mode 100644 index 000000000000..0a2ad8b4cd62 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_complex_access_pattern.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 3.0, 2.0, 1.0 ], + "strideX": -1, + "offsetX": 2, + "AP": [ 3.0, 0.0, 2.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 1.0 ], + "strideAP": -2, + "offsetAP": 10, + "AP_out": [ 12.0, 0.0, 8.0, 0.0, 4.0, 0.0, 6.0, 0.0, 3.0, 0.0, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_l.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_l.json new file mode 100644 index 000000000000..d2ef326a78ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_l.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 1.0, 1.0, 2.0, 1.0, 2.0, 3.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 3.0, 6.0, 4.0, 8.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_oap.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_oap.json new file mode 100644 index 000000000000..252589c28ed4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_oap.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 0.0, 1.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ], + "strideAP": 2, + "offsetAP": 1, + "AP_out": [ 0.0, 2.0, 0.0, 3.0, 0.0, 6.0, 0.0, 4.0, 0.0, 8.0, 0.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_ox.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_ox.json new file mode 100644 index 000000000000..10560f4c253a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_ox.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 0.0, 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 1, + "AP": [ 1.0, 1.0, 2.0, 1.0, 2.0, 3.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 3.0, 6.0, 4.0, 8.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sap.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sap.json new file mode 100644 index 000000000000..f4aaa27759a4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sap.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 1.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ], + "strideAP": 2, + "offsetAP": 0, + "AP_out": [ 2.0, 0.0, 3.0, 0.0, 6.0, 0.0, 4.0, 0.0, 8.0, 0.0, 12.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sapn.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sapn.json new file mode 100644 index 000000000000..982895e4648e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_sapn.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "lower", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 3.0, 0.0, 2.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 1.0 ], + "strideAP": -2, + "offsetAP": 10, + "AP_out": [ 12.0, 0.0, 8.0, 0.0, 4.0, 0.0, 6.0, 0.0, 3.0, 0.0, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_u.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_u.json new file mode 100644 index 000000000000..fa7dc425beed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_u.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 2.0, 3.0 ], + "strideX": 1, + "offsetX": 0, + "AP": [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xn.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xn.json new file mode 100644 index 000000000000..19dc2ca8dd73 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xn.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 3.0, 2.0, 1.0 ], + "strideX": -1, + "offsetX": 2, + "AP": [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xp.json b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xp.json new file mode 100644 index 000000000000..ed86f58d9836 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/fixtures/row_major_xp.json @@ -0,0 +1,13 @@ +{ + "order": "row-major", + "uplo": "upper", + "N": 3, + "alpha": 1.0, + "x": [ 1.0, 0.0, 2.0, 0.0, 3.0 ], + "strideX": 2, + "offsetX": 0, + "AP": [ 1.0, 2.0, 3.0, 1.0, 2.0, 1.0 ], + "strideAP": 1, + "offsetAP": 0, + "AP_out": [ 2.0, 4.0, 6.0, 5.0, 8.0, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/test.js b/lib/node_modules/@stdlib/blas/base/gspr/test/test.js new file mode 100644 index 000000000000..658ae474d6a0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var gspr = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspr, '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 gspr.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/test.main.js b/lib/node_modules/@stdlib/blas/base/gspr/test/test.main.js new file mode 100644 index 000000000000..b1dce19dfd35 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/test.main.js @@ -0,0 +1,414 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var gspr = require( './../lib/main.js' ); + + +// FIXTURES // + +var rl = require( './fixtures/row_major_l.json' ); +var ru = require( './fixtures/row_major_u.json' ); +var rxp = require( './fixtures/row_major_xp.json' ); +var rxn = require( './fixtures/row_major_xn.json' ); +var cl = require( './fixtures/column_major_l.json' ); +var cu = require( './fixtures/column_major_u.json' ); +var cxp = require( './fixtures/column_major_xp.json' ); +var cxn = require( './fixtures/column_major_xn.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gspr.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( value, data.uplo, data.N, data.alpha, copy( data.x ), data.strideX, data.AP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, value, data.N, data.alpha, copy( data.x ), data.strideX, data.AP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, data.uplo, value, data.alpha, copy( data.x ), data.strideX, data.AP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, data.uplo, data.N, data.alpha, copy( data.x ), value, data.AP ); + }; + } +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, lower)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rl; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (column-major, lower)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cl; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, upper)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = ru; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (column-major, upper)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cu; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the packed form of a symmetric matrix `A`', function test( t ) { + var data; + var out; + var ap; + var x; + + data = rl; + + ap = copy( data.AP ); + x = copy( data.x ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or `α` is zero, respectively, the function returns `AP` unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = ru; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP ); + + out = gspr( data.order, data.uplo, 0, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + out = gspr( data.order, data.uplo, data.N, 0.0, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or `α` is zero, respectively, the function returns `AP` unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cu; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP ); + + out = gspr( data.order, data.uplo, 0, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + out = gspr( data.order, data.uplo, data.N, 0.0, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rxp; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cxp; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rxn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cxn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var fixtures; + var expected; + var apbuf; + var data; + var out; + var ap; + var x; + var i; + + fixtures = [ rl, cl, ru, cu, rxp, cxp, rxn, cxn ]; + for ( i = 0; i < fixtures.length; i++ ) { + data = fixtures[ i ]; + apbuf = copy( data.AP ); + ap = toAccessorArray( apbuf ); + x = toAccessorArray( copy( data.x ) ); + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, ap ); + t.strictEqual( out, ap, 'returns the accessor array' ); + t.deepEqual( apbuf, expected, 'returns expected values for fixture '+i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/gspr/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/gspr/test/test.ndarray.js new file mode 100644 index 000000000000..5f3236a33fb3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/gspr/test/test.ndarray.js @@ -0,0 +1,676 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var gspr = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var rl = require( './fixtures/row_major_l.json' ); +var ru = require( './fixtures/row_major_u.json' ); +var rxp = require( './fixtures/row_major_xp.json' ); +var rxn = require( './fixtures/row_major_xn.json' ); +var rox = require( './fixtures/row_major_ox.json' ); +var rsap = require( './fixtures/row_major_sap.json' ); +var rsapn = require( './fixtures/row_major_sapn.json' ); +var roap = require( './fixtures/row_major_oap.json' ); +var rcap = require( './fixtures/row_major_complex_access_pattern.json' ); +var cl = require( './fixtures/column_major_l.json' ); +var cu = require( './fixtures/column_major_u.json' ); +var cxp = require( './fixtures/column_major_xp.json' ); +var cxn = require( './fixtures/column_major_xn.json' ); +var cox = require( './fixtures/column_major_ox.json' ); +var csap = require( './fixtures/column_major_sap.json' ); +var csapn = require( './fixtures/column_major_sapn.json' ); +var coap = require( './fixtures/column_major_oap.json' ); +var ccap = require( './fixtures/column_major_complex_access_pattern.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gspr, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gspr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( value, data.uplo, data.N, data.alpha, copy( data.x ), data.strideX, data.offsetX, data.AP, data.strideAP, data.offsetAP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, value, data.N, data.alpha, copy( data.x ), data.strideX, data.offsetX, data.AP, data.strideAP, data.offsetAP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, data.uplo, value, data.alpha, copy( data.x ), data.strideX, data.offsetX, data.AP, data.strideAP, data.offsetAP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, data.uplo, data.N, data.alpha, copy( data.x ), value, data.offsetX, data.AP, data.strideAP, data.offsetAP ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid ninth argument', function test( t ) { + var values; + var data; + var i; + + data = rl; + + 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() { + gspr( data.order, data.uplo, data.N, data.alpha, copy( data.x ), data.strideX, data.offsetX, data.AP, value, data.offsetAP ); + }; + } +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, lower)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rl; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (column-major, lower)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cl; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, upper)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = ru; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the symmetric rank 1 operation `A = α*x*x^T + A` (column-major, upper)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cu; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the packed form of a symmetric matrix `A`', function test( t ) { + var data; + var out; + var ap; + var x; + + data = rl; + + ap = copy( data.AP ); + x = copy( data.x ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or `α` is zero, respectively, the function returns `AP` unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = ru; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP ); + + out = gspr( data.order, data.uplo, 0, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + out = gspr( data.order, data.uplo, data.N, 0.0, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or `α` is zero, respectively, the function returns `AP` unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cu; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP ); + + out = gspr( data.order, data.uplo, 0, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + out = gspr( data.order, data.uplo, data.N, 0.0, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( ap, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rxp; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cxp; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rxn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cxn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` offset (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rox; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an `x` offset (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = cox; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `AP` (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rsap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `AP` (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = csap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `AP` (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rsapn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `AP` (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = csapn; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset for `AP` (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = roap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset for `AP` (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = coap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = rcap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var data; + var out; + var ap; + var x; + + data = ccap; + + ap = copy( data.AP ); + x = copy( data.x ); + + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var fixtures; + var expected; + var apbuf; + var data; + var out; + var ap; + var x; + var i; + + fixtures = [ + rl, + cl, + ru, + cu, + rxp, + cxp, + rxn, + cxn, + rox, + cox, + rsap, + csap, + rsapn, + csapn, + roap, + coap, + rcap, + ccap + ]; + for ( i = 0; i < fixtures.length; i++ ) { + data = fixtures[ i ]; + apbuf = copy( data.AP ); + ap = toAccessorArray( apbuf ); + x = toAccessorArray( copy( data.x ) ); + expected = copy( data.AP_out ); + + out = gspr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, ap, data.strideAP, data.offsetAP ); + t.strictEqual( out, ap, 'returns the accessor array' ); + t.deepEqual( apbuf, expected, 'returns expected values for fixture '+i ); + } + t.end(); +});