Skip to content

Commit 7454ee8

Browse files
committed
feat: add blas/base/ssymm
--- 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 45783cb commit 7454ee8

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

+6319
-0
lines changed
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
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+
# ssymm
22+
23+
> Perform the matrix-matrix operation `C = α*A*B + β*C` or `C = α*B*A + β*C` where `α` and `β` are scalars, `A` is a symmetric matrix and `B` and `C` are `M` by `N` matrices.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ssymm = require( '@stdlib/blas/base/ssymm' );
31+
```
32+
33+
#### ssymm( ord, side, uplo, M, N, α, A, lda, B, ldb, β, C, ldc )
34+
35+
Performs the matrix-matrix operation `C = α*A*B + β*C` or `C = α*B*A + β*C` where `α` and `β` are scalars, `A` is a symmetric matrix and `B` and `C` are `M` by `N` matrices.
36+
37+
```javascript
38+
var Float32Array = require( '@stdlib/array/float32' );
39+
40+
var A = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0 ] );
41+
var B = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
42+
var C = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
43+
44+
ssymm( 'row-major', 'left', 'lower', 3, 3, 1.0, A, 3, B, 3, 1.0, C, 3 );
45+
// C => <Float32Array>[ 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **ord**: storage layout.
51+
- **side**: specifies whether `A` appears on the left or right of `B`.
52+
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
53+
- **M**: number of rows in the matrix `op(A)` and in the matrix `C`.
54+
- **N**: number of columns in the matrix `op(B)` and in the matrix `C`.
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+
<!-- eslint-disable max-len -->
67+
68+
```javascript
69+
var Float32Array = require( '@stdlib/array/float32' );
70+
71+
var A = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 3.0, 0.0, 0.0, 0.0 ] );
72+
var B = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] );
73+
var C = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
74+
75+
ssymm( 'row-major', 'left', 'lower', 3, 3, 1.0, A, 6, B, 6, 1.0, C, 3 );
76+
// C => <Float32Array>[ 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0 ]
77+
```
78+
79+
<!-- lint disable maximum-heading-length -->
80+
81+
#### ssymm.ndarray( side, uplo, M, N, α, A, sa1, sa2, oa, B, sb1, sb2, ob, β, C, sc1, sc2, oc )
82+
83+
Performs the matrix-matrix operation `C = α*A*B + β*C` or `C = α*B*A + β*C` using alternative indexing semantics and where `α` and `β` are scalars, `A` is a symmetric matrix and `B` and `C` are `M` by `N` matrices.
84+
85+
```javascript
86+
var Float32Array = require( '@stdlib/array/float32' );
87+
88+
var A = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0 ] );
89+
var B = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
90+
var C = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
91+
92+
ssymm.ndarray( 'left', 'lower', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0, 1.0, C, 3, 1, 0 );
93+
// C => <Float32Array>[ 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.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, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0 ] );
114+
var B = new Float32Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
115+
var C = new Float32Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
116+
117+
ssymm.ndarray( 'left', 'lower', 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, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0 ]
119+
```
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<section class="notes">
126+
127+
## Notes
128+
129+
- `ssymm()` corresponds to the [BLAS][blas] level 3 function [`ssymm`][blas-ssymm].
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 ssymm = require( '@stdlib/blas/base/ssymm' );
144+
145+
var opts = {
146+
'dtype': 'float32'
147+
};
148+
149+
var M = 3;
150+
var N = 3;
151+
152+
var A = discreteUniform( M*N, 0, 10, opts );
153+
var B = discreteUniform( M*N, 0, 10, opts );
154+
var C = discreteUniform( M*N, 0, 10, opts );
155+
156+
ssymm( 'row-major', 'left', 'lower', M, N, 1.0, A, M, B, N, 1.0, C, N );
157+
console.log( C );
158+
159+
ssymm.ndarray( 'left', 'lower', M, N, 1.0, A, M, 1, 0, B, N, 1, 0, 1.0, C, N, 1, 0 );
160+
console.log( C );
161+
```
162+
163+
</section>
164+
165+
<!-- /.examples -->
166+
167+
<!-- C interface documentation. -->
168+
169+
* * *
170+
171+
<section class="c">
172+
173+
## C APIs
174+
175+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
176+
177+
<section class="intro">
178+
179+
</section>
180+
181+
<!-- /.intro -->
182+
183+
<!-- C usage documentation. -->
184+
185+
<section class="usage">
186+
187+
### Usage
188+
189+
```c
190+
#include "stdlib/blas/base/ssymm.h"
191+
```
192+
193+
#### TODO
194+
195+
TODO.
196+
197+
```c
198+
TODO
199+
```
200+
201+
TODO
202+
203+
```c
204+
TODO
205+
```
206+
207+
</section>
208+
209+
<!-- /.usage -->
210+
211+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
212+
213+
<section class="notes">
214+
215+
</section>
216+
217+
<!-- /.notes -->
218+
219+
<!-- C API usage examples. -->
220+
221+
<section class="examples">
222+
223+
### Examples
224+
225+
```c
226+
TODO
227+
```
228+
229+
</section>
230+
231+
<!-- /.examples -->
232+
233+
</section>
234+
235+
<!-- /.c -->
236+
237+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
238+
239+
<section class="related">
240+
241+
</section>
242+
243+
<!-- /.related -->
244+
245+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
246+
247+
<section class="links">
248+
249+
[blas]: http://www.netlib.org/blas
250+
251+
[blas-ssymm]: https://netlib.org/lapack/explore-html-3.6.1/db/dc9/group__single__blas__level3_ga8e8391a9873114d97e2b63e39fe83b2e.html
252+
253+
[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
254+
255+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
256+
257+
</section>
258+
259+
<!-- /.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 ssymm = require( './../lib/ssymm.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 = ssymm( 'row-major', 'left', 'lower', 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 = 5; // 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+':order(A)=row-major,order(B)=row-major,order(C)=row-major,trans(A)=false,trans(B)=false,size='+(len*len), f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)