diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/README.md b/lib/node_modules/@stdlib/lapack/base/dlapy3/README.md new file mode 100644 index 000000000000..8348d403836f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/README.md @@ -0,0 +1,175 @@ + + +# dlapy3 + +> LAPACK routine to calculate `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow. + +
+ +## Usage + +```javascript +var dlapy3 = require( '@stdlib/lapack/base/dlapy3' ); +``` + +#### dlapy3( x, y, z ) + +Computes `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow. + +```javascript +var out = dlapy3( 3.0, 4.0, 12.0 ); +// returns 13.0 +``` + +The function has the following parameters: + +- **x**: first input number. +- **y**: second input number. +- **z**: third input number. + +
+ + + +
+ +## Notes + +- `dlapy3()` corresponds to the [LAPACK][LAPACK] function [`dlapy3`][lapack-dlapy3]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var dlapy3 = require( '@stdlib/lapack/base/dlapy3' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 100, -50, 50, opts ); +var y = discreteUniform( 100, -50, 50, opts ); +var z = discreteUniform( 100, -50, 50, opts ); + +logEachMap( 'dlapy3( %d, %d, %d ) = %0.4f', x, y, z, dlapy3 ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlapy3/benchmark/benchmark.js new file mode 100644 index 000000000000..b1540f81c9e6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pkg = require( './../package.json' ).name; +var dlapy3 = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var len; + var t; + var x; + var y; + var z; + var i; + + len = 100; + x = uniform( len, -50, 50 ); + y = uniform( len, -50, 50 ); + z = uniform( len, -50, 50 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + t = dlapy3( x[ i % len ], y[ i % len ], z[ i % len ] ); + if ( isnan( t ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( t ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/repl.txt new file mode 100644 index 000000000000..891ae73c847b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( x, y, z ) + Computes `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause + unnecessary overflow. + + Parameters + ---------- + x: number + First input number. + + y: number + Second input number. + + z: number + Third input number. + + Returns + ------- + out: number + Square root of sum of squares. + + Examples + -------- + > var h = {{alias}}( 3.0, 4.0, 12.0 ) + 13.0 + > h = {{alias}}( -0.0, -0.0, 0.0 ) + 0.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/index.d.ts new file mode 100644 index 000000000000..df29afac6093 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @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 + +/** +* LAPACK routine to calculate `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow. +* +* @param x - first input number +* @param y - second input number +* @param z - third input number +* @returns `sqrt(x^2 + y^2 + z^2)` +* +* @example +* var h = dlapy3( 3.0, 4.0, 12.0 ); +* // returns 13.0 +* +* @example +* var h = dlapy3( -0.0, -0.0, 0.0 ); +* // returns 0.0 +*/ +declare function dlapy3( x: number, y: number, z: number ): number; + + +// EXPORTS // + +export = dlapy3; diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/test.ts new file mode 100644 index 000000000000..be1d768cc47b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/docs/types/test.ts @@ -0,0 +1,64 @@ +/* +* @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 dlapy3 = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + dlapy3( 8, 2, 10 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + dlapy3( true, 3, 1 ); // $ExpectError + dlapy3( false, 2, 1 ); // $ExpectError + dlapy3( '5', 1, 1 ); // $ExpectError + dlapy3( [], 1, 1 ); // $ExpectError + dlapy3( {}, 2, 1 ); // $ExpectError + dlapy3( ( x: number ): number => x, 2, 1 ); // $ExpectError + + dlapy3( 9, true, 1 ); // $ExpectError + dlapy3( 9, false, 1 ); // $ExpectError + dlapy3( 5, '5', 1 ); // $ExpectError + dlapy3( 8, [], 1 ); // $ExpectError + dlapy3( 9, {}, 1 ); // $ExpectError + dlapy3( 8, ( x: number ): number => x, 1 ); // $ExpectError + + dlapy3( 9, 1, true ); // $ExpectError + dlapy3( 9, 1, false ); // $ExpectError + dlapy3( 5, 1, '5' ); // $ExpectError + dlapy3( 8, 1, [] ); // $ExpectError + dlapy3( 9, 1, {} ); // $ExpectError + dlapy3( 8, 1, ( x: number ): number => x ); // $ExpectError + + dlapy3( [], true, void 0 ); // $ExpectError + dlapy3( {}, false, [] ); // $ExpectError + dlapy3( false, '5', {} ); // $ExpectError + dlapy3( {}, [], 'beep' ); // $ExpectError + dlapy3( '5', ( x: number ): number => x, [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + dlapy3(); // $ExpectError + dlapy3( 3 ); // $ExpectError + dlapy3( 3, 5 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlapy3/examples/index.js new file mode 100644 index 000000000000..9db81db83ecc --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 dlapy3 = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 100, -50, 50, opts ); +var y = discreteUniform( 100, -50, 50, opts ); +var z = discreteUniform( 100, -50, 50, opts ); + +logEachMap( 'dlapy3( %d, %d, %d ) = %0.4f', x, y, z, dlapy3 ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/index.js new file mode 100644 index 000000000000..39d1f9d75cc9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/index.js @@ -0,0 +1,40 @@ +/** +* @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'; + +/** +* LAPACK routine to calculate `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow. +* +* @module @stdlib/lapack/base/dlapy3 +* +* @example +* var dlapy3 = require( '@stdlib/lapack/base/dlapy3' ); +* +* var out = dlapy3( 3.0, 4.0, 12.0 ); +* // returns 13.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/main.js new file mode 100644 index 000000000000..40c9c76d5ff0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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/abs' ); +var dlamch = require( '@stdlib/lapack/base/dlamch' ); +var max = require( '@stdlib/math/base/special/maxn' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var abs2 = require( '@stdlib/math/base/special/abs2' ); + + +// MAIN // + +/** +* Computes `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow. +* +* @param {number} x - first input number +* @param {number} y - second input number +* @param {number} z - third input number +* @returns {number} `sqrt(x^2 + y^2 + z^2)` +* +* @example +* var out = dlapy3( 3.0, 4.0, 12.0 ); +* // returns 13.0 +*/ +function dlapy3( x, y, z ) { + var hugeval; + var xabs; + var yabs; + var zabs; + var w; + + hugeval = dlamch( 'O' ); + xabs = abs( x ); + yabs = abs( y ); + zabs = abs( z ); + + w = max( xabs, yabs, zabs ); + + if ( w === 0.0 || w > hugeval ) { + return xabs + yabs + zabs; + } + return w * sqrt( abs2( xabs / w ) + abs2( yabs / w ) + abs2( zabs / w ) ); +} + + +// EXPORTS // + +module.exports = dlapy3; diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/package.json b/lib/node_modules/@stdlib/lapack/base/dlapy3/package.json new file mode 100644 index 000000000000..3e103f68ca3e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dlapy3", + "version": "0.0.0", + "description": "LAPACK routine to calculate sqrt(x^2 + y^2 + z^2) in a manner which doesn't cause unnecessary overflow.", + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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", + "stdmath", + "mathematics", + "math", + "lapack", + "dlapy3", + "copy", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "matrix", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlapy3/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlapy3/test/test.js new file mode 100644 index 000000000000..aea63ecd5d2f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlapy3/test/test.js @@ -0,0 +1,122 @@ +/** +* @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 PINF = require( '@stdlib/constants/float64/pinf' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var dlapy3 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlapy3, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `+0` if all arguments are `+-0`', function test( t ) { + var h; + + h = dlapy3( +0.0, +0.0, +0.0 ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); + + h = dlapy3( -0.0, +0.0, -0.0 ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); + + h = dlapy3( +0.0, -0.0, 0.0 ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); + + h = dlapy3( -0.0, -0.0, -0.0 ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if one or more arguments is `NaN`', function test( t ) { + var h; + + h = dlapy3( NaN, 0.0, 0.0 ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( 0.0, NaN, 0.0 ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( 0.0, 0.0, NaN ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( NaN, NaN, 0.0 ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( NaN, 0.0, NaN ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( 0.0, NaN, NaN ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + h = dlapy3( NaN, NaN, NaN ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Euclidian norm', function test( t ) { + var h; + + h = dlapy3( 1234.0, 7863.0, 1298.0 ); + t.strictEqual( h, 8064.3864614736813, 'returns expected value' ); + + h = dlapy3( 7.0, 9.0, 12.0 ); + t.strictEqual( h, 16.552945357246848, 'returns expected value' ); + + h = dlapy3( 3.0, 4.0, 12.0 ); + t.strictEqual( h, 13.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function avoids overflow', function test( t ) { + var h; + + h = sqrt( pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = dlapy3( 1.0e308, 1.0e308, 1.0e308 ); + t.strictEqual( h, 1.7320508075688772e+308, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function avoids underflow', function test( t ) { + var h; + + h = sqrt( pow( 1.0e-200, 2 ) + pow( 1e-200, 2 ) + pow( 1e-200, 2 ) ); + t.strictEqual( h, 0.0, 'returns expected value' ); + + h = dlapy3( 1.0e-200, 1.0e-200, 1.0e-200 ); + t.strictEqual( h, 1.7320508075688772e-200, 'returns expected value' ); + + t.end(); +});