Skip to content

Commit adef3c5

Browse files
aayush0325kgryte
andauthored
feat: add lapack/base/dladiv
PR-URL: #7916 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent aab41ab commit adef3c5

31 files changed

+2764
-0
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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+
# dladiv
22+
23+
> Divide two double-precision complex floating-point numbers in real arithmetic.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dladiv = require( '@stdlib/lapack/base/dladiv' );
31+
```
32+
33+
#### dladiv( a, b, c, d, P, Q )
34+
35+
Divides two double-precision complex floating-point numbers in real arithmetic.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var P = new Float64Array( 1 );
41+
var Q = new Float64Array( 1 );
42+
43+
dladiv( -13.0, -1.0, -2.0, 1.0, P, Q );
44+
// P => <Float64Array>[ 5.0 ]
45+
// Q => <Float64Array>[ 3.0 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **a**: real component of numerator.
51+
- **b**: imaginary component of numerator.
52+
- **c**: real component of denominator.
53+
- **d**: imaginary component of denominator.
54+
- **P**: [`Float64Array`][mdn-float64array] containing a single element which is overwritten by the real part of the quotient.
55+
- **Q**: [`Float64Array`][mdn-float64array] containing a single element which is overwritten by the imaginary part of the quotient.
56+
57+
#### dladiv.ndarray( a, b, c, d, P, offsetP, Q, offsetQ )
58+
59+
Divides two double-precision complex floating-point numbers in real arithmetic using alternative indexing semantics.
60+
61+
```javascript
62+
var Float64Array = require( '@stdlib/array/float64' );
63+
64+
var P = new Float64Array( 1 );
65+
var Q = new Float64Array( 1 );
66+
67+
dladiv.ndarray( -13.0, -1.0, -2.0, 1.0, P, 0, Q, 0 );
68+
// P => <Float64Array>[ 5.0 ]
69+
// Q => <Float64Array>[ 3.0 ]
70+
```
71+
72+
The function has the following parameters:
73+
74+
- **a**: real component of numerator.
75+
- **b**: imaginary component of numerator.
76+
- **c**: real component of denominator.
77+
- **d**: imaginary component of denominator.
78+
- **P**: [`Float64Array`][mdn-float64array] containing an element which is overwritten by the real part of the quotient.
79+
- **offsetP**: index of the element in `P`.
80+
- **Q**: [`Float64Array`][mdn-float64array] containing an element which is overwritten by the imaginary part of the quotient.
81+
- **offsetQ**: index of the element in `Q`.
82+
83+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,
84+
85+
```javascript
86+
var Float64Array = require( '@stdlib/array/float64' );
87+
88+
var P = new Float64Array( [ 0.0, 0.0, 0.0 ] );
89+
var Q = new Float64Array( [ 0.0, 0.0, 0.0 ] );
90+
91+
dladiv.ndarray( 2.0, 1.0, 3.0, 4.0, P, 1, Q, 2 );
92+
// P => <Float64Array>[ 0.0, 0.4, 0.0 ]
93+
// Q => <Float64Array>[ 0.0, 0.0, -0.2 ]
94+
```
95+
96+
</section>
97+
98+
<!-- /.usage -->
99+
100+
<section class="notes">
101+
102+
## Notes
103+
104+
- `dladiv()` corresponds to the [LAPACK][LAPACK] function [`dladiv`][lapack-dladiv].
105+
106+
</section>
107+
108+
<!-- /.notes -->
109+
110+
<section class="examples">
111+
112+
## Examples
113+
114+
<!-- eslint no-undef: "error" -->
115+
116+
```javascript
117+
var Float64Array = require( '@stdlib/array/float64' );
118+
var dladiv = require( '@stdlib/lapack/base/dladiv' );
119+
120+
var P = new Float64Array( 1 );
121+
var Q = new Float64Array( 1 );
122+
dladiv( 2.0, 1.0, 3.0, 4.0, P, Q );
123+
console.log( '(2+i)/(3+4i) =', P[ 0 ], '+', Q[ 0 ], 'i' );
124+
```
125+
126+
</section>
127+
128+
<!-- /.examples -->
129+
130+
<!-- C interface documentation. -->
131+
132+
* * *
133+
134+
<section class="c">
135+
136+
## C APIs
137+
138+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
139+
140+
<section class="intro">
141+
142+
</section>
143+
144+
<!-- /.intro -->
145+
146+
<!-- C usage documentation. -->
147+
148+
<section class="usage">
149+
150+
### Usage
151+
152+
```c
153+
TODO
154+
```
155+
156+
#### TODO
157+
158+
TODO.
159+
160+
```c
161+
TODO
162+
```
163+
164+
TODO
165+
166+
```c
167+
TODO
168+
```
169+
170+
</section>
171+
172+
<!-- /.usage -->
173+
174+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
175+
176+
<section class="notes">
177+
178+
</section>
179+
180+
<!-- /.notes -->
181+
182+
<!-- C API usage examples. -->
183+
184+
<section class="examples">
185+
186+
### Examples
187+
188+
```c
189+
TODO
190+
```
191+
192+
</section>
193+
194+
<!-- /.examples -->
195+
196+
</section>
197+
198+
<!-- /.c -->
199+
200+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
201+
202+
<section class="related">
203+
204+
</section>
205+
206+
<!-- /.related -->
207+
208+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
209+
210+
<section class="links">
211+
212+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
213+
214+
[lapack-dladiv]: https://www.netlib.org/lapack/explore-html/d5/db7/group__ladiv_gacbc97eb1922a833ffe257e1731bb0aaa.html
215+
216+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
217+
218+
[lapack]: https://www.netlib.org/lapack/explore-html/
219+
220+
</section>
221+
222+
<!-- /.links -->
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var dladiv = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg, function benchmark( b ) {
41+
var re;
42+
var im;
43+
var N;
44+
var P;
45+
var Q;
46+
var i;
47+
var j;
48+
var k;
49+
50+
N = 100;
51+
re = uniform( N, -500.0, 500.0, options );
52+
im = uniform( N, -500.0, 500.0, options );
53+
54+
P = new Float64Array( 1 );
55+
Q = new Float64Array( 1 );
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
j = i % N;
60+
k = ( i+1 ) % N;
61+
dladiv( re[ j ], im[ j ], re[ k ], im[ k ], P, Q );
62+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
}
66+
b.toc();
67+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var dladiv = require( './../lib/ndarray.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg+':ndarray', function benchmark( b ) {
41+
var re;
42+
var im;
43+
var N;
44+
var P;
45+
var Q;
46+
var i;
47+
var j;
48+
var k;
49+
50+
N = 100;
51+
re = uniform( N, -500.0, 500.0, options );
52+
im = uniform( N, -500.0, 500.0, options );
53+
54+
P = new Float64Array( 1 );
55+
Q = new Float64Array( 1 );
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
j = i % N;
60+
k = ( i+1 ) % N;
61+
dladiv( re[ j ], im[ j ], re[ k ], im[ k ], P, 0, Q, 0 );
62+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
}
66+
b.toc();
67+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});

0 commit comments

Comments
 (0)