From 5568d7a2a707b00bfe33af4402e6e1c60bc5dae5 Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Thu, 13 Nov 2025 22:11:26 +0530 Subject: [PATCH 1/6] feat: add `math/base/special/fast/alpha-max-plus-beta-minf` --- 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 --- --- .../fast/alpha-max-plus-beta-minf/README.md | 251 ++++++++++ .../benchmark/benchmark.js | 380 ++++++++++++++ .../benchmark/benchmark.native.js | 63 +++ .../benchmark/c/native/Makefile | 146 ++++++ .../benchmark/c/native/benchmark.c | 135 +++++ .../fast/alpha-max-plus-beta-minf/binding.gyp | 170 +++++++ .../alpha-max-plus-beta-minf/docs/repl.txt | 56 +++ .../docs/types/index.d.ts | 89 ++++ .../docs/types/test.ts | 129 +++++ .../examples/c/Makefile | 146 ++++++ .../examples/c/example.c | 31 ++ .../examples/index.js | 31 ++ .../alpha-max-plus-beta-minf/include.gypi | 53 ++ .../special/fast/alpha_max_plus_beta_minf.h | 38 ++ .../lib/closuref1a.js | 68 +++ .../lib/closuref1b.js | 72 +++ .../alpha-max-plus-beta-minf/lib/factory.js | 73 +++ .../alpha-max-plus-beta-minf/lib/hypotf1a.js | 49 ++ .../alpha-max-plus-beta-minf/lib/hypotf1b.js | 53 ++ .../alpha-max-plus-beta-minf/lib/hypotf2a.js | 49 ++ .../alpha-max-plus-beta-minf/lib/hypotf2b.js | 53 ++ .../alpha-max-plus-beta-minf/lib/index.js | 47 ++ .../fast/alpha-max-plus-beta-minf/lib/main.js | 61 +++ .../alpha-max-plus-beta-minf/lib/native.js | 47 ++ .../alpha-max-plus-beta-minf/manifest.json | 78 +++ .../alpha-max-plus-beta-minf/package.json | 78 +++ .../alpha-max-plus-beta-minf/src/Makefile | 70 +++ .../fast/alpha-max-plus-beta-minf/src/addon.c | 22 + .../fast/alpha-max-plus-beta-minf/src/main.c | 49 ++ .../test/test.factory.js | 473 ++++++++++++++++++ .../alpha-max-plus-beta-minf/test/test.js | 71 +++ .../test/test.native.js | 72 +++ 32 files changed, 3203 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/include/stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/factory.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.factory.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md new file mode 100644 index 000000000000..45d67d5587db --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md @@ -0,0 +1,251 @@ + + +# Alpha Max Plus Beta Minf + +> Compute the [hypotenuse][hypotenuse] of a single-precision floating point number using the [alpha max plus beta min algorithm][alpha-max-plus-beta-min]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var ampbmf = require( '@stdlib/math/base/special/fast/alpha-max-plus-beta-minf' ); +``` + +#### ampbmf( x, y ) + +Computes the [hypotenuse][hypotenuse] of a single-precision floating point number using the [alpha max plus beta min algorithm][alpha-max-plus-beta-min]. + +```javascript +var h = ampbmf( -5.0, 12.0 ); +// returns ~13.5 +``` + +#### ampbmf.factory( alpha, beta, \[nonnegative\[, ints]] ) + +Returns a function for computing the [hypotenuse][hypotenuse] using coefficients `alpha` and `beta`. + +```javascript +var hypotf = ampbmf.factory( 1.0, 0.5 ); + +var h = hypotf( -5.0, 12.0 ); +// returns 14.5 +``` + +If the returned function should only expect nonnegative arguments, set the `nonnegative` argument to `true`. + +```javascript +var hypotf = ampbmf.factory( 1.0, 0.5, true ); + +var h = hypotf( 5.0, 12.0 ); +// returns 14.5 +``` + +If the returned function should only expect signed 32-bit integers, set the `ints` argument to `true`. + +```javascript +var hypotf = ampbmf.factory( 1.0, 0.5, false, true ); + +var h = hypotf( -5.0, 12.0 ); +// returns 14 +``` + +If the returned function should only expect unsigned 32-bit integer valued arguments, set the `nonnegative` and `ints` arguments to `true`. + +```javascript +var hypotf = ampbmf.factory( 1.0, 0.5, true, true ); + +var h = hypotf( 5.0, 12.0 ); +// returns 14 +``` + +
+ + + + + +
+ +## Notes + +- The algorithm computes only an **approximation**. For precise results, use [`hypot`][@stdlib/math/base/special/hypot]. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var ampbmf = require( '@stdlib/math/base/special/fast/alpha-max-plus-beta-minf' ); + +var opts = { + 'dtype': 'float32' +}; +var x = discreteUniform( 100, -50, 50, opts ); +var y = discreteUniform( 100, -50, 50, opts ); + +logEachMap( 'hypotf(%d,%d) = %0.4f', x, y, ampbmf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +``` + +#### stdlib_base_fast_ampbmf( x, y ) + +Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. + +```c +float h = stdlib_base_fast_ampbmf( -5.0f, 12.0f ); +// returns ~13.5 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +#include + +int main( void ) { + const float x[] = { 3.0f, 4.0f, 5.0f, 12.0f }; + + float y; + int i; + for ( i = 0; i < 4; i += 2 ) { + y = stdlib_base_fast_ampbmf( x[ i ], x[ i + 1 ] ); + printf( "ampbmf(%d, %d) = %d\n", x[ i ], x[ i + 1 ], y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +## References + +- Lyons, Richard G. 2011. _Understanding Digital Signal Processing, 3rd Edition_. Prentice Hall. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.js new file mode 100644 index 000000000000..0f5cabee06f7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.js @@ -0,0 +1,380 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var ceilf = require( '@stdlib/math/base/special/ceilf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var pkg = require( './../package.json' ).name; +var ampbmf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var h; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 50.0; + y = ( randu()*100.0 ) - 50.0; + h = ampbmf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.5, true, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 0.0; + y = ( randu()*100.0 ) - 0.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=true,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.5, true, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 0; + y = ceilf( randu()*100.0 ) - 0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.5, false, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 50.0; + y = ( randu()*100.0 ) - 50.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.5,nonnegative=false,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.5, false, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 50; + y = ceilf( randu()*100.0 ) - 50; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.25, true, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 0.0; + y = ( randu()*100.0 ) - 0.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=true,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.25, true, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 0; + y = ceilf( randu()*100.0 ) - 0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.25, false, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 50.0; + y = ( randu()*100.0 ) - 50.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=0.25,nonnegative=false,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 0.25, false, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 50; + y = ceilf( randu()*100.0 ) - 50; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 3.0/8.0, true, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 0.0; + y = ( randu()*100.0 ) - 0.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=true,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 3.0/8.0, true, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 0; + y = ceilf( randu()*100.0 ) - 0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=false,ints=false', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 3.0/8.0, false, false ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*100.0 ) - 50.0; + y = ( randu()*100.0 ) - 50.0; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +bench( pkg+':factory:alpha=1.0,beta=3/8,nonnegative=false,ints=true', function benchmark( b ) { + var hypotf; + var x; + var y; + var h; + var i; + + hypotf = ampbmf.factory( 1.0, 3.0/8.0, false, true ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ceilf( randu()*100.0 ) - 50; + y = ceilf( randu()*100.0 ) - 50; + h = hypotf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f8a53d3ae2f4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/benchmark.native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var ampbmf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( ampbmf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var h; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 100.0 ) - 50.0; + y = ( randu() * 100.0 ) - 50.0; + h = ampbmf( f32( x ), f32( y ) ); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( h ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.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/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..c76874c04592 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/benchmark/c/native/benchmark.c @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +#include +#include +#include +#include +#include + +#define NAME "alpha-max-plus-beta-minf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* 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 elapsed elapsed time in seconds +*/ +static void print_results( 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. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + float x; + float y; + float z; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 100.0f * rand_float() ) - 50.0f; + y = ( 100.0f * rand_float() ) - 50.0f; + z = stdlib_base_fast_ampbmf( x, y ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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', + + # 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 + }, # 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/math/base/special/fast/alpha-max-plus-beta-minf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/repl.txt new file mode 100644 index 000000000000..4805dc5bd603 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/repl.txt @@ -0,0 +1,56 @@ + +{{alias}}( x, y ) + Computes the hypotenuse using the alpha max plus beta min algorithm. + + The algorithm computes only an approximation. + + Parameters + ---------- + x: number + First number. + + y: number + Second number. + + Returns + ------- + out: number + Hypotenuse. + + Examples + -------- + > var h = {{alias}}( 5.0, 12.0 ) + ~13.514 + + +{{alias}}.factory( alpha, beta, [nonnegative[, ints]] ) + Returns a function to compute a hypotenuse using the alpha max plus beta min + algorithm. + + Parameters + ---------- + alpha: number + Alpha. + + beta: number + Beta. + + nonnegative: boolean (optional) + Boolean indicating whether input values are always nonnegative. + + ints: boolean (optional) + Boolean indicating whether input values are always 32-bit integers. + + Returns + ------- + fcn: Function + Function to compute a hypotenuse. + + Examples + -------- + > var hypotf = {{alias}}.factory( 1.0, 0.5 ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/index.d.ts new file mode 100644 index 000000000000..a5104963112f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/index.d.ts @@ -0,0 +1,89 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +* +* @param x - number +* @param y - number +* @returns hypotenuse +*/ +type HypotFunctionF32 = ( x: number, y: number ) => number; + +/** +* Interface for computing the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +*/ +interface HypotF32 { + /** + * Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. + * + * @param x - number + * @param y - number + * @returns hypotenuse + * + * @example + * var h = hypotf( -5.0, 12.0 ); + * // returns ~13.5 + */ + ( x: number, y: number ): number; + + /** + * Returns a function to compute a hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. + * + * @param alpha - alpha + * @param beta - beta + * @param nonnegative - boolean indicating whether input values are always nonnegative + * @param ints - boolean indicating whether input values are always 32-bit integers + * @returns function to compute a hypotenuse of a single-precision floating point number + * + * @example + * var fcn = hypotf.factory( 1.0, 0.5 ); + * // returns + * + * var h = fcn( -5.0, 12.0 ); + * // returns 14.5 + */ + factory( alpha: number, beta: number, nonnegative?: boolean, ints?: boolean ): HypotFunctionF32; +} + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +* +* @param x - number +* @param y - number +* @returns hypotenuse +* +* @example +* var h = hypotf( -5.0, 12.0 ); +* // returns ~13.5 +* +* @example +* var fcn = hypotf.factory( 1.0, 0.5 ); +* // returns +* +* var h = fcn( -5.0, 12.0 ); +* // returns 14.5 +*/ +declare var hypotf: HypotF32; + + +// EXPORTS // + +export = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/test.ts new file mode 100644 index 000000000000..51f6ab9fe161 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/docs/types/test.ts @@ -0,0 +1,129 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import ampbmf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + ampbmf( 2, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + ampbmf( true, 3 ); // $ExpectError + ampbmf( false, 2 ); // $ExpectError + ampbmf( '5', 1 ); // $ExpectError + ampbmf( [], 1 ); // $ExpectError + ampbmf( {}, 2 ); // $ExpectError + ampbmf( ( x: number ): number => x, 2 ); // $ExpectError + + ampbmf( 9, true ); // $ExpectError + ampbmf( 9, false ); // $ExpectError + ampbmf( 5, '5' ); // $ExpectError + ampbmf( 8, [] ); // $ExpectError + ampbmf( 9, {} ); // $ExpectError + ampbmf( 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + ampbmf(); // $ExpectError + ampbmf( 2 ); // $ExpectError + ampbmf( 2, 3, 4 ); // $ExpectError + ampbmf( 2, 3, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + ampbmf.factory( 1.0, 0.5 ); // $ExpectType HypotFunctionF32 + ampbmf.factory( 1.0, 0.5, true ); // $ExpectType HypotFunctionF32 + ampbmf.factory( 1.0, 0.5, true, false ); // $ExpectType HypotFunctionF32 +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = ampbmf.factory( 1.0, 0.5 ); + fcn( 2, 3 ); // $ExpectType number +} + +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... +{ + const fcn = ampbmf.factory( 3, 4 ); + fcn( true ); // $ExpectError + fcn( false ); // $ExpectError + fcn( '5' ); // $ExpectError + fcn( [] ); // $ExpectError + fcn( {} ); // $ExpectError + fcn( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const fcn = ampbmf.factory( 3, 4 ); + fcn(); // $ExpectError + fcn( 2 ); // $ExpectError + fcn( 2, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a first argument that is not a number... +{ + ampbmf.factory( true, 3 ); // $ExpectError + ampbmf.factory( false, 2 ); // $ExpectError + ampbmf.factory( '5', 1 ); // $ExpectError + ampbmf.factory( [], 1 ); // $ExpectError + ampbmf.factory( {}, 2 ); // $ExpectError + ampbmf.factory( ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a second argument that is not a number... +{ + ampbmf.factory( 9, true ); // $ExpectError + ampbmf.factory( 9, false ); // $ExpectError + ampbmf.factory( 5, '5' ); // $ExpectError + ampbmf.factory( 8, [] ); // $ExpectError + ampbmf.factory( 9, {} ); // $ExpectError + ampbmf.factory( 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a third argument that is not a boolean... +{ + ampbmf.factory( 3, 9, 123 ); // $ExpectError + ampbmf.factory( 3, 5, '5' ); // $ExpectError + ampbmf.factory( 3, 8, [] ); // $ExpectError + ampbmf.factory( 3, 9, {} ); // $ExpectError + ampbmf.factory( 3, 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a fourth argument that is not a boolean... +{ + ampbmf.factory( 3, 9, true, 123 ); // $ExpectError + ampbmf.factory( 3, 5, true, '5' ); // $ExpectError + ampbmf.factory( 3, 8, true, [] ); // $ExpectError + ampbmf.factory( 3, 9, true, {} ); // $ExpectError + ampbmf.factory( 3, 8, true, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + ampbmf.factory(); // $ExpectError + ampbmf.factory( 0 ); // $ExpectError + ampbmf.factory( 0, 4, false, true, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c new file mode 100644 index 000000000000..81b8c0e5047b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +#include + +int main( void ) { + const float x[] = { 3.0f, 4.0f, 5.0f, 12.0f }; + + float y; + int i; + for ( i = 0; i < 4; i += 2 ) { + y = stdlib_base_fast_ampbmf( x[ i ], x[ i + 1 ] ); + printf( "ampbmf(%d, %d) = %d\n", x[ i ], x[ i + 1 ], y ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js new file mode 100644 index 000000000000..61ae13af977d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var ampbmf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; +var x = discreteUniform( 100, -50, 50, opts ); +var y = discreteUniform( 100, -50, 50, opts ); + +logEachMap( 'hypotf(%d,%d) = %0.4f', x, y, ampbmf ); diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/include.gypi b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +*/ +function wrapf( alpha, beta ) { + alpha = f32( alpha ); + beta = f32( beta ); + + return hypotf; + + /** + * Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. + * + * @private + * @param {NonNegativeNumber} x - number + * @param {NonNegativeNumber} y - number + * @returns {number} hypotenuse + * + * @example + * var h = hypotf( 5.0, 12.0 ); + * // returns + */ + function hypotf( x, y ) { + x = f32( x ); + y = f32( y ); + if ( x > y ) { + return f32( ( f32( alpha*x ) ) + f32( ( beta*y ) ) ); + } + return f32( ( f32( beta*x ) ) + f32( ( alpha*y ) ) ); + } +} + + +// EXPORTS // + +module.exports = wrapf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js new file mode 100644 index 000000000000..7daa02c02223 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var absf = require( '@stdlib/math/base/special/fast/absf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Returns a function to compute the hypotenuse using the alpha max plus beta min algorithm. +* +* @private +* @param {number} alpha - alpha +* @param {number} beta - beta +* @returns {Function} function to compute the hypotenuse +* +* @example +* var fcn = wrapf( 1.0, 0.5 ); +* // returns +*/ +function wrapf( alpha, beta ) { + alpha = f32( alpha ); + beta = f32( beta ); + + return hypotf; + + /** + * Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. + * + * @private + * @param {number} x - number + * @param {number} y - number + * @returns {number} hypotenuse + * + * @example + * var h = hypotf( 5.0, 12.0 ); + * // returns + */ + function hypotf( x, y ) { + x = absf( x ); + y = absf( y ); + if ( x > y ) { + return f32( ( f32( alpha*x ) ) + ( f32( beta*y ) ) ); + } + return f32( ( f32( beta*x ) ) + ( f32( alpha*y ) ) ); + } +} + + +// EXPORTS // + +module.exports = wrapf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/factory.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/factory.js new file mode 100644 index 000000000000..0765dc0229fd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/factory.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var hypotf1a = require( './hypotf1a.js' ); +var hypotf1b = require( './hypotf1b.js' ); +var hypotf2a = require( './hypotf2a.js' ); +var hypotf2b = require( './hypotf2b.js' ); +var closuref1a = require( './closuref1a.js' ); +var closuref1b = require( './closuref1b.js' ); + + +// MAIN // + +/** +* Returns a function to compute a hypotenuse using the alpha max plus beta min algorithm. +* +* @param {number} alpha - alpha +* @param {number} beta - beta +* @param {boolean} [nonnegative] - boolean indicating whether input values are always nonnegative +* @param {boolean} [ints] - boolean indicating whether input values are always 32-bit integers +* @returns {Function} function to compute a hypotenuse +* +* @example +* var hypotf = factory( 1.0, 0.5 ); +* // returns +*/ +function factory( alpha, beta, nonnegative, ints ) { + alpha = f32( alpha ); + beta = f32( beta ); + if ( ints ) { + if ( alpha === 1.0 && beta === 0.5 ) { + if ( nonnegative ) { + return hypotf1a; + } + return hypotf1b; + } + if ( alpha === 1.0 && beta === 0.25 ) { + if ( nonnegative ) { + return hypotf2a; + } + return hypotf2b; + } + } + if ( nonnegative ) { + return closuref1a( alpha, beta ); + } + return closuref1b( alpha, beta ); +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js new file mode 100644 index 000000000000..44ee34cdcc08 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm, where `alpha = 1` and `beta = 1/2`. +* +* @private +* @param {uinteger32} x - integer +* @param {uinteger32} y - integer +* @returns {number} hypotenuse +* +* @example +* var h = hypotf( 5.0, 12.0 ); +* // returns +*/ +function hypotf( x, y ) { + x = f32( x ); + y = f32( y ); + if ( x > y ) { + return f32( x + f32( y>>>1 ) ); + } + return f32( f32( x>>>1 ) + y ); +} + + +// EXPORTS // + +module.exports = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js new file mode 100644 index 000000000000..c5c8f1ef7b51 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var abs = require( '@stdlib/math/base/special/labs' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm, where `alpha = 1` and `beta = 1/2`. +* +* @private +* @param {integer32} x - integer +* @param {integer32} y - integer +* @returns {number} hypotenuse +* +* @example +* var h = hypotf( 5.0, 12.0 ); +* // returns +*/ +function hypotf( x, y ) { + x = f32( abs( x ) ); + y = f32( abs( y ) ); + if ( x > y ) { + return f32( x + f32( y>>>1 ) ); + } + return f32( f32( x>>>1 ) + y ); +} + + +// EXPORTS // + +module.exports = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js new file mode 100644 index 000000000000..80e31b727e3b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm, where `alpha = 1` and `beta = 1/4`. +* +* @private +* @param {uinteger32} x - integer +* @param {uinteger32} y - integer +* @returns {number} hypotenuse +* +* @example +* var h = hypotf( 5.0, 12.0 ); +* // returns +*/ +function hypotf( x, y ) { + x = f32( x ); + y = f32( y ); + if ( x > y ) { + return f32( x + f32( y>>>2 ) ); + } + return f32( f32( x>>>2 ) + y ); +} + + +// EXPORTS // + +module.exports = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js new file mode 100644 index 000000000000..1933e7ea9e0d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var abs = require( '@stdlib/math/base/special/labs' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm, where `alpha = 1` and `beta = 1/4`. +* +* @private +* @param {integer32} x - integer +* @param {integer32} y - integer +* @returns {number} hypotenuse +* +* @example +* var h = hypotf( 5.0, 12.0 ); +* // returns +*/ +function hypotf( x, y ) { + x = f32( abs( x ) ); + y = f32( abs( y ) ); + if ( x > y ) { + return f32( x + f32( y>>>2 ) ); + } + return f32( f32( x>>>2 ) + y ); +} + + +// EXPORTS // + +module.exports = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/index.js new file mode 100644 index 000000000000..8055f9869532 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the hypotenuse of a single-precision floating point number. +* +* @module @stdlib/math/base/special/fast/alpha-max-plus-beta-minf +* +* @example +* var hypotf = require( '@stdlib/math/base/special/fast/alpha-max-plus-beta-minf' ); +* +* var h = hypotf( 5.0, 12.0 ); +* // returns ~13.5 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/main.js new file mode 100644 index 000000000000..6c1ebc7a4bd9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/main.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var absf = require( '@stdlib/math/base/special/fast/absf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// VARIABLES // + +// 2*cos(pi/8)/(1+cos(pi/8)): +var ALPHA = f32( 0.96043387010342 ); + +// 2*sin(pi/8)/(1+cos(pi/8)): +var BETA = f32( 0.397824734759316 ); + + +// MAIN // + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +* +* @param {number} x - number +* @param {number} y - number +* @returns {number} hypotenuse +* +* @example +* var h = hypotf( -5.0, 12.0 ); +* // returns ~13.5 +*/ +function hypotf( x, y ) { + x = absf( x ); + y = absf( y ); + if ( x > y ) { + return f32( f32( ALPHA*x ) + f32( BETA*y ) ); + } + return f32( f32( ALPHA*y ) + f32( BETA*x ) ); +} + + +// EXPORTS // + +module.exports = hypotf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/native.js new file mode 100644 index 000000000000..566ac5753bc6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/native.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +* +* @private +* @param {number} x - number +* @param {number} y - number +* @returns {number} hypotenuse +* +* @example +* var h = ampbmf( -5.0, 12.0 ); +* // returns ~13.5 +*/ +function ampbmf( x, y ) { + return addon( x, y ); +} + + +// EXPORTS // + +module.exports = ampbmf; diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/manifest.json b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/manifest.json new file mode 100644 index 000000000000..af2433d30dd2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/manifest.json @@ -0,0 +1,78 @@ +{ + "options": { + "task": "build" + }, + "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", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/special/fast/absf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/fast/absf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/fast/absf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/package.json b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/package.json new file mode 100644 index 000000000000..677b8ffd5fd8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/package.json @@ -0,0 +1,78 @@ +{ + "name": "@stdlib/math/base/special/fast/alpha-max-plus-beta-minf", + "version": "0.0.0", + "description": "Compute the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm.", + "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", + "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": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdfastmath", + "math", + "mathematics", + "fastmath", + "fast", + "euclid", + "euclidean", + "hypotenuse", + "geometry", + "hypotf", + "triangle", + "pythagoras", + "pythagorean theorem", + "trigonometry", + "trig", + "alpha max plus beta minf", + "approximation", + "approx", + "single-precision", + "float", + "single" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# 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/math/base/special/fast/alpha-max-plus-beta-minf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/addon.c new file mode 100644 index 000000000000..17c4b2feebae --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_FF_F( stdlib_base_fast_ampbmf ) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/main.c new file mode 100644 index 000000000000..a882dc10267a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/src/main.c @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/fast/alpha_max_plus_beta_minf.h" +#include "stdlib/math/base/special/fast/absf.h" + +// 2*cos(pi/8)/(1+cos(pi/8)): +static const float ALPHA = 0.96043387010342f; + +// 2*sin(pi/8)/(1+cos(pi/8)): +static const float BETA = 0.397824734759316f; + +/** +* Computes the hypotenuse of a single-precision floating point number using the alpha max plus beta min algorithm. +* +* @param x number +* @param y number +* @return hypotenuse +* +* @example +* float h = stdlib_base_fast_ampbmf( -5.0f, 12.0f ); +* // returns ~13.5 +*/ +float stdlib_base_fast_ampbmf( const float x, const float y ) { + float ax; + float ay; + + ay = stdlib_base_fast_absf( y ); + ax = stdlib_base_fast_absf( x ); + if( ax > ay ) { + return ( ALPHA * ax ) + ( BETA * ay ); + } + return ( ALPHA * ay ) + ( BETA * ax ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.factory.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.factory.js new file mode 100644 index 000000000000..9137c3e6c49e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.factory.js @@ -0,0 +1,473 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var randu = require( '@stdlib/random/base/randu' ).factory; +var absf = require( '@stdlib/math/base/special/absf' ); +var roundn = require( '@stdlib/math/base/special/roundn' ); +var hypotf = require( '@stdlib/math/base/special/hypotf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var factory = require( './../lib' ).factory; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var approx = factory( 1.0, 0.5 ); + t.strictEqual( typeof approx, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/2)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.5 ); + tol = 0.1180; + + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/2, always nonnegative)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.5, true ); + tol = 0.1180; + + for ( i = 0; i < 500; i++ ) { + x = rand()*100.0; + y = rand()*100.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/2, always integers)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.5, false, true ); + tol = 0.30; // mainly due to |x| = |y| = 1 + + for ( i = 0; i < 500; i++ ) { + x = roundn( rand()*100.0, 0 ) - 50.0; + y = roundn( rand()*100.0, 0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/2, always nonnegative integers)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.5, true, true ); + tol = 0.30; // mainly due to |x| = |y| = 1 + + for ( i = 0; i < 500; i++ ) { + x = roundn( rand()*100.0, 0 ); + y = roundn( rand()*100.0, 0 ); + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/4)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.25 ); + tol = 0.1161; + + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/4, always nonnegative)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.25, true ); + tol = 0.1161; + + for ( i = 0; i < 500; i++ ) { + x = rand()*100.0; + y = rand()*100.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/4, always integers)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.25, false, true ); + tol = 0.30; // mainly due to |x| = |y| = 1 + + for ( i = 0; i < 500; i++ ) { + x = roundn( rand()*100.0, 0 ) - 50.0; + y = roundn( rand()*100.0, 0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 1/4, always nonnegative integers)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 0.25, true, true ); + tol = 0.30; // mainly due to |x| = |y| = 1 + + for ( i = 0; i < 500; i++ ) { + x = roundn( rand()*100.0, 0 ); + y = roundn( rand()*100.0, 0 ); + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 3/8)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 3.0/8.0 ); + tol = 0.0680; + + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 3/8, always positive)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 3.0/8.0, true ); + tol = 0.0680; + + for ( i = 0; i < 500; i++ ) { + x = rand()*100.0; + y = rand()*100.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 1, beta = 3/8, always nonnegative)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 1.0, 3.0/8.0, true ); + tol = 0.0680; + + for ( i = 0; i < 500; i++ ) { + x = rand()*100.0; + y = rand()*100.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 7/8, beta = 7/16)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 7.0/8.0, 7.0/16.0 ); + tol = 0.1250; + + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the returned function computes the hypotenuse using the alpha max plus beta min algorithm (alpha = 15/16, beta = 15/32)', function test( t ) { + var expected; + var approx; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + approx = factory( 15.0/16.0, 15.0/32.0 ); + tol = 0.0625; + + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + err = roundn( err, -4 ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.js new file mode 100644 index 000000000000..effe53c96ea7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var randu = require( '@stdlib/random/base/randu' ).factory; +var absf = require( '@stdlib/math/base/special/absf' ); +var hypotf = require( '@stdlib/math/base/special/hypotf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var approx = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof approx, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method', function test( t ) { + t.strictEqual( typeof approx.factory, 'function', 'has factory method' ); + t.end(); +}); + +tape( 'the function computes the hypotenuse using the alpha max plus beta min algorithm', function test( t ) { + var expected; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + tol = 0.0396; + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.native.js new file mode 100644 index 000000000000..1f685e60e7a3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/test/test.native.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var randu = require( '@stdlib/random/base/randu' ).factory; +var absf = require( '@stdlib/math/base/special/absf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var hypotf = require( '@stdlib/math/base/special/hypotf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + +var approx = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( approx instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof approx, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the hypotenuse using the alpha max plus beta min algorithm', opts, function test( t ) { + var expected; + var rand; + var err; + var tol; + var h; + var x; + var y; + var i; + + rand = randu(); + t.ok( true, 'seed: '+rand.seed ); + + tol = 0.0396; + for ( i = 0; i < 500; i++ ) { + x = ( rand()*100.0 ) - 50.0; + y = ( rand()*100.0 ) - 50.0; + expected = hypotf( f32( x ), f32( y ) ); + h = approx( f32( x ), f32( y ) ); + if ( h === expected ) { + t.ok( true, 'x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'.' ); + } else { + err = absf( h - expected ) / absf( expected ); + t.strictEqual( err <= tol, true, 'within tolerance. x: '+x+'. y: '+y+'. h: '+h+'. Expected: '+expected+'. Error: '+err+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); From 44257d7569771fa48da1a2e3a00b45037abe169b Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Thu, 13 Nov 2025 23:01:17 +0530 Subject: [PATCH 2/6] chore: fix lint error --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../math/base/special/fast/alpha-max-plus-beta-minf/README.md | 4 ++-- .../fast/alpha-max-plus-beta-minf/examples/c/example.c | 2 +- .../special/fast/alpha-max-plus-beta-minf/examples/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md index 45d67d5587db..d8bcccf17cf0 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/README.md @@ -122,7 +122,7 @@ var opts = { var x = discreteUniform( 100, -50, 50, opts ); var y = discreteUniform( 100, -50, 50, opts ); -logEachMap( 'hypotf(%d,%d) = %0.4f', x, y, ampbmf ); +logEachMap( 'hypotf(%f,%f) = %0.4f', x, y, ampbmf ); ``` @@ -193,7 +193,7 @@ int main( void ) { int i; for ( i = 0; i < 4; i += 2 ) { y = stdlib_base_fast_ampbmf( x[ i ], x[ i + 1 ] ); - printf( "ampbmf(%d, %d) = %d\n", x[ i ], x[ i + 1 ], y ); + printf( "ampbmf(%f, %f) = %f\n", x[ i ], x[ i + 1 ], y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c index 81b8c0e5047b..437b5312d7c6 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/c/example.c @@ -26,6 +26,6 @@ int main( void ) { int i; for ( i = 0; i < 4; i += 2 ) { y = stdlib_base_fast_ampbmf( x[ i ], x[ i + 1 ] ); - printf( "ampbmf(%d, %d) = %d\n", x[ i ], x[ i + 1 ], y ); + printf( "ampbmf(%f, %f) = %f\n", x[ i ], x[ i + 1 ], y ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js index 61ae13af977d..384056437ad8 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/examples/index.js @@ -28,4 +28,4 @@ var opts = { var x = discreteUniform( 100, -50, 50, opts ); var y = discreteUniform( 100, -50, 50, opts ); -logEachMap( 'hypotf(%d,%d) = %0.4f', x, y, ampbmf ); +logEachMap( 'hypotf(%f,%f) = %0.4f', x, y, ampbmf ); From 673fdd3be7f2525e0aabb5ed2560dccfe7c2af4f Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 13 Nov 2025 20:31:51 -0800 Subject: [PATCH 3/6] style: remove unnecessary parentheses Signed-off-by: Athan --- .../special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js index 5e62798342a4..43a632d11b8b 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js @@ -58,7 +58,7 @@ function wrapf( alpha, beta ) { if ( x > y ) { return f32( ( f32( alpha*x ) ) + f32( ( beta*y ) ) ); } - return f32( ( f32( beta*x ) ) + f32( ( alpha*y ) ) ); + return f32( f32( beta*x ) + f32( alpha*y ) ); } } From da79f09206ce54eb289a46b97b00a3116cd46fdb Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 13 Nov 2025 20:32:08 -0800 Subject: [PATCH 4/6] style: remove unnecessary parentheses Signed-off-by: Athan --- .../special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js index 43a632d11b8b..42cfec4a6183 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1a.js @@ -56,7 +56,7 @@ function wrapf( alpha, beta ) { x = f32( x ); y = f32( y ); if ( x > y ) { - return f32( ( f32( alpha*x ) ) + f32( ( beta*y ) ) ); + return f32( f32( alpha*x ) + f32( beta*y ) ); } return f32( f32( beta*x ) + f32( alpha*y ) ); } From 65c272b4d338aa7bc36bb73206cb075548dea05a Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 13 Nov 2025 20:33:02 -0800 Subject: [PATCH 5/6] style: remove unnecessary parentheses Signed-off-by: Athan --- .../special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js index 7daa02c02223..d26505041048 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/closuref1b.js @@ -60,9 +60,9 @@ function wrapf( alpha, beta ) { x = absf( x ); y = absf( y ); if ( x > y ) { - return f32( ( f32( alpha*x ) ) + ( f32( beta*y ) ) ); + return f32( f32( alpha*x ) + f32( beta*y ) ); } - return f32( ( f32( beta*x ) ) + ( f32( alpha*y ) ) ); + return f32( f32( beta*x ) + f32( alpha*y ) ); } } From f8b44186a0958ef0bb027c32552224c36e703b9d Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Fri, 14 Nov 2025 11:07:25 +0530 Subject: [PATCH 6/6] chore: update according to code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js | 6 ++---- .../special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js | 8 ++++---- .../special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js | 6 ++---- .../special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js | 8 ++++---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js index 44ee34cdcc08..ae40f57ae463 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1a.js @@ -35,12 +35,10 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns */ function hypotf( x, y ) { - x = f32( x ); - y = f32( y ); if ( x > y ) { - return f32( x + f32( y>>>1 ) ); + return f32( x + ( y>>>1 ) ); } - return f32( f32( x>>>1 ) + y ); + return f32( ( x>>>1 ) + y ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js index c5c8f1ef7b51..cdce8c1c0518 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf1b.js @@ -39,12 +39,12 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns */ function hypotf( x, y ) { - x = f32( abs( x ) ); - y = f32( abs( y ) ); + x = abs( x ); + y = abs( y ); if ( x > y ) { - return f32( x + f32( y>>>1 ) ); + return f32( x + ( y>>>1 ) ); } - return f32( f32( x>>>1 ) + y ); + return f32( ( x>>>1 ) + y ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js index 80e31b727e3b..e9120feff826 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2a.js @@ -35,12 +35,10 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns */ function hypotf( x, y ) { - x = f32( x ); - y = f32( y ); if ( x > y ) { - return f32( x + f32( y>>>2 ) ); + return f32( x + ( y>>>2 ) ); } - return f32( f32( x>>>2 ) + y ); + return f32( ( x>>>2 ) + y ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js index 1933e7ea9e0d..b01c174ef7f1 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-minf/lib/hypotf2b.js @@ -39,12 +39,12 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns */ function hypotf( x, y ) { - x = f32( abs( x ) ); - y = f32( abs( y ) ); + x = abs( x ); + y = abs( y ); if ( x > y ) { - return f32( x + f32( y>>>2 ) ); + return f32( x + ( y>>>2 ) ); } - return f32( f32( x>>>2 ) + y ); + return f32( ( x>>>2 ) + y ); }