Skip to content

Commit 6f9e180

Browse files
committed
feat: add blas/base/ctrsm
--- 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 0c31eaf commit 6f9e180

40 files changed

Lines changed: 6230 additions & 0 deletions
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# ctrsm
22+
23+
> Solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ctrsm = require( '@stdlib/blas/base/ctrsm' );
31+
```
32+
33+
#### ctrsm( order, side, uplo, transa, diag, M, N, alpha, A, LDA, B, LDB )
34+
35+
Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `alpha` 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`, `op(A) = A^T`, or `op(A) = A^H`. The matrix `X` is overwritten on `B`.
36+
37+
```javascript
38+
var Complex64Array = require( '@stdlib/array/complex64' );
39+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
40+
41+
var A = new Complex64Array( [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] );
42+
var B = new Complex64Array( [ 4.0, 0.0, 2.0, 0.0 ] );
43+
var alpha = new Complex64( 1.0, 0.0 );
44+
45+
ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 );
46+
// B => <Complex64Array>[ 1.5, 0.0, 1.0, 0.0 ]
47+
```
48+
49+
The function has the following parameters:
50+
51+
- **order**: storage layout.
52+
- **side**: specifies whether `A` appears on the `'left'` or `'right'` of `X`.
53+
- **uplo**: specifies whether the `'upper'` or `'lower'` triangular part of `A` is used.
54+
- **transa**: transpose operation applied to `A` (`'no-transpose'`, `'transpose'`, or `'conjugate-transpose'`).
55+
- **diag**: specifies whether `A` is `'unit'` or `'non-unit'` triangular.
56+
- **M**: number of rows in `B`.
57+
- **N**: number of columns in `B`.
58+
- **alpha**: scalar constant of type `Complex64`.
59+
- **A**: input triangular matrix stored in a `Complex64Array`.
60+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of `A`).
61+
- **B**: input/output matrix stored in a `Complex64Array`. On exit, overwritten with solution `X`.
62+
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of `B`).
63+
64+
#### ctrsm.ndarray( ord, sd, ul, ta, dg, M, N, aRe, aIm, A, sa1, oa, B, sb1, ob )
65+
66+
Solves one of the matrix equations using alternative indexing semantics.
67+
68+
```javascript
69+
var Complex64Array = require( '@stdlib/array/complex64' );
70+
71+
var A = new Complex64Array( [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] );
72+
var B = new Complex64Array( [ 4.0, 0.0, 2.0, 0.0 ] );
73+
74+
ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 );
75+
// B => <Complex64Array>[ 1.5, 0.0, 1.0, 0.0 ]
76+
```
77+
78+
The function accepts the following additional parameters:
79+
80+
- **aRe**: real part of scalar constant `alpha`.
81+
- **aIm**: imaginary part of scalar constant `alpha`.
82+
- **sa1**: stride of the first dimension of `A`.
83+
- **oa**: starting index for `A`.
84+
- **sb1**: stride of the first dimension of `B`.
85+
- **ob**: starting index for `B`.
86+
87+
</section>
88+
89+
<!-- /.usage -->
90+
91+
<section class="notes">
92+
93+
## Notes
94+
95+
- `ctrsm()` corresponds to the [BLAS][blas] level 3 function [`ctrsm`][blas-ctrsm].
96+
- Neither routine tests for singularity or near-singularity of `A`. Such tests must be performed before calling these routines.
97+
98+
</section>
99+
100+
<!-- /.notes -->
101+
102+
<section class="examples">
103+
104+
## Examples
105+
106+
```javascript
107+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
108+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
109+
var ctrsm = require( '@stdlib/blas/base/ctrsm' );
110+
111+
var N = 3;
112+
113+
var opts = {
114+
'dtype': 'complex64'
115+
};
116+
var A = discreteUniform( N * N, -10, 10, opts );
117+
var B = discreteUniform( N * N, -10, 10, opts );
118+
var alpha = new Complex64( 1.0, 0.0 );
119+
120+
ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N );
121+
console.log( B );
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
129+
130+
<section class="related">
131+
132+
* * *
133+
134+
## See Also
135+
136+
- <span class="package-name">[`@stdlib/blas/base/strsm`][@stdlib/blas/base/strsm]</span><span class="delimiter">: </span><span class="description">solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `A` is a real single-precision triangular matrix.</span>
137+
- <span class="package-name">[`@stdlib/blas/base/dtrsm`][@stdlib/blas/base/dtrsm]</span><span class="delimiter">: </span><span class="description">solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `A` is a real double-precision triangular matrix.</span>
138+
- <span class="package-name">[`@stdlib/blas/base/ztrsm`][@stdlib/blas/base/ztrsm]</span><span class="delimiter">: </span><span class="description">solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `A` is a complex double-precision triangular matrix.</span>
139+
140+
</section>
141+
142+
<!-- /.related -->
143+
144+
<section class="links">
145+
146+
[blas]: http://www.netlib.org/blas
147+
148+
[blas-ctrsm]: https://www.netlib.org/lapack/explore-html/d1/d54/group__complex__blas__level3_ga7dbc51a6f35e10bc3c63dfc62c1d6db8.html
149+
150+
[@stdlib/blas/base/strsm]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/strsm
151+
152+
[@stdlib/blas/base/dtrsm]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dtrsm
153+
154+
[@stdlib/blas/base/ztrsm]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ztrsm
155+
156+
</section>
157+
158+
<!-- /.links -->
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 Complex64Array = require( '@stdlib/array/complex64' );
28+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
var ctrsm = require( './../lib' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float32'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - matrix dimension
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var alpha;
52+
var abuf;
53+
var bbuf;
54+
var A;
55+
var B;
56+
57+
abuf = uniform( N*N*2, -100.0, 100.0, options );
58+
bbuf = uniform( N*N*2, -100.0, 100.0, options );
59+
A = new Complex64Array( abuf.buffer );
60+
B = new Complex64Array( bbuf.buffer );
61+
alpha = new Complex64( 1.0, 0.0 );
62+
63+
return benchmark;
64+
65+
/**
66+
* Benchmark function.
67+
*
68+
* @private
69+
* @param {Benchmark} b - benchmark instance
70+
*/
71+
function benchmark( b ) {
72+
var i;
73+
74+
b.tic();
75+
for ( i = 0; i < b.iterations; i++ ) {
76+
ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N );
77+
if ( isnanf( bbuf[ i%(N*N*2) ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
}
81+
b.toc();
82+
if ( isnanf( bbuf[ i%(N*N*2) ] ) ) {
83+
b.fail( 'should not return NaN' );
84+
}
85+
b.pass( 'benchmark finished' );
86+
b.end();
87+
}
88+
}
89+
90+
91+
// MAIN //
92+
93+
/**
94+
* Main execution sequence.
95+
*
96+
* @private
97+
*/
98+
function main() {
99+
var len;
100+
var min;
101+
var max;
102+
var f;
103+
var i;
104+
105+
min = 1; // 10^min
106+
max = 3; // 10^max
107+
108+
for ( i = min; i <= max; i++ ) {
109+
len = pow( 10, i );
110+
f = createBenchmark( len );
111+
bench( format( '%s:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), f );
112+
}
113+
}
114+
115+
main();
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var Complex64Array = require( '@stdlib/array/complex64' );
29+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var format = require( '@stdlib/string/format' );
32+
var pkg = require( './../package.json' ).name;
33+
34+
35+
// VARIABLES //
36+
37+
var ctrsm = tryRequire( resolve( __dirname, './../lib/ctrsm.native.js' ) );
38+
var opts = {
39+
'skip': ( ctrsm instanceof Error )
40+
};
41+
var options = {
42+
'dtype': 'float32'
43+
};
44+
45+
46+
// FUNCTIONS //
47+
48+
/**
49+
* Creates a benchmark function.
50+
*
51+
* @private
52+
* @param {PositiveInteger} N - matrix dimension
53+
* @returns {Function} benchmark function
54+
*/
55+
function createBenchmark( N ) {
56+
var alpha;
57+
var abuf;
58+
var bbuf;
59+
var A;
60+
var B;
61+
62+
abuf = uniform( N*N*2, -100.0, 100.0, options );
63+
bbuf = uniform( N*N*2, -100.0, 100.0, options );
64+
A = new Complex64Array( abuf.buffer );
65+
B = new Complex64Array( bbuf.buffer );
66+
alpha = new Complex64( 1.0, 0.0 );
67+
68+
return benchmark;
69+
70+
/**
71+
* Benchmark function.
72+
*
73+
* @private
74+
* @param {Benchmark} b - benchmark instance
75+
*/
76+
function benchmark( b ) {
77+
var i;
78+
79+
b.tic();
80+
for ( i = 0; i < b.iterations; i++ ) {
81+
ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N );
82+
if ( isnanf( bbuf[ i%(N*N*2) ] ) ) {
83+
b.fail( 'should not return NaN' );
84+
}
85+
}
86+
b.toc();
87+
if ( isnanf( bbuf[ i%(N*N*2) ] ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
b.pass( 'benchmark finished' );
91+
b.end();
92+
}
93+
}
94+
95+
96+
// MAIN //
97+
98+
/**
99+
* Main execution sequence.
100+
*
101+
* @private
102+
*/
103+
function main() {
104+
var len;
105+
var min;
106+
var max;
107+
var f;
108+
var i;
109+
110+
min = 1; // 10^min
111+
max = 3; // 10^max
112+
113+
for ( i = min; i <= max; i++ ) {
114+
len = pow( 10, i );
115+
f = createBenchmark( len );
116+
bench( format( '%s::native:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), opts, f );
117+
}
118+
}
119+
120+
main();

0 commit comments

Comments
 (0)