Skip to content

Commit 2928651

Browse files
feat: add lapack/base/dlartgp
--- 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 040d8ec commit 2928651

File tree

16 files changed

+1412
-0
lines changed

16 files changed

+1412
-0
lines changed
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
# dlartgp
22+
23+
> Generates a plane rotation so that the diagonal is nonnegative.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dlartgp = require( '@stdlib/lapack/base/dlartgp' );
31+
```
32+
33+
#### dlartgp( F, G, out )
34+
35+
Generates a plane rotation so that the diagonal is nonnegative.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var out = new Float64Array( 3 );
41+
dlartgp( 1.0, 2.0, out );
42+
// out => <Float64Array>[ ~0.447, ~0.894, ~2.236 ]
43+
```
44+
45+
The function has the following parameters:
46+
47+
- **F**: the first component of vector to be rotated.
48+
- **G**: the second component of vector to be rotated.
49+
- **out**: output [`Float64Array`][mdn-float64array] output array containing the cosine and sine of the rotation and the non zero component of the rotated vector.
50+
51+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
52+
53+
<!-- eslint-disable stdlib/capitalized-comments -->
54+
55+
```javascript
56+
var Float64Array = require( '@stdlib/array/float64' );
57+
58+
// Initial array:
59+
var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] );
60+
61+
// Create an offset view...
62+
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
63+
64+
dlartgp( 1.0, 2.0, out1 );
65+
// out0 => <Float64Array>[ 0.0, ~0.447, ~0.894, ~2.236 ]
66+
```
67+
68+
#### dlartgp.ndarray( F, G, out, strideOut, offsetOut )
69+
70+
Generates a plane rotation so that the diagonal is nonnegative using alternative indexing semantics.
71+
72+
```javascript
73+
var Float64Array = require( '@stdlib/array/float64' );
74+
75+
var out = new Float64Array( 3 );
76+
dlartgp.ndarray( 1.0, 2.0, out, 1, 0 );
77+
// out => <Float64Array>[ ~0.447, ~0.894, ~2.236 ]
78+
```
79+
80+
The function has the following additional parameters:
81+
82+
- **strideOut**: stride length for `out`.
83+
- **offsetOut**: starting index of `out`
84+
85+
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,
86+
87+
```javascript
88+
var Float64Array = require( '@stdlib/array/float64' );
89+
90+
var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] );
91+
dlartgp.ndarray( 1.0, 2.0, out, -1, 3 );
92+
// out => <Float64Array>[ 0.0, ~2.236, ~0.894, ~0.447 ]
93+
```
94+
95+
</section>
96+
97+
<!-- /.usage -->
98+
99+
<section class="notes">
100+
101+
## Notes
102+
103+
- `dlartgp()` corresponds to the [LAPACK][lapack] routine [`dlartgp`][lapack-dlartgp].
104+
105+
</section>
106+
107+
<!-- /.notes -->
108+
109+
<section class="examples">
110+
111+
## Examples
112+
113+
<!-- eslint no-undef: "error" -->
114+
115+
```javascript
116+
var Float64Array = require( '@stdlib/array/float64' );
117+
var dlartgp = require( '@stdlib/lapack/base/dlartgp' );
118+
119+
var out = new Float64Array( 3 );
120+
dlartgp( 1.0, 2.0, out );
121+
console.log( out );
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- C interface documentation. -->
129+
130+
* * *
131+
132+
<section class="c">
133+
134+
## C APIs
135+
136+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
137+
138+
<section class="intro">
139+
140+
</section>
141+
142+
<!-- /.intro -->
143+
144+
<!-- C usage documentation. -->
145+
146+
<section class="usage">
147+
148+
### Usage
149+
150+
```c
151+
TODO
152+
```
153+
154+
#### TODO
155+
156+
TODO.
157+
158+
```c
159+
TODO
160+
```
161+
162+
TODO
163+
164+
```c
165+
TODO
166+
```
167+
168+
</section>
169+
170+
<!-- /.usage -->
171+
172+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
173+
174+
<section class="notes">
175+
176+
</section>
177+
178+
<!-- /.notes -->
179+
180+
<!-- C API usage examples. -->
181+
182+
<section class="examples">
183+
184+
### Examples
185+
186+
```c
187+
TODO
188+
```
189+
190+
</section>
191+
192+
<!-- /.examples -->
193+
194+
</section>
195+
196+
<!-- /.c -->
197+
198+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
199+
200+
<section class="related">
201+
202+
</section>
203+
204+
<!-- /.related -->
205+
206+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
207+
208+
<section class="links">
209+
210+
[lapack]: https://www.netlib.org/lapack/explore-html/
211+
212+
[lapack-dlartgp]: https://www.netlib.org/lapack/explore-html/d6/db2/group__lartgp_gaf4d25f845ad7e0a3c474b3ebe45e7223.html#gaf4d25f845ad7e0a3c474b3ebe45e7223
213+
214+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
215+
216+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
217+
218+
</section>
219+
220+
<!-- /.links -->
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 Float64Array = require( '@stdlib/array/float64' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var dlartgp = require( './../lib/dlartgp.js' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var out;
35+
var A;
36+
var B;
37+
var i;
38+
39+
b.tic();
40+
A = ( randu() * 100.0 ) - 50.0;
41+
B = ( randu() * 100.0 ) - 50.0;
42+
out = new Float64Array( 3 );
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
out = dlartgp( A, B, out );
45+
A = out[ i%out.length ];
46+
B = out[ i%out.length ];
47+
if ( isnan( out[ i%out.length ] ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
}
51+
b.toc();
52+
if ( isnan( out[ i%out.length ] ) ) {
53+
b.fail( 'should not return NaN' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});
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) 2026 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 Float64Array = require( '@stdlib/array/float64' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var dlartgp = require( './../lib/ndarray.js' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+':ndarray', function benchmark( b ) {
34+
var out;
35+
var A;
36+
var B;
37+
var i;
38+
39+
A = ( randu() * 100.0 ) - 50.0;
40+
B = ( randu() * 100.0 ) - 50.0;
41+
out = new Float64Array( 3 );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
out = dlartgp( A, B, out, 1, 0 );
46+
A = out[ i%out.length ];
47+
B = out[ i%out.length ];
48+
if ( isnan( out[ i%out.length ] ) ) {
49+
b.fail( 'should not return NaN' );
50+
}
51+
}
52+
b.toc();
53+
if ( isnan( out[ i%out.length ] ) ) {
54+
b.fail( 'should not return NaN' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});

0 commit comments

Comments
 (0)