Skip to content

Commit 40f34ac

Browse files
feat: add package
--- 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 ---
1 parent e5f0fb5 commit 40f34ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4730
-0
lines changed
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# zrotg
22+
23+
> Construct a Givens plane rotation.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zrotg = require( '@stdlib/blas/base/zrotg' );
31+
```
32+
33+
#### zrotg( za, zb )
34+
35+
Constructs a Givens plane rotation provided two double-precision complex floating-point values `za` and `zb`.
36+
37+
```javascript
38+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
39+
40+
var za = new Complex128( 4.0, 3.0 );
41+
var zb = new Complex128( 0.0, 0.0 );
42+
43+
var out = zrotg( za, zb );
44+
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **za**: rotational elimination parameter (complex number).
50+
- **zb**: rotational elimination parameter (complex number).
51+
52+
The function returns an array with the following elements:
53+
54+
- **r**: real part of the rotated vector (real number).
55+
- **r_imag**: imaginary part of the rotated vector (real number).
56+
- **c**: cosine of the rotation angle (real number).
57+
- **s**: real part of the sine of the rotation angle (real number).
58+
- **s_imag**: imaginary part of the sine of the rotation angle (real number).
59+
60+
#### zrotg.assign( za, zb, out, stride, offset )
61+
62+
Constructs a Givens plane rotation provided two double-precision complex floating-point values `za` and `zb` and assigns results to an output array.
63+
64+
```javascript
65+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
68+
var za = new Complex128( 4.0, 3.0 );
69+
var zb = new Complex128( 0.0, 0.0 );
70+
71+
var out = new Float64Array( 5 );
72+
73+
var y = zrotg.assign( za, zb, out, 1, 0 );
74+
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
75+
76+
var bool = ( y === out );
77+
// returns true
78+
```
79+
80+
</section>
81+
82+
<!-- /.usage -->
83+
84+
<section class="notes">
85+
86+
## Notes
87+
88+
- `zrotg()` corresponds to the [BLAS][blas] level 1 function [`zrotg`][blas-zrotg].
89+
90+
</section>
91+
92+
<!-- /.notes -->
93+
94+
<section class="examples">
95+
96+
## Examples
97+
98+
```javascript
99+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
100+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
101+
var zrotg = require( '@stdlib/blas/base/zrotg' );
102+
103+
var out;
104+
var i;
105+
106+
function rand() {
107+
return new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
108+
}
109+
110+
for ( i = 0; i < 100; i++ ) {
111+
out = zrotg( rand(), rand() );
112+
console.log( out );
113+
}
114+
```
115+
116+
</section>
117+
118+
<!-- /.examples -->
119+
120+
<!-- C interface documentation. -->
121+
122+
* * *
123+
124+
<section class="c">
125+
126+
## C APIs
127+
128+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
129+
130+
<section class="intro">
131+
132+
</section>
133+
134+
<!-- /.intro -->
135+
136+
<!-- C usage documentation. -->
137+
138+
<section class="usage">
139+
140+
### Usage
141+
142+
```c
143+
#include "stdlib/blas/base/zrotg.h"
144+
```
145+
146+
#### c_zrotg( a, b, \*Out, strideOut )
147+
148+
Constructs a Givens plane rotation provided two double-precision complex floating-point values `a` and `b`.
149+
150+
```c
151+
#include "stdlib/complex/float64/ctor.h"
152+
153+
double Out[ 5 ];
154+
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
155+
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );
156+
157+
c_zrotg( a, b, Out, 1 );
158+
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]
159+
```
160+
161+
The function accepts the following arguments:
162+
163+
- **a**: `[in] stdlib_complex128_t` rotational elimination parameter.
164+
- **b**: `[in] stdlib_complex128_t` rotational elimination parameter.
165+
- **Out**: `[out] double*` output array.
166+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
167+
168+
```c
169+
void c_zrotg( const stdlib_complex128_t a, const stdlib_complex128_t b, double *Out, const CBLAS_INT strideOut );
170+
```
171+
172+
#### c_zrotg_assign( a, b, \*Out, strideOut, offsetOut )
173+
174+
Constructs a Givens plane rotation provided two double-precision complex floating-point values `a` and `b` using alternative indexing semantics.
175+
176+
```c
177+
#include "stdlib/complex/float64/ctor.h"
178+
179+
double Out[ 5 ];
180+
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
181+
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );
182+
183+
c_zrotg_assign( a, b, Out, 1, 0 );
184+
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]
185+
```
186+
187+
The function accepts the following arguments:
188+
189+
- **a**: `[in] stdlib_complex128_t` rotational elimination parameter.
190+
- **b**: `[in] stdlib_complex128_t` rotational elimination parameter.
191+
- **Out**: `[out] double*` output array.
192+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
193+
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
194+
195+
```c
196+
void c_zrotg_assign( const stdlib_complex128_t a, const stdlib_complex128_t b, double *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
197+
```
198+
199+
</section>
200+
201+
<!-- /.usage -->
202+
203+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
204+
205+
<section class="notes">
206+
207+
</section>
208+
209+
<!-- /.notes -->
210+
211+
<!-- C API usage examples. -->
212+
213+
<section class="examples">
214+
215+
### Examples
216+
217+
```c
218+
#include "stdlib/blas/base/zrotg.h"
219+
#include "stdlib/complex/float64/ctor.h"
220+
#include <stdio.h>
221+
222+
int main( void ) {
223+
// Specify rotational elimination parameters:
224+
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
225+
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );
226+
int i;
227+
228+
// Create output array:
229+
double Out[ 5 ];
230+
231+
// Specify stride length:
232+
const int strideOut = 1;
233+
234+
// Apply plane rotation:
235+
c_zrotg( a, b, Out, strideOut );
236+
237+
// Print the result:
238+
for ( i = 0; i < 5; i++ ) {
239+
printf( "Out[%d] = %lf\n", i, Out[ i ] );
240+
}
241+
242+
// Apply plane rotation using alternative indexing semantics:
243+
c_zrotg_assign( a, b, Out, strideOut, 0 );
244+
245+
// Print the result:
246+
for ( i = 0; i < 5; i++ ) {
247+
printf( "Out[%d] = %lf\n", i, Out[ i ] );
248+
}
249+
}
250+
```
251+
252+
</section>
253+
254+
<!-- /.examples -->
255+
256+
</section>
257+
258+
<!-- /.c -->
259+
260+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
261+
262+
<section class="related">
263+
264+
</section>
265+
266+
<!-- /.related -->
267+
268+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
269+
270+
<section class="links">
271+
272+
[blas]: http://www.netlib.org/blas
273+
274+
[blas-zrotg]: https://www.netlib.org/lapack/explore-html/d7/dc5/group__rotg_ga97ce56a6808661b36ab62269393ac10e.html
275+
276+
</section>
277+
278+
<!-- /.links -->
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var zrotg = require( './../lib/assign.js' );
30+
31+
32+
// MAIN //
33+
34+
bench( pkg, function benchmark( b ) {
35+
var za;
36+
var zb;
37+
var z;
38+
var i;
39+
40+
za = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
41+
zb = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
z = zrotg( za, zb, new Float64Array(5), 1, 0 );
46+
if ( isnan( z[ i%4 ] ) ) {
47+
b.fail( 'should not return NaN' );
48+
}
49+
}
50+
b.toc();
51+
if ( isnan( z[ i%4 ] ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});

0 commit comments

Comments
 (0)