Skip to content

Commit 987cc80

Browse files
committed
feat: add blas/base/strmm
1 parent 84cf373 commit 987cc80

File tree

126 files changed

+8120
-0
lines changed

Some content is hidden

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

126 files changed

+8120
-0
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
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+
# strmm
22+
23+
> Perform one of the matrix-matrix operations `B = alpha * op(A) * B` or `B = alpha * B * op(A)` where alpha is a scalar, B is an m by n matrix, A is a unit, or non-unit, upper or lower triangular matrix and op( A ) is one of `op( A ) = A` or `op( A ) = A**T`.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var strmm = require( '@stdlib/blas/base/strmm' );
31+
```
32+
33+
#### strmm( order, side, uplo, transa, diag, m, n, alpha, A, LDA, B, LDB )
34+
35+
Performs one of the matrix-matrix operations `B = alpha * op(A) * B` or `B = alpha * B * op(A)` where alpha is a scalar, B is an m by n matrix, A is a unit, or non-unit, upper or lower triangular matrix and op( A ) is one of `op( A ) = A` or `op( A ) = A**T`.
36+
37+
```javascript
38+
var Float32Array = require( '@stdlib/array/float32' );
39+
40+
var A = new Float32Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 5.0, 6.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+
43+
strmm( 'row-major', 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, B, 3 );
44+
// B => <Float32Array>[ 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout of `A` and `B`.
50+
- **side**: specifies whether `op( A )` appears on the left or right side of `X`.
51+
- **uplo**: specifies whether the upper or lower triangular part of the matrix `A` is supplied.
52+
- **transa**: specifies the form of `op( A )` to be used in the matrix multiplication.
53+
- **diag**: specifies whether or not `A` is unit triangular.
54+
- **m**: number of rows in `B`.
55+
- **n**: number of columns in `B`.
56+
- **alpha**: scalar constant.
57+
- **A**: input matrix `A`.
58+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
59+
- **B**: input matrix `B`.
60+
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).
61+
62+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
63+
64+
<!-- eslint-disable stdlib/capitalized-comments -->
65+
66+
```javascript
67+
var Float32Array = require( '@stdlib/array/float32' );
68+
69+
// Initial arrays...
70+
var A0 = new Float32Array( [ 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
71+
var B0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] );
72+
73+
// Create offset views...
74+
var A1 = new Float32Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
75+
var B1 = new Float32Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
76+
77+
strmm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 3, 3, 1.0, A1, 3, B1, 3 );
78+
// B => <Float32Array>[ 0.0, 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ]
79+
```
80+
81+
#### strmm.ndarray( s, ul, t, d, m, n, α, A, sa1, sa2, oa, B, sb1, sb2, ob )
82+
83+
Performs one of the matrix-matrix operations `B = alpha * op(A) * B` or `B = alpha * B * op(A)` using alternative indexing semantics and where alpha is a scalar, B is an m by n matrix, A is a unit, or non-unit, upper or lower triangular matrix and op( A ) is one of `op( A ) = A` or `op( A ) = A**T`.
84+
85+
```javascript
86+
var Float32Array = require( '@stdlib/array/float32' );
87+
88+
var A = new Float32Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 5.0, 6.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+
91+
strmm.ndarray( 'left', 'upper', 'no-transpose', 'non-unit', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0 );
92+
// B => <Float32Array>[ 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ]
93+
```
94+
95+
The function has the following parameters:
96+
97+
- **side**: specifies whether `op( A )` appears on the left or right side of `X`.
98+
- **uplo**: specifies whether the upper or lower triangular part of the matrix `A` is supplied.
99+
- **transa**: specifies the form of `op( A )` to be used in the matrix multiplication.
100+
- **diag**: specifies whether or not `A` is unit triangular.
101+
- **m**: number of rows in `B`.
102+
- **n**: number of columns in `B`.
103+
- **alpha**: scalar constant.
104+
- **A**: input matrix `A`.
105+
- **sa1**: stride of the first dimension of `A`.
106+
- **sa2**: stride of the second dimension of `A`.
107+
- **oa**: starting index for `A`.
108+
- **B**: input matrix `B`.
109+
- **sb1**: stride of the first dimension of `B`.
110+
- **sb2**: stride of the second dimension of `B`.
111+
- **ob**: starting index for `B`.
112+
113+
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,
114+
115+
```javascript
116+
var Float32Array = require( '@stdlib/array/float32' );
117+
118+
var A = new Float32Array( [ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
119+
var B = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
120+
121+
strmm.ndarray( 'left', 'upper', 'no-transpose', 'non-unit', 3, 3, 1.0, A, 3, 1, 2, B, 3, 1, 1 );
122+
// B => <Float32Array>[ 0.0, 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ]
123+
```
124+
125+
</section>
126+
127+
<!-- /.usage -->
128+
129+
<section class="notes">
130+
131+
## Notes
132+
133+
- `strmm()` corresponds to the [BLAS][blas] level 3 function [`strmm`][strmm].
134+
135+
</section>
136+
137+
<!-- /.notes -->
138+
139+
<section class="examples">
140+
141+
## Examples
142+
143+
<!-- eslint no-undef: "error" -->
144+
145+
```javascript
146+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
147+
var strmm = require( '@stdlib/blas/base/strmm' );
148+
149+
var opts = {
150+
'dtype': 'float32'
151+
};
152+
153+
var M = 3;
154+
var N = 3;
155+
156+
var A = discreteUniform( M*N, -10.0, 10.0, opts );
157+
var B = discreteUniform( M*N, -10.0, 10.0, opts );
158+
159+
var out = strmm( 'column-major', 'left', 'upper', 'no-transpose', 'non-unit', M, N, 1.0, A, N, B, N );
160+
console.log( out );
161+
162+
out = strmm.ndarray( 'left', 'upper', 'no-transpose', 'non-unit', M, N, 1.0, A, N, 1, 0, B, N, 1, 0 );
163+
console.log( out );
164+
```
165+
166+
</section>
167+
168+
<!-- /.examples -->
169+
170+
<!-- C interface documentation. -->
171+
172+
* * *
173+
174+
<section class="c">
175+
176+
## C APIs
177+
178+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
179+
180+
<section class="intro">
181+
182+
</section>
183+
184+
<!-- /.intro -->
185+
186+
<!-- C usage documentation. -->
187+
188+
<section class="usage">
189+
190+
### Usage
191+
192+
```c
193+
TODO
194+
```
195+
196+
#### TODO
197+
198+
TODO.
199+
200+
```c
201+
TODO
202+
```
203+
204+
TODO
205+
206+
```c
207+
TODO
208+
```
209+
210+
</section>
211+
212+
<!-- /.usage -->
213+
214+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
215+
216+
<section class="notes">
217+
218+
</section>
219+
220+
<!-- /.notes -->
221+
222+
<!-- C API usage examples. -->
223+
224+
<section class="examples">
225+
226+
### Examples
227+
228+
```c
229+
TODO
230+
```
231+
232+
</section>
233+
234+
<!-- /.examples -->
235+
236+
</section>
237+
238+
<!-- /.c -->
239+
240+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
241+
242+
<section class="related">
243+
244+
</section>
245+
246+
<!-- /.related -->
247+
248+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
249+
250+
<section class="links">
251+
252+
[blas]: http://www.netlib.org/blas
253+
254+
[strmm]: https://www.netlib.org/lapack/explore-html/dd/dab/group__trmm_gae6343b11d5dff934bf1e461ba6b9e5dc.html
255+
256+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
257+
258+
</section>
259+
260+
<!-- /.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 ones = require( '@stdlib/array/ones' );
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 strmm = require( './../lib/strmm.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 = ones( N*N, options.dtype );
50+
var B = ones( N*N, options.dtype );
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 = strmm( 'row-major', 'left', 'lower', 'no-transpose', 'non-unit', N, N, 1.0, A, N, B, N );
66+
if ( isnanf( z[ i%z.length ] ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnanf( 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 = 6; // 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)