From b2357cfa913374ee13a06ec950c1cc78c7198518 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sun, 12 Apr 2026 17:08:08 +0530 Subject: [PATCH 1/4] feat: add C implementation for lapack/base/dlaswp --- 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: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - 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/lapack/base/dlaswp/README.md | 94 ++++++- .../lapack/base/dlaswp/benchmark/c/Makefile | 146 ++++++++++ .../base/dlaswp/benchmark/c/benchmark.size.c | 206 ++++++++++++++ .../@stdlib/lapack/base/dlaswp/binding.gyp | 265 ++++++++++++++++++ .../lapack/base/dlaswp/examples/c/Makefile | 146 ++++++++++ .../lapack/base/dlaswp/examples/c/example.c | 69 +++++ .../@stdlib/lapack/base/dlaswp/include.gypi | 70 +++++ .../include/stdlib/lapack/base/dlaswp.h | 45 +++ .../lapack/base/dlaswp/lib/dlaswp.native.js | 72 +++++ .../@stdlib/lapack/base/dlaswp/lib/native.js | 35 +++ .../lapack/base/dlaswp/lib/ndarray.native.js | 62 ++++ .../@stdlib/lapack/base/dlaswp/manifest.json | 263 +++++++++++++++++ .../@stdlib/lapack/base/dlaswp/package.json | 4 + .../@stdlib/lapack/base/dlaswp/src/Makefile | 70 +++++ .../@stdlib/lapack/base/dlaswp/src/addon.c | 129 +++++++++ .../@stdlib/lapack/base/dlaswp/src/dlaswp.c | 73 +++++ .../lapack/base/dlaswp/src/dlaswp_ndarray.c | 119 ++++++++ .../base/dlaswp/test/test.dlaswp.native.js | 221 +++++++++++++++ .../base/dlaswp/test/test.ndarray.native.js | 185 ++++++++++++ 19 files changed, 2263 insertions(+), 11 deletions(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/benchmark.size.c create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/binding.gyp create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/include/stdlib/lapack/base/dlaswp.h create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/lib/dlaswp.native.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/lib/native.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/manifest.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/src/Makefile create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp.c create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp_ndarray.c create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.dlaswp.native.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/README.md b/lib/node_modules/@stdlib/lapack/base/dlaswp/README.md index 7ce5fd11b41f..e8b14ea8ccea 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlaswp/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/README.md @@ -38,7 +38,7 @@ Performs a series of row interchanges on an input matrix `A` using pivot indices var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var IPIV = new Int32Array( [ 2, 0, 1 ] ); dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 1 ); @@ -62,7 +62,7 @@ The sign of the increment parameter `incx` determines the order in which pivots var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var IPIV = new Int32Array( [ 2, 0, 1 ] ); dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, -1 ); @@ -75,7 +75,7 @@ To perform strided access over `IPIV`, provide an `abs(incx)` value greater than var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var IPIV = new Int32Array( [ 2, 999, 0, 999, 1 ] ); dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 2 ); @@ -110,7 +110,7 @@ Performs a series of row interchanges on the matrix `A` using pivot indices stor var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var IPIV = new Int32Array( [ 2, 0, 1 ] ); dlaswp.ndarray( 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 ); @@ -219,21 +219,66 @@ console.log( ndarray2array( A, shape, strides, offset, order ) ); ### Usage ```c -TODO +#include "stdlib/lapack/base/dlaswp.h" ``` -#### TODO +#### c\_dlaswp( layout, N, \*A, LDA, k1, k2, \*IPIV, incx ) -TODO. +Performs a series of row interchanges on a matrix `A` using pivot indices stored in `IPIV`. ```c -TODO +#include "stdlib/lapack/base/shared.h" + +double A[ 3*2 ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; +const LAPACK_INT IPIV[ 3 ] = { 2, 0, 1 }; + +c_dlaswp( LAPACK_ROW_MAJOR, 2, A, 2, 0, 2, IPIV, 1 ); +``` + +The function accepts the following arguments: + +- **layout**: `[in] LAPACK_LAYOUT` storage layout. +- **N**: `[in] LAPACK_INT` number of columns in `A`. +- **A**: `[inout] double*` input matrix. +- **LDA**: `[in] LAPACK_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **k1**: `[in] LAPACK_INT` index of first row to interchange. +- **k2**: `[in] LAPACK_INT` index of last row to interchange. +- **IPIV**: `[in] LAPACK_INT*` vector of pivot indices. +- **incx**: `[in] LAPACK_INT` increment between successive values of `IPIV`. + +```c +void c_dlaswp( const LAPACK_LAYOUT layout, const LAPACK_INT N, double *A, const LAPACK_INT LDA, const LAPACK_INT k1, const LAPACK_INT k2, const LAPACK_INT *IPIV, const LAPACK_INT incx ); ``` -TODO +#### c\_dlaswp\_ndarray( N, \*A, sa1, sa2, oa, k1, k2, inck, \*IPIV, si, oi ) + +Performs a series of row interchanges on a matrix `A` using pivot indices stored in `IPIV` and alternative indexing semantics. + +```c +#include "stdlib/lapack/base/shared.h" + +double A[ 3*2 ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; +const LAPACK_INT IPIV[ 3 ] = { 2, 0, 1 }; + +c_dlaswp_ndarray( 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] LAPACK_INT` number of columns in `A`. +- **A**: `[inout] double*` input matrix. +- **sa1**: `[in] LAPACK_INT` stride of the first dimension of `A`. +- **sa2**: `[in] LAPACK_INT` stride of the second dimension of `A`. +- **oa**: `[in] LAPACK_INT` starting index for `A`. +- **k1**: `[in] LAPACK_INT` index of first row to interchange. +- **k2**: `[in] LAPACK_INT` index of last row to interchange. +- **inck**: `[in] LAPACK_INT` direction in which to apply pivots (-1 to apply pivots in reverse order; otherwise, apply in provided order). +- **IPIV**: `[in] LAPACK_INT*` vector of pivot indices. +- **si**: `[in] LAPACK_INT` index increment for `IPIV`. +- **oi**: `[in] LAPACK_INT` starting index for `IPIV`. ```c -TODO +void c_dlaswp_ndarray( const LAPACK_INT N, double *A, const LAPACK_INT strideA1, const LAPACK_INT strideA2, const LAPACK_INT offsetA, const LAPACK_INT k1, const LAPACK_INT k2, const LAPACK_INT inck, const LAPACK_INT *IPIV, const LAPACK_INT strideIPIV, const LAPACK_INT offsetIPIV ); ``` @@ -255,7 +300,34 @@ TODO ### Examples ```c -TODO +#include "stdlib/lapack/base/dlaswp.h" +#include "stdlib/lapack/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 matrix stored in row-major order: + double A[ 3*3 ] = { + 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, + 7.0, 8.0, 9.0 + }; + + // Define a vector of pivot indices: + const LAPACK_INT IPIV[ 3 ] = { 2, 0, 1 }; + + // Specify the number of columns: + const int N = 3; + + // Perform row interchanges: + c_dlaswp( LAPACK_ROW_MAJOR, N, A, N, 0, 2, IPIV, 1 ); + + // Print the result: + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "A[ %i, %i ] = %lf\n", i, j, A[ (i*N)+j ] ); + } + } +} ``` diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/Makefile new file mode 100644 index 000000000000..c8f741a095c6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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.size.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/lapack/base/dlaswp/benchmark/c/benchmark.size.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/benchmark.size.c new file mode 100644 index 000000000000..fef260ec610c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/benchmark/c/benchmark.size.c @@ -0,0 +1,206 @@ +/** +* @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/lapack/base/dlaswp.h" +#include "stdlib/lapack/base/shared.h" +#include +#include +#include +#include +#include + +#define NAME "dlaswp" +#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 *A; + LAPACK_INT *IPIV; + double t; + int i; + + A = (double *)malloc( N * N * sizeof(double) ); + IPIV = (LAPACK_INT *)malloc( N * sizeof(LAPACK_INT) ); + for ( i = 0; i < N*N; i++ ) { + A[ i ] = ( rand_double() * 20.0 ) - 10.0; + } + for ( i = 0; i < N; i++ ) { + IPIV[ i ] = (LAPACK_INT)( rand_double() * N ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + c_dlaswp( LAPACK_ROW_MAJOR, N, A, N, 0, N-1, IPIV, 1 ); + if ( A[ i%(N*N) ] != A[ i%(N*N) ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( A[ i%(N*N) ] != A[ i%(N*N) ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( IPIV ); + 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 *A; + LAPACK_INT *IPIV; + double t; + int i; + + A = (double *)malloc( N * N * sizeof(double) ); + IPIV = (LAPACK_INT *)malloc( N * sizeof(LAPACK_INT) ); + for ( i = 0; i < N*N; i++ ) { + A[ i ] = ( rand_double() * 20.0 ) - 10.0; + } + for ( i = 0; i < N; i++ ) { + IPIV[ i ] = (LAPACK_INT)( rand_double() * N ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + c_dlaswp_ndarray( N, A, N, 1, 0, 0, N-1, 1, IPIV, 1, 0 ); + if ( A[ i%(N*N) ] != A[ i%(N*N) ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( A[ i%(N*N) ] != A[ i%(N*N) ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( IPIV ); + 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 = (int)floor( pow( pow( 10, i ), 1.0/2.0 ) ); + iter = ITERATIONS / (int)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/lapack/base/dlaswp/binding.gyp b/lib/node_modules/@stdlib/lapack/base/dlaswp/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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/lapack/base/dlaswp/examples/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlaswp/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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/lapack/base/dlaswp/examples/c/example.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/examples/c/example.c new file mode 100644 index 000000000000..16032d0e33c3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/examples/c/example.c @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/lapack/base/dlaswp.h" +#include "stdlib/lapack/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 matrix stored in row-major order: + double A[ 3*3 ] = { + 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, + 7.0, 8.0, 9.0 + }; + + // Define a vector of pivot indices: + const LAPACK_INT IPIV[ 3 ] = { 2, 0, 1 }; + + // Specify the number of columns: + const int N = 3; + + // Perform row interchanges: + c_dlaswp( LAPACK_ROW_MAJOR, N, A, N, 0, 2, IPIV, 1 ); + + // Print the result: + printf( "After c_dlaswp:\n" ); + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "A[ %i, %i ] = %lf\n", i, j, A[ (i*N)+j ] ); + } + } + + // Reset the matrix: + A[ 0 ] = 1.0; + A[ 1 ] = 2.0; + A[ 2 ] = 3.0; + A[ 3 ] = 4.0; + A[ 4 ] = 5.0; + A[ 5 ] = 6.0; + A[ 6 ] = 7.0; + A[ 7 ] = 8.0; + A[ 8 ] = 9.0; + + // Perform row interchanges using alternative indexing semantics: + c_dlaswp_ndarray( N, A, N, 1, 0, 0, 2, 1, IPIV, 1, 0 ); + + // Print the result: + printf( "\nAfter c_dlaswp_ndarray:\n" ); + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "A[ %i, %i ] = %lf\n", i, j, A[ (i*N)+j ] ); + } + } +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi b/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi new file mode 100644 index 000000000000..d73f4968c8a0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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)', + ' [ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] +*/ +function dlaswp( order, N, A, LDA, k1, k2, IPIV, incx ) { + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isRowMajor( order ) && LDA < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDA ) ); + } + addon( resolveOrder( order ), N, A, LDA, k1, k2, IPIV, incx ); + return A; +} + + +// EXPORTS // + +module.exports = dlaswp; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/native.js b/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/native.js new file mode 100644 index 000000000000..bc6ee622fdc6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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 dlaswp = require( './dlaswp.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dlaswp, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlaswp; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js b/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js new file mode 100644 index 000000000000..673b785e9d89 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js @@ -0,0 +1,62 @@ +/** +* @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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs a series of row interchanges on the matrix `A` using pivot indices stored in `IPIV` and alternative indexing semantics. +* +* @param {PositiveInteger} N - number of columns in `A` +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - index offset for `A` +* @param {NonNegativeInteger} k1 - index of first row to interchange +* @param {NonNegativeInteger} k2 - index of last row to interchange +* @param {integer} inck - direction in which to apply pivots (-1 to apply pivots in reverse order; otherwise, apply in provided order) +* @param {Int32Array} IPIV - vector of pivot indices +* @param {integer} strideIPIV - `IPIV` stride length +* @param {NonNegativeInteger} offsetIPIV - index offset for `IPIV` +* @returns {Float64Array} permuted matrix `A` +* +* @example +* var Int32Array = require( '@stdlib/array/int32' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var IPIV = new Int32Array( [ 2, 0, 1 ] ); +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* dlaswp( 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 ); +* // A => [ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] +*/ +function dlaswp( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-len, max-params + addon.ndarray( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV ); // eslint-disable-line max-len + return A; +} + + +// EXPORTS // + +module.exports = dlaswp; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/manifest.json b/lib/node_modules/@stdlib/lapack/base/dlaswp/manifest.json new file mode 100644 index 000000000000..d26ed340b8ce --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/manifest.json @@ -0,0 +1,263 @@ +{ + "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/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-strided-float64array2d", + "@stdlib/napi/argv-strided-int32array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-strided-float64array2d", + "@stdlib/napi/argv-strided-int32array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-strided-float64array2d", + "@stdlib/napi/argv-strided-int32array" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/dlaswp.c", + "./src/dlaswp_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/lapack/base/xerbla", + "@stdlib/blas/base/dswap", + "@stdlib/ndarray/base/assert/is-row-major" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/package.json b/lib/node_modules/@stdlib/lapack/base/dlaswp/package.json index 670119590fdf..ff1c6fb9a2e4 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlaswp/package.json +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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/lapack/base/dlaswp/src/Makefile b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/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/lapack/base/dlaswp/src/addon.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c new file mode 100644 index 000000000000..3f663f698e62 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c @@ -0,0 +1,129 @@ +/** +* @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/lapack/base/dlaswp.h" +#include "stdlib/lapack/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_strided_float64array2d.h" +#include "stdlib/napi/argv_strided_int32array.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 ) { + CBLAS_INT sa1; + CBLAS_INT sa2; + + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + + STDLIB_NAPI_ARGV_INT32( env, layout, argv, 0 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, k1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, k2, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, incx, argv, 7 ); + + if ( layout == LAPACK_COL_MAJOR ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == LAPACK_ROW_MAJOR + sa1 = LDA; + sa2 = 1; + } + + // Compute the number of rows to interchange for determining the matrix dimensions: + CBLAS_INT nrows = k2 + 1; + // Also account for pivot target rows which may be beyond k2: + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, nrows, N, sa1, sa2, argv, 2 ); + + // Compute the number of elements needed for IPIV: + CBLAS_INT nipiv; + CBLAS_INT absIncx; + if ( incx > 0 ) { + absIncx = incx; + } else { + absIncx = -incx; + } + nipiv = k1 + ( ( k2 - k1 ) * absIncx ) + 1; + STDLIB_NAPI_ARGV_STRIDED_INT32ARRAY( env, IPIV, nipiv, 1, argv, 6 ); + + API_SUFFIX(c_dlaswp)( layout, N, A, LDA, k1, k2, IPIV, incx ); + + 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, 11 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + + STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideA2, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 4 ); + + STDLIB_NAPI_ARGV_INT64( env, k1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, k2, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, inck, argv, 7 ); + + STDLIB_NAPI_ARGV_INT64( env, strideIPIV, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, offsetIPIV, argv, 10 ); + + // Determine the number of rows for IPIV: + CBLAS_INT nrows; + if ( inck > 0 ) { + nrows = k2 - k1 + 1; + } else { + nrows = k1 - k2 + 1; + } + + // For the matrix, we need enough elements; use a generous bound: + CBLAS_INT mrows = ( k1 > k2 ) ? k1 + 1 : k2 + 1; + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, mrows, N, strideA1, strideA2, argv, 1 ); + + // For IPIV, compute the total number of elements needed: + CBLAS_INT absStride; + if ( strideIPIV > 0 ) { + absStride = strideIPIV; + } else { + absStride = -strideIPIV; + } + CBLAS_INT nipiv = offsetIPIV + ( ( nrows - 1 ) * absStride ) + 1; + STDLIB_NAPI_ARGV_STRIDED_INT32ARRAY( env, IPIV, nipiv, 1, argv, 8 ); + + API_SUFFIX(c_dlaswp_ndarray)( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp.c new file mode 100644 index 000000000000..33506385ba4e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp.c @@ -0,0 +1,73 @@ +/** +* @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/lapack/base/dlaswp.h" +#include "stdlib/lapack/base/shared.h" +#include "stdlib/lapack/base/xerbla.h" + +/** +* Performs a series of row interchanges on a matrix `A` using pivot indices stored in `IPIV`. +* +* @param layout storage layout +* @param N number of columns in `A` +* @param A input matrix +* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param k1 index of first row to interchange +* @param k2 index of last row to interchange +* @param IPIV vector of pivot indices +* @param incx increment between successive values of `IPIV` +*/ +void API_SUFFIX(c_dlaswp)( const LAPACK_LAYOUT layout, const LAPACK_INT N, double *A, const LAPACK_INT LDA, const LAPACK_INT k1, const LAPACK_INT k2, const LAPACK_INT *IPIV, const LAPACK_INT incx ) { + LAPACK_INT strideIPIV; + LAPACK_INT offsetIPIV; + LAPACK_INT sa1; + LAPACK_INT sa2; + LAPACK_INT ck1; + LAPACK_INT ck2; + LAPACK_INT inc; + LAPACK_INT tmp; + + if ( layout != LAPACK_ROW_MAJOR && layout != LAPACK_COL_MAJOR ) { + lapack_xerbla( "c_dlaswp", -1 ); + return; + } + ck1 = k1; + ck2 = k2; + if ( incx > 0 ) { + inc = 1; + offsetIPIV = ck1; + strideIPIV = incx; + } else if ( incx < 0 ) { + inc = -1; + offsetIPIV = ck1 + ( ( ck1 - ck2 ) * incx ); + strideIPIV = -incx; + tmp = ck1; + ck1 = ck2; + ck2 = tmp; + } else { + return; + } + if ( layout == LAPACK_COL_MAJOR ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == LAPACK_ROW_MAJOR + sa1 = LDA; + sa2 = 1; + } + API_SUFFIX(c_dlaswp_ndarray)( N, A, sa1, sa2, 0, ck1, ck2, inc, IPIV, strideIPIV, offsetIPIV ); +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp_ndarray.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp_ndarray.c new file mode 100644 index 000000000000..67e2e3ee021a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/dlaswp_ndarray.c @@ -0,0 +1,119 @@ +/** +* @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/lapack/base/dlaswp.h" +#include "stdlib/lapack/base/shared.h" +#include "stdlib/blas/base/dswap.h" +#include "stdlib/ndarray/base/assert/is_row_major.h" +#include + +#define BLOCK_SIZE 32 + +/** +* Performs a series of row interchanges on a matrix `A` using pivot indices stored in `IPIV` and alternative indexing semantics. +* +* @param N number of columns in `A` +* @param A input matrix +* @param strideA1 stride of the first dimension of `A` +* @param strideA2 stride of the second dimension of `A` +* @param offsetA starting index for `A` +* @param k1 index of first row to interchange +* @param k2 index of last row to interchange +* @param inck direction in which to apply pivots (-1 to apply pivots in reverse order; otherwise, apply in provided order) +* @param IPIV vector of pivot indices +* @param strideIPIV `IPIV` stride length +* @param offsetIPIV starting index for `IPIV` +*/ +void API_SUFFIX(c_dlaswp_ndarray)( const LAPACK_INT N, double *A, const LAPACK_INT strideA1, const LAPACK_INT strideA2, const LAPACK_INT offsetA, const LAPACK_INT k1, const LAPACK_INT k2, const LAPACK_INT inck, const LAPACK_INT *IPIV, const LAPACK_INT strideIPIV, const LAPACK_INT offsetIPIV ) { + int64_t sa[ 2 ]; + LAPACK_INT nrows; + LAPACK_INT n32; + LAPACK_INT row; + LAPACK_INT ia1; + LAPACK_INT ia2; + LAPACK_INT ip; + LAPACK_INT i; + LAPACK_INT j; + LAPACK_INT k; + LAPACK_INT n; + LAPACK_INT o; + double tmp; + + // Compute the number of rows to be interchanged: + if ( inck > 0 ) { + nrows = k2 - k1; + } else { + nrows = k1 - k2; + } + nrows += 1; + + // Extract the strides for purposes of determining layout: + sa[ 0 ] = strideA1; + sa[ 1 ] = strideA2; + + // If the order is row-major, we can delegate to the Level 1 routine `dswap` for interchanging rows... + if ( stdlib_ndarray_is_row_major( 2, sa ) ) { + ip = offsetIPIV; + for ( i = 0, k = k1; i < nrows; i++, k += inck ) { + row = IPIV[ ip ]; + if ( row != k ) { + c_dswap_ndarray( N, A, strideA2, offsetA + ( k * strideA1 ), A, strideA2, offsetA + ( row * strideA1 ) ); + } + ip += strideIPIV; + } + return; + } + // If the order is column-major, we need to use loop tiling to ensure efficient cache access when accessing matrix elements... + n32 = ( N / BLOCK_SIZE ) * BLOCK_SIZE; + if ( n32 != 0 ) { + for ( j = 0; j < n32; j += BLOCK_SIZE ) { + ip = offsetIPIV; + for ( i = 0, k = k1; i < nrows; i++, k += inck ) { + row = IPIV[ ip ]; + if ( row != k ) { + ia1 = offsetA + ( k * strideA1 ); + ia2 = offsetA + ( row * strideA1 ); + for ( n = j; n < j + BLOCK_SIZE; n++ ) { + o = n * strideA2; + tmp = A[ ia1+o ]; + A[ ia1+o ] = A[ ia2+o ]; + A[ ia2+o ] = tmp; + } + } + ip += strideIPIV; + } + } + } + if ( n32 != N ) { + ip = offsetIPIV; + for ( i = 0, k = k1; i < nrows; i++, k += inck ) { + row = IPIV[ ip ]; + if ( row != k ) { + ia1 = offsetA + ( k * strideA1 ); + ia2 = offsetA + ( row * strideA1 ); + for ( n = n32; n < N; n++ ) { + o = n * strideA2; + tmp = A[ ia1+o ]; + A[ ia1+o ] = A[ ia2+o ]; + A[ ia2+o ] = tmp; + } + } + ip += strideIPIV; + } + } +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.dlaswp.native.js b/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.dlaswp.native.js new file mode 100644 index 000000000000..04d1b3e2f47a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.dlaswp.native.js @@ -0,0 +1,221 @@ +/** +* @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 tape = require( 'tape' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dlaswp = tryRequire( resolve( __dirname, './../lib/dlaswp.native.js' ) ); +var opts = { + 'skip': ( dlaswp instanceof Error ) +}; + + +// FIXTURES // + +var COL_MAJOR = require( './fixtures/column_major_no_offsets.json' ); +var COL_MAJOR_REV_PIVOTS = require( './fixtures/column_major_reverse_pivots.json' ); +var ROW_MAJOR = require( './fixtures/row_major_no_offsets.json' ); +var ROW_MAJOR_REV_PIVOTS = require( './fixtures/row_major_reverse_pivots.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlaswp, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', opts, function test( t ) { + t.strictEqual( dlaswp.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a valid order', opts, function test( t ) { + var values; + var data; + var i; + + data = COL_MAJOR; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + dlaswp( value, data.N, data.A, data.LDA, data.k1, data.k2, data.IPIV, data.strideIPIV ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not a valid `LDA` value (row-major)', opts, function test( t ) { + var values; + var data; + var i; + + data = ROW_MAJOR; + + values = [ + 0, + 1 + ]; + + 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() { + dlaswp( data.order, data.N, data.A, value, data.k1, data.k2, data.IPIV, data.strideIPIV ); + }; + } +}); + +tape( 'the function performs a series of row interchanges (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.order, data.N, A, data.LDA, data.k1, data.k2, IPIV, data.strideIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports applying pivots in reverse order (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR_REV_PIVOTS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.order, data.N, A, data.LDA, data.k1, data.k2, IPIV, data.strideIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a series of row interchanges (row-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = ROW_MAJOR; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.order, data.N, A, data.LDA, data.k1, data.k2, IPIV, data.strideIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports applying pivots in reverse order (row-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = ROW_MAJOR_REV_PIVOTS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.order, data.N, A, data.LDA, data.k1, data.k2, IPIV, data.strideIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an increment between successive values of `IPIV` equal to `0`, the function returns the input matrix unchanged (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A ); + + out = dlaswp( data.order, data.N, A, data.LDA, data.k1, data.k2, IPIV, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.ndarray.native.js b/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.ndarray.native.js new file mode 100644 index 000000000000..c87ac3e12a6d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/test/test.ndarray.native.js @@ -0,0 +1,185 @@ +/** +* @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 tape = require( 'tape' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dlaswp = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dlaswp instanceof Error ) +}; + + +// FIXTURES // + +var COL_MAJOR = require( './fixtures/column_major_no_offsets.json' ); +var COL_MAJOR_IPIV_STRIDE_POS = require( './fixtures/column_major_ipiv_stride_positive.json' ); +var COL_MAJOR_REV_PIVOTS = require( './fixtures/column_major_reverse_pivots.json' ); +var ROW_MAJOR = require( './fixtures/row_major_no_offsets.json' ); +var ROW_MAJOR_IPIV_STRIDE_POS = require( './fixtures/row_major_ipiv_stride_positive.json' ); +var ROW_MAJOR_REV_PIVOTS = require( './fixtures/row_major_reverse_pivots.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlaswp, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', opts, function test( t ) { + t.strictEqual( dlaswp.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a series of row interchanges (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports applying pivots in reverse order (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR_REV_PIVOTS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `IPIV` stride (column-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = COL_MAJOR_IPIV_STRIDE_POS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a series of row interchanges (row-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = ROW_MAJOR; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports applying pivots in reverse order (row-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = ROW_MAJOR_REV_PIVOTS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `IPIV` stride (row-major)', opts, function test( t ) { + var expected; + var IPIV; + var data; + var out; + var A; + + data = ROW_MAJOR_IPIV_STRIDE_POS; + + A = new Float64Array( data.A ); + IPIV = new Int32Array( data.IPIV ); + + expected = new Float64Array( data.A_out ); + + out = dlaswp( data.N, A, data.strideA1, data.strideA2, data.offsetA, data.k1, data.k2, data.incK, IPIV, data.strideIPIV, data.offsetIPIV ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); From fe78fc0257d9378262e7e0386852a5f3ada4808d Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 13 Apr 2026 00:05:45 +0530 Subject: [PATCH 2/4] fix: correct gyp syntax error in dlaswp build config --- 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: 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 --- --- lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi b/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi index d73f4968c8a0..dcb556d250e8 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/include.gypi @@ -44,7 +44,7 @@ # Include directories: 'include_dirs': [ '<@(blas_dir)', - ' Date: Mon, 13 Apr 2026 00:23:53 +0530 Subject: [PATCH 3/4] fix: normalize bounds in dlaswp ndarray native wrapper --- 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: passed - 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: 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 --- --- .../@stdlib/lapack/base/dlaswp/lib/ndarray.native.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js b/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js index 673b785e9d89..62d54bc90388 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/lib/ndarray.native.js @@ -52,6 +52,18 @@ var addon = require( './../src/addon.node' ); * // A => [ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] */ function dlaswp( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-len, max-params + var tmp; + if ( inck < 0 ) { + offsetIPIV += k2 * strideIPIV; + strideIPIV *= -1; + tmp = k1; + k1 = k2; + k2 = tmp; + inck = -1; + } else { + offsetIPIV += k1 * strideIPIV; + inck = 1; + } addon.ndarray( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV ); // eslint-disable-line max-len return A; } From 78684d9791e9a94dc436a824341183f6e5869582 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 13 Apr 2026 00:38:47 +0530 Subject: [PATCH 4/4] fix: correct memory bounds check for negative strides --- 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: passed - 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 --- --- .../@stdlib/lapack/base/dlaswp/src/addon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c index 3f663f698e62..3907ae528712 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c +++ b/lib/node_modules/@stdlib/lapack/base/dlaswp/src/addon.c @@ -112,13 +112,14 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, mrows, N, strideA1, strideA2, argv, 1 ); // For IPIV, compute the total number of elements needed: - CBLAS_INT absStride; - if ( strideIPIV > 0 ) { - absStride = strideIPIV; + CBLAS_INT nipiv; + if ( nrows <= 0 ) { + nipiv = 0; + } else if ( strideIPIV < 0 ) { + nipiv = offsetIPIV + 1; } else { - absStride = -strideIPIV; + nipiv = offsetIPIV + ( ( nrows - 1 ) * strideIPIV ) + 1; } - CBLAS_INT nipiv = offsetIPIV + ( ( nrows - 1 ) * absStride ) + 1; STDLIB_NAPI_ARGV_STRIDED_INT32ARRAY( env, IPIV, nipiv, 1, argv, 8 ); API_SUFFIX(c_dlaswp_ndarray)( N, A, strideA1, strideA2, offsetA, k1, k2, inck, IPIV, strideIPIV, offsetIPIV );