Skip to content

Commit 2105c59

Browse files
rreusserkgryte
authored andcommitted
feat: add lapack/base/zlacgv
PR-URL: stdlib-js#4725 Ref: stdlib-js#2464 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 5768c16 commit 2105c59

File tree

15 files changed

+1821
-0
lines changed

15 files changed

+1821
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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+
# zlacgv
22+
23+
> Conjugate each element in a double-precision complex floating-point vector.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zlacgv = require( '@stdlib/lapack/base/zlacgv' );
31+
```
32+
33+
#### zlacgv( N, zx, strideZX )
34+
35+
Conjugates each element in a double-precision complex floating-point vector.
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
var real = require( '@stdlib/complex/float64/real' );
40+
var imag = require( '@stdlib/complex/float64/imag' );
41+
42+
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
43+
44+
zlacgv( 2, zx, 1 );
45+
46+
var z = zx.get( 0 );
47+
// returns <Complex128>
48+
49+
var re = real( z );
50+
// returns 1.0
51+
52+
var im = imag( z );
53+
// returns -2.0
54+
```
55+
56+
The function has the following parameters:
57+
58+
- **N**: number of indexed elements.
59+
- **zx**: input [`Complex128Array`][@stdlib/array/complex128].
60+
- **strideZX**: stride length for `zx`.
61+
62+
The `N` and stride parameters determine which elements in `zx` are conjugated. For example, to conjugate every other element in `zx`,
63+
64+
```javascript
65+
var Complex128Array = require( '@stdlib/array/complex128' );
66+
var real = require( '@stdlib/complex/float64/real' );
67+
var imag = require( '@stdlib/complex/float64/imag' );
68+
69+
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
70+
71+
zlacgv( 2, zx, 2 );
72+
73+
var z = zx.get( 0 );
74+
// returns <Complex128>
75+
76+
var re = real( z );
77+
// returns 1.0
78+
79+
var im = imag( z );
80+
// returns -2.0
81+
```
82+
83+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
84+
85+
<!-- eslint-disable stdlib/capitalized-comments -->
86+
87+
```javascript
88+
var Complex128Array = require( '@stdlib/array/complex128' );
89+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
90+
var real = require( '@stdlib/complex/float64/real' );
91+
var imag = require( '@stdlib/complex/float64/imag' );
92+
93+
// Initial array:
94+
var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
95+
96+
// Create an offset view:
97+
var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
98+
99+
// Conjugate every element in `zx1`:
100+
zlacgv( 3, zx1, 1 );
101+
102+
var z = zx0.get( 1 );
103+
// returns <Complex128>
104+
105+
var re = real( z );
106+
// returns 3.0
107+
108+
var im = imag( z );
109+
// returns -4.0
110+
```
111+
112+
#### zlacgv.ndarray( N, zx, strideZX, offsetZX )
113+
114+
Conjugates each element in a double-precision floating-point vector using alternative indexing semantics.
115+
116+
```javascript
117+
var Complex128Array = require( '@stdlib/array/complex128' );
118+
var real = require( '@stdlib/complex/float64/real' );
119+
var imag = require( '@stdlib/complex/float64/imag' );
120+
121+
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
122+
123+
zlacgv.ndarray( 3, zx, 1, 0 );
124+
125+
var z = zx.get( 0 );
126+
// returns <Complex128>
127+
128+
var re = real( z );
129+
// returns 1.0
130+
131+
var im = imag( z );
132+
// returns -2.0
133+
```
134+
135+
The function has the following additional parameters:
136+
137+
- **offsetZX**: starting index for `zx`.
138+
139+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to conjugate every other element in the input strided array starting from the second element,
140+
141+
```javascript
142+
var Complex128Array = require( '@stdlib/array/complex128' );
143+
var real = require( '@stdlib/complex/float64/real' );
144+
var imag = require( '@stdlib/complex/float64/imag' );
145+
146+
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
147+
148+
zlacgv.ndarray( 2, zx, 2, 1 );
149+
150+
var z = zx.get( 3 );
151+
// returns <Complex128>
152+
153+
var re = real( z );
154+
// returns 7.0
155+
156+
var im = imag( z );
157+
// returns -8.0
158+
```
159+
160+
</section>
161+
162+
<!-- /.usage -->
163+
164+
<section class="notes">
165+
166+
## Notes
167+
168+
- If `N <= 0`, both functions return `zx` unchanged.
169+
- `zlacgv()` corresponds to the [LAPACK][lapack] BLAS-like level 1 routine [`zlacgv`][zlacgv].
170+
171+
</section>
172+
173+
<!-- /.notes -->
174+
175+
<section class="examples">
176+
177+
## Examples
178+
179+
<!-- eslint no-undef: "error" -->
180+
181+
```javascript
182+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
183+
var filledarrayBy = require( '@stdlib/array/filled-by' );
184+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
185+
var zlacgv = require( '@stdlib/lapack/base/zlacgv' );
186+
187+
function rand() {
188+
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
189+
}
190+
191+
var zx = filledarrayBy( 10, 'complex128', rand );
192+
console.log( zx.toString() );
193+
194+
// Conjugate elements:
195+
zlacgv( zx.length, zx, 1 );
196+
console.log( zx.get( zx.length-1 ).toString() );
197+
```
198+
199+
</section>
200+
201+
<!-- /.examples -->
202+
203+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
204+
205+
<section class="related">
206+
207+
</section>
208+
209+
<!-- /.related -->
210+
211+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
212+
213+
<section class="links">
214+
215+
[lapack]: https://www.netlib.org/lapack
216+
217+
[zlacgv]: https://www.netlib.org/lapack/explore-html/d9/d50/group__lacgv_gae42087fcabd33130fcbac2aff031de8b.html#gae42087fcabd33130fcbac2aff031de8b
218+
219+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
220+
221+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
222+
223+
</section>
224+
225+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 pow = require( '@stdlib/math/base/special/pow' );
27+
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var pkg = require( './../package.json' ).name;
29+
var zlacgv = require( './../lib/zlacgv.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var zxbuf;
50+
var zx;
51+
52+
zxbuf = uniform( len*2, -100.0, 100.0, options );
53+
zx = new Complex128Array( zxbuf.buffer );
54+
55+
return benchmark;
56+
57+
/**
58+
* Benchmark function.
59+
*
60+
* @private
61+
* @param {Benchmark} b - benchmark instance
62+
*/
63+
function benchmark( b ) {
64+
var i;
65+
66+
b.tic();
67+
for ( i = 0; i < b.iterations; i++ ) {
68+
zlacgv( zx.length, zx, 1 );
69+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
70+
b.fail( 'should not return NaN' );
71+
}
72+
}
73+
b.toc();
74+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
75+
b.fail( 'should not return NaN' );
76+
}
77+
b.pass( 'benchmark finished' );
78+
b.end();
79+
}
80+
}
81+
82+
83+
// MAIN //
84+
85+
/**
86+
* Main execution sequence.
87+
*
88+
* @private
89+
*/
90+
function main() {
91+
var len;
92+
var min;
93+
var max;
94+
var f;
95+
var i;
96+
97+
min = 1; // 10^min
98+
max = 6; // 10^max
99+
100+
for ( i = min; i <= max; i++ ) {
101+
len = pow( 10, i );
102+
f = createBenchmark( len );
103+
bench( pkg+':len='+len, f );
104+
}
105+
}
106+
107+
main();

0 commit comments

Comments
 (0)