From 18f095de9b428d926bb07f3ffd6762b13f013436 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 20 May 2024 11:34:20 +0530 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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 ); } } From 44aba3aae25a419e37acc5c45e829244df18947d Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Sun, 13 Jul 2025 15:33:41 +0530 Subject: [PATCH 5/9] refactor: update implementation --- .../base/drotg/benchmark/benchmark.assign.js | 105 +++++++++++++++++ .../benchmark/benchmark.assign.native.js | 110 ++++++++++++++++++ .../blas/base/drotg/benchmark/benchmark.js | 107 +++++++++-------- .../base/drotg/benchmark/benchmark.native.js | 86 ++++++++++---- .../base/drotg/benchmark/c/benchmark.length.c | 72 +++++++++--- .../benchmark/fortran/benchmark.length.f | 16 +-- .../@stdlib/blas/base/drotg/docs/repl.txt | 24 ++-- .../blas/base/drotg/docs/types/index.d.ts | 8 +- .../blas/base/drotg/docs/types/test.ts | 14 ++- .../blas/base/drotg/examples/c/example.c | 8 +- .../@stdlib/blas/base/drotg/examples/index.js | 5 + .../drotg/include/stdlib/blas/base/drotg.h | 5 + .../@stdlib/blas/base/drotg/lib/assign.js | 18 +-- .../@stdlib/blas/base/drotg/lib/index.js | 2 +- .../@stdlib/blas/base/drotg/lib/native.js | 2 +- .../@stdlib/blas/base/drotg/src/drotg.c | 2 +- .../blas/base/drotg/src/drotg_assign.c | 71 +++++++++++ 17 files changed, 531 insertions(+), 124 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.c 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 index 306036899132..f01fd1e29536 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. @@ -22,45 +22,87 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +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/native.js' ) ); +var drotg = tryRequire( resolve( __dirname, './../lib/drotg.native.js' ) ); var opts = { 'skip': ( drotg instanceof Error ) }; -var OPTS = { +var options = { 'dtype': 'float64' }; -// MAIN // +// FUNCTIONS // -bench( pkg+'::native', opts, 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, options ); + var y = uniform( -10.0, 10.0, options ); + 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' ); +} + + +// 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 ); } - b.pass( 'benchmark finished' ); - b.end(); -}); +} + +main(); 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 41d3ff158bb0..0ba6986cf0df 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 @@ -17,6 +17,7 @@ */ #include "stdlib/blas/base/drotg.h" +#include "stdlib/blas/ext/base/dfill.h" #include #include #include @@ -91,32 +92,62 @@ double rand_double( void ) { * Runs a benchmark. * * @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds +* @param N array length +* @return elapsed time in seconds */ -double benchmark( int iterations ) { +static double benchmark1( int iterations, int N ) { double elapsed; - double x; - double y; - double c; - double s; + double out[ N ]; + double a; + double b; 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 ) { + 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 ( y != y ) { + 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; @@ -129,6 +160,7 @@ int main( void ) { double elapsed; int count; int iter; + int N; int i; int j; @@ -138,11 +170,19 @@ int main( void ) { 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", NAME ); - elapsed = benchmark( iter ); + 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 ); } 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 b945c06a51e4..940b974b83bb 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 @@ -123,8 +123,8 @@ double precision function benchmark( iterations ) ! .. ! External functions: interface - subroutine drotg( da, db, c, s ) - double precision :: c, da, db, s + subroutine drotg( a, b, c, s ) + double precision :: c, a, b, s end subroutine drotg end interface ! .. @@ -137,21 +137,21 @@ end subroutine drotg integer :: i ! .. ! Local scalar: - double precision :: da, db + double precision :: a, b ! .. ! Intrinsic functions: intrinsic random_number, cpu_time ! .. call random_number( r1 ) call random_number( r2 ) - da = (r1*100.0d0)-50.0d0 - db = (r2*100.0d0)-50.0d0 + a = (r1*100.0d0)-50.0d0 + b = (r2*100.0d0)-50.0d0 ! .. call cpu_time( t1 ) ! .. do i = 1, iterations - call drotg( da, db, 0.8d0, 0.6d0 ) - if ( db /= db ) then + call drotg( a, b, 0.8d0, 0.6d0 ) + if ( b /= b ) then print '(A)', 'unexpected result' exit end if @@ -161,7 +161,7 @@ end subroutine drotg ! .. elapsed = t2 - t1 ! .. - if ( db /= db ) then + if ( b /= b ) then print '(A)', 'unexpected result' end if ! .. 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/example.c b/lib/node_modules/@stdlib/blas/base/drotg/examples/c/example.c index 3fb4f70c4eff..e80ab8576581 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 @@ -20,14 +20,14 @@ #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 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( &da[i], &db[i], &c, &s ); - printf( "da: %lf, db: %lf, c: %lf, s: %lf\n", da[i], db[i], c, s ); + 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/stdlib/blas/base/drotg.h b/lib/node_modules/@stdlib/blas/base/drotg/include/stdlib/blas/base/drotg.h index 19154590ac65..956efdcdce89 100644 --- 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 @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ); +/** +* Constructs a Givens plane rotation provided two double-precision floating-point values and assigns the results to an output array. +*/ +void API_SUFFIX(c_drotg_assign)( double *a, double *b, double *c, double *s, double *out, CBLAS_INT strideX, CBLAS_INT offsetX ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/drotg/lib/assign.js b/lib/node_modules/@stdlib/blas/base/drotg/lib/assign.js index f236348ca14c..144221b88835 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/lib/assign.js @@ -34,8 +34,8 @@ var copysign = require( '@stdlib/math/base/special/copysign' ); * @param {number} a - rotational elimination parameter * @param {number} b - rotational elimination parameter * @param {Float64Array} out - output array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length for output array +* @param {NonNegativeInteger} offsetX - starting index for output array * @returns {Float64Array} output array * * @example @@ -44,7 +44,7 @@ var copysign = require( '@stdlib/math/base/special/copysign' ); * var out = drotg( 0.0, 2.0, new Float64Array( 4 ), 1, 0 ); * // returns [ 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 index f69c3217960a..ecddd13248e0 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/lib/native.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/lib/native.js @@ -40,7 +40,7 @@ var addon = require( './../src/addon.node' ); function drotg( a, b ) { var out = new Float64Array( 4 ); addon( out, a, b ); - return [ out[ 0 ], out[ 1 ], out[ 2 ], out[ 3 ] ]; + return out; } 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 6468c48fef03..bd8a1d529ed3 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c @@ -30,7 +30,7 @@ * @param b rotational elimination parameter * @param out output array * @param stride index increment -* @param offset starting index +* @param offsetX starting index */ void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { double scale; 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; +} From 44f1d82aae86eefb117bf70ed11b853837bcfc9e Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Wed, 16 Jul 2025 15:18:15 +0530 Subject: [PATCH 6/9] bench: update benchmarking --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/drotg/benchmark/benchmark.assign.js | 11 +++++----- .../benchmark/benchmark.assign.native.js | 9 ++++---- .../base/drotg/benchmark/c/benchmark.length.c | 22 +++++++++++++------ 3 files changed, 24 insertions(+), 18 deletions(-) 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 index 2b2c793b2583..80329c2d3bba 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js @@ -46,6 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark() { + var out = new Float64Array( 4 ); var x = uniform( -10.0, 10.0, options ); var y = uniform( -10.0, 10.0, options ); return benchmark; @@ -57,19 +58,17 @@ function createBenchmark() { * @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 ] ) ) { + drotg( x, y, out, 1, 0 ); + if ( isnan( out[ i%4 ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnan( out[ i%4 ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); @@ -86,9 +85,9 @@ function createBenchmark() { * @private */ function main() { - var N; var min; var max; + var N; var f; var i; 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 index e89a5d1bd0e7..66c5d306a5d2 100644 --- 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 @@ -51,6 +51,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark() { + var out = new Float64Array( 4 ); var x = uniform( -10.0, 10.0, options ); var y = uniform( -10.0, 10.0, options ); return benchmark; @@ -62,19 +63,17 @@ function createBenchmark() { * @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 ] ) ) { + drotg( x, y, out, 1, 0 ); + if ( isnan( out[ i%4 ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnan( out[ i%4 ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); 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 0ba6986cf0df..5cb475677206 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 @@ -100,14 +100,18 @@ static double benchmark1( int iterations, int N ) { double out[ N ]; double a; double b; + double c; + double s; double t; int i; + a = ( rand_double()*200.0 ) - 100.0; + b = ( rand_double()*200.0 ) - 100.0; + c = 0.8; + s = 0.6; 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 ); + out = c_drotg( &a, &b, &c, &s ); if ( out[ i%N ] != out[ i%N ] ) { printf( "should not return NaN\n" ); break; @@ -132,15 +136,19 @@ static double benchmark2( int iterations, int N ) { double out[ N ]; double a; double b; + double c; + double s; double t; int i; - stdlib_strided_dfill( 4, 0.0, out, 1 ); + a = ( rand_double()*200.0 ) - 100.0; + b = ( rand_double()*200.0 ) - 100.0; + c = 0.8; + s = 0.6; 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 ); + stdlib_strided_dfill( 4, 0.0, out, 1 ); + c_drotg_assign( &a, &b, &c, &s, out, 1, 0 ); if ( out[ i%N ] != out[ i%N ] ) { printf( "should not return NaN\n" ); break; From 4abf8fac05224e8e1f9c514dceb63bf5980f00d9 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Wed, 16 Jul 2025 15:33:13 +0530 Subject: [PATCH 7/9] bench: revert changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/drotg/benchmark/c/benchmark.length.c | 72 ++++--------------- 1 file changed, 12 insertions(+), 60 deletions(-) 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 5cb475677206..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 @@ -17,7 +17,6 @@ */ #include "stdlib/blas/base/drotg.h" -#include "stdlib/blas/ext/base/dfill.h" #include #include #include @@ -92,70 +91,32 @@ double rand_double( void ) { * Runs a benchmark. * * @param iterations number of iterations -* @param N array length -* @return elapsed time in seconds +* @param len array length +* @return elapsed time in seconds */ -static double benchmark1( int iterations, int N ) { +double benchmark( int iterations ) { double elapsed; - double out[ N ]; - double a; - double b; + double x; + double y; double c; double s; double t; int i; - a = ( rand_double()*200.0 ) - 100.0; - b = ( rand_double()*200.0 ) - 100.0; + 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++ ) { - out = c_drotg( &a, &b, &c, &s ); - if ( out[ i%N ] != out[ i%N ] ) { + c_drotg( &x, &y, &c, &s ); + if ( y != y ) { 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 c; - double s; - double t; - int i; - - a = ( rand_double()*200.0 ) - 100.0; - b = ( rand_double()*200.0 ) - 100.0; - c = 0.8; - s = 0.6; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dfill( 4, 0.0, out, 1 ); - c_drotg_assign( &a, &b, &c, &s, 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 ] ) { + if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; @@ -168,7 +129,6 @@ int main( void ) { double elapsed; int count; int iter; - int N; int i; int j; @@ -178,19 +138,11 @@ int main( void ) { 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 ); + printf( "# c::%s", NAME ); + elapsed = benchmark( iter ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } From d7d1c7399adccecac90518ef0a23229f455f34fa Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Wed, 16 Jul 2025 16:19:41 +0530 Subject: [PATCH 8/9] chore: add comments and declarations in examples --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/drotg/examples/c/example.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 e80ab8576581..074d35270509 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 @@ -23,9 +23,11 @@ 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; + double c = 0.8; + double s = 0.6; int i; + + // Constructs a Givens plane rotation 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 ); From e54cf182b01a3288a46882e25861e81331558817 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Wed, 16 Jul 2025 16:51:41 +0530 Subject: [PATCH 9/9] refactor: remove assign implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../drotg/include/stdlib/blas/base/drotg.h | 5 -- .../@stdlib/blas/base/drotg/src/drotg.c | 9 +-- .../@stdlib/blas/base/drotg/src/drotg.f | 30 ++++---- .../blas/base/drotg/src/drotg_assign.c | 71 ------------------- .../@stdlib/blas/base/drotg/src/drotg_cblas.c | 2 + .../@stdlib/blas/base/drotg/src/drotg_f.c | 2 + 6 files changed, 24 insertions(+), 95 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.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 index 956efdcdce89..19154590ac65 100644 --- 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 @@ -36,11 +36,6 @@ extern "C" { */ void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ); -/** -* Constructs a Givens plane rotation provided two double-precision floating-point values and assigns the results to an output array. -*/ -void API_SUFFIX(c_drotg_assign)( double *a, double *b, double *c, double *s, double *out, CBLAS_INT strideX, CBLAS_INT offsetX ); - #ifdef __cplusplus } #endif 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 bd8a1d529ed3..ef05b0d152d8 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.c @@ -28,9 +28,8 @@ * * @param a rotational elimination parameter * @param b rotational elimination parameter -* @param out output array -* @param stride index increment -* @param offsetX starting index +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation */ void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { double scale; @@ -38,6 +37,7 @@ void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { double aa; double ab; double r; + double v; double z; aa = stdlib_base_abs( *a ); @@ -54,7 +54,8 @@ void API_SUFFIX(c_drotg)( double* a, double* b, double* c, double* s ) { r = 0.0; z = 0.0; } else { - r = scale * stdlib_base_sqrt( stdlib_base_abs2( *a/scale ) + stdlib_base_abs2( *b/scale ) ); + v = stdlib_base_abs2( *a/scale ) + stdlib_base_abs2( *b/scale ); + r = scale * stdlib_base_sqrt( v ); r *= sign; *c = *a / r; *s = *b / r; 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 6586cd3a9a95..5ed2114b8639 100644 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f +++ b/lib/node_modules/@stdlib/blas/base/drotg/src/drotg.f @@ -47,16 +47,16 @@ ! > ! > * 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} a - rotational elimination parameter +! @param {double} b - 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 ) +subroutine drotg( a, b, c, s ) implicit none ! .. ! Scalar arguments: - double precision :: c, da, db, s + double precision :: c, a, b, s ! .. ! Local scalars: double precision :: r, roe, scale, z @@ -64,24 +64,24 @@ subroutine drotg( da, db, c, s ) ! Intrinsic functions: intrinsic dabs, dsign, dsqrt ! .. - roe = db - if (dabs(da) > dabs(db)) roe = da - scale = dabs(da) + dabs(db) + roe = b + if (dabs(a) > dabs(b)) roe = a + scale = dabs(a) + dabs(b) 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 = scale * dsqrt( (a/scale)**2 + (b/scale)**2 ) r = dsign( 1.0d0, roe ) * r - c = da / r - s = db / r + c = a / r + s = b / r z = 1.0d0 - if (dabs(da) > dabs(db)) z = s - if (dabs(db) >= dabs(da) .and. c /= 0.0d0) z = 1.0d0 / c + if (dabs(a) > dabs(b)) z = s + if (dabs(b) >= dabs(a) .and. c /= 0.0d0) z = 1.0d0 / c end if - da = r - db = z + a = r + b = z return -end subroutine drotg \ No newline at end of file +end subroutine drotg 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 deleted file mode 100644 index 25c9af8f8089..000000000000 --- a/lib/node_modules/@stdlib/blas/base/drotg/src/drotg_assign.c +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @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 index 183bb3123299..5d467ed167be 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 @@ -25,6 +25,8 @@ * * @param a rotational elimination parameter * @param b rotational elimination parameter +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation */ 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 56e842295f63..ffa1d02ed48f 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 @@ -25,6 +25,8 @@ * * @param a rotational elimination parameter * @param b rotational elimination parameter +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation */ void API_SUFFIX(c_drotg)( double *a, double *b, double *c, double *s ) { drotg( a, b, c, s );