diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/README.md b/lib/node_modules/@stdlib/lapack/base/dlassq/README.md index 63826edd883a..e6bc1bc1bb5b 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlassq/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/README.md @@ -185,23 +185,54 @@ console.log( out ); ### Usage ```c -TODO +#include "stdlib/lapack/base/dlassq.h" ``` -#### TODO +#### c\_dlassq( N, \*X, incX, \*scale, \*sumsq ) -TODO. +Returns an updated sum of squares represented in scaled form. ```c -TODO +double X[] = { 1.0, 2.0, 3.0, 4.0 }; +double scale = 1.0; +double sumsq = 0.0; + +c_dlassq( 4, X, 1, &scale, &sumsq ); +// scale => 1.0 +// sumsq => 30.0 ``` -TODO +The function has the following parameters: + +- **N**: `[in] LAPACK_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **incX**: `[in] LAPACK_INT` stride length for `X`. +- **scale**: `[in,out] double*` pointer to scaling factor. +- **sumsq**: `[in,out] double*` pointer to sum of squares. + +#### c\_dlassq\_ndarray( N, \*X, strideX, offsetX, \*scale, \*sumsq ) + +Returns an updated sum of squares represented in scaled form using alternative indexing semantics. ```c -TODO +double X[] = { 0.0, 1.0, 2.0, 3.0, 4.0 }; +double scale = 1.0; +double sumsq = 0.0; + +c_dlassq_ndarray( 4, X, 1, 1, &scale, &sumsq ); +// scale => 1.0 +// sumsq => 30.0 ``` +The function has the following parameters: + +- **N**: `[in] LAPACK_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] LAPACK_INT` stride length for `X`. +- **offsetX**: `[in] LAPACK_INT` starting index for `X`. +- **scale**: `[in,out] double*` pointer to scaling factor. +- **sumsq**: `[in,out] double*` pointer to sum of squares. + @@ -221,7 +252,32 @@ TODO ### Examples ```c -TODO +#include "stdlib/lapack/base/dlassq.h" +#include + +int main( void ) { + // Create a strided array: + double X[] = { 1.0, 2.0, 3.0, 4.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 1; + + // Initialize scaling factor and sum of squares: + double scale = 1.0; + double sumsq = 0.0; + + // Compute the updated sum of squares in scaled form: + c_dlassq( N, X, strideX, &scale, &sumsq ); + + // Print the results: + printf( "scale: %f\n", scale ); + printf( "sumsq: %f\n", sumsq ); + + return 0; +} ``` diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/c/Makefile new file mode 100644 index 000000000000..c8f741a095c6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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/dlassq/benchmark/c/benchmark.size.c b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/c/benchmark.size.c new file mode 100644 index 000000000000..b6d81204b61a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/c/benchmark.size.c @@ -0,0 +1,203 @@ +/** +* @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/dlassq.h" +#include +#include +#include +#include +#include + +#define NAME "dlassq" +#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 ); + 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 len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double *X; + double scale; + double sumsq; + double elapsed; + double t; + int i; + + X = (double *)malloc( len * sizeof(double) ); + for ( i = 0; i < len; i++ ) { + X[ i ] = ( rand_double() * 20.0 ) - 10.0; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + scale = 1.0; + sumsq = 0.0; + c_dlassq( len, X, 1, &scale, &sumsq ); + if ( scale != scale ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + + if ( scale != scale ) { + printf( "should not return NaN\n" ); + } + free( X ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double *X; + double scale; + double sumsq; + double elapsed; + double t; + int i; + + X = (double *)malloc( len * sizeof(double) ); + for ( i = 0; i < len; i++ ) { + X[ i ] = ( rand_double() * 20.0 ) - 10.0; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + scale = 1.0; + sumsq = 0.0; + c_dlassq_ndarray( len, X, 1, 0, &scale, &sumsq ); + if ( scale != scale ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + + if ( scale != scale ) { + printf( "should not return NaN\n" ); + } + free( X ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + 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++ ) { + len = (int)floor( pow( 10, i ) ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:size=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + 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, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/binding.gyp b/lib/node_modules/@stdlib/lapack/base/dlassq/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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/dlassq/examples/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlassq/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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/dlassq/examples/c/example.c b/lib/node_modules/@stdlib/lapack/base/dlassq/examples/c/example.c new file mode 100644 index 000000000000..aedea74b4486 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/examples/c/example.c @@ -0,0 +1,44 @@ +/** +* @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/dlassq.h" +#include + +int main( void ) { + // Create a strided array: + double X[] = { 1.0, 2.0, 3.0, 4.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 1; + + // Initialize scaling factor and sum of squares: + double scale = 1.0; + double sumsq = 0.0; + + // Compute the updated sum of squares in scaled form: + API_SUFFIX(c_dlassq)( N, X, strideX, &scale, &sumsq ); + + // Print the results: + printf( "scale: %f\n", scale ); + printf( "sumsq: %f\n", sumsq ); + + return 0; +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/include.gypi b/lib/node_modules/@stdlib/lapack/base/dlassq/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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)', + '[ 1.0, 30.0 ] +*/ +function dlassq( N, X, strideX, scale, sumsq ) { + var out = new Float64Array( 2 ); + addon( N, X, strideX, scale, sumsq, out, 1 ); + return out; +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/native.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/native.js new file mode 100644 index 000000000000..b2a7d262c5d0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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 dlassq = require( './dlassq.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dlassq, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.native.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.native.js new file mode 100644 index 000000000000..ab0802d8a569 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.native.js @@ -0,0 +1,59 @@ +/** +* @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 // + +/** +* Returns an updated sum of squares represented in scaled form using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - number of indexed elements +* @param {Float64Array} X - input array +* @param {integer} strideX - stride length for `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @param {number} scale - scaling factor +* @param {number} sumsq - basic sum of squares from which output is factored out +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0 ] ); +* +* dlassq( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +* // out => [ 1.0, 30.0 ] +*/ +function dlassq( N, X, strideX, offsetX, scale, sumsq, out, strideOut, offsetOut ) { // eslint-disable-line max-len + addon.ndarray( N, X, strideX, offsetX, scale, sumsq, out, strideOut, offsetOut ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/manifest.json b/lib/node_modules/@stdlib/lapack/base/dlassq/manifest.json new file mode 100644 index 000000000000..d2c6651ffad0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/manifest.json @@ -0,0 +1,230 @@ +{ + "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/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/dlassq.c", + "./src/dlassq_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/package.json b/lib/node_modules/@stdlib/lapack/base/dlassq/package.json index 074d20812a4a..7a938131814a 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlassq/package.json +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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/dlassq/src/Makefile b/lib/node_modules/@stdlib/lapack/base/dlassq/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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/dlassq/src/addon.c b/lib/node_modules/@stdlib/lapack/base/dlassq/src/addon.c new file mode 100644 index 000000000000..c230208b52dc --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/src/addon.c @@ -0,0 +1,100 @@ +/** +* @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/dlassq.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_double.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include +#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, 7 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, incX, argv, 2 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, scale, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sumsq, argv, 4 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, incX, argv, 1 ); + + // Output array: + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, out, 2, 1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 6 ); + + if ( isnan( scale ) || isnan( sumsq ) ) { + return NULL; + } + + API_SUFFIX(c_dlassq)( N, X, incX, &scale, &sumsq ); + + out[ 0 ] = scale; + out[ strideOut ] = sumsq; + + 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, 9 ); + + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + + STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 3 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, scale, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sumsq, argv, 5 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideA1, argv, 1 ); + + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 8 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, out, 2, strideOut, argv, 6 ); + + if ( isnan( scale ) || isnan( sumsq ) ) { + return NULL; + } + + API_SUFFIX(c_dlassq_ndarray)( N, X, strideA1, offsetA, &scale, &sumsq ); + + out[ offsetOut ] = scale; + out[ offsetOut + strideOut ] = sumsq; + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq.c b/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq.c new file mode 100644 index 000000000000..f16dd46195d0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq.c @@ -0,0 +1,36 @@ +/** +* @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/dlassq.h" + +/** +* Returns an updated sum of squares represented in scaled form. +* +* @param N number of indexed elements +* @param X input array +* @param incX stride length for `X` +* @param scale scaling factor +* @param sumsq basic sum of squares from which output is factored out +*/ +void API_SUFFIX(c_dlassq)( const LAPACK_INT N, const double *X, const LAPACK_INT incX, double *scale, double *sumsq ) { + LAPACK_INT ox = 0; + if ( incX < 0 ) { + ox = ( 1 - N ) * incX; + } + API_SUFFIX(c_dlassq_ndarray)( N, X, incX, ox, scale, sumsq ); +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq_ndarray.c b/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq_ndarray.c new file mode 100644 index 000000000000..8840b6effdc0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/src/dlassq_ndarray.c @@ -0,0 +1,142 @@ +/** +* @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/dlassq.h" +#include + +#define SBIG 1.11137937474253874e-162 +#define SSML 4.49891379454319638e+161 +#define TBIG 1.99791907220223503e+146 +#define TSML 1.49166814624004135e-154 + +/** +* Returns an updated sum of squares represented in scaled form using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length for `X` +* @param offsetX starting index for `X` +* @param scale scaling factor +* @param sumsq basic sum of squares from which output is factored out +*/ +void API_SUFFIX(c_dlassq_ndarray)( const LAPACK_INT N, const double *X, const LAPACK_INT strideX, const LAPACK_INT offsetX, double *scale, double *sumsq ) { + int notbig; + double abig; + double asml; + double amed; + double ymin; + double ymax; + double ax; + double tmp; + LAPACK_INT ox; + LAPACK_INT i; + + if ( isnan( *scale ) || isnan( *sumsq ) ) { + return; + } + if ( *sumsq == 0.0 ) { + *scale = 1.0; + } + if ( *scale == 0.0 ) { + *scale = 1.0; + *sumsq = 0.0; + } + if ( N <= 0 ) { + return; + } + + notbig = 1; + asml = 0.0; + amed = 0.0; + abig = 0.0; + ox = offsetX; + + for ( i = 0; i < N; i++ ) { + ax = fabs( X[ ox ] ); + if ( ax > TBIG ) { + tmp = ax * SBIG; + abig += ( tmp * tmp ); + notbig = 0; + } else if ( ax < TSML ) { + if ( notbig ) { + tmp = ax * SSML; + asml += ( tmp * tmp ); + } + } else { + amed += ( ax * ax ); + } + ox += strideX; + } + + if ( *sumsq > 0.0 ) { + ax = *scale * sqrt( *sumsq ); + if ( ax > TBIG ) { + if ( *scale > 1.0 ) { + *scale *= SBIG; + abig += *scale * ( *scale * ( *sumsq ) ); + } else { + abig += *scale * ( *scale * ( SBIG * ( SBIG * ( *sumsq ) ) ) ); + } + } else if ( ax < TSML ) { + if ( notbig ) { + if ( *scale < 1.0 ) { + *scale *= SSML; + asml += *scale * ( *scale * ( *sumsq ) ); + } else { + asml += *scale * ( *scale * ( SSML * ( SSML * ( *sumsq ) ) ) ); + } + } + } else { + amed += *scale * ( *scale * ( *sumsq ) ); + } + } + + if ( abig > 0.0 ) { + if ( amed > 0.0 || isnan( amed ) ) { + abig += ( amed * SBIG ) * SBIG; + } + *scale = 1.0 / SBIG; + *sumsq = abig; + return; + } + + if ( asml > 0.0 ) { + if ( amed > 0.0 || isnan( amed ) ) { + amed = sqrt( amed ); + asml = sqrt( asml ) / SSML; + if ( asml > amed ) { + ymin = amed; + ymax = asml; + } else { + ymin = asml; + ymax = amed; + } + *scale = 1.0; + tmp = ymin / ymax; + *sumsq = ( ymax * ymax ) * ( 1.0 + ( tmp * tmp ) ); + } else { + *scale = 1.0 / SSML; + *sumsq = asml; + } + return; + } + + *scale = 1.0; + *sumsq = amed; + return; +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.native.js b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.native.js new file mode 100644 index 000000000000..3c1dbd528bd5 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.native.js @@ -0,0 +1,231 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var dlassq = tryRequire( __dirname, '../lib/dlassq.native.js' ); +var opts = { + 'skip': ( dlassq instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlassq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( dlassq.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, 30.0 ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (NaNs)', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, NaN, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + X = new Float64Array( [ 1.0e-160, 1.0e-160, NaN, 1.0e-160 ] ); + expected = new Float64Array( [ 1.0, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, NaN, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (large values)', opts, function test( t ) { + var expected; + var out; + var X; + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 4.940656458412465e-24 ] ); // returns 4.0e300 + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 9.881312916824931e-24 ] ); // returns 8.0e300 + + out = dlassq( 4, X, 1, 2.0, 1.0e300 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 6.1758205730155814e-24 ] ); // returns 5.0e300 + + out = dlassq( 4, X, 1, 1.0, 1.0e300 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e308, 1.0e308, 1.0e308, 1.0e308 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 1.0/0.0 ] ); + + out = dlassq( 4, X, 1, 1.0e308, 1.0e308 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (small values)', opts, function test( t ) { + var expected; + var out; + var X; + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 8096.090132292425 ] ); // returns ~4.0e-320 + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 8602.090132292426 ] ); // returns ~4.24e-320 + + out = dlassq( 4, X, 1, 0.5, 1.0e-320 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 10120.090132292426 ] ); // returns ~5.0e-320 + + out = dlassq( 4, X, 1, 1.0, 1.0e-320 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (sum of squares > 0)', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + out = dlassq( 4, X, 1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + out = dlassq( 4, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns initialized values if provided an `N` argument less than or equal to `0`', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 1.0 ] ); + + out = dlassq( 0, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dlassq( -5, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 0.0 ] ); + + out = dlassq( 0, X, 1, 0.0, 999.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the scale factor is `NaN`', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlassq( 4, X, -1, NaN, 1.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the sum of squares is `NaN`', opts, function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlassq( 4, X, -1, 1.0, NaN ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.native.js b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.native.js new file mode 100644 index 000000000000..d075d0b5458e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.native.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var dlassq = tryRequire( __dirname, '../lib/ndarray.native.js' ); +var opts = { + 'skip': ( dlassq instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlassq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', opts, function test( t ) { + t.strictEqual( dlassq.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 30.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (sum of squares > 0)', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + actual = dlassq( 4, X, -1, 3, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 31.0, 1.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 1.0, out, -1, 1 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns initialized values if provided an `N` argument less than or equal to `0`', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 1.0 ] ); + + actual = dlassq( 0, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + actual = dlassq( -5, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 0.0 ] ); + + actual = dlassq( 0, X, 1, 0, 0.0, 999.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the scale factor is `NaN`', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + actual = dlassq( 4, X, 1, 0, NaN, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the sum of squares is `NaN`', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, NaN, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0 ] ); // eslint-disable-line max-len + out = new Float64Array( [ 0.0, 0.0, 0.0, 999.9, 0.0, 0.0, 999.9 ] ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 30.0 ] ); + + actual = dlassq( 4, X, -4, 14, 1.0, 0.0, out, 3, 3 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});