Skip to content

Commit 3c82dfc

Browse files
committed
feat: add blas/base/ctrsv
1 parent 75860d1 commit 3c82dfc

50 files changed

Lines changed: 5544 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# ctrsv
22+
23+
> Solve one of the systems of equations `A*x = b` or `A^T*x = b` or `A^H*x = b`.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ctrsv = require( '@stdlib/blas/base/ctrsv' );
31+
```
32+
33+
#### ctrsv( order, uplo, trans, diag, N, A, LDA, x, sx )
34+
35+
Solves one of the systems of equations `A*x = b`, `A^T*x = b`, or `A^H*x = b` where `b` and `x` are `N` element vectors and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
36+
37+
```javascript
38+
var Complex64Array = require( '@stdlib/array/complex64' );
39+
40+
var A = new Complex64Array( [ 1.0, 0.0, 3.0, 4.0, 0.0, 0.0, 1.0, 0.0 ] );
41+
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
42+
43+
ctrsv( 'row-major', 'upper', 'no-transpose', 'unit', 2, A, 2, x, 1 );
44+
// x => <Complex64Array>[ 8.0, -22.0, 3.0, 4.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout.
50+
- **uplo**: specifies whether `A` is an upper or lower triangular matrix.
51+
- **trans**: specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
52+
- **diag**: specifies whether `A` has a unit diagonal.
53+
- **N**: number of elements along each dimension of `A`.
54+
- **A**: input matrix stored in linear memory as a [`Complex64Array`][@stdlib/array/complex64].
55+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
56+
- **x**: input vector [`Complex64Array`][@stdlib/array/complex64].
57+
- **sx**: `x` stride length.
58+
59+
The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `x` in reverse order,
60+
61+
```javascript
62+
var Complex64Array = require( '@stdlib/array/complex64' );
63+
64+
var A = new Complex64Array( [ 1.0, 0.0, 3.0, 4.0, 0.0, 0.0, 1.0, 0.0 ] );
65+
var x = new Complex64Array( [ 3.0, 4.0, 1.0, 2.0 ] );
66+
67+
ctrsv( 'row-major', 'upper', 'no-transpose', 'unit', 2, A, 2, x, -1 );
68+
// x => <Complex64Array>[ 3.0, 4.0, 8.0, -22.0 ]
69+
```
70+
71+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
72+
73+
<!-- eslint-disable stdlib/capitalized-comments -->
74+
75+
```javascript
76+
var Complex64Array = require( '@stdlib/array/complex64' );
77+
78+
// Initial arrays...
79+
var x0 = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] );
80+
var A = new Complex64Array( [ 1.0, 0.0, 3.0, 4.0, 0.0, 0.0, 1.0, 0.0 ] );
81+
82+
// Create offset views...
83+
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
84+
85+
ctrsv( 'row-major', 'upper', 'no-transpose', 'unit', 2, A, 2, x1, 1 );
86+
// x0 => <Complex64Array>[ 1.0, 1.0, 5.0, -19.0, 3.0, 3.0, 4.0, 4.0 ]
87+
```
88+
89+
#### ctrsv.ndarray( uplo, trans, diag, N, A, sa1, sa2, oa, x, sx, ox )
90+
91+
Solves one of the systems of equations `A*x = b` or `A^T*x = b` or `A^H*x = b`, using alternative indexing semantics and where `b` and `x` are `N` element vectors and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
92+
93+
```javascript
94+
var Complex64Array = require( '@stdlib/array/complex64' );
95+
96+
var A = new Complex64Array( [ 1.0, 0.0, 3.0, 4.0, 0.0, 0.0, 1.0, 0.0 ] );
97+
var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
98+
99+
ctrsv.ndarray( 'upper', 'no-transpose', 'unit', 2, A, 2, 1, 0, x, 1, 0 );
100+
// x => <Complex64Array>[ 8.0, -22.0, 3.0, 4.0 ]
101+
```
102+
103+
The function has the following additional parameters:
104+
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+
- **ox**: starting index for `x`.
109+
110+
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,
111+
112+
```javascript
113+
var Complex64Array = require( '@stdlib/array/complex64' );
114+
115+
var A = new Complex64Array( [ 1.0, 0.0, 3.0, 4.0, 0.0, 0.0, 1.0, 0.0 ] );
116+
var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
117+
118+
ctrsv.ndarray( 'upper', 'no-transpose', 'unit', 2, A, 2, 1, 0, x, 1, 1 );
119+
// x => <Complex64Array>[ 1.0, 1.0, 5.0, -19.0, 3.0, 3.0 ]
120+
```
121+
122+
</section>
123+
124+
<!-- /.usage -->
125+
126+
<section class="notes">
127+
128+
## Notes
129+
130+
- `ctrsv()` corresponds to the [BLAS][blas] level 2 function [`ctrsv`][blas-ctrsv].
131+
- Neither routine tests for singularity or near-singularity. Such tests must be performed before calling the routines.
132+
133+
</section>
134+
135+
<!-- /.notes -->
136+
137+
<section class="examples">
138+
139+
## Examples
140+
141+
<!-- eslint no-undef: "error" -->
142+
143+
```javascript
144+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
145+
var Complex64Array = require( '@stdlib/array/complex64' );
146+
var ctrsv = require( '@stdlib/blas/base/ctrsv' );
147+
148+
var opts = {
149+
'dtype': 'float32'
150+
};
151+
152+
var N = 5;
153+
154+
// Generate interleaved real and imaginary components:
155+
var Abuf = discreteUniform( N * N * 2, -10.0, 10.0, opts );
156+
var A = new Complex64Array( Abuf.buffer );
157+
158+
var xbuf = discreteUniform( N * 2, -10.0, 10.0, opts );
159+
var x = new Complex64Array( xbuf.buffer );
160+
161+
ctrsv( 'column-major', 'upper', 'no-transpose', 'unit', N, A, N, x, 1 );
162+
console.log( x );
163+
164+
ctrsv.ndarray( 'upper', 'no-transpose', 'unit', N, A, 1, N, 0, x, 1, 0 );
165+
console.log( x );
166+
```
167+
168+
</section>
169+
170+
<!-- /.examples -->
171+
172+
<!-- C interface documentation. -->
173+
174+
* * *
175+
176+
<section class="c">
177+
178+
## C APIs
179+
180+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
181+
182+
<section class="intro">
183+
184+
</section>
185+
186+
<!-- /.intro -->
187+
188+
<!-- C usage documentation. -->
189+
190+
<section class="usage">
191+
192+
### Usage
193+
194+
```c
195+
TODO
196+
```
197+
198+
#### TODO
199+
200+
TODO.
201+
202+
```c
203+
TODO
204+
```
205+
206+
TODO
207+
208+
```c
209+
TODO
210+
```
211+
212+
</section>
213+
214+
<!-- /.usage -->
215+
216+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
217+
218+
<section class="notes">
219+
220+
</section>
221+
222+
<!-- /.notes -->
223+
224+
<!-- C API usage examples. -->
225+
226+
<section class="examples">
227+
228+
### Examples
229+
230+
```c
231+
TODO
232+
```
233+
234+
</section>
235+
236+
<!-- /.examples -->
237+
238+
</section>
239+
240+
<!-- /.c -->
241+
242+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
243+
244+
<section class="related">
245+
246+
</section>
247+
248+
<!-- /.related -->
249+
250+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
251+
252+
<section class="links">
253+
254+
[blas]: http://www.netlib.org/blas
255+
256+
[blas-ctrsv]: https://www.netlib.org/lapack/explore-html/dd/dc3/group__trsv_gab8c2d2a6476f67197ba1f92aff4a0b92.html
257+
258+
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
259+
260+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
261+
262+
</section>
263+
264+
<!-- /.links -->
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var format = require( '@stdlib/string/format' );
29+
var Complex64Array = require( '@stdlib/array/complex64' );
30+
var pkg = require( './../package.json' ).name;
31+
var ctrsv = require( './../lib/ctrsv.js' );
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} len - array length
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( len ) {
51+
var xbuf;
52+
var x;
53+
var A;
54+
55+
xbuf = uniform( len*2, -100.0, 100.0, options );
56+
x = new Complex64Array( xbuf.buffer );
57+
A = new Complex64Array( uniform( len*len*2, -100.0, 100.0, options ).buffer );
58+
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var z;
69+
var i;
70+
71+
b.tic();
72+
for ( i = 0; i < b.iterations; i++ ) {
73+
z = ctrsv( 'row-major', 'upper', 'transpose', 'non-unit', len, A, len, x, 1 );
74+
if ( isnanf( xbuf[ i%(len*2) ] ) ) {
75+
b.fail( 'should not return NaN' );
76+
}
77+
}
78+
b.toc();
79+
if ( isnanf( xbuf[ i%(len*2) ] ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
b.pass( 'benchmark finished' );
83+
b.end();
84+
}
85+
}
86+
87+
88+
// MAIN //
89+
90+
/**
91+
* Main execution sequence.
92+
*
93+
* @private
94+
*/
95+
function main() {
96+
var len;
97+
var min;
98+
var max;
99+
var f;
100+
var i;
101+
102+
min = 1; // 10^min
103+
max = 6; // 10^max
104+
105+
for ( i = min; i <= max; i++ ) {
106+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
107+
f = createBenchmark( len );
108+
bench( format( '%s:len=%d', pkg, len ), f );
109+
}
110+
}
111+
112+
main();

0 commit comments

Comments
 (0)