Skip to content

Commit 0f663c1

Browse files
committed
feat: add blas/base/zrotg
--- 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: 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: passed - task: lint_license_headers status: passed ---
1 parent c82ae2b commit 0f663c1

File tree

10 files changed

+769
-0
lines changed

10 files changed

+769
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
# zrotg
22+
23+
> Constructs 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 single-precision floating-point values `a` and `b`.
36+
37+
```javascript
38+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
39+
40+
var za = new Complex128( 4.0, 3.0 );
41+
// returns <Complex128>
42+
43+
var zb = new Complex128( 0.0, 0.0 );
44+
// returns <Complex128>
45+
46+
var out = zrotg( za, zb );
47+
// out => <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
48+
```
49+
50+
The function has the following parameters:
51+
52+
- **za**: rotational elimination parameter.
53+
- **za**: rotational elimination parameter.
54+
55+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
56+
57+
<!-- eslint-disable stdlib/capitalized-comments -->
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<section class="notes">
64+
65+
## Notes
66+
67+
- `zrotg()` corresponds to the [BLAS][blas] level 1 function [`zrotg`][zrotg].
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<section class="examples">
74+
75+
## Examples
76+
77+
<!-- eslint no-undef: "error" -->
78+
79+
```javascript
80+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
81+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
82+
var zrotg = require( '@stdlib/blas/base/zrotg' );
83+
84+
var out;
85+
var i;
86+
87+
function rand() {
88+
return new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
89+
}
90+
91+
for ( i = 0; i < 100; i++ ) {
92+
out = zrotg( rand(), rand() );
93+
console.log( out );
94+
}
95+
```
96+
97+
</section>
98+
99+
<!-- /.examples -->
100+
101+
<!-- C interface documentation. -->
102+
103+
* * *
104+
105+
<section class="c">
106+
107+
## C APIs
108+
109+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
110+
111+
<section class="intro">
112+
113+
</section>
114+
115+
<!-- /.intro -->
116+
117+
<!-- C usage documentation. -->
118+
119+
<section class="usage">
120+
121+
### Usage
122+
123+
```c
124+
TODO
125+
```
126+
127+
#### TODO
128+
129+
TODO.
130+
131+
```c
132+
TODO
133+
```
134+
135+
TODO
136+
137+
```c
138+
TODO
139+
```
140+
141+
</section>
142+
143+
<!-- /.usage -->
144+
145+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
146+
147+
<section class="notes">
148+
149+
</section>
150+
151+
<!-- /.notes -->
152+
153+
<!-- C API usage examples. -->
154+
155+
<section class="examples">
156+
157+
### Examples
158+
159+
```c
160+
TODO
161+
```
162+
163+
</section>
164+
165+
<!-- /.examples -->
166+
167+
</section>
168+
169+
<!-- /.c -->
170+
171+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
172+
173+
<section class="related">
174+
175+
</section>
176+
177+
<!-- /.related -->
178+
179+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
180+
181+
<section class="links">
182+
183+
[blas]: http://www.netlib.org/blas
184+
185+
[zrotg]: https://www.netlib.org/lapack/explore-html/d7/dc5/group__rotg_ga97ce56a6808661b36ab62269393ac10e.html
186+
187+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
188+
189+
</section>
190+
191+
<!-- /.links -->
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 pkg = require( './../package.json' ).name;
28+
var zrotg = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var za;
35+
var zb;
36+
var z;
37+
var i;
38+
39+
za = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
40+
zb = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
z = zrotg( za, zb );
45+
if ( isnan( z[ i%4 ] ) ) {
46+
b.fail( 'should not return NaN' );
47+
}
48+
}
49+
b.toc();
50+
if ( isnan( z[ i%4 ] ) ) {
51+
b.fail( 'should not return NaN' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{alias}}( za, zb )
3+
Constructs a Givens plane rotation from two double-precision complex
4+
floating-point numbers.
5+
6+
Parameters
7+
----------
8+
za: Complex128
9+
Rotational elimination parameter.
10+
11+
zb: Complex128
12+
Rotational elimination parameter.
13+
14+
Returns
15+
-------
16+
out: Float64Array
17+
Computed values.
18+
19+
Examples
20+
--------
21+
// Standard usage:
22+
> var za = new {{alias:@stdlib/complex/float64/ctor}}( 4.0, 3.0 );
23+
> var zb = new {{alias:@stdlib/complex/float64/ctor}}( 0.0, 0.0 );
24+
> var out = {{alias}}( za, zb )
25+
out => <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
26+
27+
See Also
28+
--------
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { Complex128 } from '@stdlib/types/complex';
24+
25+
/**
26+
* Constructs a Givens plane rotation.
27+
*
28+
* @param za - rotational elimination parameter
29+
* @param zb - rotational elimination parameter
30+
* @returns output array
31+
*
32+
* @example
33+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
34+
*
35+
* var za = new Complex128( 4.0, 3.0 );
36+
* var zb = new Complex128( 0.0, 0.0 );
37+
*
38+
* var out = zrotg( za, zb );
39+
* // returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
40+
*
41+
* @example
42+
* var za = new Complex128( 1.0, 2.0 );
43+
* var zb = new Complex128( 3.0, 4.0 );
44+
*
45+
* var out = zrotg( za, zb );
46+
* // returns <Float64Array>[ ~1.732, ~5.1961, ~0.5773, ~0.8082, ~0.1154 ]
47+
*/
48+
declare function zrotg( za: Complex128, zb: Complex128 ): Float64Array;
49+
50+
51+
// EXPORTS //
52+
53+
export = zrotg;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 Complex128 = require( '@stdlib/complex/float64/ctor' );
20+
import zrotg = require( './index' );
21+
22+
23+
// TESTS //
24+
25+
// The function returns a Float64Array...
26+
{
27+
const za = new Complex128( 1.0, 1.0 );
28+
const zb = new Complex128( 2.0, 2.0 );
29+
30+
zrotg( za, zb ); // $ExpectType Float64Array
31+
}
32+
33+
// The compiler throws an error if the function is provided an argument which is not a number...
34+
{
35+
const za = new Complex128( 1.0, 1.0 );
36+
const zb = new Complex128( 2.0, 2.0 );
37+
38+
zrotg( true, zb ); // $ExpectError
39+
zrotg( false, zb ); // $ExpectError
40+
zrotg( null, zb ); // $ExpectError
41+
zrotg( undefined, zb ); // $ExpectError
42+
zrotg( '5', zb ); // $ExpectError
43+
zrotg( [], zb ); // $ExpectError
44+
zrotg( {}, zb ); // $ExpectError
45+
46+
zrotg( za, true ); // $ExpectError
47+
zrotg( za, false ); // $ExpectError
48+
zrotg( za, null ); // $ExpectError
49+
zrotg( za, undefined ); // $ExpectError
50+
zrotg( za, '5' ); // $ExpectError
51+
zrotg( za, [] ); // $ExpectError
52+
zrotg( za, {} ); // $ExpectError
53+
}
54+
55+
// The compiler throws an error if the function is provided an unsupported number of arguments...
56+
{
57+
const za = new Complex128( 1.0, 1.0 );
58+
const zb = new Complex128( 2.0, 2.0 );
59+
60+
zrotg(); // $ExpectError
61+
zrotg( za ); // $ExpectError
62+
zrotg( za, zb, 3.0 ); // $ExpectError
63+
}

0 commit comments

Comments
 (0)