Skip to content

Commit e8234b6

Browse files
committed
feat: add blas/base/dsyrk
--- 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 0409af2 commit e8234b6

Some content is hidden

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

51 files changed

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

0 commit comments

Comments
 (0)