Skip to content

Commit fa8250e

Browse files
aayush0325kgryte
andauthored
feat: add lapack/base/dlapy3
PR-URL: #7144 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 7e4dc08 commit fa8250e

File tree

10 files changed

+699
-0
lines changed

10 files changed

+699
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# dlapy3
22+
23+
> LAPACK routine to calculate `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dlapy3 = require( '@stdlib/lapack/base/dlapy3' );
31+
```
32+
33+
#### dlapy3( x, y, z )
34+
35+
Computes `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow.
36+
37+
```javascript
38+
var out = dlapy3( 3.0, 4.0, 12.0 );
39+
// returns 13.0
40+
```
41+
42+
The function has the following parameters:
43+
44+
- **x**: first input number.
45+
- **y**: second input number.
46+
- **z**: third input number.
47+
48+
</section>
49+
50+
<!-- /.usage -->
51+
52+
<section class="notes">
53+
54+
## Notes
55+
56+
- `dlapy3()` corresponds to the [LAPACK][LAPACK] function [`dlapy3`][lapack-dlapy3].
57+
58+
</section>
59+
60+
<!-- /.notes -->
61+
62+
<section class="examples">
63+
64+
## Examples
65+
66+
<!-- eslint no-undef: "error" -->
67+
68+
```javascript
69+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
70+
var logEachMap = require( '@stdlib/console/log-each-map' );
71+
var dlapy3 = require( '@stdlib/lapack/base/dlapy3' );
72+
73+
var opts = {
74+
'dtype': 'float64'
75+
};
76+
var x = discreteUniform( 100, -50, 50, opts );
77+
var y = discreteUniform( 100, -50, 50, opts );
78+
var z = discreteUniform( 100, -50, 50, opts );
79+
80+
logEachMap( 'dlapy3( %d, %d, %d ) = %0.4f', x, y, z, dlapy3 );
81+
```
82+
83+
</section>
84+
85+
<!-- /.examples -->
86+
87+
<!-- C interface documentation. -->
88+
89+
* * *
90+
91+
<section class="c">
92+
93+
## C APIs
94+
95+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
96+
97+
<section class="intro">
98+
99+
</section>
100+
101+
<!-- /.intro -->
102+
103+
<!-- C usage documentation. -->
104+
105+
<section class="usage">
106+
107+
### Usage
108+
109+
```c
110+
TODO
111+
```
112+
113+
#### TODO
114+
115+
TODO.
116+
117+
```c
118+
TODO
119+
```
120+
121+
TODO
122+
123+
```c
124+
TODO
125+
```
126+
127+
</section>
128+
129+
<!-- /.usage -->
130+
131+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="notes">
134+
135+
</section>
136+
137+
<!-- /.notes -->
138+
139+
<!-- C API usage examples. -->
140+
141+
<section class="examples">
142+
143+
### Examples
144+
145+
```c
146+
TODO
147+
```
148+
149+
</section>
150+
151+
<!-- /.examples -->
152+
153+
</section>
154+
155+
<!-- /.c -->
156+
157+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
158+
159+
<section class="related">
160+
161+
</section>
162+
163+
<!-- /.related -->
164+
165+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
166+
167+
<section class="links">
168+
169+
[lapack]: https://www.netlib.org/lapack/explore-html/
170+
171+
[lapack-dlapy3]: https://netlib.org/lapack/explore-html/d3/dba/group__lapy3_ga7ba5106d26a131c0d1ac7fa7ca3904b7.html
172+
173+
</section>
174+
175+
<!-- /.links -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var pkg = require( './../package.json' ).name;
27+
var dlapy3 = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var len;
34+
var t;
35+
var x;
36+
var y;
37+
var z;
38+
var i;
39+
40+
len = 100;
41+
x = uniform( len, -50, 50 );
42+
y = uniform( len, -50, 50 );
43+
z = uniform( len, -50, 50 );
44+
45+
b.tic();
46+
for ( i = 0; i < b.iterations; i++ ) {
47+
t = dlapy3( x[ i % len ], y[ i % len ], z[ i % len ] );
48+
if ( isnan( t ) ) {
49+
b.fail( 'should not return NaN' );
50+
}
51+
}
52+
b.toc();
53+
if ( isnan( t ) ) {
54+
b.fail( 'should not return NaN' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{{alias}}( x, y, z )
3+
Computes `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause
4+
unnecessary overflow.
5+
6+
Parameters
7+
----------
8+
x: number
9+
First input number.
10+
11+
y: number
12+
Second input number.
13+
14+
z: number
15+
Third input number.
16+
17+
Returns
18+
-------
19+
out: number
20+
Square root of sum of squares.
21+
22+
Examples
23+
--------
24+
> var h = {{alias}}( 3.0, 4.0, 12.0 )
25+
13.0
26+
> h = {{alias}}( -0.0, -0.0, 0.0 )
27+
0.0
28+
29+
See Also
30+
--------
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* LAPACK routine to calculate `sqrt(x^2 + y^2 + z^2)` in a manner which doesn't cause unnecessary overflow.
23+
*
24+
* @param x - first input number
25+
* @param y - second input number
26+
* @param z - third input number
27+
* @returns `sqrt(x^2 + y^2 + z^2)`
28+
*
29+
* @example
30+
* var h = dlapy3( 3.0, 4.0, 12.0 );
31+
* // returns 13.0
32+
*
33+
* @example
34+
* var h = dlapy3( -0.0, -0.0, 0.0 );
35+
* // returns 0.0
36+
*/
37+
declare function dlapy3( x: number, y: number, z: number ): number;
38+
39+
40+
// EXPORTS //
41+
42+
export = dlapy3;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import dlapy3 = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
dlapy3( 8, 2, 10 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided values other than three numbers...
30+
{
31+
dlapy3( true, 3, 1 ); // $ExpectError
32+
dlapy3( false, 2, 1 ); // $ExpectError
33+
dlapy3( '5', 1, 1 ); // $ExpectError
34+
dlapy3( [], 1, 1 ); // $ExpectError
35+
dlapy3( {}, 2, 1 ); // $ExpectError
36+
dlapy3( ( x: number ): number => x, 2, 1 ); // $ExpectError
37+
38+
dlapy3( 9, true, 1 ); // $ExpectError
39+
dlapy3( 9, false, 1 ); // $ExpectError
40+
dlapy3( 5, '5', 1 ); // $ExpectError
41+
dlapy3( 8, [], 1 ); // $ExpectError
42+
dlapy3( 9, {}, 1 ); // $ExpectError
43+
dlapy3( 8, ( x: number ): number => x, 1 ); // $ExpectError
44+
45+
dlapy3( 9, 1, true ); // $ExpectError
46+
dlapy3( 9, 1, false ); // $ExpectError
47+
dlapy3( 5, 1, '5' ); // $ExpectError
48+
dlapy3( 8, 1, [] ); // $ExpectError
49+
dlapy3( 9, 1, {} ); // $ExpectError
50+
dlapy3( 8, 1, ( x: number ): number => x ); // $ExpectError
51+
52+
dlapy3( [], true, void 0 ); // $ExpectError
53+
dlapy3( {}, false, [] ); // $ExpectError
54+
dlapy3( false, '5', {} ); // $ExpectError
55+
dlapy3( {}, [], 'beep' ); // $ExpectError
56+
dlapy3( '5', ( x: number ): number => x, [] ); // $ExpectError
57+
}
58+
59+
// The compiler throws an error if the function is provided insufficient arguments...
60+
{
61+
dlapy3(); // $ExpectError
62+
dlapy3( 3 ); // $ExpectError
63+
dlapy3( 3, 5 ); // $ExpectError
64+
}

0 commit comments

Comments
 (0)