diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..2b2c793b2583 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var drotg = require( './../lib/assign.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @returns {Function} benchmark function +*/ +function createBenchmark() { + var x = uniform( -10.0, 10.0, options ); + var y = uniform( -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = new Float64Array( 4 ); + z = drotg( x, y, out, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var N; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':assign:size='+(N*N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.native.js b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.native.js new file mode 100644 index 000000000000..e89a5d1bd0e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.native.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( '@stdlib/blas/base/drotg/package.json' ).name; + + +// VARIABLES // + +var drotg = tryRequire( resolve( __dirname, './../lib/assign.native.js' ) ); +var opts = { + 'skip': ( drotg instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @returns {Function} benchmark function +*/ +function createBenchmark() { + var x = uniform( -10.0, 10.0, options ); + var y = uniform( -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = new Float64Array( 4 ); + z = drotg( x, y, out, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+'::native:assign:size='+(N*N), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js index c4193eda5229..0b618395c9ab 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,68 +21,83 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); var pkg = require( './../package.json' ).name; -var drotg = require( './../lib' ); +var drotg = require( './../lib/drotg.js' ); // VARIABLES // -var OPTS = { +var options = { 'dtype': 'float64' }; -// MAIN // +// FUNCTIONS // -bench( pkg, function benchmark( b ) { - var out; - var x; - var y; - var i; +/** +* Creates a benchmark function. +* +* @private +* @returns {Function} benchmark function +*/ +function createBenchmark() { + var x = uniform( -10.0, 10.0 ); + var y = uniform( -10.0, 10.0 ); + return benchmark; - x = discreteUniform( 100, -5, 5, OPTS ); - y = discreteUniform( 100, -5, 5, OPTS ); + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = drotg( x[ i%x.length ], y[ i%y.length ] ); - if ( isnan( out[ i%4 ] ) ) { + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = drotg( x, y ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { b.fail( 'should not return NaN' ); } + b.pass( 'benchmark finished' ); + b.end(); } - b.toc(); - if ( isnan( out[ i%4 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':assign', function benchmark( b ) { - var out; - var x; - var y; - var z; +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; var i; - x = discreteUniform( 100, -5, 5, OPTS ); - y = discreteUniform( 100, -5, 5, OPTS ); - out = new Float64Array( 4 ); + min = 1; // 10^min + max = 6; // 10^max - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = drotg.assign( x[ i%x.length ], y[ i%y.length ], out, 1, 0 ); - if ( typeof z !=='object' ) { - b.fail( 'should return an array' ); - } + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':size='+(N*N), f ); } - b.toc(); - if ( isnan( z[ i%4 ] ) ) { - b.fail( 'should return the output array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f01fd1e29536 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drotg = tryRequire( resolve( __dirname, './../lib/drotg.native.js' ) ); +var opts = { + 'skip': ( drotg instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @returns {Function} benchmark function +*/ +function createBenchmark() { + var x = uniform( -10.0, 10.0, options ); + var y = uniform( -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = drotg( x, y ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+'::native:size='+(N*N), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/Makefile new file mode 100644 index 000000000000..9f97140e7cb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..0ba6986cf0df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/benchmark.length.c @@ -0,0 +1,191 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/ext/base/dfill.h" +#include +#include +#include +#include +#include + +#define NAME "drotg" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +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 +*/ +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 +*/ +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 +*/ +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 +*/ +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 length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int N ) { + double elapsed; + double out[ N ]; + double a; + double b; + double t; + int i; + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + a = ( rand_double()*200.0 ) - 100.0; + b = ( rand_double()*200.0 ) - 100.0; + out = c_drotg( &a, &b, &0.8, &0.6 ); + if ( out[ i%N ] != out[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( out[ i%N ] != out[ i%N ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param N array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int N ) { + double elapsed; + double out[ N ]; + double a; + double b; + double t; + int i; + + stdlib_strided_dfill( 4, 0.0, out, 1 ); + t = tic(); + for ( i = 0; i < iterations; i++ ) { + a = ( rand_double()*200.0 ) - 100.0; + b = ( rand_double()*200.0 ) - 100.0; + c_drotg_assign( &a, &b, &0.8, &0.6, out, 1, 0 ); + if ( out[ i%N ] != out[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( out[ i%N ] != out[ i%N ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int N; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + N = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:size=%d\n", NAME, 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:assign:size=%d\n", NAME, N ); + elapsed = benchmark2( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/Makefile new file mode 100644 index 000000000000..6544ed1723aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/Makefile @@ -0,0 +1,141 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# 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 Fortran source files: +ifdef FORTRAN_COMPILER + FC := $(FORTRAN_COMPILER) +else + FC := gfortran +endif + +# Define the command-line options when compiling Fortran files: +FFLAGS ?= \ + -std=f95 \ + -ffree-form \ + -O3 \ + -Wall \ + -Wextra \ + -Wno-compare-reals \ + -Wimplicit-interface \ + -fno-underscoring \ + -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 ?= + +# List of Fortran source files: +SOURCE_FILES ?= ../../src/drotg.f + +# List of Fortran targets: +f_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles Fortran source files. +# +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} [FORTRAN_COMPILER] - Fortran compiler +# @param {string} [FFLAGS] - Fortran compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(f_targets) + +.PHONY: all + +#/ +# Compiles Fortran source files. +# +# @private +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} FC - Fortran compiler +# @param {string} FFLAGS - Fortran compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(f_targets): %.out: %.f + $(QUIET) $(FC) $(FFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(f_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/benchmark.length.f new file mode 100644 index 000000000000..940b974b83bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/benchmark.length.f @@ -0,0 +1,204 @@ +!> +! @license Apache-2.0 +! +! Copyright (c) 2024 The Stdlib Authors. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. +!< + +!> Benchmark `drotg`. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'drotg' ! if changed, be sure to adjust length + integer, parameter :: iterations = 1000000 + integer, parameter :: repeats = 3 + integer, parameter :: min = 1 + integer, parameter :: max = 6 + ! .. + ! Run the benchmarks: + call main() + ! .. + ! Functions: +contains + ! .. + ! Prints the TAP version. + ! .. + subroutine print_version() + print '(A)', 'TAP version 13' + end subroutine print_version + ! .. + ! Prints the TAP summary. + ! + ! @param {integer} total - total number of tests + ! @param {integer} passing - total number of passing tests + ! .. + subroutine print_summary( total, passing ) + ! .. + ! Scalar arguments: + integer, intent(in) :: total, passing + ! .. + ! Local variables: + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + print '(A)', '#' + ! .. + write (str, '(I15)') total ! TAP plan + tmp = adjustl( str ) + print '(A,A)', '1..', trim( tmp ) + ! .. + print '(A,A)', '# total ', trim( tmp ) + ! .. + write (str, '(I15)') passing + tmp = adjustl( str ) + print '(A,A)', '# pass ', trim( tmp ) + ! .. + print '(A)', '#' + print '(A)', '# ok' + end subroutine print_summary + ! .. + ! Prints benchmarks results. + ! + ! @param {integer} iterations - number of iterations + ! @param {double} elapsed - elapsed time in seconds + ! .. + subroutine print_results( iterations, elapsed ) + ! .. + ! Scalar arguments: + double precision, intent(in) :: elapsed + integer, intent(in) :: iterations + ! .. + ! Local variables: + double precision :: rate + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic dble, adjustl, trim + ! .. + rate = dble( iterations ) / elapsed + ! .. + print '(A)', ' ---' + ! .. + write (str, '(I15)') iterations + tmp = adjustl( str ) + print '(A,A)', ' iterations: ', trim( tmp ) + ! .. + write (str, '(f0.9)') elapsed + tmp = adjustl( str ) + print '(A,A)', ' elapsed: ', trim( tmp ) + ! .. + write( str, '(f0.9)') rate + tmp = adjustl( str ) + print '(A,A)', ' rate: ', trim( tmp ) + ! .. + print '(A)', ' ...' + end subroutine print_results + ! .. + ! Runs a benchmark. + ! + ! @param {integer} iterations - number of iterations + ! @return {double} elapsed time in seconds + ! .. + double precision function benchmark( iterations ) + ! .. + ! External functions: + interface + subroutine drotg( a, b, c, s ) + double precision :: c, a, b, s + end subroutine drotg + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2 + integer :: i + ! .. + ! Local scalar: + double precision :: a, b + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time + ! .. + call random_number( r1 ) + call random_number( r2 ) + a = (r1*100.0d0)-50.0d0 + b = (r2*100.0d0)-50.0d0 + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call drotg( a, b, 0.8d0, 0.6d0 ) + if ( b /= b ) then + print '(A)', 'unexpected result' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( b /= b ) then + print '(A)', 'unexpected result' + end if + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + character(len=999) :: str, tmp + double precision :: elapsed + integer :: i, j, count, iter + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + call print_version() + count = 0 + do i = min, max + iter = iterations / 10**(i-1) + do j = 1, repeats + count = count + 1 + ! .. + print '(A,A,A,A)', '# fortran::', name + ! .. + elapsed = benchmark( iter ) + ! .. + call print_results( iter, elapsed ) + ! .. + write (str, '(I15)') count + tmp = adjustl( str ) + print '(A,A,A)', 'ok ', trim( tmp ), ' benchmark finished' + end do + end do + call print_summary( count, count ) + end subroutine main +end program bench \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/drotg/binding.gyp b/lib/node_modules/@stdlib/blas/base/drotg/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/binding.gyp @@ -0,0 +1,265 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drotg/docs/repl.txt index a4b2f68ef338..0010651a5586 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drotg/docs/repl.txt @@ -5,10 +5,10 @@ Parameters ---------- - a: float + a: number Rotational elimination parameter. - - b: float + + b: number Rotational elimination parameter. Returns @@ -22,7 +22,7 @@ [ 2.0, 1.0, 0.0, 1.0 ] -{{alias}}.assign( a, b, out, stride, offset ) +{{alias}}.assign( a, b, out, strideX, offset ) Constructs a Givens plane rotation from two double-precision floating-point numbers and assigns the results to an output array. @@ -33,21 +33,21 @@ b: float Rotational elimination parameter. - + out: Float64Array Output array. - - stride: integer - Output array stride. - + + strideX: integer + Stride length for output array. + offset: integer - Output array index offset. + Starting index for output array. Returns ------- out: Float64Array Output array. - + Examples -------- > var out = new {{alias:@stdlib/array/float64}}( 4 ); @@ -55,6 +55,6 @@ [ 2.0, 1.0, 0.0, 1.0 ] > var bool = ( y === out ) true - + See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/drotg/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drotg/docs/types/index.d.ts index 4237ba224bca..200a4ca35b06 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drotg/docs/types/index.d.ts @@ -40,13 +40,13 @@ interface Routine { ( a: number, b: number ): Float64Array; /** - * Constructs a Givens plane rotation. + * Constructs a Givens plane rotation and assigns the results to an output array. * * @param a - rotational elimination parameter * @param b - rotational elimination parameter * @param out - output array - * @param stride - index increment - * @param offset - starting index + * @param strideX - stride length for output array + * @param offsetX - starting index for output array * @returns output array * * @example @@ -60,7 +60,7 @@ interface Routine { * var bool = ( y === out ); * // returns true */ - assign( a: number, b: number, out: Float64Array, stride: number, offset: number ): Float64Array; + assign( a: number, b: number, out: Float64Array, strideX: number, offsetX: number ): Float64Array; } /** diff --git a/lib/node_modules/@stdlib/blas/base/drotg/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/drotg/docs/types/test.ts index f2e9e262e635..cb3b48f42bae 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/drotg/docs/types/test.ts @@ -35,6 +35,7 @@ import drotg = require( './index' ); drotg( '5', 2.0 ); // $ExpectError drotg( [], 2.0 ); // $ExpectError drotg( {}, 2.0 ); // $ExpectError + drotg( ( x: number ): number => x, 2.0 ); // $ExpectError drotg( 0.0, true ); // $ExpectError drotg( 0.0, false ); // $ExpectError @@ -43,6 +44,7 @@ import drotg = require( './index' ); drotg( 0.0, '5' ); // $ExpectError drotg( 0.0, [] ); // $ExpectError drotg( 0.0, {} ); // $ExpectError + drotg( 0.0, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -59,7 +61,7 @@ import drotg = require( './index' ); drotg.assign( 0.0, 2.0, out, 1, 0 ); // $ExpectType Float64Array } -// The compiler throws an error if the `assign` method is provided a first or second argument which is not a number... +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... { const out = new Float64Array( 4 ); @@ -70,6 +72,12 @@ import drotg = require( './index' ); drotg.assign( '5', 2.0, out, 1, 0 ); // $ExpectError drotg.assign( [], 2.0, out, 1, 0 ); // $ExpectError drotg.assign( {}, 2.0, out, 1, 0 ); // $ExpectError + drotg.assign( ( x: number ): number => x, 2.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Float64Array( 4 ); drotg.assign( 0.0, true, out, 1, 0 ); // $ExpectError drotg.assign( 0.0, false, out, 1, 0 ); // $ExpectError @@ -78,6 +86,7 @@ import drotg = require( './index' ); drotg.assign( 0.0, '5', out, 1, 0 ); // $ExpectError drotg.assign( 0.0, [], out, 1, 0 ); // $ExpectError drotg.assign( 0.0, {}, out, 1, 0 ); // $ExpectError + drotg.assign( 0.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a third argument which is not a Float64Array... @@ -90,6 +99,7 @@ import drotg = require( './index' ); drotg.assign( 1.0, 2.0, '5', 1, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, [], 1, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + drotg.assign( 1.0, 2.0, ( x: number ): number => x, 1, 0 ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... @@ -100,6 +110,7 @@ import drotg = require( './index' ); drotg.assign( 1.0, 2.0, out, true, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, out, false, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, out, null, 0 ); // $ExpectError + drotg.assign( 1.0, 2.0, out, undefined, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, out, [], 0 ); // $ExpectError drotg.assign( 1.0, 2.0, out, {}, 0 ); // $ExpectError drotg.assign( 1.0, 2.0, out, ( x: number ): number => x, 0 ); // $ExpectError @@ -113,6 +124,7 @@ import drotg = require( './index' ); drotg.assign( 1.0, 2.0, out, 1, true ); // $ExpectError drotg.assign( 1.0, 2.0, out, 1, false ); // $ExpectError drotg.assign( 1.0, 2.0, out, 1, null ); // $ExpectError + drotg.assign( 1.0, 2.0, out, 1, undefined ); // $ExpectError drotg.assign( 1.0, 2.0, out, 1, [] ); // $ExpectError drotg.assign( 1.0, 2.0, out, 1, {} ); // $ExpectError drotg.assign( 1.0, 2.0, out, 1, ( x: number ): number => x ); // $ExpectError diff --git a/lib/node_modules/@stdlib/blas/base/drotg/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c new file mode 100644 index 000000000000..e80ab8576581 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include + +int main( void ) { + double a[] = { 0.3, 0.0, -0.0, 1.0, -1.0, 3.14, -3.14 }; + double b[] = { 0.4, 0.0, -0.0, 1.0, -1.0, 3.14, -3.14 }; + + double c; + double s; + int i; + for ( i = 0; i < 7; i++ ) { + c_drotg( &a[i], &b[i], &c, &s ); + printf( "a: %lf, b: %lf, c: %lf, s: %lf\n", a[i], b[i], c, s ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/examples/index.js b/lib/node_modules/@stdlib/blas/base/drotg/examples/index.js index 6ce1cc133e96..a3f3ff0b8556 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/examples/index.js @@ -19,6 +19,7 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var drotg = require( './../lib' ); var out; @@ -27,4 +28,8 @@ var i; for ( i = 0; i < 100; i++ ) { out = drotg( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) ); console.log( out ); + + out = new Float64Array( 4 ); + drotg.assign( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ), out, 1, 0 ); + console.log( out ); } diff --git a/lib/node_modules/@stdlib/blas/base/drotg/include.gypi b/lib/node_modules/@stdlib/blas/base/drotg/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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)', + '[ 2.0, 1.0, 0.0, 1.0 ] */ -function drotg( a, b, out, stride, offset ) { +function drotg( a, b, out, strideX, offsetX ) { var scale; var sign; var aa; @@ -52,6 +52,7 @@ function drotg( a, b, out, stride, offset ) { var r; var c; var s; + var v; var z; aa = abs( a ); @@ -68,7 +69,8 @@ function drotg( a, b, out, stride, offset ) { r = 0.0; z = 0.0; } else { - r = scale * sqrt( abs2( a/scale ) + abs2( b/scale ) ); + v = abs2( a/scale ) + abs2( b/scale ); + r = scale * sqrt( v ); r *= sign; c = a / r; s = b / r; @@ -81,10 +83,10 @@ function drotg( a, b, out, stride, offset ) { } a = r; b = z; - out[ offset ] = a; - out[ offset + stride ] = b; - out[ offset + ( 2 * stride ) ] = c; - out[ offset + ( 3 * stride ) ] = s; + out[ offsetX ] = a; + out[ offsetX + strideX ] = b; + out[ offsetX + ( 2 * strideX ) ] = c; + out[ offsetX + ( 3 * strideX ) ] = s; return out; } diff --git a/lib/node_modules/@stdlib/blas/base/drotg/lib/index.js b/lib/node_modules/@stdlib/blas/base/drotg/lib/index.js index 5e634c06d912..3f9d14717532 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Construct a Givens plane rotation. +* BLAS level 1 routine to construct a Givens plane rotation. * * @module @stdlib/blas/base/drotg * diff --git a/lib/node_modules/@stdlib/blas/base/drotg/lib/native.js b/lib/node_modules/@stdlib/blas/base/drotg/lib/native.js new file mode 100644 index 000000000000..ecddd13248e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/lib/native.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Constructs a Givens plane rotation. +* +* @param {number} a - rotational elimination parameter +* @param {number} b - rotational elimination parameter +* @returns {Float64Array} output array +* +* @example +* var out = drotg( 0.0, 2.0 ); +* // returns [ 2.0, 1.0, 0.0, 1.0 ] +*/ +function drotg( a, b ) { + var out = new Float64Array( 4 ); + addon( out, a, b ); + return out; +} + + +// EXPORTS // + +module.exports = drotg; diff --git a/lib/node_modules/@stdlib/blas/base/drotg/manifest.json b/lib/node_modules/@stdlib/blas/base/drotg/manifest.json new file mode 100644 index 000000000000..ca496b270c24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/manifest.json @@ -0,0 +1,463 @@ +{ + "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/drotg.f", + "./src/drotg_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.f", + "./src/drotg_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotg_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/drotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/special/copysign", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs2" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/package.json b/lib/node_modules/@stdlib/blas/base/drotg/package.json index 08b1975ad980..2af94f53f846 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/package.json +++ b/lib/node_modules/@stdlib/blas/base/drotg/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/Makefile b/lib/node_modules/@stdlib/blas/base/drotg/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c b/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c new file mode 100644 index 000000000000..de6a3b47a20b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c @@ -0,0 +1,132 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include +#include +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @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 ) { + napi_status status; + + // Get callback arguments: + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + // Check whether we were provided the correct number of arguments: + if ( argc < 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); + assert( status == napi_ok ); + return NULL; + } + if ( argc > 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); + assert( status == napi_ok ); + return NULL; + } + + bool res; + status = napi_is_typedarray( env, argv[ 0 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_typedarray_type vtype0; + size_t len; + void *Out; + status = napi_get_typedarray_info( env, argv[ 0 ], &vtype0, &len, &Out, NULL, NULL ); + assert( status == napi_ok ); + if ( vtype0 != napi_float64_array ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." ); + assert( status == napi_ok ); + return NULL; + } + if ( len != 4 ) { + status = napi_throw_range_error( env, NULL, "invalid argument. First argument must have 4 elements." ); + assert( status == napi_ok ); + return NULL; + } + + double da; + status = napi_get_value_double( env, argv[ 1 ], &da ); + assert( status == napi_ok ); + + double db; + status = napi_get_value_double( env, argv[ 2 ], &db ); + assert( status == napi_ok ); + + double c; + double s; + c_drotg( &da, &db, &c, &s ); + + double *op = (double *)Out; + op[ 0 ] = da; + op[ 1 ] = db; + op[ 2 ] = c; + op[ 3 ] = s; + + return NULL; +} + +/** +* Initializes a Node-API module. +* +* @private +* @param env environment under which the function is invoked +* @param exports exports object +* @return main export +*/ +static napi_value init( napi_env env, napi_value exports ) { + napi_value fcn; + napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; +} + +NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c new file mode 100644 index 000000000000..bd8a1d529ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/copysign.h" +#include "stdlib/math/base/special/abs2.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/abs.h" + +/** +* Constructs a Givens plane rotation. +* +* @param a rotational elimination parameter +* @param b rotational elimination parameter +* @param out output array +* @param stride index increment +* @param offsetX starting index +*/ +void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { + double scale; + double sign; + double aa; + double ab; + double r; + double z; + + aa = stdlib_base_abs( *a ); + ab = stdlib_base_abs( *b ); + if ( aa > ab ) { + sign = stdlib_base_copysign( 1.0, *a ); + } else { + sign = stdlib_base_copysign( 1.0, *b ); + } + scale = aa + ab; + if ( scale == 0.0 ) { + *c = 1.0; + *s = 0.0; + r = 0.0; + z = 0.0; + } else { + r = scale * stdlib_base_sqrt( stdlib_base_abs2( *a/scale ) + stdlib_base_abs2( *b/scale ) ); + r *= sign; + *c = *a / r; + *s = *b / r; + z = 1.0; + if ( aa > ab ) { + z = *s; + } else if ( *c != 0.0 ) { + z = 1.0 / *c; + } + } + *a = r; + *b = z; + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f new file mode 100644 index 000000000000..6586cd3a9a95 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f @@ -0,0 +1,87 @@ +!> +! @license Apache-2.0 +! +! Copyright (c) 2024 The Stdlib Authors. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. +!< + +!> Constructs a Givens plane rotation. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.7.0). Updated to "free form" Fortran 95. +! +! ## Authors +! +! * Univ. of Tennessee +! * Univ. of California Berkeley +! * Univ. of Colorado Denver +! * NAG Ltd. +! +! ## History +! +! * Jack Dongarra, linpack, 3/11/78. +! +! - modified 12/3/93, array(1) declarations changed to array(*) +! +! ## License +! +! From : +! +! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. +! > +! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: +! > +! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. +! > +! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. +! +! @param {double} da - rotational elimination parameter +! @param {double} db - rotational elimination parameter +! @param {double} c - cosine of the angle of rotation +! @param {double} s - sine of the angle of rotation +!< +subroutine drotg( da, db, c, s ) + implicit none + ! .. + ! Scalar arguments: + double precision :: c, da, db, s + ! .. + ! Local scalars: + double precision :: r, roe, scale, z + ! .. + ! Intrinsic functions: + intrinsic dabs, dsign, dsqrt + ! .. + roe = db + if (dabs(da) > dabs(db)) roe = da + scale = dabs(da) + dabs(db) + if (scale == 0.0d0) then + c = 1.0d0 + s = 0.0d0 + r = 0.0d0 + z = 0.0d0 + else + r = scale * dsqrt( (da/scale)**2 + (db/scale)**2 ) + r = dsign( 1.0d0, roe ) * r + c = da / r + s = db / r + z = 1.0d0 + if (dabs(da) > dabs(db)) z = s + if (dabs(db) >= dabs(da) .and. c /= 0.0d0) z = 1.0d0 / c + end if + da = r + db = z + return +end subroutine drotg \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.c b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.c new file mode 100644 index 000000000000..25c9af8f8089 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.c @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/copysign.h" +#include "stdlib/math/base/special/abs2.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/abs.h" + +/** +* Constructs a Givens plane rotation. +* +* @param a rotational elimination parameter +* @param b rotational elimination parameter +* @param out output array +* @param strideX stride length for output array +* @param offsetX starting index for output array +*/ +void API_SUFFIX(c_drotg_assign)( double* a, double* b, double* c, double* s ) { + double scale; + double sign; + double aa; + double ab; + double r; + double z; + + aa = stdlib_base_abs( *a ); + ab = stdlib_base_abs( *b ); + if ( aa > ab ) { + sign = stdlib_base_copysign( 1.0, *a ); + } else { + sign = stdlib_base_copysign( 1.0, *b ); + } + scale = aa + ab; + if ( scale == 0.0 ) { + *c = 1.0; + *s = 0.0; + r = 0.0; + z = 0.0; + } else { + r = scale * stdlib_base_sqrt( stdlib_base_abs2( *a/scale ) + stdlib_base_abs2( *b/scale ) ); + r *= sign; + *c = *a / r; + *s = *b / r; + z = 1.0; + if ( aa > ab ) { + z = *s; + } else if ( *c != 0.0 ) { + z = 1.0 / *c; + } + } + *a = r; + *b = z; + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c new file mode 100644 index 000000000000..183bb3123299 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/base/drotg_cblas.h" +#include "stdlib/blas/base/shared.h" + +/** +* Constructs a Givens plane rotation. +* +* @param a rotational elimination parameter +* @param b rotational elimination parameter +*/ +void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ) { + API_SUFFIX(cblas_drotg)( a, b, c, s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c new file mode 100644 index 000000000000..56e842295f63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/base/drotg_fortran.h" +#include "stdlib/blas/base/shared.h" + +/** +* Constructs a Givens plane rotation. +* +* @param a rotational elimination parameter +* @param b rotational elimination parameter +*/ +void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ) { + drotg( a, b, c, s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotg/test/test.native.js b/lib/node_modules/@stdlib/blas/base/drotg/test/test.native.js new file mode 100644 index 000000000000..6d7fbc46c1b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/test/test.native.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 Float64Array = require( '@stdlib/array/float64' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var drotg = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( drotg instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', opts, function test( t ) { + t.strictEqual( drotg.length, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes a Givens plane rotation', opts, function test( t ) { + var expected; + var values; + var delta; + var tol; + var out; + var i; + var j; + var e; + + expected = [ + [ 0.5, 1.0/0.6, 0.6, 0.8 ], + [ 0.5, 0.6, 0.8, 0.6 ], + [ 0.5, -1.0/0.6, -0.6, 0.8 ], + [ -0.5, -0.6, 0.8, -0.6 ], + [ -0.5, 1.0/0.6, 0.6, 0.8 ], + [ 0.0, 0.0, 1.0, 0.0 ], + [ 1.0, 1.0, 0.0, 1.0 ], + [ 1.0, 0.0, 1.0, 0.0 ] + ]; + values = [ + [ 0.3, 0.4 ], + [ 0.4, 0.3 ], + [ -0.3, 0.4 ], + [ -0.4, 0.3 ], + [ -0.3, -0.4 ], + [ 0.0, 0.0 ], + [ 0.0, 1.0 ], + [ 1.0, 0.0 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + e = new Float64Array( expected[i] ); + out = drotg( values[i][0], values[i][1] ); + for ( j = 0; j < out.length; j++ ) { + if ( out[j] === expected[j] ) { + t.strictEqual( out[j], e[j], 'returns expected value' ); + } else { + delta = abs( out[j] - e[j] ); + tol = 1.5 * EPS * abs( e[j] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[j]+'. expected: '+e[j]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function returns an array of NaNs if provided a rotational elimination parameter equal to NaN', opts, function test( t ) { + var actual; + var i; + + actual = drotg( NaN, 1.0 ); + for ( i = 0; i < actual.length; i++ ) { + t.strictEqual( isnan( abs( actual[i] ) ), true, 'returns expected value' ); + } + + actual = drotg( 1.0, NaN ); + for ( i = 0; i < actual.length; i++ ) { + t.strictEqual( isnan( abs( actual[i] ) ), true, 'returns expected value' ); + } + + actual = drotg( NaN, NaN ); + for ( i = 0; i < actual.length; i++ ) { + t.strictEqual( isnan( abs( actual[i] ) ), true, 'returns expected value' ); + } + t.end(); +});