Skip to content

Commit f86f889

Browse files
committed
feat: add blas/base/dtrsv
--- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0643a79 commit f86f889

23 files changed

+3717
-7
lines changed

lib/node_modules/@stdlib/blas/base/dtrsv/README.md

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,75 @@ console.log( x );
184184

185185
<section class="usage">
186186

187+
<!-- C usage documentation. -->
188+
189+
<section class="usage">
190+
187191
### Usage
188192

189193
```c
190-
TODO
194+
#include "stdlib/blas/base/dtrsv.h"
195+
```
196+
197+
#### c_dtrsv( order, uplo, trans, diag, N, \*A, LDA, \*X, strideX )
198+
199+
Solves one of the systems of equations `A*x = b` or `A^T*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.
200+
201+
```c
202+
#include "stdlib/blas/base/shared.h"
203+
204+
double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
205+
const double x[] = { 1.0, 2.0, 3.0 };
206+
207+
c_dtrsv( CblasRowMajor, CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, x, 1 );
208+
```
209+
210+
The function accepts the following arguments:
211+
212+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
213+
- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
214+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
215+
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
216+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
217+
- **A**: `[inout] double*` input matrix.
218+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
219+
- **X**: `[in] double*` input vector.
220+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
221+
222+
```c
223+
void c_dtrsv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const CBLAS_DIAG diag, const CBLAS_INT N, const double *A, const CBLAS_INT LDA, double *x, const CBLAS_INT strideX )
191224
```
192225

193-
#### TODO
226+
<!-- lint disable maximum-heading-length -->
227+
#### c_dtrsv_ndarray( uplo, trans, diag, N, \*A, strideA1, strideA2, offsetA, \*X, strideX, offsetA )
194228

195-
TODO.
229+
Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x` using alternative indexing semantics, where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
196230

197231
```c
198-
TODO
232+
#include "stdlib/blas/base/shared.h"
233+
234+
double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
235+
const double x[] = { 1.0, 2.0, 3.0 };
236+
237+
c_dtrsv_ndarray( CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, 1, 0, x, 1, 0 );
199238
```
200239
201-
TODO
240+
The function accepts the following arguments:
241+
242+
- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
243+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
244+
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
245+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
246+
- **A**: `[inout] double*` input matrix.
247+
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
248+
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
249+
- **offsetA**: `[in] CBLAS_INT` starting index for `A`.
250+
- **X**: `[in] double*` input vector.
251+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
252+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
202253
203254
```c
204-
TODO
255+
void c_dtrsv_ndarray( const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const CBLAS_DIAG diag, const CBLAS_INT N, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, double *x, const CBLAS_INT strideX, const CBLAS_INT offsetX )
205256
```
206257

207258
</section>
@@ -223,7 +274,34 @@ TODO
223274
### Examples
224275

225276
```c
226-
TODO
277+
#include "stdlib/blas/base/dtrsv.h"
278+
#include "stdlib/blas/base/shared.h"
279+
#include <stdio.h>
280+
281+
int main( void ) {
282+
// Create a strided array:
283+
const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
284+
double X[] = { 1.0, 2.0, 3.0 };
285+
286+
// Specify the number of elements along each dimension of `A`:
287+
const int N = 3;
288+
289+
// Perform the matrix-vector operations `A*X = b` for `lower` triangular matrix `A`:
290+
c_dtrsv( CblasRowMajor, CblasLower, CblasNoTrans, CblasNonUnit, N, A, N, X, 1 );
291+
292+
// Print the result:
293+
for ( int i = 0; i < N; i++ ) {
294+
printf( "X[ %i ] = %f\n", i, X[ i ] );
295+
}
296+
297+
// Perform the matrix-vector operations `A*X = b` for `lower` triangular matrix `A`:
298+
c_dtrsv_ndarray( CblasLower, CblasNoTrans, CblasNonUnit, N, A, N, 1, 0, X, 1, 0 );
299+
300+
// Print the result:
301+
for ( int i = 0; i < N; i++ ) {
302+
printf( "X[ %i ] = %f\n", i, X[ i ] );
303+
}
304+
}
227305
```
228306
229307
</section>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
'use strict';
21+
22+
// MODULES //
23+
24+
var resolve = require( 'path' ).resolve;
25+
var bench = require( '@stdlib/bench' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
29+
var pow = require( '@stdlib/math/base/special/pow' );
30+
var floor = require( '@stdlib/math/base/special/floor' );
31+
var tryRequire = require( '@stdlib/utils/try-require' );
32+
var pkg = require( './../package.json' ).name;
33+
34+
35+
// VARIABLES //
36+
37+
var dtrsv = tryRequire( resolve( __dirname, './../lib/dtrsv.native.js' ) );
38+
var opts = {
39+
'skip': ( dtrsv instanceof Error )
40+
};
41+
var options = {
42+
'dtype': 'float64'
43+
};
44+
45+
46+
// FUNCTIONS //
47+
48+
/**
49+
* Creates a benchmark function.
50+
*
51+
* @private
52+
* @param {PositiveInteger} N - number of elements along each dimension
53+
* @returns {Function} benchmark function
54+
*/
55+
function createBenchmark( N ) {
56+
var A = discreteUniform( N*N, -10.0, 10.0, options );
57+
var x = zeros( N, options.dtype );
58+
return benchmark;
59+
60+
/**
61+
* Benchmark function.
62+
*
63+
* @private
64+
* @param {Benchmark} b - benchmark instance
65+
*/
66+
function benchmark( b ) {
67+
var z;
68+
var i;
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
z = dtrsv( 'row-major', 'upper', 'transpose', 'non-unit', N, A, N, x, 1 );
73+
if ( isnan( z[ i%z.length ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( z[ i%z.length ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var min;
96+
var max;
97+
var N;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
106+
f = createBenchmark( N );
107+
bench( pkg+':size='+(N*N), opts, f );
108+
}
109+
}
110+
111+
main();
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
27+
var zeros = require( '@stdlib/array/zeros' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var dtrsv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
37+
var opts = {
38+
'skip': ( dtrsv instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} N - number of elements along each dimension
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( N ) {
55+
var A = discreteUniform( N*N, -10.0, 10.0, options );
56+
var x = zeros( N, options.dtype );
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var z;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
z = dtrsv( 'upper', 'transpose', 'non-unit', N, A, N, 1, 0, x, 1, 0 );
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnan( z[ i%z.length ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var min;
95+
var max;
96+
var N;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( N );
106+
bench( pkg+':ndarray:size='+(N*N), opts, f );
107+
}
108+
}
109+
110+
main();

0 commit comments

Comments
 (0)