Skip to content

Commit a350d78

Browse files
committed
feat: add blas/base/zher2
--- 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 5752f78 commit a350d78

Some content is hidden

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

44 files changed

+4330
-0
lines changed
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
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+
# zher2
22+
23+
> Perform the hermitian rank 1 operation `A = alpha*x*x**H + A`, where `alpha` is a real scalar, `X` is an `N` element vector and `A` is an `N` by `N` hermitian matrix.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zher2 = require( '@stdlib/blas/base/zher2' );
31+
```
32+
33+
#### zher2( order, uplo, N, α, x, strideX, y, strideY, A, LDA )
34+
35+
Performs the hermitian rank 1 operation `A = alpha*x*x**H + A`, where `alpha` is a real scalar, `X` is an `N` element vector and `A` is an `N` by `N` hermitian matrix.
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
40+
41+
var x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
42+
var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
43+
var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 0.0 ] );
44+
var alpha = new Complex128( 1.0, 0.0 );
45+
46+
zher2( 'row-major', 'lower', x.length, alpha, x, 1, y, 1, A, 2 );
47+
// A => <Complex128Array>[ 5.0, 0.0, 0.0, 0.0, 6.0, 3.0, 8.0, 0.0 ]
48+
```
49+
50+
The function has the following parameters:
51+
52+
- **order**: storage layout.
53+
- **uplo**: specifies whether the upper or lower triangular part of the matrix `A` is supplied.
54+
- **N**: specifies the order of the matrix `A`.
55+
- **α**: scalar constant.
56+
- **x**: first input vector [`Complex128Array`][@stdlib/array/complex128].
57+
- **strideX**: index increment for `x`.
58+
- **y**: second input vector [`Complex128Array`][@stdlib/array/complex128].
59+
- **strideY**: index increment for `y`.
60+
- **A**: input matrix stored in linear memory as [`Complex128Array`][@stdlib/array/complex128].
61+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
62+
63+
The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `x` in reverse order,
64+
65+
```javascript
66+
var Complex128Array = require( '@stdlib/array/complex128' );
67+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
68+
69+
var x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
70+
var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
71+
var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 0.0 ] );
72+
var alpha = new Complex128( 1.0, 0.0 );
73+
74+
zher2( 'row-major', 'lower', x.length, alpha, x, 1, y, 1, A, 2 );
75+
// A => <Complex128Array>[ 5.0, 0.0, 0.0, 0.0, 6.0, 3.0, 8.0, 0.0 ]
76+
```
77+
78+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
79+
80+
<!-- eslint-disable stdlib/capitalized-comments -->
81+
82+
```javascript
83+
var Complex128Array = require( '@stdlib/array/complex128' );
84+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
85+
86+
// Initial array:
87+
var x0 = new Complex128Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] );
88+
var y0 = new Complex128Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] );
89+
90+
var alpha = new Complex128( 1.0, 0.0 );
91+
92+
// Define a input matrix:
93+
var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 0.0 ] );
94+
95+
// Create an offset view:
96+
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
97+
var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
98+
99+
zher2( 'row-major', 'lower', x1.length, alpha, x1, 1, y1, 1, A, 2 );
100+
// A => <Complex128Array>[ 5.0, 0.0, 0.0, 0.0, 6.0, 3.0, 8.0, 0.0 ]
101+
```
102+
103+
<!-- lint disable maximum-heading-length -->
104+
105+
#### zher2.ndarray( uplo, N, α, x, strideX, offsetX, y, strideY, offsetY, A, strideA1, strideA2, offsetA )
106+
107+
Performs the hermitian rank 1 operation `A = alpha*x*x**H + A`, where `alpha` is a real scalar, `X` is an `N` element vector and `A` is an `N` by `N` hermitian matrix using alternative indexing semantics.
108+
109+
```javascript
110+
var Complex128Array = require( '@stdlib/array/complex128' );
111+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
112+
113+
var x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
114+
var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
115+
var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 0.0 ] );
116+
var alpha = new Complex128( 1.0, 0.0 );
117+
118+
zher2.ndarray( 'lower', x.length, alpha, x, 1, 0, y, 1, 0, A, 2, 1, 0 );
119+
// A => <Complex128Array>[ 5.0, 0.0, 0.0, 0.0, 6.0, 3.0, 8.0, 0.0 ]
120+
```
121+
122+
The function has the following additional parameters:
123+
124+
- **strideA1**: stride of the first dimension of `A`.
125+
- **strideA2**: stride of the second dimension of `A`.
126+
- **offsetX**: starting index for `x`.
127+
- **offsetY**: starting index for `y`.
128+
- **offsetA**: starting index for `A`.
129+
130+
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 scale every other value in the input strided array starting from the second element,
131+
132+
```javascript
133+
var Complex128Array = require( '@stdlib/array/complex128' );
134+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
135+
136+
var x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
137+
var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0 ] );
138+
var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 0.0 ] );
139+
var alpha = new Complex128( 1.0, 0.0 );
140+
141+
zher2.ndarray( 'lower', x.length, alpha, x, -1, 0, y, -1, 0, A, 2, 1, 0 );
142+
// A => <Complex128Array>[ 5.0, 0.0, 0.0, 0.0, 6.0, 3.0, 8.0, 0.0 ]
143+
```
144+
145+
</section>
146+
147+
<!-- /.usage -->
148+
149+
<section class="notes">
150+
151+
## Notes
152+
153+
- If `N = 0` or `real( α ) = 0.0` or `imag( α ) = 0.0`, both functions return `x` unchanged.
154+
- `zher2()` corresponds to the [BLAS][blas] level 2 function [`zher2`][zher2].
155+
156+
</section>
157+
158+
<!-- /.notes -->
159+
160+
<section class="examples">
161+
162+
## Examples
163+
164+
<!-- eslint no-undef: "error" -->
165+
166+
```javascript
167+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
168+
var filledarrayBy = require( '@stdlib/array/filled-by' );
169+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
170+
var logEach = require( '@stdlib/console/log-each' );
171+
var zher2 = require( '@stdlib/blas/base/zher2' );
172+
173+
function rand() {
174+
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
175+
}
176+
177+
var x = filledarrayBy( 3, 'complex128', rand );
178+
console.log( x.get( 0 ).toString() );
179+
180+
var y = filledarrayBy( 3, 'complex128', rand );
181+
console.log( y.get( 0 ).toString() );
182+
183+
var A = filledarrayBy( 9, 'complex128', rand );
184+
console.log( A.get( 0 ).toString() );
185+
186+
var alpha = new Complex128( 2.0, 2.0 );
187+
console.log( alpha.toString() );
188+
189+
zher2( 'row-major', 'upper', 3, alpha, x, 1, y, 1, A, 3 );
190+
191+
// Print the results:
192+
logEach( '(%s)', A );
193+
194+
zher2.ndarray( 'upper', 3, alpha, x, 1, 0, y, 1, 0, A, 3, 1, 0 );
195+
196+
// Print the results:
197+
logEach( '(%s)', A );
198+
```
199+
200+
</section>
201+
202+
<!-- /.examples -->
203+
204+
<!-- C interface documentation. -->
205+
206+
* * *
207+
208+
<section class="c">
209+
210+
## C APIs
211+
212+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
213+
214+
<section class="intro">
215+
216+
</section>
217+
218+
<!-- /.intro -->
219+
220+
<!-- C usage documentation. -->
221+
222+
<section class="usage">
223+
224+
### Usage
225+
226+
```c
227+
TODO
228+
```
229+
230+
#### TODO
231+
232+
TODO.
233+
234+
```c
235+
TODO
236+
```
237+
238+
TODO
239+
240+
```c
241+
TODO
242+
```
243+
244+
</section>
245+
246+
<!-- /.usage -->
247+
248+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
249+
250+
<section class="notes">
251+
252+
</section>
253+
254+
<!-- /.notes -->
255+
256+
<!-- C API usage examples. -->
257+
258+
<section class="examples">
259+
260+
### Examples
261+
262+
```c
263+
TODO
264+
```
265+
266+
</section>
267+
268+
<!-- /.examples -->
269+
270+
</section>
271+
272+
<!-- /.c -->
273+
274+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
275+
276+
<section class="related">
277+
278+
</section>
279+
280+
<!-- /.related -->
281+
282+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
283+
284+
<section class="links">
285+
286+
[blas]: http://www.netlib.org/blas
287+
288+
[zher2]: https://www.netlib.org/lapack/explore-html/dd/de5/group__her2_gaf421f493e6422d08e3acfc6d33bfbf46.html
289+
290+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
291+
292+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
293+
294+
</section>
295+
296+
<!-- /.links -->

0 commit comments

Comments
 (0)