From e72d12e078d62546e55e69dc3dfed24110f5c94e Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Mon, 9 Mar 2026 16:31:24 +0530 Subject: [PATCH 1/3] feat: add C implementation for `blas/base/dspmv` --- 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 status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/dspmv/README.md | 99 ++- .../base/dspmv/benchmark/benchmark.native.js | 111 ++++ .../benchmark/benchmark.ndarray.native.js | 111 ++++ .../blas/base/dspmv/benchmark/c/Makefile | 146 +++++ .../base/dspmv/benchmark/c/benchmark.length.c | 201 ++++++ .../@stdlib/blas/base/dspmv/binding.gyp | 265 ++++++++ .../blas/base/dspmv/examples/c/Makefile | 146 +++++ .../blas/base/dspmv/examples/c/example.c | 51 ++ .../@stdlib/blas/base/dspmv/include.gypi | 70 +++ .../dspmv/include/stdlib/blas/base/dspmv.h | 48 ++ .../include/stdlib/blas/base/dspmv_cblas.h | 48 ++ .../blas/base/dspmv/lib/dspmv.native.js | 87 +++ .../@stdlib/blas/base/dspmv/lib/native.js | 35 ++ .../blas/base/dspmv/lib/ndarray.native.js | 89 +++ .../@stdlib/blas/base/dspmv/manifest.json | 535 ++++++++++++++++ .../@stdlib/blas/base/dspmv/package.json | 4 + .../@stdlib/blas/base/dspmv/src/Makefile | 70 +++ .../@stdlib/blas/base/dspmv/src/addon.c | 91 +++ .../@stdlib/blas/base/dspmv/src/dspmv.c | 68 +++ .../@stdlib/blas/base/dspmv/src/dspmv_cblas.c | 40 ++ .../blas/base/dspmv/src/dspmv_ndarray.c | 143 +++++ .../blas/base/dspmv/test/test.dspmv.native.js | 572 ++++++++++++++++++ .../base/dspmv/test/test.ndarray.native.js | 572 ++++++++++++++++++ 23 files changed, 3594 insertions(+), 8 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv.h create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/lib/dspmv.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_ndarray.c create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/README.md b/lib/node_modules/@stdlib/blas/base/dspmv/README.md index a219c0bac186..6cf26dc8e7bb 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/README.md +++ b/lib/node_modules/@stdlib/blas/base/dspmv/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +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. @@ -190,21 +190,72 @@ console.log( y ); ### Usage ```c -TODO +#include "stdlib/blas/base/dspmv.h" ``` -#### TODO +#### c_dspmv( order, uplo, N, alpha, \*AP, \*X, strideX, beta, \*Y, strideY ) -TODO. +Performs the matrix-vector operation `y = α*A*x + β*y` where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form `AP`. + +```c +#include "stdlib/blas/base/shared.h" + +const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; +const double x[] = { 1.0, 1.0, 1.0 }; +double y[] = { 1.0, 1.0, 1.0 }; + +c_dspmv( CblasColMajor, CblasLower, 3, 1.0, AP, x, 1, 1.0, y, 1 ); +``` + +The function accepts the following arguments: + +- **order**: `[in] CBLAS_LAYOUT` storage layout. +- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. +- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`. +- **alpha**: `[in] double` scalar constant. +- **AP**: `[in] double*` packed form of a symmetric matrix `A`. +- **X**: `[in] double*` first input vector. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **beta**: `[in] double` scalar constant. +- **Y**: `[inout] double*` second input vector. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. ```c -TODO +void c_dspmv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) +``` + +#### c_dspmv_ndarray( order, uplo, N, alpha, \*AP, oap, \*X, sx, ox, beta, \*Y, sy, oy ) + +Performs the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form `AP`. + +```c +#include "stdlib/blas/base/shared.h" + +const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; +const double x[] = { 1.0, 1.0, 1.0 }; +double y[] = { 1.0, 1.0, 1.0 }; + +c_dspmv_ndarray( CblasColMajor, CblasLower, 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); ``` -TODO +The function accepts the following arguments: + +- **order**: `[in] CBLAS_LAYOUT` storage layout. +- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied. +- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`. +- **alpha**: `[in] double` scalar. +- **AP**: `[in] double*` packed form of a symmetric matrix `A`. +- **oap**: `[in] CBLAS_INT` starting index for `AP`. +- **X**: `[in] double*` first input vector. +- **sx**: `[in] CBLAS_INT` stride length for `X`. +- **ox**: `[in] CBLAS_INT` starting index for `X`. +- **beta**: `[in] double` scalar. +- **Y**: `[inout] double*` second input vector. +- **sy**: `[in] CBLAS_INT` stride length for `Y`. +- **oy**: `[in] CBLAS_INT` starting index for `Y`. ```c -TODO +void c_dspmv_ndarray( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const CBLAS_INT offsetAP, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) ``` @@ -226,7 +277,39 @@ TODO ### Examples ```c -TODO +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define `AP`, a packed form of a symmetric matrix `A`: + const double AP[ 3*(3+1)/2 ] = { + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 + }; + + // Define `x` and `y` vectors: + const double x[ 3 ] = { 1.0, 1.0, 1.0 }; + double y[ 3 ] = { 1.0, 1.0, 1.0 }; + + // Specify the number of elements along each dimension of `A`: + const int N = 3; + + // Perform the matrix-vector operation `y = α*A*x + β*y`: + c_dspmv( CblasColMajor, CblasLower, N, 1.0, AP, x, 1, 1.0, y, 1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } + + // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: + c_dspmv_ndarray( CblasColMajor, CblasLower, N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} ``` diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f4430efdfaec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.native.js @@ -0,0 +1,111 @@ +/** +* @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 resolve = require( 'path' ).resolve; +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 tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) ); +var opts = { + 'skip': ( dspmv instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 1.0, y, 1 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s::native:size=%d', pkg, len * ( len + 1 ) / 2 ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..f9a362bf8cd3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,111 @@ +/** +* @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 resolve = require( 'path' ).resolve; +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 tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) ); +var opts = { + 'skip': ( dspmv instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dspmv( 'row-major', 'upper', len, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:size=%d', pkg, len * ( len + 1 ) / 2 ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..762ec4a5c6f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/c/benchmark.length.c @@ -0,0 +1,201 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include +#include +#include +#include +#include + +#define NAME "dspmv" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param N array dimension size +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int N ) { + double elapsed; + double AP[ N*N ]; + double x[ N ]; + double y[ N ]; + double t; + int i; + int j; + + for ( i = 0, j = 0; i < N; i++, j += 2 ) { + x[ i ] = ( rand_double()*20.0 ) - 10.0; + y[ i ] = ( rand_double()*20.0 ) - 10.0; + AP[ j ] = ( rand_double()*20.0 ) - 10.0; + AP[ j+1 ] = ( rand_double()*20.0 ) - 10.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + c_dspmv( CblasRowMajor, CblasUpper, N, 1.0, AP, x, 1, 1.0, y, 1 ); + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param N array dimension size +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int N ) { + double elapsed; + double AP[ N*N ]; + double x[ N ]; + double y[ N ]; + double t; + int i; + int j; + + for ( i = 0, j = 0; i < N; i++, j += 2 ) { + x[ i ] = ( rand_double()*20.0 ) - 10.0; + y[ i ] = ( rand_double()*20.0 ) - 10.0; + AP[ j ] = ( rand_double()*20.0 ) - 10.0; + AP[ j+1 ] = ( rand_double()*20.0 ) - 10.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + c_dspmv_ndarray( CblasRowMajor, CblasUpper, N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%N ] != y[ i%N ] ){ + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int N; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:size=%d\n", NAME, N*N ); + elapsed = benchmark1( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:size=%d\n", NAME, N*N ); + elapsed = benchmark2( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/binding.gyp b/lib/node_modules/@stdlib/blas/base/dspmv/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/binding.gyp @@ -0,0 +1,265 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c new file mode 100644 index 000000000000..b5ebfaed016b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define `AP`, a packed form of a symmetric matrix `A`: + const double AP[ 3*(3+1)/2 ] = { + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 + }; + + // Define `x` and `y` vectors: + const double x[ 3 ] = { 1.0, 1.0, 1.0 }; + double y[ 3 ] = { 1.0, 1.0, 1.0 }; + + // Specify the number of elements along each dimension of `A`: + const int N = 3; + + // Perform the matrix-vector operation `y = α*A*x + β*y`: + c_dspmv( CblasColMajor, CblasLower, N, 1.0, AP, x, 1, 1.0, y, 1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } + + // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: + c_dspmv_ndarray( CblasColMajor, CblasLower, N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/include.gypi b/lib/node_modules/@stdlib/blas/base/dspmv/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/include.gypi @@ -0,0 +1,70 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' [ ~7.0, ~12.0, ~15.0 ] +*/ +function dspmv( order, uplo, N, alpha, AP, x, strideX, beta, y, strideY ) { + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideY ) ); + } + + addon( resolveOrder( order ), resolveUplo( uplo ), N, alpha, AP, x, strideX, beta, y, strideY ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/native.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/native.js new file mode 100644 index 000000000000..a386ed7cc0d8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/native.js @@ -0,0 +1,35 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dspmv = require( './dspmv.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dspmv, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.native.js new file mode 100644 index 000000000000..2c559f49b19f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/lib/ndarray.native.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); +var resolveOrder = require( '@stdlib/blas/base/layout-resolve-enum' ); +var resolveUplo = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var format = require( '@stdlib/string/format' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param {string} order - storage layout +* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param {NonNegativeInteger} N - number of elements along each dimension of `A` +* @param {number} alpha - scalar constant +* @param {Float64Array} AP - packed form of a symmetric matrix `A` +* @param {NonNegativeInteger} offsetAP - starting `AP` index +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {number} beta - scalar constant +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} second argument must specify whether the lower or upper triangular matrix is supplied +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} eighth argument must be non-zero +* @throws {RangeError} twelfth argument must be non-zero +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dspmv( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ ~7.0, ~12.0, ~15.0 ] +*/ +function dspmv( order, uplo, N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether the lower or upper triangular matrix is supplied. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + addon.ndarray( resolveOrder( order ), resolveUplo( uplo ), N, alpha, AP, offsetAP, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = dspmv; diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/manifest.json b/lib/node_modules/@stdlib/blas/base/dspmv/manifest.json new file mode 100644 index 000000000000..f230152d9b85 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/manifest.json @@ -0,0 +1,535 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dspmv_cblas.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/dspmv.c", + "./src/dspmv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/package.json b/lib/node_modules/@stdlib/blas/base/dspmv/package.json index a3796aeb02c6..8dc4332ba579 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/package.json +++ b/lib/node_modules/@stdlib/blas/base/dspmv/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/Makefile b/lib/node_modules/@stdlib/blas/base/dspmv/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c b/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c new file mode 100644 index 000000000000..075ec864fca7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c @@ -0,0 +1,91 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/argv_strided_float64array2d.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 10 ); + + STDLIB_NAPI_ARGV_INT32( env, order, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 1 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 9 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 7 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, AP, (N*(N+1)/2), 1, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 8 ); + + API_SUFFIX(c_dspmv)( order, uplo, N, alpha, AP, X, strideX, beta, Y, strideY ); + + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 13 ); + + STDLIB_NAPI_ARGV_INT32( env, order, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 1 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 12 ); + STDLIB_NAPI_ARGV_INT64( env, offsetAP, argv, 5 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 9 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, AP, (N*(N+1)/2), strideX, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 10 ); + + API_SUFFIX(c_dspmv_ndarray)( order, uplo, N, alpha, AP, offsetAP, X, strideX, offsetX, beta, Y, strideY, offsetY ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv.c b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv.c new file mode 100644 index 000000000000..2b6395a0ffa5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv.c @@ -0,0 +1,68 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Performs the matrix-vector operation `Y = alpha*A*X + beta*Y` where `alpha` and `beta` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param order storage layout +* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param N number of elements along each dimension of `A` +* @param alpha scalar constant +* @param AP packed form of a symmetric matrix `A` +* @param X first input array +* @param strideX `X` stride length +* @param beta scalar constant +* @param Y second input array +* @param strideY `Y` stride length +* @return output value +*/ +void API_SUFFIX(c_dspmv)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { + CBLAS_INT offsetX; + CBLAS_INT offsetY; + + // Perform input argument validation... + if ( order != CblasRowMajor && order != CblasColMajor ) { + c_xerbla( 1, "c_dspmv", "Error: invalid argument. First argument must be a valid storage layout. Value: `%d`.", order ); + return; + } + if ( uplo != CblasUpper && uplo != CblasLower ) { + c_xerbla( 2, "c_dspmv", "Error: invalid argument. Second argument must be a either upper or lower. Value: `%d`.", uplo ); + return; + } + if ( N < 0 ) { + c_xerbla( 3, "c_dspmv", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", N ); + return; + } + if ( strideX == 0 ) { + c_xerbla( 7, "c_dspmv", "Error: invalid argument. Seventh argument must be a nonzero. Value: `%d`.", strideX ); + return; + } + if ( strideY == 0 ) { + c_xerbla( 10, "c_dspmv", "Error: invalid argument. Tenth argument must be a nonzero. Value: `%d`.", strideY ); + return; + } + offsetX = stdlib_strided_stride2offset( N, strideX ); + offsetY = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_dspmv_ndarray)( order, uplo, N, alpha, AP, 0, X, strideX, offsetX, beta, Y, strideY, offsetY ); + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_cblas.c b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_cblas.c new file mode 100644 index 000000000000..4516be9e7fa5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_cblas.c @@ -0,0 +1,40 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/dspmv_cblas.h" +#include "stdlib/blas/base/shared.h" + +/** +* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param order storage layout +* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param N number of elements along each dimension of `A` +* @param alpha scalar constant +* @param AP packed form of a symmetric matrix `A` +* @param x first input array +* @param strideX `x` stride length +* @param beta scalar constant +* @param y second input array +* @param strideY `y` stride length +* @return output value +*/ +void API_SUFFIX(c_dspmv)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { + API_SUFFIX(cblas_dspmv)( order, uplo, N, alpha, AP, X, strideX, beta, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_ndarray.c b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_ndarray.c new file mode 100644 index 000000000000..fa93821319e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/dspmv_ndarray.c @@ -0,0 +1,143 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/dspmv.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" +#include "stdlib/blas/base/dscal.h" +#include "stdlib/blas/ext/base/dfill.h" + +/** +* Performs the matrix-vector operation `Y = alpha*A*X + beta*Y` where `alpha` and `beta` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form. +* +* @param order storage layout +* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied +* @param N number of elements along each dimension of `A` +* @param alpha scalar constant +* @param AP packed form of a symmetric matrix `A` +* @param offsetAP starting `AP` index +* @param X first input array +* @param strideX `X` stride length +* @param offsetX starting `X` index +* @param beta scalar constant +* @param Y second input array +* @param strideY `Y` stride length +* @param offsetY starting `Y` index +* @returns output value +*/ +void API_SUFFIX(c_dspmv_ndarray)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const CBLAS_INT offsetAP, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT jx; + CBLAS_INT jy; + CBLAS_INT kk; + CBLAS_INT kx; + CBLAS_INT ky; + CBLAS_INT j; + CBLAS_INT k; + double temp1; + double temp2; + + // Note on variable naming convention: da#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Perform input argument validation... + if ( order != CblasColMajor && order != CblasRowMajor ) { + c_xerbla( 1, "c_dspmv_ndarray", "Error: invalid argument. First argument must be a valid storage order. Value: `%d`.", order ); + return; + } + if ( uplo != CblasUpper && uplo != CblasLower ) { + c_xerbla( 2, "c_dspmv_ndarray", "Error: invalid argument. Second argument must be a either upper or lower. Value: `%d`.", uplo ); + return; + } + if ( N < 0 ) { + c_xerbla( 3, "c_dspmv_ndarray", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", N ); + return; + } + if ( strideX == 0 ) { + c_xerbla( 8, "c_dspmv_ndarray", "Error: invalid argument. Eighth argument must be a nonzero. Value: `%d`.", strideX ); + return; + } + if ( strideY == 0 ) { + c_xerbla( 12, "c_dspmv_ndarray", "Error: invalid argument. Twelfth argument must be a nonzero. Value: `%d`.", strideY ); + return; + } + // Check whether we can avoid computation altogether... + if ( N == 0 || ( alpha == 0.0 && beta == 1.0 ) ) { + return; + } + // Form: y = beta*y + if ( beta != 1.0 ) { + if ( beta == 0.0 ) { + API_SUFFIX(stdlib_strided_dfill_ndarray)( N, 0.0, Y, strideY, offsetY ); + } else { + API_SUFFIX(c_dscal_ndarray)( N, beta, Y, strideY, offsetY ); + } + } + if ( alpha == 0.0 ) { + return; + } + // Form: y = alpha*A*x + y + kx = offsetX; + ky = offsetY; + kk = offsetAP; + if ( + ( order == CblasRowMajor && uplo == CblasUpper ) || + ( order == CblasColMajor && uplo == CblasLower ) + ) { + jx = kx; + jy = ky; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * X[ jx ]; + temp2 = 0.0; + Y[ jy ] += temp1 * AP[ kk ]; + ix = jx; + iy = jy; + for ( k = kk + 1; k < kk + N - j; k++ ) { + ix += strideX; + iy += strideY; + Y[ iy ] += temp1 * AP[ k ]; + temp2 += AP[ k ] * X[ ix ]; + } + Y[ jy ] += alpha * temp2; + jx += strideX; + jy += strideY; + kk += N - j; + } + return; + } + // ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' ) + jx = kx; + jy = ky; + for ( j = 0; j < N; j++ ) { + temp1 = alpha * X[ jx ]; + temp2 = 0.0; + ix = kx; + iy = ky; + for ( k = kk; k < kk + j; k++ ) { + Y[ iy ] += temp1 * AP[ k ]; + temp2 += AP[ k ] * X[ ix ]; + ix += strideX; + iy += strideY; + } + Y[ jy ] += ( temp1 * AP[ kk + j ] ) + ( alpha * temp2 ); + jx += strideX; + jy += strideY; + kk += j + 1; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.native.js new file mode 100644 index 000000000000..262cef273073 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.dspmv.native.js @@ -0,0 +1,572 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ones = require( '@stdlib/array/ones' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var rxoyt = require( './fixtures/row_major_xoyt.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var cxoyt = require( './fixtures/column_major_xoyt.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); + + +// VARIABLES // + +var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) ); +var opts = { + 'skip': ( dspmv instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', opts, function test( t ) { + t.strictEqual( dspmv.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( value, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, value, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, value, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', opts, function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), value, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid tenth argument', opts, function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.beta, new Float64Array( rxpyp.y ), value ); + }; + } +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y_out ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y_out ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.beta, y, cxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=2)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxoyt.AP ); + x = new Float64Array( rxoyt.x ); + y = new Float64Array( rxoyt.y ); + + expected = new Float64Array( rxoyt.y_out ); + + out = dspmv( rxoyt.order, rxoyt.uplo, rxoyt.N, rxoyt.alpha, ap, x, rxoyt.strideX, rxoyt.beta, y, rxoyt.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=2)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxoyt.AP ); + x = new Float64Array( cxoyt.x ); + y = new Float64Array( cxoyt.y ); + + expected = new Float64Array( cxoyt.y_out ); + + out = dspmv( cxoyt.order, cxoyt.uplo, cxoyt.N, cxoyt.alpha, ap, x, cxoyt.strideX, cxoyt.beta, y, cxoyt.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=1, sy=-1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyn.AP ); + x = new Float64Array( rxpyn.x ); + y = new Float64Array( rxpyn.y ); + + expected = new Float64Array( rxpyn.y_out ); + + out = dspmv( rxpyn.order, rxpyn.uplo, rxpyn.N, rxpyn.alpha, ap, x, rxpyn.strideX, rxpyn.beta, y, rxpyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=1, sy=-1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyn.AP ); + x = new Float64Array( cxpyn.x ); + y = new Float64Array( cxpyn.y ); + + expected = new Float64Array( cxpyn.y_out ); + + out = dspmv( cxpyn.order, cxpyn.uplo, cxpyn.N, cxpyn.alpha, ap, x, cxpyn.strideX, cxpyn.beta, y, cxpyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (row-major, sx=-1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyp.AP ); + x = new Float64Array( rxnyp.x ); + y = new Float64Array( rxnyp.y ); + + expected = new Float64Array( rxnyp.y_out ); + + out = dspmv( rxnyp.order, rxnyp.uplo, rxnyp.N, rxnyp.alpha, ap, x, rxnyp.strideX, rxnyp.beta, y, rxnyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form (column-major, sx=-1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyp.AP ); + x = new Float64Array( cxnyp.x ); + y = new Float64Array( cxnyp.y ); + + expected = new Float64Array( cxnyp.y_out ); + + out = dspmv( cxnyp.order, cxnyp.uplo, cxnyp.N, cxnyp.alpha, ap, x, cxnyp.strideX, cxnyp.beta, y, cxnyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', opts, function test( t ) { + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, 0, rxpyp.alpha, ap, x, rxpyp.strideX, rxpyp.beta, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, 0.0, ap, x, rxpyp.strideX, 1.0, y, rxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y ); + + out = dspmv( cxpyp.order, cxpyp.uplo, 0, cxpyp.alpha, ap, x, cxpyp.strideX, cxpyp.beta, y, cxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, 0.0, ap, x, cxpyp.strideX, 1.0, y, cxpyp.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, upper)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, x, 1, 5.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, x, 1, 0.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, lower)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, x, 1, 5.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, x, 1, 0.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, upper)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, x, 1, 5.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, x, 1, 0.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, lower)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, x, 1, 5.0, y, -1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, x, 1, 0.0, y, 1 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyn.AP.slice( rxnyn.offsetAP ) ); + x = new Float64Array( rxnyn.x ); + y = new Float64Array( rxnyn.y ); + + expected = new Float64Array( rxnyn.y_out ); + + out = dspmv( rxnyn.order, rxnyn.uplo, rxnyn.N, rxnyn.alpha, ap, x, rxnyn.strideX, rxnyn.beta, y, rxnyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyn.AP.slice( cxnyn.offsetAP ) ); + x = new Float64Array( cxnyn.x ); + y = new Float64Array( cxnyn.y ); + + expected = new Float64Array( cxnyn.y_out ); + + out = dspmv( cxnyn.order, cxnyn.uplo, cxnyn.N, cxnyn.alpha, ap, x, cxnyn.strideX, cxnyn.beta, y, cxnyn.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.native.js new file mode 100644 index 000000000000..699450977af0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dspmv/test/test.ndarray.native.js @@ -0,0 +1,572 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ones = require( '@stdlib/array/ones' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var rxoyt = require( './fixtures/row_major_xoyt.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var cxoyt = require( './fixtures/column_major_xoyt.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); + + +// VARIABLES // + +var dspmv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dspmv instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dspmv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 13', opts, function test( t ) { + t.strictEqual( dspmv.length, 13, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( value, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), rxpyp.offsetAP, new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, value, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), rxpyp.offsetAP, new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { + var values; + var i; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, value, rxpyp.alpha, new Float64Array( rxpyp.AP ), rxpyp.offsetAP, new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument', opts, function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), rxpyp.offsetAP, new Float64Array( rxpyp.x ), value, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), rxpyp.strideY, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid twelfth argument', opts, function test( t ) { + var values; + var i; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, new Float64Array( rxpyp.AP ), rxpyp.offsetAP, new Float64Array( rxpyp.x ), rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, new Float64Array( rxpyp.y ), value, rxpyp.offsetY ); + }; + } +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (row-major, sx=1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y_out ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, rxpyp.offsetAP, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (column-major, sx=1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y_out ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, cxpyp.alpha, ap, cxpyp.offsetAP, x, cxpyp.strideX, cxpyp.offsetX, cxpyp.beta, y, cxpyp.strideY, cxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (row-major, sx=1, sy=2)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxoyt.AP ); + x = new Float64Array( rxoyt.x ); + y = new Float64Array( rxoyt.y ); + + expected = new Float64Array( rxoyt.y_out ); + + out = dspmv( rxoyt.order, rxoyt.uplo, rxoyt.N, rxoyt.alpha, ap, rxoyt.offsetAP, x, rxoyt.strideX, rxoyt.offsetX, rxoyt.beta, y, rxoyt.strideY, rxoyt.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (column-major, sx=1, sy=2)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxoyt.AP ); + x = new Float64Array( cxoyt.x ); + y = new Float64Array( cxoyt.y ); + + expected = new Float64Array( cxoyt.y_out ); + + out = dspmv( cxoyt.order, cxoyt.uplo, cxoyt.N, cxoyt.alpha, ap, cxoyt.offsetAP, x, cxoyt.strideX, cxoyt.offsetX, cxoyt.beta, y, cxoyt.strideY, cxoyt.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (row-major, sx=1, sy=-1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyn.AP ); + x = new Float64Array( rxpyn.x ); + y = new Float64Array( rxpyn.y ); + + expected = new Float64Array( rxpyn.y_out ); + + out = dspmv( rxpyn.order, rxpyn.uplo, rxpyn.N, rxpyn.alpha, ap, rxpyn.offsetAP, x, rxpyn.strideX, rxpyn.offsetX, rxpyn.beta, y, rxpyn.strideY, rxpyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (column-major, sx=1, sy=-1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyn.AP ); + x = new Float64Array( cxpyn.x ); + y = new Float64Array( cxpyn.y ); + + expected = new Float64Array( cxpyn.y_out ); + + out = dspmv( cxpyn.order, cxpyn.uplo, cxpyn.N, cxpyn.alpha, ap, cxpyn.offsetAP, x, cxpyn.strideX, cxpyn.offsetX, cxpyn.beta, y, cxpyn.strideY, cxpyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (row-major, sx=-1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyp.AP ); + x = new Float64Array( rxnyp.x ); + y = new Float64Array( rxnyp.y ); + + expected = new Float64Array( rxnyp.y_out ); + + out = dspmv( rxnyp.order, rxnyp.uplo, rxnyp.N, rxnyp.alpha, ap, rxnyp.offsetAP, x, rxnyp.strideX, rxnyp.offsetX, rxnyp.beta, y, rxnyp.strideY, rxnyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `n` element vectors, and `A` is an `n` by `n` symmetric matrix supplied in packed form (column-major, sx=-1, sy=1)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyp.AP ); + x = new Float64Array( cxnyp.x ); + y = new Float64Array( cxnyp.y ); + + expected = new Float64Array( cxnyp.y_out ); + + out = dspmv( cxnyp.order, cxnyp.uplo, cxnyp.N, cxnyp.alpha, ap, cxnyp.offsetAP, x, cxnyp.strideX, cxnyp.offsetX, cxnyp.beta, y, cxnyp.strideY, cxnyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector', opts, function test( t ) { + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, rxpyp.alpha, ap, rxpyp.offsetAP, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxpyp.AP ); + x = new Float64Array( rxpyp.x ); + y = new Float64Array( rxpyp.y ); + + expected = new Float64Array( rxpyp.y ); + + out = dspmv( rxpyp.order, rxpyp.uplo, 0, rxpyp.alpha, ap, rxpyp.offsetAP, x, rxpyp.strideX, rxpyp.offsetX, rxpyp.beta, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( rxpyp.order, rxpyp.uplo, rxpyp.N, 0.0, ap, rxpyp.offsetAP, x, rxpyp.strideX, rxpyp.offsetX, 1.0, y, rxpyp.strideY, rxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `N` is zero or the scalar constants are zero and unity, respectively, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxpyp.AP ); + x = new Float64Array( cxpyp.x ); + y = new Float64Array( cxpyp.y ); + + expected = new Float64Array( cxpyp.y ); + + out = dspmv( cxpyp.order, cxpyp.uplo, 0, cxpyp.alpha, ap, cxpyp.offsetAP, x, cxpyp.strideX, cxpyp.offsetX, cxpyp.beta, y, cxpyp.strideY, cxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + out = dspmv( cxpyp.order, cxpyp.uplo, cxpyp.N, 0.0, ap, cxpyp.offsetAP, x, cxpyp.strideX, cxpyp.offsetX, 1.0, y, cxpyp.strideY, cxpyp.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, upper)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (row-major, lower)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'row-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, upper)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'upper', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `α` is zero, the function scales the second input vector (column-major, lower)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = ones( 6, 'float64' ); + x = ones( 3, 'float64' ); + y = ones( 3, 'float64' ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 5.0, y, -1, 2 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + + out = dspmv( 'column-major', 'lower', 3, 0.0, ap, 0, x, 1, 0, 0.0, y, 1, 0 ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( rxnyn.AP ); + x = new Float64Array( rxnyn.x ); + y = new Float64Array( rxnyn.y ); + + expected = new Float64Array( rxnyn.y_out ); + + out = dspmv( rxnyn.order, rxnyn.uplo, rxnyn.N, rxnyn.alpha, ap, rxnyn.offsetAP, x, rxnyn.strideX, rxnyn.offsetX, rxnyn.beta, y, rxnyn.strideY, rxnyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { + var expected; + var out; + var ap; + var x; + var y; + + ap = new Float64Array( cxnyn.AP ); + x = new Float64Array( cxnyn.x ); + y = new Float64Array( cxnyn.y ); + + expected = new Float64Array( cxnyn.y_out ); + + out = dspmv( cxnyn.order, cxnyn.uplo, cxnyn.N, cxnyn.alpha, ap, cxnyn.offsetAP, x, cxnyn.strideX, cxnyn.offsetX, cxnyn.beta, y, cxnyn.strideY, cxnyn.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + isApprox( t, y, expected, 2.0 ); + + t.end(); +}); From e413e9b0171cda9b720b0a1417349d154ae63703 Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Mon, 9 Mar 2026 16:52:36 +0530 Subject: [PATCH 2/3] refactor: remove unnecessary imports --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - 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: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c | 2 +- .../blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h | 2 +- lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c index b5ebfaed016b..9658863c1706 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dspmv/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h b/lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h index 6a36170599af..ef226da12822 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h +++ b/lib/node_modules/@stdlib/blas/base/dspmv/include/stdlib/blas/base/dspmv_cblas.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c b/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c index 075ec864fca7..e210c7ca6187 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dspmv/src/addon.c @@ -24,7 +24,6 @@ #include "stdlib/napi/argv_int32.h" #include "stdlib/napi/argv_double.h" #include "stdlib/napi/argv_strided_float64array.h" -#include "stdlib/napi/argv_strided_float64array2d.h" #include /** From fdf26da99fc6ce9e57b7d6e93e14bc57f50bc904 Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Mon, 9 Mar 2026 17:00:40 +0530 Subject: [PATCH 3/3] chore: minor clean-up --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_license_headers status: passed --- --- .../blas/base/dspmv/benchmark/benchmark.ndarray.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js index f9a362bf8cd3..2d16ebd6035f 100644 --- a/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dspmv/benchmark/benchmark.ndarray.native.js @@ -33,7 +33,7 @@ var pkg = require( './../package.json' ).name; // VARIABLES // -var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) ); +var dspmv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dspmv instanceof Error ) };