Skip to content

Commit 83e5f83

Browse files
committed
feat: add blas/base/ssyr2k
--- 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 f344e9d commit 83e5f83

Some content is hidden

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

72 files changed

+6267
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
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+
# ssyr2k
22+
23+
> Perform one of the symmetric rank `2K` operations `C = α*A*B**T + C = α*B*A**T + β*C` or `C = α*A**T*B + α*B**T*A + β*C` where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` and `B` are `N` by `K` matrices in the first case and `K` by `N` matrices in the second case.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ssyr2k = require( '@stdlib/blas/base/ssyr2k' );
31+
```
32+
33+
#### ssyr2k( ord, uplo, trans, N, K, α, A, lda, B, ldb, β, C, ldc )
34+
35+
Performs one of the symmetric rank `2K` operations `C = α*A*B**T + C = α*B*A**T + β*C` or `C = α*A**T*B + α*B**T*A + β*C` where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` and `B` are `N` by `K` matrices in the first case and `K` by `N` matrices in the second case.
36+
37+
```javascript
38+
var Float32Array = require( '@stdlib/array/float32' );
39+
40+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
41+
var B = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
42+
var C = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] );
43+
44+
ssyr2k( 'row-major', 'upper', 'no-transpose', 3, 3, 1.0, A, 3, B, 3, 1.0, C, 3 );
45+
// C => <Float32Array>[ 29.0, 66.0, 103.0, 0.0, 158.0, 249.0, 0.0, 0.0, 394.0 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **ord**: storage layout.
51+
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `C` is supplied.
52+
- **trans**: specifies whether `C` should be transposed, conjugate-transposed, or not transposed.
53+
- **N**: order of the matrix `C`.
54+
- **K**: number of columns or number of rows of the matrices `A` and `B`.
55+
- **α**: scalar constant.
56+
- **A**: first input matrix stored in linear memory as a [`Float32Array`][mdn-float32array].
57+
- **lda**: stride of the first dimension of `A` (leading dimension of `A`).
58+
- **B**: second input matrix stored in linear memory as a [`Float32Array`][mdn-float32array].
59+
- **ldb**: stride of the first dimension of `B` (leading dimension of `B`).
60+
- **β**: scalar constant.
61+
- **C**: third input matrix stored in linear memory as a [`Float32Array`][mdn-float32array].
62+
- **ldc**: stride of the first dimension of `C` (leading dimension of `C`).
63+
64+
The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to perform matrix multiplication of two subarrays
65+
66+
<!-- lint disable maximum-len -->
67+
68+
```javascript
69+
var Float32Array = require( '@stdlib/array/float32' );
70+
71+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0, 7.0, 8.0, 9.0 ] );
72+
var B = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0, 7.0, 8.0, 9.0 ] );
73+
var C = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] );
74+
75+
ssyr2k( 'row-major', 'upper', 'no-transpose', 3, 3, 1.0, A, 6, B, 6, 1.0, C, 3 );
76+
// C => <Float32Array>[ 29.0, 66.0, 103.0, 0.0, 158.0, 249.0, 0.0, 0.0, 394.0 ]
77+
```
78+
79+
<!-- lint disable maximum-heading-length -->
80+
81+
#### ssyr2k.ndarray( uplo, trans, N, K, α, A, sa1, sa2, oa, B, sb1, sb2, ob, β, C, sc1, sc2, oc )
82+
83+
Performs one of the symmetric rank `2K` operations `C = α*A*B**T + C = α*B*A**T + β*C` or `C = α*A**T*B + α*B**T*A + β*C`, using alternative indexing semantics and where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` and `B` are `N` by `K` matrices in the first case and `K` by `N` matrices in the second case.
84+
85+
```javascript
86+
var Float32Array = require( '@stdlib/array/float32' );
87+
88+
var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
89+
var B = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
90+
var C = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] );
91+
92+
ssyr2k.ndarray( 'upper', 'no-transpose', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0, 1.0, C, 3, 1, 0 );
93+
// C => <Float32Array>[ 29.0, 66.0, 103.0, 0.0, 158.0, 249.0, 0.0, 0.0, 394.0 ]
94+
```
95+
96+
The function has the following additional parameters:
97+
98+
- **sa1**: stride of the first dimension of `A`.
99+
- **sa2**: stride of the second dimension of `A`.
100+
- **oa**: starting index for `A`.
101+
- **sb1**: stride of the first dimension of `B`.
102+
- **sb2**: stride of the second dimension of `B`.
103+
- **ob**: starting index for `B`.
104+
- **sc1**: stride of the first dimension of `C`.
105+
- **sc2**: stride of the second dimension of `C`.
106+
- **oc**: starting index for `C`.
107+
108+
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,
109+
110+
```javascript
111+
var Float32Array = require( '@stdlib/array/float32' );
112+
113+
var A = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
114+
var B = new Float32Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
115+
var C = new Float32Array( [ 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] );
116+
117+
ssyr2k.ndarray( 'upper', 'no-transpose', 3, 3, 1.0, A, 3, 1, 1, B, 3, 1, 2, 1.0, C, 3, 1, 3 );
118+
// C => <Float32Array>[ 0.0, 0.0, 0.0, 29.0, 66.0, 103.0, 0.0, 158.0, 249.0, 0.0, 0.0, 394.0 ]
119+
```
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<section class="notes">
126+
127+
## Notes
128+
129+
- `ssyr2k()` corresponds to the [BLAS][blas] level 3 function [`ssyr2k`][blas-ssyr2k].
130+
131+
</section>
132+
133+
<!-- /.notes -->
134+
135+
<section class="examples">
136+
137+
## Examples
138+
139+
<!-- eslint no-undef: "error" -->
140+
141+
```javascript
142+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
143+
var ssyr2k = require( '@stdlib/blas/base/ssyr2k' );
144+
145+
var opts = {
146+
'dtype': 'float32'
147+
};
148+
149+
var N = 4;
150+
151+
var A = discreteUniform( N*N, 0, 10, opts ); // 4x4
152+
var B = discreteUniform( N*N, 0, 10, opts ); // 4x4
153+
var C = discreteUniform( N*N, 0, 10, opts ); // 4x4
154+
155+
ssyr2k( 'row-major', 'lower', 'no-transpose', N, N, 1.0, A, N, B, N, 1.0, C, N );
156+
console.log( C );
157+
158+
ssyr2k.ndarray( 'lower', 'no-transpose', N, N, 1.0, A, N, 1, 0, B, N, 1, 0, 1.0, C, N, 1, 0 );
159+
console.log( C );
160+
```
161+
162+
</section>
163+
164+
<!-- /.examples -->
165+
166+
<!-- C interface documentation. -->
167+
168+
* * *
169+
170+
<section class="c">
171+
172+
## C APIs
173+
174+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
175+
176+
<section class="intro">
177+
178+
</section>
179+
180+
<!-- /.intro -->
181+
182+
<!-- C usage documentation. -->
183+
184+
<section class="usage">
185+
186+
### Usage
187+
188+
```c
189+
#include "stdlib/blas/base/ssyr2k.h"
190+
```
191+
192+
#### TODO
193+
194+
TODO.
195+
196+
```c
197+
TODO
198+
```
199+
200+
TODO
201+
202+
```c
203+
TODO
204+
```
205+
206+
</section>
207+
208+
<!-- /.usage -->
209+
210+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
211+
212+
<section class="notes">
213+
214+
</section>
215+
216+
<!-- /.notes -->
217+
218+
<!-- C API usage examples. -->
219+
220+
<section class="examples">
221+
222+
### Examples
223+
224+
```c
225+
TODO
226+
```
227+
228+
</section>
229+
230+
<!-- /.examples -->
231+
232+
</section>
233+
234+
<!-- /.c -->
235+
236+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
237+
238+
<section class="related">
239+
240+
</section>
241+
242+
<!-- /.related -->
243+
244+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
245+
246+
<section class="links">
247+
248+
[blas]: http://www.netlib.org/blas
249+
250+
[blas-ssyr2k]: https://www.netlib.org/lapack/explore-html-3.6.1/d1/d54/group__double__blas__level3_ga51f6c38a43599163e670f0f6f5645587.html
251+
252+
[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
253+
254+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
255+
256+
</section>
257+
258+
<!-- /.links -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var ssyr2k = require( './../lib/ssyr2k.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} N - array dimension size
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( N ) {
49+
var A = uniform( N*N, -10.0, 10.0, options );
50+
var B = uniform( N*N, -10.0, 10.0, options );
51+
var C = uniform( N*N, -10.0, 10.0, options );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var z;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
z = ssyr2k( 'row-major', 'lower', 'no-transpose', N, N, 1.0, A, N, B, N, 1.0, C, N );
67+
if ( isnanf( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnanf( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 4; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
100+
f = createBenchmark( len );
101+
bench( pkg+':size='+(len*len), f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)