Skip to content

Commit 3cfb102

Browse files
committed
feat: add blas/base/dtrsm
1 parent b6e0aca commit 3cfb102

File tree

98 files changed

+6548
-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.

98 files changed

+6548
-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+
# dtrsm
22+
23+
> Solve matrix equation `op(A) * X = α * B` or `X * op(A) = α * B` where `α` is a scalar, `X` and `B` are `M` by `N` matrices, `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`. The matrix `X` is overwritten on `B`.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dtrsm = require( '@stdlib/blas/base/dtrsm' );
31+
```
32+
33+
#### dtrsm( order, side, uplo, transa, diag, M, N, α, A, LDA, B, LDB )
34+
35+
Solves matrix equation `op(A) * X = α * B` or `X * op(A) = α * B` where `α` is a scalar, `X` and `B` are `M` by `N` matrices, `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`. The matrix `X` is overwritten on `B`.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] );
41+
var B = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
42+
43+
dtrsm( 'row-major', 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, B, 3 );
44+
// B => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 1.0, 0.0, -7.0, -5.0, -3.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+
- **α**: 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 Float64Array = require( '@stdlib/array/float64' );
68+
69+
// Initial arrays...
70+
var A0 = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] );
71+
var B0 = new Float64Array( [ 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 Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
75+
var B1 = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
76+
77+
dtrsm( 'row-major', 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, B, 3 );
78+
// B0 => <Float64Array>[ 0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 0.0, -7.0, -5.0, -3.0 ]
79+
```
80+
81+
#### dtrsm.ndarray( s, ul, t, d, M, N, α, A, sa1, sa2, oa, B, sb1, sb2, ob )
82+
83+
Solves matrix equation `op(A) * X = α * B` or `X * op(A) = α * B` using alternative indexing semantics and where `α` is a scalar, `X` and `B` are `M` by `N` matrices, `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`. The matrix `X` is overwritten on `B`.
84+
85+
```javascript
86+
var Float64Array = require( '@stdlib/array/float64' );
87+
88+
var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] );
89+
var B = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
90+
91+
dtrsm( 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0 );
92+
// B => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 1.0, 0.0, -7.0, -5.0, -3.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+
- **α**: 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 Float64Array = require( '@stdlib/array/float64' );
117+
118+
var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] );
119+
var B = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
120+
121+
dtrsm( 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0 );
122+
// B => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 1.0, 0.0, -7.0, -5.0, -3.0 ]
123+
```
124+
125+
</section>
126+
127+
<!-- /.usage -->
128+
129+
<section class="notes">
130+
131+
## Notes
132+
133+
- `dtrsm()` corresponds to the [BLAS][blas] level 3 function [`dtrsm`][dtrsm].
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 dtrsm = require( '@stdlib/blas/base/dtrsm' );
148+
149+
var opts = {
150+
'dtype': 'float64'
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 = dtrsm( 'column-major', 'left', 'upper', 'no-transpose', 'non-unit', M, N, 1.0, A, N, B, N );
160+
console.log( out );
161+
162+
out = dtrsm.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+
[dtrsm]: https://www.netlib.org/lapack/explore-html/d9/de5/group__trsm_ga7120d931d7b1a15e12d50d328799df8a.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: 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 zeros = require( '@stdlib/array/zeros' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var pkg = require( './../package.json' ).name;
30+
var dtrsm = require( './../lib/dtrsm.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float64'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} N - array dimension size
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( N ) {
50+
var A = uniform( N*N, -10.0, 10.0, options );
51+
var B = zeros( N*N, options.dtype );
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 = dtrsm( 'row-major', 'left', 'lower', 'no-transpose', 'non-unit', N, N, 1.0, A, N, B, N );
67+
if ( isnan( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnan( 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 = 6; // 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)