From 18f095de9b428d926bb07f3ffd6762b13f013436 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 20 May 2024 11:34:20 +0530 Subject: [PATCH 1/4] feat: add C / Fortran implementation for drotg --- .../drotg/include/stdlib/blas/base/drotg.h | 43 +++++++++ .../include/stdlib/blas/base/drotg_cblas.h | 43 +++++++++ .../include/stdlib/blas/base/drotg_fortran.h | 41 +++++++++ .../@stdlib/blas/base/drotg/lib/native.js | 49 ++++++++++ .../@stdlib/blas/base/drotg/src/Makefile | 70 +++++++++++++++ .../@stdlib/blas/base/drotg/src/addon.c | 42 +++++++++ .../@stdlib/blas/base/drotg/src/drotg.c | 89 ++++++++++++++++++ .../@stdlib/blas/base/drotg/src/drotg.f | 90 +++++++++++++++++++ .../@stdlib/blas/base/drotg/src/drotg_cblas.c | 31 +++++++ .../@stdlib/blas/base/drotg/src/drotg_f.c | 31 +++++++ 10 files changed, 529 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c diff --git a/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg.h b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg.h new file mode 100644 index 000000000000..ec483aee1bc0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg.h @@ -0,0 +1,43 @@ +/** +* @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. +*/ + +/** +* Header file containing function declarations for the C interface to the BLAS Level 1 routine `drotg`. +*/ +#ifndef DROTG_H +#define DROTG_H + +#include "stdlib/blas/base/shared.h" + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Constructs a Givens plane rotation provided two double-precision floating-point values. +*/ +void API_SUFFIX(c_drotg)( double a, double b ); + +#ifdef __cplusplus +} +#endif + +#endif // !DROTG_H diff --git a/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_cblas.h b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_cblas.h new file mode 100644 index 000000000000..989dcc84137e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_cblas.h @@ -0,0 +1,43 @@ +/** +* @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. +*/ + +/** +* Header file containing function declarations for the C interface to the CBLAS Level 1 routine `cblas_drotg`. +*/ +#ifndef DROTG_CBLAS_H +#define DROTG_CBLAS_H + +#include "stdlib/blas/base/shared.h" + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Constructs a Givens plane rotation provided two double-precision floating-point values. +*/ +void API_SUFFIX(cblas_drotg)( double a, double b); + +#ifdef __cplusplus +} +#endif + +#endif // !DROTG_CBLAS_H diff --git a/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_fortran.h b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_fortran.h new file mode 100644 index 000000000000..c7d5a0d2bd2b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg_fortran.h @@ -0,0 +1,41 @@ +/** +* @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. +*/ + +/** +* Header file containing function declarations for the Fortran interface to the BLAS Level 1 routine `drotg`. +*/ +#ifndef DROTG_FORTRAN_H +#define DROTG_FORTRAN_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C/Fortran compiler (a Fortran compiler must be configured to not attach underscores). +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Constructs a Givens plane rotation provided two double-precision floating-point values. +*/ +void drotgg( double *, double * ); + +#ifdef __cplusplus +} +#endif + +#endif // !DROTG_FORTRAN_H 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..f69c3217960a --- /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[ 0 ], out[ 1 ], out[ 2 ], out[ 3 ] ]; +} + + +// EXPORTS // + +module.exports = drotg; 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..64e2e32867c0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c @@ -0,0 +1,42 @@ +/** +* @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/drot.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_double.h" +#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 ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); + STDLIB_NAPI_ARGV_DOUBLE( env, a, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, b, argv, 1 ); + API_SUFFIX(c_drotg)( a, b ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) 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..5d909a096584 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c @@ -0,0 +1,89 @@ +/** +* @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 offset starting index +*/ +static void assign( double a, double b, double *out, const CBLAS_INT stride, const CBLAS_INT offset ) { + double scale; + double sign; + double aa; + double ab; + double r; + double c; + double s; + 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; + out[ offset ] = a; + out[ offset + stride ] = b; + out[ offset + ( 2 * stride ) ] = c; + out[ offset + ( 3 * stride ) ] = s; + return; +} + +/** +* 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 out[ 4 ]; + assign( a, b, out, 1, 0 ); + 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..62e0391c5639 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f @@ -0,0 +1,90 @@ +!> +! @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 + ! .. + ! Internal parameters: + integer, parameter :: dp=kind(0.0d0) ! double-precision + ! .. + ! Scalar arguments: + real(dp) :: c, da, db, s + ! .. + ! Local scalars: + real(dp) :: 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.0_dp) then + c = 1.0_dp + s = 0.0_dp + r = 0.0_dp + z = 0.0_dp + else + r = scale * dsqrt( (da/scale)**2 + (db/scale)**2 ) + r = dsign( 1.0_dp, roe ) * r + c = da / r + s = db / r + z = 1.0_dp + if (dabs(da) > dabs(db)) z = s + if (dabs(db) >= dabs(da) .and. c /= 0.0_dp) z = 1.0_dp / 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_cblas.c b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c new file mode 100644 index 000000000000..207f1a1abb7c --- /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 ) { + API_SUFFIX(cblas_drotg)( a, b); +} 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..0b42bac77df7 --- /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 ) { + drotg( &a, &b ); +} From f5eb8368766d51d6ec74f41f448062428f57cbcd Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 20 May 2024 18:10:02 +0530 Subject: [PATCH 2/4] chore: add benchmarks --- .../base/drotg/benchmark/benchmark.native.js | 66 +++ .../blas/base/drotg/benchmark/c/Makefile | 146 ++++++ .../base/drotg/benchmark/c/benchmark.length.c | 151 ++++++ .../base/drotg/benchmark/fortran/Makefile | 141 ++++++ .../benchmark/fortran/benchmark.length.f | 194 ++++++++ .../@stdlib/blas/base/drotg/binding.gyp | 265 ++++++++++ .../blas/base/drotg/examples/c/Makefile | 146 ++++++ .../blas/base/drotg/examples/c/example.c | 35 ++ .../@stdlib/blas/base/drotg/include.gypi | 70 +++ .../drotg/include/stdlib/blas/base/drotg.h | 2 +- .../include/stdlib/blas/base/drotg_cblas.h | 2 +- .../include/stdlib/blas/base/drotg_fortran.h | 2 +- .../@stdlib/blas/base/drotg/manifest.json | 463 ++++++++++++++++++ .../@stdlib/blas/base/drotg/package.json | 4 + .../@stdlib/blas/base/drotg/src/addon.c | 110 ++++- .../@stdlib/blas/base/drotg/src/drotg.c | 48 +- .../@stdlib/blas/base/drotg/src/drotg.f | 20 +- .../@stdlib/blas/base/drotg/src/drotg_cblas.c | 4 +- .../@stdlib/blas/base/drotg/src/drotg_f.c | 4 +- 19 files changed, 1813 insertions(+), 60 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/manifest.json 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..306036899132 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js @@ -0,0 +1,66 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drotg = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( drotg instanceof Error ) +}; +var OPTS = { + 'dtype': 'float64' +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var out; + var x; + var y; + var i; + + x = discreteUniform( 100, -5, 5, OPTS ); + y = discreteUniform( 100, -5, 5, OPTS ); + + 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.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ i%4 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); 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..c6461fa50d49 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/c/benchmark.length.c @@ -0,0 +1,151 @@ +/** +* @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 +#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 len array length +* @return elapsed time in seconds +*/ +double benchmark( int iterations ) { + double elapsed; + double x; + double y; + double c; + double s; + double t; + int i; + + x = ( rand_double()*200.0 ) - 100.0; + y = ( rand_double()*200.0 ) - 100.0; + c = 0.8; + s = 0.6; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_drotg( x, y, c, s ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + 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++ ) { + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s", NAME ); + elapsed = benchmark( iter ); + 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..3da2e66b0122 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/fortran/benchmark.length.f @@ -0,0 +1,194 @@ +!> +! @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. +!< + +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'drotg' ! if changed, be sure to adjust length + integer, parameter :: iterations = 10000000 + 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 + ! @param {integer} len - array length + ! @return {double} elapsed time in seconds + ! .. + double precision function benchmark( iterations ) + ! .. + ! External functions: + interface + subroutine drotg( da, db, c, s ) + double precision :: da, db, c, s + end subroutine drotg + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations + ! .. + ! Local scalars: + double precision :: elapsed, r, x, y + real :: t1, t2 + integer :: i + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time + ! .. + call random_number( r ) + x = ( r*200.0d0 ) - 100.0d0 + y = ( r*200.0d0 ) - 100.0d0 + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call drotg( x, y, 1.0d0, 0.0d0 ); + if ( y /= y ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( y /= y ) then + print '(A)', 'should not return NaN' + end if + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + integer :: count, iter, i, j + double precision :: elapsed + character(len=999) :: str, tmp + ! .. + ! 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/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..927380013480 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c @@ -0,0 +1,35 @@ +/** +* @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 da[] = { 0.3, 0.0, -0.0, 1.0, -1.0, 3.14, -3.14 }; + double db[] = { 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++ ) { + double a = *da[ i ]; + double b = *db[ i ]; + c_drotg( &a, &b, &c, &s ); + printf( "da: %lf, db: %lf, c: %lf, s: %lf\n", a, b, c, s ); + } +} 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)', + ' +#include +#include /** * Receives JavaScript callback invocation data. @@ -32,11 +30,103 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); - STDLIB_NAPI_ARGV_DOUBLE( env, a, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, b, argv, 1 ); - API_SUFFIX(c_drotg)( a, b ); + napi_status status; + + // Get callback arguments: + size_t argc = 2; + 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 < 2 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); + assert( status == napi_ok ); + return NULL; + } + if ( argc > 2 ) { + 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; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* 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 index 5d909a096584..6468c48fef03 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c @@ -32,58 +32,40 @@ * @param stride index increment * @param offset starting index */ -static void assign( double a, double b, double *out, const CBLAS_INT stride, const CBLAS_INT offset ) { +void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { double scale; double sign; double aa; double ab; double r; - double c; - double s; double z; - aa = stdlib_base_abs( a ); - ab = stdlib_base_abs( b ); + aa = stdlib_base_abs( *a ); + ab = stdlib_base_abs( *b ); if ( aa > ab ) { - sign = stdlib_base_copysign( 1.0, a ); + sign = stdlib_base_copysign( 1.0, *a ); } else { - sign = stdlib_base_copysign( 1.0, b ); + sign = stdlib_base_copysign( 1.0, *b ); } scale = aa + ab; if ( scale == 0.0 ) { - c = 1.0; - s = 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 = scale * stdlib_base_sqrt( stdlib_base_abs2( *a/scale ) + stdlib_base_abs2( *b/scale ) ); r *= sign; - c = a / r; - s = b / r; + *c = *a / r; + *s = *b / r; z = 1.0; if ( aa > ab ) { - z = s; - } else if ( c != 0.0 ) { - z = 1.0 / c; + z = *s; + } else if ( *c != 0.0 ) { + z = 1.0 / *c; } } - a = r; - b = z; - out[ offset ] = a; - out[ offset + stride ] = b; - out[ offset + ( 2 * stride ) ] = c; - out[ offset + ( 3 * stride ) ] = s; - return; -} - -/** -* 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 out[ 4 ]; - assign( a, b, out, 1, 0 ); + *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 index 62e0391c5639..9cc9a563a215 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f @@ -59,10 +59,10 @@ subroutine drotg( da, db, c, s ) integer, parameter :: dp=kind(0.0d0) ! double-precision ! .. ! Scalar arguments: - real(dp) :: c, da, db, s + double precision :: c, da, db, s ! .. ! Local scalars: - real(dp) :: r, roe, scale, z + double precision :: r, roe, scale, z ! .. ! Intrinsic functions: intrinsic dabs, dsign, dsqrt @@ -70,19 +70,19 @@ subroutine drotg( da, db, c, s ) roe = db if (dabs(da) > dabs(db)) roe = da scale = dabs(da) + dabs(db) - if (scale == 0.0_dp) then - c = 1.0_dp - s = 0.0_dp - r = 0.0_dp - z = 0.0_dp + 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.0_dp, roe ) * r + r = dsign( 1.0d0, roe ) * r c = da / r s = db / r - z = 1.0_dp + z = 1.0d0 if (dabs(da) > dabs(db)) z = s - if (dabs(db) >= dabs(da) .and. c /= 0.0_dp) z = 1.0_dp / c + if (dabs(db) >= dabs(da) .and. c /= 0.0d0) z = 1.0d0 / c end if da = r db = z 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 index 207f1a1abb7c..183bb3123299 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_cblas.c @@ -26,6 +26,6 @@ * @param a rotational elimination parameter * @param b rotational elimination parameter */ -void API_SUFFIX(c_drotg)( double a, double b ) { - API_SUFFIX(cblas_drotg)( a, b); +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 index 0b42bac77df7..56e842295f63 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_f.c @@ -26,6 +26,6 @@ * @param a rotational elimination parameter * @param b rotational elimination parameter */ -void API_SUFFIX(c_drotg)( double a, double b ) { - drotg( &a, &b ); +void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ) { + drotg( a, b, c, s ); } From 1f2e0493b4be41241515bc2af6c88f4190ca7a78 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 24 May 2024 12:45:17 +0530 Subject: [PATCH 3/4] feat: add C / Fortran implementation for drotg --- .../base/drotg/benchmark/c/benchmark.length.c | 2 +- .../benchmark/fortran/benchmark.length.f | 40 +++--- .../@stdlib/blas/base/drotg/src/addon.c | 6 +- .../@stdlib/blas/base/drotg/src/drotg.f | 3 - .../blas/base/drotg/test/test.native.js | 119 ++++++++++++++++++ 5 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/test/test.native.js 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 index c6461fa50d49..41d3ff158bb0 100644 --- 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 @@ -109,7 +109,7 @@ double benchmark( int iterations ) { s = 0.6; t = tic(); for ( i = 0; i < iterations; i++ ) { - c_drotg( x, y, c, s ); + c_drotg( &x, &y, &c, &s ); if ( y != y ) { printf( "should not return NaN\n" ); break; 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 index 3da2e66b0122..b945c06a51e4 100644 --- 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 @@ -16,12 +16,19 @@ ! 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 = 10000000 + integer, parameter :: iterations = 1000000 integer, parameter :: repeats = 3 integer, parameter :: min = 1 integer, parameter :: max = 6 @@ -110,7 +117,6 @@ end subroutine print_results ! Runs a benchmark. ! ! @param {integer} iterations - number of iterations - ! @param {integer} len - array length ! @return {double} elapsed time in seconds ! .. double precision function benchmark( iterations ) @@ -118,7 +124,7 @@ double precision function benchmark( iterations ) ! External functions: interface subroutine drotg( da, db, c, s ) - double precision :: da, db, c, s + double precision :: c, da, db, s end subroutine drotg end interface ! .. @@ -126,23 +132,27 @@ end subroutine drotg integer, intent(in) :: iterations ! .. ! Local scalars: - double precision :: elapsed, r, x, y - real :: t1, t2 + double precision :: elapsed, r1, r2 + real :: t1, t2 integer :: i ! .. + ! Local scalar: + double precision :: da, db + ! .. ! Intrinsic functions: intrinsic random_number, cpu_time ! .. - call random_number( r ) - x = ( r*200.0d0 ) - 100.0d0 - y = ( r*200.0d0 ) - 100.0d0 + call random_number( r1 ) + call random_number( r2 ) + da = (r1*100.0d0)-50.0d0 + db = (r2*100.0d0)-50.0d0 ! .. call cpu_time( t1 ) ! .. do i = 1, iterations - call drotg( x, y, 1.0d0, 0.0d0 ); - if ( y /= y ) then - print '(A)', 'should not return NaN' + call drotg( da, db, 0.8d0, 0.6d0 ) + if ( db /= db ) then + print '(A)', 'unexpected result' exit end if end do @@ -151,8 +161,8 @@ end subroutine drotg ! .. elapsed = t2 - t1 ! .. - if ( y /= y ) then - print '(A)', 'should not return NaN' + if ( db /= db ) then + print '(A)', 'unexpected result' end if ! .. benchmark = elapsed @@ -164,9 +174,9 @@ end function benchmark subroutine main() ! .. ! Local variables: - integer :: count, iter, i, j - double precision :: elapsed character(len=999) :: str, tmp + double precision :: elapsed + integer :: i, j, count, iter ! .. ! Intrinsic functions: intrinsic adjustl, trim diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c b/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c index 4b0b11c4335b..de6a3b47a20b 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/addon.c @@ -33,18 +33,18 @@ static napi_value addon( napi_env env, napi_callback_info info ) { napi_status status; // Get callback arguments: - size_t argc = 2; + 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 < 2 ) { + if ( argc < 3 ) { status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); assert( status == napi_ok ); return NULL; } - if ( argc > 2 ) { + if ( argc > 3 ) { status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); assert( status == napi_ok ); return NULL; diff --git a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f index 9cc9a563a215..6586cd3a9a95 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f @@ -55,9 +55,6 @@ subroutine drotg( da, db, c, s ) implicit none ! .. - ! Internal parameters: - integer, parameter :: dp=kind(0.0d0) ! double-precision - ! .. ! Scalar arguments: double precision :: c, da, db, 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(); +}); From c732e89908d0feed3e56f3aa19f54e4160b8c972 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 24 May 2024 12:55:22 +0530 Subject: [PATCH 4/4] chore: resolve C examples --- .../@stdlib/blas/base/drotg/examples/c/example.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 index 927380013480..3fb4f70c4eff 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c @@ -27,9 +27,7 @@ int main( void ) { double s; int i; for ( i = 0; i < 7; i++ ) { - double a = *da[ i ]; - double b = *db[ i ]; - c_drotg( &a, &b, &c, &s ); - printf( "da: %lf, db: %lf, c: %lf, s: %lf\n", a, b, c, s ); + c_drotg( &da[i], &db[i], &c, &s ); + printf( "da: %lf, db: %lf, c: %lf, s: %lf\n", da[i], db[i], c, s ); } }