Skip to content

Commit 574b590

Browse files
committed
feat: add blas/base/dtrmm
--- 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 c08c2bf commit 574b590

File tree

126 files changed

+8119
-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

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