Skip to content

Commit b5a7f1f

Browse files
committed
feat: add blas/lapack/zlacgv
1 parent 82d6dde commit b5a7f1f

40 files changed

+4937
-0
lines changed
Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
> Conjugates a complex vector.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zlacgv = require( '@stdlib/blas/base/zlacgv' );
31+
```
32+
33+
#### zlacgv( N, zx, strideX )
34+
35+
Conjugate values of `zx`.
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( 4, zx, 0 );
45+
46+
var z = zx.get( 0 );
47+
// returns <Complex128>
48+
49+
var re = real( z );
50+
// returns 2.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+
- **strideX**: index increment for `zx`.
61+
62+
The `N` and stride parameters determine how values from `zx` conjugated. For example, to conjugate every other value 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, 1 );
72+
73+
var z = zx.get( 0 );
74+
// returns <Complex128>
75+
76+
var re = imag( z );
77+
// returns 3.0
78+
79+
var im = imag( z );
80+
// returns -4.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+
// Conjugates every other value from `zx1`...
100+
zlacgv( 3, zx1, 1 );
101+
102+
var z = zx0.get( 1 );
103+
// returns <Complex128>
104+
105+
var re = real( z );
106+
// returns -2.0
107+
108+
var im = imag( z );
109+
// returns 14.0
110+
```
111+
112+
#### zlacgv.ndarray( N, zx, strideX, offsetX )
113+
114+
Conjugate values from `zx` 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 -2.0
130+
131+
var im = imag( z );
132+
// returns 6.0
133+
```
134+
135+
The function has the following additional parameters:
136+
137+
- **offsetX**: 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 value 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 -2.0
155+
156+
var im = imag( z );
157+
// returns 30.0
158+
```
159+
160+
</section>
161+
162+
<!-- /.usage -->
163+
164+
<section class="notes">
165+
166+
## Notes
167+
168+
- If `N <= 0` or `strideX <= 0` , both functions return `zx` unchanged.
169+
- `zlacgv()` corresponds to the [BLAS][blas] level 1 function [`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/blas/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+
// Conjugates elements from `zx`:
195+
zlacgv( zx.length, zx, 1 );
196+
console.log( zx.get( zx.length-1 ).toString() );
197+
```
198+
199+
</section>
200+
201+
<!-- /.examples -->
202+
203+
<!-- C interface documentation. -->
204+
205+
* * *
206+
207+
<section class="c">
208+
209+
## C APIs
210+
211+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
212+
213+
<section class="intro">
214+
215+
</section>
216+
217+
<!-- /.intro -->
218+
219+
<!-- C usage documentation. -->
220+
221+
<section class="usage">
222+
223+
### Usage
224+
225+
```c
226+
#include "stdlib/blas/base/zlacgv.h"
227+
```
228+
229+
#### c_zlacgv( N, \*ZX, strideX )
230+
231+
Conjugate values from `ZX`.
232+
233+
```c
234+
double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
235+
236+
c_zlacgv( 4, (void *)zx, 1 );
237+
```
238+
239+
The function accepts the following arguments:
240+
241+
- **N**: `[in] CBLAS_INT` number of indexed elements.
242+
- **ZX**: `[inout] void*` input array.
243+
- **strideX**: `[in] CBLAS_INT` index increment for `ZX`.
244+
245+
```c
246+
void c_zlacgv( const CBLAS_INT N, void *ZX, const CBLAS_INT strideX );
247+
```
248+
249+
</section>
250+
251+
<!-- /.usage -->
252+
253+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
254+
255+
<section class="notes">
256+
257+
</section>
258+
259+
<!-- /.notes -->
260+
261+
<!-- C API usage examples. -->
262+
263+
<section class="examples">
264+
265+
### Examples
266+
267+
```c
268+
#include "stdlib/blas/base/zlacgv.h"
269+
#include <stdio.h>
270+
271+
int main( void ) {
272+
// Create a strided array of interleaved real and imaginary components:
273+
double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
274+
275+
// Specify the number of elements:
276+
const int N = 4;
277+
278+
// Specify stride length:
279+
const int strideX = 1;
280+
281+
// Conjugate elements of the array:
282+
c_zlacgv( N, (void *)zx, strideX );
283+
284+
// Print the result:
285+
for ( int i = 0; i < N; i++ ) {
286+
printf( "zx[ %i ] = %f + %fj\n", i, zx[ i*2 ], zx[ (i*2)+1 ] );
287+
}
288+
}
289+
```
290+
291+
</section>
292+
293+
<!-- /.examples -->
294+
295+
</section>
296+
297+
<!-- /.c -->
298+
299+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
300+
301+
<section class="related">
302+
303+
</section>
304+
305+
<!-- /.related -->
306+
307+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
308+
309+
<section class="links">
310+
311+
[blas]: http://www.netlib.org/blas
312+
313+
[zlacgv]: https://www.netlib.org/lapack/explore-html/d9/d50/group__lacgv_gae42087fcabd33130fcbac2aff031de8b.html#gae42087fcabd33130fcbac2aff031de8b
314+
315+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
316+
317+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
318+
319+
[@stdlib/complex/float64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/ctor
320+
321+
</section>
322+
323+
<!-- /.links -->

0 commit comments

Comments
 (0)