From 3c2aaa6c1cbf835dd5be75eb61f0096111fcfa98 Mon Sep 17 00:00:00 2001 From: ByteKnight28 Date: Thu, 22 Jan 2026 00:08:46 +0530 Subject: [PATCH] feat: add blas/base/crotg --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/crotg/.npmignore | 3 + .../@stdlib/blas/base/crotg/README.md | 298 ++++++++++++++++++ .../blas/base/crotg/benchmark/benchmark.js | 113 +++++++ .../base/crotg/benchmark/benchmark.native.js | 118 +++++++ .../base/crotg/benchmark/benchmark.ndarray.js | 113 +++++++ .../benchmark/benchmark.ndarray.native.js | 118 +++++++ .../blas/base/crotg/benchmark/c/Makefile | 146 +++++++++ .../base/crotg/benchmark/c/benchmark.length.c | 203 ++++++++++++ .../base/crotg/benchmark/fortran/Makefile | 141 +++++++++ .../benchmark/fortran/benchmark.length.f | 213 +++++++++++++ .../@stdlib/blas/base/crotg/binding.gyp | 265 ++++++++++++++++ .../@stdlib/blas/base/crotg/docs/repl.txt | 92 ++++++ .../blas/base/crotg/docs/types/index.d.ts | 103 ++++++ .../blas/base/crotg/docs/types/test.ts | 247 +++++++++++++++ .../blas/base/crotg/examples/c/Makefile | 146 +++++++++ .../blas/base/crotg/examples/c/example.c | 53 ++++ .../@stdlib/blas/base/crotg/examples/index.js | 50 +++ .../@stdlib/blas/base/crotg/include.gypi | 70 ++++ .../crotg/include/stdlib/blas/base/crotg.h | 42 +++ .../include/stdlib/blas/base/crotg_cblas.h | 43 +++ .../include/stdlib/blas/base/crotg_fortran.h | 41 +++ .../@stdlib/blas/base/crotg/lib/crotg.js | 122 +++++++ .../blas/base/crotg/lib/crotg.native.js | 67 ++++ .../@stdlib/blas/base/crotg/lib/index.js | 54 ++++ .../@stdlib/blas/base/crotg/lib/main.js | 55 ++++ .../@stdlib/blas/base/crotg/lib/native.js | 48 +++ .../@stdlib/blas/base/crotg/lib/ndarray.js | 42 +++ .../blas/base/crotg/lib/ndarray.native.js | 41 +++ .../@stdlib/blas/base/crotg/manifest.json | 100 ++++++ .../@stdlib/blas/base/crotg/package.json | 100 ++++++ .../@stdlib/blas/base/crotg/src/Makefile | 70 ++++ .../@stdlib/blas/base/crotg/src/addon.c | 49 +++ .../@stdlib/blas/base/crotg/src/crotg.c | 86 +++++ .../@stdlib/blas/base/crotg/src/crotg.f | 55 ++++ .../@stdlib/blas/base/crotg/src/crotg_cblas.c | 72 +++++ .../@stdlib/blas/base/crotg/src/crotg_f.c | 72 +++++ .../blas/base/crotg/src/crotg_ndarray.c | 60 ++++ .../blas/base/crotg/test/test.crotg.js | 96 ++++++ .../blas/base/crotg/test/test.crotg.native.js | 80 +++++ .../@stdlib/blas/base/crotg/test/test.js | 82 +++++ .../blas/base/crotg/test/test.ndarray.js | 98 ++++++ .../base/crotg/test/test.ndarray.native.js | 106 +++++++ .../@stdlib/blas/base/wasm/crotg/README.md | 93 ++++++ .../blas/base/wasm/crotg/lib/binary.js | 34 ++ .../@stdlib/blas/base/wasm/crotg/lib/index.js | 34 ++ .../@stdlib/blas/base/wasm/crotg/lib/main.js | 37 +++ .../blas/base/wasm/crotg/lib/module.js | 83 +++++ .../blas/base/wasm/crotg/lib/routine.js | 119 +++++++ .../blas/base/wasm/crotg/manifest.json | 36 +++ .../@stdlib/blas/base/wasm/crotg/package.json | 93 ++++++ .../blas/base/wasm/crotg/scripts/build.js | 66 ++++ .../blas/base/wasm/crotg/scripts/template.txt | 33 ++ .../@stdlib/blas/base/wasm/crotg/src/Makefile | 127 ++++++++ .../blas/base/wasm/crotg/src/exports.json | 3 + .../blas/base/wasm/crotg/src/main.wasm | Bin 0 -> 8 bytes .../@stdlib/blas/base/wasm/crotg/test/test.js | 63 ++++ 56 files changed, 4994 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/.npmignore create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/include/stdlib/blas/base/crotg.h create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/include/stdlib/blas/base/crotg_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/include/stdlib/blas/base/crotg_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/crotg.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/crotg.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/crotg.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/crotg.f create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/crotg_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/crotg_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/src/crotg_ndarray.c create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/src/exports.json create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/crotg/test/test.js diff --git a/lib/node_modules/@stdlib/blas/base/crotg/.npmignore b/lib/node_modules/@stdlib/blas/base/crotg/.npmignore new file mode 100644 index 000000000000..ac02bec69991 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/.npmignore @@ -0,0 +1,3 @@ +test/ +benchmark/ +examples/ diff --git a/lib/node_modules/@stdlib/blas/base/crotg/README.md b/lib/node_modules/@stdlib/blas/base/crotg/README.md new file mode 100644 index 000000000000..879868b40869 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/README.md @@ -0,0 +1,298 @@ + + +# crotg + +> Construct a Givens plane rotation for complex single-precision floating-point numbers. + +
+ +## Usage + +```javascript +var crotg = require( '@stdlib/blas/base/crotg' ); +``` + +#### crotg( ar, ai, br, bi\[, out\[, stride\[, offset]]] ) + +Constructs a Givens plane rotation for complex single-precision floating-point numbers. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var out = crotg( 0.0, 0.0, 2.0, 0.0 ); +// returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +``` + +The function accepts the following arguments: + +- **ar**: real component of the rotational elimination parameter `a`. +- **ai**: imaginary component of the rotational elimination parameter `a`. +- **br**: real component of the rotational elimination parameter `b`. +- **bi**: imaginary component of the rotational elimination parameter `b`. +- **out**: output [`Complex64Array`][@stdlib/array/complex64] (optional). +- **stride**: index increment (optional). +- **offset**: starting index (optional). + +The function returns a [`Complex64Array`][@stdlib/array/complex64] containing the following elements: + +- `out[ 0 ]`: real component of the rotational elimination parameter `r` +- `out[ 1 ]`: imaginary component of the rotational elimination parameter `r` +- `out[ 2 ]`: real component of the rotational elimination parameter `s` +- `out[ 3 ]`: imaginary component of the rotational elimination parameter `s` +- `out[ 4 ]`: cosine of the angle of rotation `c` +- `out[ 5 ]`: zero (reserved) + +#### crotg.ndarray( ar, ai, br, bi, out, stride, offset ) + +Constructs a Givens plane rotation for complex single-precision floating-point numbers using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var out = new Complex64Array( 3 ); +var y = crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); +// returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +``` + +The function accepts the following arguments: + +- **ar**: real component of the rotational elimination parameter `a`. +- **ai**: imaginary component of the rotational elimination parameter `a`. +- **br**: real component of the rotational elimination parameter `b`. +- **bi**: imaginary component of the rotational elimination parameter `b`. +- **out**: output [`Complex64Array`][@stdlib/array/complex64]. +- **stride**: index increment. +- **offset**: starting index. + +
+ + + +
+ +## Notes + +- `crotg` corresponds to the BLAS level 1 function [`crotg`][crotg]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var crotg = require( '@stdlib/blas/base/crotg' ); + +function rand() { + return discreteUniform( -10, 10 ); +} + +var out = new Complex64Array( 3 ); +var ar; +var ai; +var br; +var bi; +var i; + +for ( i = 0; i < 10; i++ ) { + ar = rand(); + ai = rand(); + br = rand(); + bi = rand(); + + crotg( ar, ai, br, bi, out, 1, 0 ); + + console.log( 'a: %d + %dj', ar, ai ); + console.log( 'b: %d + %dj', br, bi ); + console.log( 'r: %s', out.get( 0 ).toString() ); + console.log( 's: %s', out.get( 1 ).toString() ); + console.log( 'c: %d', out.get( 2 ).re ); + console.log( '' ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/crotg.h" +``` + +#### stdlib_blas_base_crotg( \*ca, \*cb, \*c, \*s ) + +Constructs a Givens plane rotation for complex single-precision floating-point numbers. + +```c +float ca[] = { 1.0f, 2.0f }; +float cb[] = { 3.0f, 4.0f }; +float c; +float s[] = { 0.0f, 0.0f }; + +stdlib_blas_base_crotg( (void *)ca, (void *)cb, &c, (void *)s ); +``` + +The function accepts the following arguments: + +- **ca**: `[inout] void*` complex single-precision floating-point number `a`. +- **cb**: `[inout] void*` complex single-precision floating-point number `b`. +- **c**: `[out] float*` cosine of the angle of rotation. +- **s**: `[out] void*` sine of the angle of rotation. + +```c +void stdlib_blas_base_crotg( void *ca, void *cb, float *c, void *s ); +``` + +#### c_crotg_ndarray( ar, ai, br, bi, \*out, stride, offset ) + +Constructs a Givens plane rotation for complex single-precision floating-point numbers using alternative indexing semantics. + +```c +float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +c_crotg_ndarray( 1.0f, 2.0f, 3.0f, 4.0f, (void *)out, 1, 0 ); +``` + +The function accepts the following arguments: + +- **ar**: `[in] float` real component of the rotational elimination parameter `a`. +- **ai**: `[in] float` imaginary component of the rotational elimination parameter `a`. +- **br**: `[in] float` real component of the rotational elimination parameter `b`. +- **bi**: `[in] float` imaginary component of the rotational elimination parameter `b`. +- **out**: `[out] void*` output array. +- **stride**: `[in] CBLAS_INT` index increment. +- **offset**: `[in] CBLAS_INT` starting index. + +```c +void c_crotg_ndarray( const float ar, const float ai, const float br, const float bi, void *out, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/crotg.h" +#include + +int main( void ) { + float ca[] = { 1.0f, 2.0f }; + float cb[] = { 3.0f, 4.0f }; + float s[] = { 0.0f, 0.0f }; + float c = 0.0f; + + printf( "a: %f + %fj\n", ca[ 0 ], ca[ 1 ] ); + printf( "b: %f + %fj\n", cb[ 0 ], cb[ 1 ] ); + + stdlib_blas_base_crotg( (void *)ca, (void *)cb, &c, (void *)s ); + + printf( "r: %f + %fj\n", ca[ 0 ], ca[ 1 ] ); + printf( "c: %f\n", c ); + printf( "s: %f + %fj\n", s[ 0 ], s[ 1 ] ); + printf( "\n" ); + + // Using ndarray interface: + float ar = 5.0f; + float ai = 6.0f; + float br = 7.0f; + float bi = 8.0f; + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // r_re, r_im, s_re, s_im, c, 0 + + printf( "a: %f + %fj\n", ar, ai ); + printf( "b: %f + %fj\n", br, bi ); + + c_crotg_ndarray( ar, ai, br, bi, (void *)out, 1, 0 ); + + printf( "r: %f + %fj\n", out[ 0 ], out[ 1 ] ); + printf( "s: %f + %fj\n", out[ 2 ], out[ 3 ] ); + printf( "c: %f\n", out[ 4 ] ); +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.js new file mode 100644 index 000000000000..8ddd2d556597 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.js @@ -0,0 +1,113 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var crotg = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var view; + var out; + var x; + + x = uniform( len*4, -100.0, 100.0, options ); + out = new Complex64Array( 3 ); + view = new Float32Array( out.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var k; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = (i*4) % (len*4); + crotg( x[k], x[k+1], x[k+2], x[k+3], out, 1, 0 ); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.native.js new file mode 100644 index 000000000000..4749eed0539e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.native.js @@ -0,0 +1,118 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var crotg = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( crotg instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var view; + var out; + var x; + + x = uniform( len*4, -100.0, 100.0, options ); + out = new Complex64Array( 3 ); + view = new Float32Array( out.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var k; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = (i*4) % (len*4); + crotg( x[k], x[k+1], x[k+2], x[k+3], out, 1, 0 ); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6a87aa2028ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.js @@ -0,0 +1,113 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var crotg = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var view; + var out; + var x; + + x = uniform( len*4, -100.0, 100.0, options ); + out = new Complex64Array( 3 ); + view = new Float32Array( out.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var k; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = (i*4) % (len*4); + crotg( x[k], x[k+1], x[k+2], x[k+3], out, 1, 0 ); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..e484cbb68961 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,118 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var crotg = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( crotg instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var view; + var out; + var x; + + x = uniform( len*4, -100.0, 100.0, options ); + out = new Complex64Array( 3 ); + view = new Float32Array( out.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var k; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = (i*4) % (len*4); + crotg( x[k], x[k+1], x[k+2], x[k+3], out, 1, 0 ); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/Makefile new file mode 100644 index 000000000000..e11fffe66b95 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/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 ?= -I ../../include -I ../../../shared/include -I ../../../diagonal-types/include -I ../../../layouts/include -I ../../../matrix-orientations/include -I ../../../matrix-triangles/include -I ../../../operation-sides/include -I ../../../transpose-operations/include + +# List of source files: +SOURCE_FILES ?= ../../src/crotg.c ../../src/crotg_ndarray.c + +# 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/crotg/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..79afdea03502 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/c/benchmark.length.c @@ -0,0 +1,203 @@ +/** +* @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/crotg.h" +#include +#include +#include +#include +#include + +#define NAME "crotg" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float *x; + float *out; + float c; + float s[ 2 ]; + double t; + int i; + int k; + + x = (float *) malloc( len * 4 * sizeof( float ) ); + out = (float *) malloc( 6 * sizeof( float ) ); + for ( i = 0; i < len * 4; i++ ) { + x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + k = (i*4) % (len*4); + stdlib_blas_base_crotg( (void *)&x[k], (void *)&x[k+2], &c, (void *)s ); + if ( s[ 0 ] != s[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( s[ 0 ] != s[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( out ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float *x; + float *out; + double t; + int i; + int k; + + x = (float *) malloc( len * 4 * sizeof( float ) ); + out = (float *) malloc( 6 * sizeof( float ) ); + for ( i = 0; i < len * 4; i++ ) { + x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + k = (i*4) % (len*4); + c_crotg_ndarray( x[k], x[k+1], x[k+2], x[k+3], (void *)out, 1, 0 ); + if ( out[ 0 ] != out[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( out[ 0 ] != out[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( out ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS; + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/Makefile new file mode 100644 index 000000000000..22a6ede7ae17 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/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/crotg.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/crotg/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/benchmark.length.f new file mode 100644 index 000000000000..f166e88bfd31 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/benchmark/fortran/benchmark.length.f @@ -0,0 +1,213 @@ +!> +! @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 = 'crotg' ! 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, '(f100.9)') elapsed + tmp = adjustl( str ) + print '(A,A)', ' elapsed: ', trim( tmp ) + ! .. + write( str, '(f100.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, len ) + ! .. + ! External functions: + interface + subroutine crotg( ca, cb, c, s ) + complex :: ca, cb, s + real :: c + end subroutine crotg + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, len + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2 + real :: c + complex :: s + integer :: i + integer :: k + ! .. + ! Local arrays: + complex, allocatable :: x(:) + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time, cmplx, mod + ! .. + ! Allocate arrays: + allocate( x(len*4) ) + ! .. + do i = 1, len*4 + call random_number( r1 ) + call random_number( r2 ) + x( i ) = cmplx( (real(r1)*10000.0)-5000.0, (real(r2)*1000.0)-5000.0 ) + end do + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + k = mod( (i-1)*4, len*4 ) + 1 + call crotg( x(k), x(k+2), c, s ) + if ( c /= c ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( c /= c ) then + print '(A)', 'should not return NaN' + end if + ! .. + ! Deallocate arrays: + deallocate( x ) + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + integer :: count, iter, len, i, j + double precision :: elapsed + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + call print_version() + count = 0 + do i = min, max + len = 10**i + iter = iterations + do j = 1, repeats + count = count + 1 + ! .. + write (str, '(I15)') len + tmp = adjustl( str ) + print '(A,A,A,A)', '# fortran::', name, ':len=', trim( tmp ) + ! .. + elapsed = benchmark( iter, len ) + ! .. + 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 diff --git a/lib/node_modules/@stdlib/blas/base/crotg/binding.gyp b/lib/node_modules/@stdlib/blas/base/crotg/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/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/crotg/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/crotg/docs/repl.txt new file mode 100644 index 000000000000..75eaabebf40a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/docs/repl.txt @@ -0,0 +1,92 @@ + +{{alias}}( ar, ai, br, bi[, out[, stride[, offset]]] ) + Constructs a Givens plane rotation for complex single-precision + floating-point numbers. + + Parameters + ---------- + ar: number + Real component of the rotational elimination parameter `a`. + + ai: number + Imaginary component of the rotational elimination parameter `a`. + + br: number + Real component of the rotational elimination parameter `b`. + + bi: number + Imaginary component of the rotational elimination parameter `b`. + + out: Complex64Array (optional) + Output array. + + stride: integer (optional) + Index increment. + + offset: integer (optional) + Starting index. + + Returns + ------- + out: Complex64Array + Output array. + + Examples + -------- + // Standard usage: + > var out = {{alias}}( 0.0, 0.0, 2.0, 0.0 ); + > out + [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] + + // Using an output array: + > var Complex64Array = require( '@stdlib/array/complex64' ); + > var out = new Complex64Array( 3 ); + > {{alias}}( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); + > out + [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] + + +{{alias}}.ndarray( ar, ai, br, bi, out, stride, offset ) + Constructs a Givens plane rotation for complex single-precision + floating-point numbers using alternative indexing semantics. + + Parameters + ---------- + ar: number + Real component of the rotational elimination parameter `a`. + + ai: number + Imaginary component of the rotational elimination parameter `a`. + + br: number + Real component of the rotational elimination parameter `b`. + + bi: number + Imaginary component of the rotational elimination parameter `b`. + + out: Complex64Array + Output array. + + stride: integer + Index increment. + + offset: integer + Starting index. + + Returns + ------- + out: Complex64Array + Output array. + + Examples + -------- + // Standard usage: + > var Complex64Array = require( '@stdlib/array/complex64' ); + > var out = new Complex64Array( 3 ); + > {{alias}}.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); + > out + [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/crotg/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/crotg/docs/types/index.d.ts new file mode 100644 index 000000000000..920f6b23a9e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/docs/types/index.d.ts @@ -0,0 +1,103 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex64Array } from '@stdlib/types/array'; + +/** +* Interface describing `crotg`. +*/ +interface Routine { + /** + * Constructs a Givens plane rotation for complex single-precision floating-point numbers. + * + * @param ar - real component of the rotational elimination parameter `a` + * @param ai - imaginary component of the rotational elimination parameter `a` + * @param br - real component of the rotational elimination parameter `b` + * @param bi - imaginary component of the rotational elimination parameter `b` + * @param out - output array + * @param stride - index increment + * @param offset - starting index + * @returns output array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var out = new Complex64Array( 3 ); + * var y = crotg( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); + * // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] + */ + ( ar: number, ai: number, br: number, bi: number, out?: Complex64Array, stride?: number, offset?: number ): Complex64Array; + + /** + * Constructs a Givens plane rotation for complex single-precision floating-point numbers using alternative indexing semantics. + * + * @param ar - real component of the rotational elimination parameter `a` + * @param ai - imaginary component of the rotational elimination parameter `a` + * @param br - real component of the rotational elimination parameter `b` + * @param bi - imaginary component of the rotational elimination parameter `b` + * @param out - output array + * @param stride - index increment + * @param offset - starting index + * @returns output array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var out = new Complex64Array( 3 ); + * var y = crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); + * // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] + */ + ndarray( ar: number, ai: number, br: number, bi: number, out?: Complex64Array, stride?: number, offset?: number ): Complex64Array; +} + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param ar - real component of the rotational elimination parameter `a` +* @param ai - imaginary component of the rotational elimination parameter `a` +* @param br - real component of the rotational elimination parameter `b` +* @param bi - imaginary component of the rotational elimination parameter `b` +* @param out - output array +* @param stride - index increment +* @param offset - starting index +* @returns output array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var out = new Complex64Array( 3 ); +* var y = crotg( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var out = new Complex64Array( 3 ); +* var y = crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ +declare var crotg: Routine; + + +// EXPORTS // + +export = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/crotg/docs/types/test.ts new file mode 100644 index 000000000000..fa59c6da290d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/docs/types/test.ts @@ -0,0 +1,247 @@ +/* +* @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. +*/ + +import Complex64Array = require( '@stdlib/array/complex64' ); +import crotg = require( './index' ); + + +// TESTS // + +// The function returns a Complex64Array... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectType Complex64Array + crotg( 0.0, 0.0, 2.0, 0.0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( '10', 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( true, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( false, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( null, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( undefined, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( [], 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( {}, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( ( x: number ): number => x, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, '10', 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, true, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, false, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, null, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, undefined, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, [], 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, {}, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, ( x: number ): number => x, 2.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, 0.0, '10', 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, true, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, false, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, null, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, undefined, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, [], 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, {}, 0.0, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, ( x: number ): number => x, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, 0.0, 2.0, '10', out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, true, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, false, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, null, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, undefined, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, [], out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, {}, out, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Complex64Array... +{ + crotg( 0.0, 0.0, 2.0, 0.0, '10', 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, true, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, false, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, null, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, [ '1' ], 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, {}, 1, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, 0.0, 2.0, 0.0, out, '10', 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, true, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, false, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, null, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, [], 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, {}, 0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, '10' ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, true ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, false ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, null ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, [] ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, {} ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const out = new Complex64Array( 3 ); + + crotg(); // $ExpectError + crotg( 0.0 ); // $ExpectError + crotg( 0.0, 0.0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0 ); // $ExpectError + crotg( 0.0, 0.0, 2.0, 0.0, out, 1, 0, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex64Array... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectType Complex64Array + crotg.ndarray( 0.0, 0.0, 2.0, 0.0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( '10', 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( true, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( false, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( null, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( undefined, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( [], 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( {}, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( ( x: number ): number => x, 0.0, 2.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, '10', 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, true, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, false, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, null, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, undefined, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, [], 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, {}, 2.0, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, ( x: number ): number => x, 2.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, 0.0, '10', 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, true, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, false, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, null, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, undefined, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, [], 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, {}, 0.0, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, ( x: number ): number => x, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, 0.0, 2.0, '10', out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, true, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, false, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, null, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, undefined, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, [], out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, {}, out, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Complex64Array... +{ + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, '10', 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, true, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, false, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, null, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, [ '1' ], 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, {}, 1, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, '10', 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, true, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, false, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, null, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, [], 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, {}, 0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, '10' ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, true ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, false ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, null ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, [] ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, {} ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const out = new Complex64Array( 3 ); + + crotg.ndarray(); // $ExpectError + crotg.ndarray( 0.0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0 ); // $ExpectError + crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/crotg/examples/c/Makefile new file mode 100644 index 000000000000..24da6aae0c8a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/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 ?= -I ../../include -I ../../../shared/include -I ../../../diagonal-types/include -I ../../../layouts/include -I ../../../matrix-orientations/include -I ../../../matrix-triangles/include -I ../../../operation-sides/include -I ../../../transpose-operations/include + +# List of source files: +SOURCE_FILES ?= ../../src/crotg.c ../../src/crotg_ndarray.c + +# 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/crotg/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/crotg/examples/c/example.c new file mode 100644 index 000000000000..5ce10abb9965 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/examples/c/example.c @@ -0,0 +1,53 @@ +/** +* @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/crotg.h" +#include + +int main( void ) { + float ca[] = { 1.0f, 2.0f }; + float cb[] = { 3.0f, 4.0f }; + float s[] = { 0.0f, 0.0f }; + float c = 0.0f; + + printf( "a: %f + %fj\n", ca[ 0 ], ca[ 1 ] ); + printf( "b: %f + %fj\n", cb[ 0 ], cb[ 1 ] ); + + stdlib_blas_base_crotg( (void *)ca, (void *)cb, &c, (void *)s ); + + printf( "r: %f + %fj\n", ca[ 0 ], ca[ 1 ] ); + printf( "c: %f\n", c ); + printf( "s: %f + %fj\n", s[ 0 ], s[ 1 ] ); + printf( "\n" ); + + // Using ndarray interface: + float ar = 5.0f; + float ai = 6.0f; + float br = 7.0f; + float bi = 8.0f; + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // r_re, r_im, s_re, s_im, c, 0 + + printf( "a: %f + %fj\n", ar, ai ); + printf( "b: %f + %fj\n", br, bi ); + + c_crotg_ndarray( ar, ai, br, bi, (void *)out, 1, 0 ); + + printf( "r: %f + %fj\n", out[ 0 ], out[ 1 ] ); + printf( "s: %f + %fj\n", out[ 2 ], out[ 3 ] ); + printf( "c: %f\n", out[ 4 ] ); +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/examples/index.js b/lib/node_modules/@stdlib/blas/base/crotg/examples/index.js new file mode 100644 index 000000000000..7fe774deca51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/examples/index.js @@ -0,0 +1,50 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var crotg = require( './../lib' ); + +function rand() { + return discreteUniform( -10, 10 ); +} + +var out = new Complex64Array( 3 ); +var ar; +var ai; +var br; +var bi; +var i; + +for ( i = 0; i < 10; i++ ) { + ar = rand(); + ai = rand(); + br = rand(); + bi = rand(); + + crotg( ar, ai, br, bi, out, 1, 0 ); + + console.log( 'a: %d + %dj', ar, ai ); + console.log( 'b: %d + %dj', br, bi ); + console.log( 'r: %s', out.get( 0 ).toString() ); + console.log( 's: %s', out.get( 1 ).toString() ); + console.log( 'c: %d', out.get( 2 ).re ); + console.log( '' ); +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/include.gypi b/lib/node_modules/@stdlib/blas/base/crotg/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + '[ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var out = new Complex64Array( 3 ); +* var y = crotg( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ +function crotg( ar, ai, br, bi, out, stride, offset ) { + var alphaR; + var alphaI; + var norm; + var absA; + var absB; + var view; + var sR; + var sI; + var rR; + var rI; + var c; + + if ( out === void 0 ) { + out = new Complex64Array( 3 ); + stride = 1; + offset = 0; + } + absA = hypot( ar, ai ); + if ( absA === 0.0 ) { + c = 0.0; + sR = 1.0; + sI = 0.0; + rR = br; + rI = bi; + } else { + absB = hypot( br, bi ); + + // Optimization: Use hypot for robust norm calculation + norm = hypot( absA, absB ); + + alphaR = ar / absA; + alphaI = ai / absA; + + c = absA / norm; + + // S = alpha * conj(b) / norm + + // S = (alphaR + i*alphaI) * (br - i*bi) / norm + + // S = ( (alphaR*br + alphaI*bi) + i*(alphaI*br - alphaR*bi) ) / norm + sR = ( (alphaR*br) + (alphaI*bi) ) / norm; + sI = ( (alphaI*br) - (alphaR*bi) ) / norm; + + // R = alpha * norm + rR = alphaR * norm; + rI = alphaI * norm; + } + + view = reinterpret( out, 0 ); + + // R + view[ offset*2 ] = rR; + view[ (offset*2) + 1 ] = rI; + + // S + view[ (offset+stride)*2 ] = sR; + view[ ((offset+stride)*2) + 1 ] = sI; + + // c + view[ (offset+(2*stride))*2 ] = c; + view[ ((offset+(2*stride))*2) + 1 ] = 0.0; + + return out; +} + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/crotg.native.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/crotg.native.js new file mode 100644 index 000000000000..7da8ae20e6d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/crotg.native.js @@ -0,0 +1,67 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param {number} ar - real component of the rotational elimination parameter `a` +* @param {number} ai - imaginary component of the rotational elimination parameter `a` +* @param {number} br - real component of the rotational elimination parameter `b` +* @param {number} bi - imaginary component of the rotational elimination parameter `b` +* @param {Complex64Array} out - output array +* @param {integer} stride - index increment +* @param {NonNegativeInteger} offset - starting index +* @returns {Complex64Array} output array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var out = crotg( 0.0, 0.0, 2.0, 0.0, new Complex64Array( 3 ), 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ +function crotg( ar, ai, br, bi, out, stride, offset ) { + var view; + if ( out === void 0 ) { + out = new Complex64Array( 3 ); + stride = 1; + offset = 0; + } + if ( out instanceof Complex64Array ) { + view = new Float32Array( out.buffer, out.byteOffset, out.length * 2 ); + addon( ar, ai, br, bi, view, stride, offset ); + } else { + addon( ar, ai, br, bi, out, stride, offset ); + } + return out; +} + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/index.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/index.js new file mode 100644 index 000000000000..8f0817408950 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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'; + +/** +* Construct a Givens plane rotation for complex single-precision floating-point numbers. +* +* @module @stdlib/blas/base/crotg +* +* @example +* var crotg = require( '@stdlib/blas/base/crotg' ); +* +* var out = crotg( 0.0, 0.0, 2.0, 0.0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var crotg; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + crotg = main; +} else { + crotg = tmp; +} + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/main.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/main.js new file mode 100644 index 000000000000..882f04ccab7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var crotg = require( './crotg.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param {number} ar - real component of the rotational elimination parameter `a` +* @param {number} ai - imaginary component of the rotational elimination parameter `a` +* @param {number} br - real component of the rotational elimination parameter `b` +* @param {number} bi - imaginary component of the rotational elimination parameter `b` +* @param {Complex64Array} [out] - output array +* @param {integer} [stride] - index increment +* @param {NonNegativeInteger} [offset] - starting index +* @returns {Complex64Array} output array +* +* @example +* var out = crotg( 0.0, 0.0, 2.0, 0.0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ +function main( ar, ai, br, bi, out, stride, offset ) { + return crotg( ar, ai, br, bi, out, stride, offset ); +} + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/native.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/native.js new file mode 100644 index 000000000000..810276ee84bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/native.js @@ -0,0 +1,48 @@ +/** +* @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'; + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @module @stdlib/blas/base/crotg +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var crotg = require( '@stdlib/blas/base/crotg/lib/native.js' ); +* +* var out = crotg( 0.0, 0.0, 2.0, 0.0, new Complex64Array( 3 ), 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var crotg = require( './crotg.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( crotg, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.js new file mode 100644 index 000000000000..463729438f3e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.js @@ -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. +*/ + +'use strict'; + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @module @stdlib/blas/base/crotg/ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var crotg = require( '@stdlib/blas/base/crotg' ); +* +* var out = new Complex64Array( 3 ); +* var y = crotg.ndarray( 0.0, 0.0, 2.0, 0.0, out, 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ + +// MODULES // + +var crotg = require( './crotg.js' ); + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.native.js new file mode 100644 index 000000000000..9da454c6408a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/lib/ndarray.native.js @@ -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. +*/ + +'use strict'; + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @module @stdlib/blas/base/crotg/ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var crotg = require( '@stdlib/blas/base/crotg/lib/ndarray.native.js' ); +* +* var out = crotg( 0.0, 0.0, 2.0, 0.0, new Complex64Array( 3 ), 1, 0 ); +* // returns [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] +*/ + +// MODULES // + +var crotg = require( './crotg.native.js' ); + + +// EXPORTS // + +module.exports = crotg; diff --git a/lib/node_modules/@stdlib/blas/base/crotg/manifest.json b/lib/node_modules/@stdlib/blas/base/crotg/manifest.json new file mode 100644 index 000000000000..e0b9537c3c25 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/manifest.json @@ -0,0 +1,100 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/crotg.c", + "./src/crotg_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/crotg.c", + "./src/crotg_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/crotg.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/blas/base/shared" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/package.json b/lib/node_modules/@stdlib/blas/base/crotg/package.json new file mode 100644 index 000000000000..8a7a50eea39f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/package.json @@ -0,0 +1,100 @@ +{ + "name": "@stdlib/blas/base/crotg", + "version": "0.0.0", + "description": "Construct a Givens plane rotation.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/array/complex64": "^0.0.x", + "@stdlib/array/float32": "^0.0.x", + "@stdlib/complex/float32/ctor": "^0.0.x", + "@stdlib/complex/float32/imag": "^0.0.x", + "@stdlib/complex/float32/real": "^0.0.x", + "@stdlib/math/base/special/abs": "^0.0.x", + "@stdlib/math/base/special/hypot": "^0.0.x", + "@stdlib/math/base/special/sqrt": "^0.0.x", + "@stdlib/types": "^0.0.x", + "@stdlib/utils/library-manifest": "^0.0.x" + }, + "devDependencies": { + "@stdlib/math/base/assert/is-nan": "^0.0.x", + "@stdlib/random/base/uniform": "^0.0.x", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git", + "@stdlib/array/complex64": "^0.0.x", + "@stdlib/bench/harness": "^0.0.x" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "linear", + "algebra", + "subroutines", + "crotg", + "rotation", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex64", + "float", + "float32", + "single", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/Makefile b/lib/node_modules/@stdlib/blas/base/crotg/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/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/crotg/src/addon.c b/lib/node_modules/@stdlib/blas/base/crotg/src/addon.c new file mode 100644 index 000000000000..527f2a549d35 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/addon.c @@ -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. +*/ + +#include "stdlib/blas/base/crotg.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_float.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_complex64array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_FLOAT( env, ar, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, ai, argv, 1 ); + STDLIB_NAPI_ARGV_FLOAT( env, br, argv, 2 ); + STDLIB_NAPI_ARGV_FLOAT( env, bi, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, out, 3, stride, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, offset, argv, 6 ); + + API_SUFFIX(c_crotg_ndarray)( ar, ai, br, bi, (void *)out, stride, offset ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.c b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.c new file mode 100644 index 000000000000..40a07cd19216 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.c @@ -0,0 +1,86 @@ +/** +* @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/crotg.h" +#include + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param ca real and imaginary components of the rotational elimination parameter `a` +* @param cb real and imaginary components of the rotational elimination parameter `b` +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void stdlib_blas_base_crotg( void *ca, const void *cb, float *c, void *s ) { + float *CA = (float *)ca; + float *CB = (float *)cb; + float *S = (float *)s; + float scale; + float norm; + float alphaR; + float alphaI; + float sR; + float sI; + float rR; + float rI; + float absA; + float ar; + float ai; + float br; + float bi; + + ar = CA[ 0 ]; + ai = CA[ 1 ]; + br = CB[ 0 ]; + bi = CB[ 1 ]; + + absA = hypotf( ar, ai ); + if ( absA == 0.0f ) { + *c = 0.0f; + S[ 0 ] = 1.0f; + S[ 1 ] = 0.0f; + CA[ 0 ] = br; + CA[ 1 ] = bi; + } else { + scale = absA + hypotf( br, bi ); + // norm = scale * sqrt( (absA/scale)^2 + (|b|/scale)^2 ) + float sa = absA / scale; + float sb = hypotf( br, bi ) / scale; + norm = scale * sqrtf( (sa*sa) + (sb*sb) ); + + alphaR = ar / absA; + alphaI = ai / absA; + + *c = absA / norm; + + // s = alpha * conj(b) / norm + // s = (alphaR + i*alphaI) * (br - i*bi) / norm + // s = ( (alphaR*br + alphaI*bi) + i*(alphaI*br - alphaR*bi) ) / norm + sR = ( (alphaR*br) + (alphaI*bi) ) / norm; + sI = ( (alphaI*br) - (alphaR*bi) ) / norm; + S[ 0 ] = sR; + S[ 1 ] = sI; + + // r = alpha * norm + rR = alphaR * norm; + rI = alphaI * norm; + CA[ 0 ] = rR; + CA[ 1 ] = rI; + } +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.f b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.f new file mode 100644 index 000000000000..849f4d445a32 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg.f @@ -0,0 +1,55 @@ +!> +! @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 for complex single-precision floating-point numbers. +! +! @param {complex} ca - rotational elimination parameter `a` +! @param {complex} cb - rotational elimination parameter `b` +! @param {real} c - cosine of the angle of rotation +! @param {complex} s - sine of the angle of rotation +subroutine crotg( ca, cb, c, s ) + implicit none + ! .. + ! Scalar arguments: + complex, intent(inout) :: ca + complex, intent(in) :: cb + real, intent(out) :: c + complex, intent(out) :: s + ! .. + ! Local scalars: + real :: norm + real :: scale + complex :: alpha + ! .. + ! Intrinsic functions: + intrinsic cabs, sqrt, conjg, real, aimag + ! .. + if ( cabs(ca) == 0.0 ) then + c = 0.0 + s = ( 1.0, 0.0 ) + ca = cb + else + scale = cabs(ca) + cabs(cb) + norm = scale * sqrt( (cabs(ca/scale))**2 + (cabs(cb/scale))**2 ) + alpha = ca / cabs(ca) + c = cabs(ca) / norm + s = alpha * conjg(cb) / norm + ca = alpha * norm + end if + return +end subroutine crotg diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_cblas.c b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_cblas.c new file mode 100644 index 000000000000..7c2a45649f1b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_cblas.c @@ -0,0 +1,72 @@ +/** +* @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/crotg.h" +#include "stdlib/blas/base/crotg_cblas.h" + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param ca rotational elimination parameter `a` (input/output) +* @param cb rotational elimination parameter `b` (input) +* @param c cosine of the angle of rotation (output) +* @param s sine of the angle of rotation (output) +*/ +void stdlib_blas_base_crotg( void *ca, const void *cb, float *c, void *s ) { + API_SUFFIX(cblas_crotg)( ca, (void *)cb, c, s ); +} + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers using alternative indexing semantics. +* +* @param ar real component of the rotational elimination parameter `a` +* @param ai imaginary component of the rotational elimination parameter `a` +* @param br real component of the rotational elimination parameter `b` +* @param bi imaginary component of the rotational elimination parameter `b` +* @param out output array +* @param stride output array stride +* @param offset output array offset +*/ +void API_SUFFIX(c_crotg_ndarray)( const float ar, const float ai, const float br, const float bi, void *out, const CBLAS_INT stride, const CBLAS_INT offset ) { + float ca[ 2 ]; + float cb[ 2 ]; + float s[ 2 ]; + float c; + float *o = (float *)out; + + ca[ 0 ] = ar; + ca[ 1 ] = ai; + cb[ 0 ] = br; + cb[ 1 ] = bi; + + API_SUFFIX(cblas_crotg)( ca, cb, &c, s ); + + CBLAS_INT so = stride * 2; + CBLAS_INT io = offset * 2; + + o[ io ] = ca[ 0 ]; + o[ io + 1 ] = ca[ 1 ]; + + io += so; + o[ io ] = s[ 0 ]; + o[ io + 1 ] = s[ 1 ]; + + io += so; + o[ io ] = c; + o[ io + 1 ] = 0.0f; +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_f.c b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_f.c new file mode 100644 index 000000000000..0f8405845066 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_f.c @@ -0,0 +1,72 @@ +/** +* @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/crotg.h" +#include "stdlib/blas/base/crotg_fortran.h" + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param ca rotational elimination parameter `a` (input/output) +* @param cb rotational elimination parameter `b` (input) +* @param c cosine of the angle of rotation (output) +* @param s sine of the angle of rotation (output) +*/ +void stdlib_blas_base_crotg( void *ca, const void *cb, float *c, void *s ) { + crotg( ca, (void *)cb, c, s ); +} + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers using alternative indexing semantics. +* +* @param ar real component of the rotational elimination parameter `a` +* @param ai imaginary component of the rotational elimination parameter `a` +* @param br real component of the rotational elimination parameter `b` +* @param bi imaginary component of the rotational elimination parameter `b` +* @param out output array +* @param stride output array stride +* @param offset output array offset +*/ +void API_SUFFIX(c_crotg_ndarray)( const float ar, const float ai, const float br, const float bi, void *out, const CBLAS_INT stride, const CBLAS_INT offset ) { + float ca[ 2 ]; + float cb[ 2 ]; + float s[ 2 ]; + float c; + float *o = (float *)out; + + ca[ 0 ] = ar; + ca[ 1 ] = ai; + cb[ 0 ] = br; + cb[ 1 ] = bi; + + stdlib_blas_base_crotg( (void *)ca, (void *)cb, &c, (void *)s ); + + CBLAS_INT so = stride * 2; + CBLAS_INT io = offset * 2; + + o[ io ] = ca[ 0 ]; + o[ io + 1 ] = ca[ 1 ]; + + io += so; + o[ io ] = s[ 0 ]; + o[ io + 1 ] = s[ 1 ]; + + io += so; + o[ io ] = c; + o[ io + 1 ] = 0.0f; +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_ndarray.c b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_ndarray.c new file mode 100644 index 000000000000..3f73f074a3a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/src/crotg_ndarray.c @@ -0,0 +1,60 @@ +/** +* @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/crotg.h" +#include "stdlib/blas/base/shared.h" + +/** +* Constructs a Givens plane rotation for complex single-precision floating-point numbers. +* +* @param ar real component of the rotational elimination parameter `a` +* @param ai imaginary component of the rotational elimination parameter `a` +* @param br real component of the rotational elimination parameter `b` +* @param bi imaginary component of the rotational elimination parameter `b` +* @param out output array +* @param stride output array stride +* @param offset output array offset +*/ +void API_SUFFIX(c_crotg_ndarray)( const float ar, const float ai, const float br, const float bi, void *out, const CBLAS_INT stride, const CBLAS_INT offset ) { + float ca[ 2 ]; + float cb[ 2 ]; + float s[ 2 ]; + float c; + float *o = (float *)out; + + ca[ 0 ] = ar; + ca[ 1 ] = ai; + cb[ 0 ] = br; + cb[ 1 ] = bi; + + stdlib_blas_base_crotg( (void *)ca, (void *)cb, &c, (void *)s ); + + CBLAS_INT so = stride * 2; + CBLAS_INT io = offset * 2; + + o[ io ] = ca[ 0 ]; + o[ io + 1 ] = ca[ 1 ]; + + io += so; + o[ io ] = s[ 0 ]; + o[ io + 1 ] = s[ 1 ]; + + io += so; + o[ io ] = c; + o[ io + 1 ] = 0.0f; +} diff --git a/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.js b/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.js new file mode 100644 index 000000000000..8032d056957b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.js @@ -0,0 +1,96 @@ +/** +* @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 tape = require( 'tape' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var crotg = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function constructs a Givens plane rotation', function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = crotg( ar, ai, br, bi ); + view = reinterpret( out, 0 ); + + // Check r + t.ok( abs( view[ 0 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 1 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s + t.ok( abs( view[ 2 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 3 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c + t.ok( abs( view[ 4 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); + +tape( 'the function handles the case where |a| is zero', function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 0.0; + ai = 0.0; + br = 3.0; + bi = 4.0; + + out = crotg( ar, ai, br, bi ); + view = reinterpret( out, 0 ); + + // C = 0 + + // S = (1, 0) + + // R = b = (3, 4) + + t.strictEqual( view[ 0 ], 3.0, 'returns expected r_re' ); + t.strictEqual( view[ 1 ], 4.0, 'returns expected r_im' ); + t.strictEqual( view[ 2 ], 1.0, 'returns expected s_re' ); + t.strictEqual( view[ 3 ], 0.0, 'returns expected s_im' ); + t.strictEqual( view[ 4 ], 0.0, 'returns expected c' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.native.js b/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.native.js new file mode 100644 index 000000000000..610cf1142dfa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/test/test.crotg.native.js @@ -0,0 +1,80 @@ +/** +* @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 tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var crotg = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( crotg instanceof Error ) || typeof crotg !== 'function' +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function constructs a Givens plane rotation', opts, function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + if ( opts.skip ) { + return t.end(); + } + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = new Complex64Array( 3 ); + crotg( ar, ai, br, bi, out, 1, 0 ); + view = reinterpret( out, 0 ); + + // Check r + t.ok( abs( view[ 0 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 1 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s + t.ok( abs( view[ 2 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 3 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c + t.ok( abs( view[ 4 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/test/test.js b/lib/node_modules/@stdlib/blas/base/crotg/test/test.js new file mode 100644 index 000000000000..20cc2469c786 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var crotg = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof crotg.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var crotg = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( crotg, mock, 'returns native implementation' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var crotg; + var main; + + main = require( './../lib/main.js' ); + + crotg = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( crotg, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.js new file mode 100644 index 000000000000..58f8b4214270 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.js @@ -0,0 +1,98 @@ +/** +* @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 tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var crotg = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function constructs a Givens plane rotation', function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = new Complex64Array( 3 ); + crotg( ar, ai, br, bi, out, 1, 0 ); + view = reinterpret( out, 0 ); + + // Check r + t.ok( abs( view[ 0 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 1 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s + t.ok( abs( view[ 2 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 3 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c + t.ok( abs( view[ 4 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); + +tape( 'the function supports strides and offsets', function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = new Complex64Array( 6 ); + crotg( ar, ai, br, bi, out, 2, 1 ); + view = reinterpret( out, 0 ); + + // Check r at offset 1 (complex index 1 -> float index 2) + t.ok( abs( view[ 2 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 3 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s at offset 1 + stride 2 = 3 (complex index 3 -> float index 6) + t.ok( abs( view[ 6 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 7 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c at offset 1 + 2*stride 4 = 5 (complex index 5 -> float index 10) + t.ok( abs( view[ 10 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.native.js new file mode 100644 index 000000000000..f04d32ededb8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/crotg/test/test.ndarray.native.js @@ -0,0 +1,106 @@ +/** +* @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 tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var crotg = tryRequire( './../lib/ndarray.native.js' ); +var opts = { + 'skip': ( crotg instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function constructs a Givens plane rotation', opts, function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = new Complex64Array( 3 ); + crotg( ar, ai, br, bi, out, 1, 0 ); + view = reinterpret( out, 0 ); + + // Check r + t.ok( abs( view[ 0 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 1 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s + t.ok( abs( view[ 2 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 3 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c + t.ok( abs( view[ 4 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); + +tape( 'the function supports strides and offsets', opts, function test( t ) { + var view; + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = new Complex64Array( 6 ); + crotg( ar, ai, br, bi, out, 2, 1 ); + view = reinterpret( out, 0 ); + + // Check r at offset 1 (complex index 1 -> float index 2) + t.ok( abs( view[ 2 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( view[ 3 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s at offset 1 + stride 2 = 3 (complex index 3 -> float index 6) + t.ok( abs( view[ 6 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( view[ 7 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c at offset 1 + 2*stride 4 = 5 (complex index 5 -> float index 10) + t.ok( abs( view[ 10 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/README.md b/lib/node_modules/@stdlib/blas/base/wasm/crotg/README.md new file mode 100644 index 000000000000..1ee73b0e5795 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/README.md @@ -0,0 +1,93 @@ + + +# crotg + +> Construct a Givens plane rotation for complex single-precision floating-point numbers via WebAssembly. + +
+ +## Usage + +```javascript +var crotg = require( '@stdlib/blas/base/wasm/crotg' ); +``` + +#### crotg( ar, ai, br, bi ) + +Constructs a Givens plane rotation for complex single-precision floating-point numbers. + +The function returns a `Float32Array` containing the following elements: + +- `out[ 0 ]`: real component of the rotational elimination parameter `r` +- `out[ 1 ]`: imaginary component of the rotational elimination parameter `r` +- `out[ 2 ]`: real component of the rotational elimination parameter `s` +- `out[ 3 ]`: imaginary component of the rotational elimination parameter `s` +- `out[ 4 ]`: cosine of the angle of rotation `c` + +
+ + + +
+ +## Notes + +- `crotg` corresponds to the BLAS level 1 function [`crotg`][crotg]. + +
+ + + +
+ +## Examples + + + +```javascript +var crotg = require( '@stdlib/blas/base/wasm/crotg' ); + +var out = crotg( 1.0, 2.0, 3.0, 4.0 ); +console.log( out ); +// => [ ~2.449, ~4.899, ~0.898, ~0.163, ~0.408 ] +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/binary.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/binary.js new file mode 100644 index 000000000000..6f02393f96e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @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 readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/index.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/index.js new file mode 100644 index 000000000000..4477ddae2bd6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/index.js @@ -0,0 +1,34 @@ +/** +* @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'; + +/** +* Construct a Givens plane rotation for complex single-precision floating-point numbers. +* +* @module @stdlib/blas/base/wasm/crotg +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/main.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/main.js new file mode 100644 index 000000000000..ea1ff5cf9b90 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/main.js @@ -0,0 +1,37 @@ +/** +* @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 Routine = require( './routine.js' ); + + +// MAIN // + +var routine = new Routine(); + +// eslint-disable-next-line node/no-sync +routine.initializeSync(); + + +// EXPORTS // + +// eslint-disable-next-line stdlib/no-dynamic-exports +module.exports = routine.main.bind( routine ); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/module.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/module.js new file mode 100644 index 000000000000..9ee00ab9d8ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/module.js @@ -0,0 +1,83 @@ +/** +* @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 isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Constructs a Givens plane rotation. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {NonNegativeInteger} captr - pointer to `a` (input/output) +* @param {NonNegativeInteger} cbptr - pointer to `b` (input) +* @param {NonNegativeInteger} cptr - pointer to `c` (output) +* @param {NonNegativeInteger} sptr - pointer to `s` (output) +*/ + +// eslint-disable-next-line no-restricted-syntax +setReadOnly( Module.prototype, 'main', function crotg( captr, cbptr, cptr, sptr ) { + // eslint-disable-next-line no-invalid-this + this._instance.exports.stdlib_blas_base_crotg( captr, cbptr, cptr, sptr ); +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/routine.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/routine.js new file mode 100644 index 000000000000..89ea5959c277 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/lib/routine.js @@ -0,0 +1,119 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 1 // 64KiB + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Constructs a Givens plane rotation. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {number} ar - real component of `a` +* @param {number} ai - imaginary component of `a` +* @param {number} br - real component of `b` +* @param {number} bi - imaginary component of `b` +* @returns {Float32Array} output array +*/ + +// eslint-disable-next-line no-restricted-syntax +setReadOnly( Routine.prototype, 'main', function crotg( ar, ai, br, bi ) { + var view; + var out; + + // Offsets in memory (assuming base 0): + + // ca: 0 (2 floats) + + // cb: 8 (2 floats) + + // c: 16 (1 float) + + // s: 20 (2 floats) + + // eslint-disable-next-line no-invalid-this + view = new Float32Array( this.memory.buffer ); + + // Write inputs: + view[ 0 ] = ar; + view[ 1 ] = ai; + view[ 2 ] = br; + view[ 3 ] = bi; + + // Call Wasm function: + + // Pointers are byte offsets. + + // ca: 0 + + // cb: 8 + + // c: 16 + + // s: 20 + + // eslint-disable-next-line no-invalid-this + Module.prototype.main.call( this, 0, 8, 16, 20 ); + + // Read results: + out = new Float32Array( 5 ); + out[ 0 ] = view[ 0 ]; // r_re + out[ 1 ] = view[ 1 ]; // r_im + out[ 2 ] = view[ 5 ]; // s_re (offset 20 bytes = 5 floats) + out[ 3 ] = view[ 6 ]; // s_im + out[ 4 ] = view[ 4 ]; // c (offset 16 bytes = 4 floats) + + return out; +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/manifest.json b/lib/node_modules/@stdlib/blas/base/wasm/crotg/manifest.json new file mode 100644 index 000000000000..7498ff4d20dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/crotg" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/package.json b/lib/node_modules/@stdlib/blas/base/wasm/crotg/package.json new file mode 100644 index 000000000000..d3a6e1a6b5d8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/package.json @@ -0,0 +1,93 @@ +{ + "name": "@stdlib/blas/base/wasm/crotg", + "version": "0.0.0", + "description": "Construct a Givens plane rotation.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/blas/base/crotg": "^0.0.x", + "@stdlib/utils/library-manifest": "^0.0.x", + "@stdlib/wasm/memory": "^0.0.x", + "@stdlib/wasm/module-wrapper": "^0.0.x" + }, + "devDependencies": { + "@stdlib/bench/harness": "^0.0.x", + "@stdlib/random/base/uniform": "^0.0.x", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "linear", + "algebra", + "subroutines", + "crotg", + "rotation", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex64", + "float", + "float32", + "single", + "float32array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/build.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/build.js new file mode 100644 index 000000000000..365c8718d624 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/build.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +/** +* @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 readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); +var currentYear = require( '@stdlib/time/current-year' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; +var YEAR = '{{YEAR}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, YEAR, currentYear().toString() ); + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/template.txt new file mode 100644 index 000000000000..f66cdb9735b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} 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 base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/Makefile b/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/Makefile new file mode 100644 index 000000000000..6431f7f994e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/Makefile @@ -0,0 +1,127 @@ +#/ +# @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 + +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 + +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -flto \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +EMCCFLAGS ?= $(CFLAGS) + +EMCC_SHARED_FLAGS := \ + -fwasm-exceptions \ + -s SUPPORT_LONGJMP=1 \ + -s SIDE_MODULE=2 \ + -s EXPORTED_FUNCTIONS="$(shell cat exports.json | tr -d ' \t\n' | sed s/\"/\'/g)" + +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 \ + -s WASM_BIGINT=0 + +INCLUDE ?= +SOURCE_FILES ?= +LIBRARIES ?= +LIBPATH ?= + +wasm_targets := main.wasm +wat_targets := main.wat +wasm_js_targets := main.wasm.js +browser_js_targets := ./../lib/binary.browser.js + +# RULES # + +all: wasm + +.PHONY: all + +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js $(browser_js_targets) + +.PHONY: clean-wasm + +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/exports.json b/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/exports.json new file mode 100644 index 000000000000..dbf50834942d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/exports.json @@ -0,0 +1,3 @@ +[ + "_stdlib_blas_base_crotg" +] diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/main.wasm b/lib/node_modules/@stdlib/blas/base/wasm/crotg/src/main.wasm new file mode 100644 index 0000000000000000000000000000000000000000..d8fc92d022fbf4d1072da17bc8e0840054b51ddc GIT binary patch literal 8 PcmZQbEY4+QU|;|M2ZjMd literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/wasm/crotg/test/test.js b/lib/node_modules/@stdlib/blas/base/wasm/crotg/test/test.js new file mode 100644 index 000000000000..ecaf9eba34b0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/crotg/test/test.js @@ -0,0 +1,63 @@ +/** +* @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 // + +// eslint-disable-next-line node/no-unpublished-require +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var crotg = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof crotg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function constructs a Givens plane rotation', function test( t ) { + var out; + var ar; + var ai; + var br; + var bi; + + ar = 1.0; + ai = 2.0; + br = 3.0; + bi = 4.0; + + out = crotg( ar, ai, br, bi ); + + // Check r + t.ok( abs( out[ 0 ] - 2.4494897 ) < 1e-5, 'returns expected r_re' ); + t.ok( abs( out[ 1 ] - 4.898979 ) < 1e-5, 'returns expected r_im' ); + + // Check s + t.ok( abs( out[ 2 ] - 0.8981462 ) < 1e-5, 'returns expected s_re' ); + t.ok( abs( out[ 3 ] - 0.1632993 ) < 1e-5, 'returns expected s_im' ); + + // Check c + t.ok( abs( out[ 4 ] - 0.4082483 ) < 1e-5, 'returns expected c' ); + + t.end(); +});