Skip to content

Commit 4cdad25

Browse files
committed
feat: add c implementation for blas/base/dtrmv
--- 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 696cf19 commit 4cdad25

File tree

23 files changed

+3532
-18
lines changed

23 files changed

+3532
-18
lines changed

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

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ dtrmv( 'row-major', 'upper', 'no-transpose', 'unit', 3, A, 3, x1, 1 );
8686
// x0 => <Float64Array>[ 1.0, 6.0, 3.0, 1.0 ]
8787
```
8888

89+
<!-- lint disable maximum-heading-length -->
90+
8991
#### dtrmv.ndarray( uplo, trans, diag, N, A, sa1, sa2, oa, x, sx, ox )
9092

9193
Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, using alternative indexing semantics and where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
@@ -163,44 +165,74 @@ console.log( x );
163165

164166
<!-- /.examples -->
165167

166-
<!-- C interface documentation. -->
168+
<!-- C usage documentation. -->
167169

168-
* * *
170+
<section class="usage">
169171

170-
<section class="c">
172+
### Usage
171173

172-
## C APIs
174+
```c
175+
#include "stdlib/blas/base/dtrmv.h"
176+
```
173177

174-
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
178+
#### c_dtrmv( order, uplo, trans, diag, N, \*A, LDA, \*X, strideX )
175179

176-
<section class="intro">
180+
Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
177181

178-
</section>
182+
```c
183+
#include "stdlib/blas/base/shared.h"
179184

180-
<!-- /.intro -->
185+
double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
186+
const double x[] = { 1.0, 2.0, 3.0 };
181187

182-
<!-- C usage documentation. -->
188+
c_dtrmv( CblasRowMajor, CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, x, 1 );
189+
```
183190
184-
<section class="usage">
191+
The function accepts the following arguments:
185192
186-
### Usage
193+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
194+
- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
195+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
196+
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
197+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
198+
- **A**: `[inout] double*` input matrix.
199+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
200+
- **X**: `[in] double*` input vector.
201+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
187202
188203
```c
189-
TODO
204+
void c_dtrmv( 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 )
190205
```
191206

192-
#### TODO
207+
#### c_dtrmv_ndarray( uplo, trans, diag, N, \*A, strideA1, strideA2, offsetA, \*X, strideX, offsetA )
193208

194-
TODO.
209+
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.
195210

196211
```c
197-
TODO
212+
#include "stdlib/blas/base/shared.h"
213+
214+
double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
215+
const double x[] = { 1.0, 2.0, 3.0 };
216+
217+
c_dtrmv_ndarray( CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, 1, 0, x, 1, 0 );
198218
```
199219
200-
TODO
220+
The function accepts the following arguments:
221+
222+
- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
223+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
224+
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
225+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
226+
- **A**: `[inout] double*` input matrix.
227+
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
228+
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
229+
- **offsetA**: `[in] CBLAS_INT` starting index for `A`.
230+
- **X**: `[in] double*` input vector.
231+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
232+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
201233
202234
```c
203-
TODO
235+
void c_dtrmv_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 )
204236
```
205237

206238
</section>
@@ -222,7 +254,34 @@ TODO
222254
### Examples
223255

224256
```c
225-
TODO
257+
#include "stdlib/blas/base/dtrmv.h"
258+
#include "stdlib/blas/base/shared.h"
259+
#include <stdio.h>
260+
261+
int main( void ) {
262+
// Create a strided array:
263+
const double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
264+
double x[] = { 1.0, 2.0, 3.0 };
265+
266+
// Specify the number of elements along each dimension of `A`:
267+
const int N = 3;
268+
269+
// Perform the matrix-vector operations `y = α*A*x + β*y`:
270+
c_dtrmv( CblasRowMajor, CblasUpper, CblasNoTrans, CblasUnit, N, A, N, x, 1 );
271+
272+
// Print the result:
273+
for ( int i = 0; i < N; i++ ) {
274+
printf( "x[ %i ] = %lf\n", i, x[ i ] );
275+
}
276+
277+
// Perform the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`:
278+
c_dtrmv_ndarray( CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, 1, 0, x, 1, 0 );
279+
280+
// Print the result:
281+
for ( int i = 0; i < N; i++ ) {
282+
printf( "x[ %i ] = %lf\n", i, x[ i ] );
283+
}
284+
}
226285
```
227286
228287
</section>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 ones = require( '@stdlib/array/ones' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var dgemv = tryRequire( resolve( __dirname, './../lib/dgemv.native.js' ) );
36+
var opts = {
37+
'skip': ( dgemv instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float64'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} len - array length
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( len ) {
54+
var x = ones( len, options.dtype );
55+
var A = ones( len*len, options.dtype );
56+
return benchmark;
57+
58+
function benchmark( b ) {
59+
var z;
60+
var i;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
z = dgemv( 'row-major', 'upper', 'transpose', 'non-unit', len, A, len, x, 1 );
65+
if ( isnan( z ) ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
}
69+
b.toc();
70+
if ( isnan( z ) ) {
71+
b.fail( 'should not return NaN' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
}
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var min;
88+
var max;
89+
var len;
90+
var f;
91+
var i;
92+
93+
min = 1; // 10^min
94+
max = 6; // 10^max
95+
96+
for ( i = min; i <= max; i++ ) {
97+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
98+
f = createBenchmark( len );
99+
bench( pkg+':size='+(len*len), opts, f );
100+
}
101+
}
102+
103+
main();
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 ones = require( '@stdlib/array/ones' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var dgemv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
36+
var opts = {
37+
'skip': ( dgemv instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float64'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} len - array length
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( len ) {
54+
var x = ones( len, options.dtype );
55+
var A = ones( len*len, options.dtype );
56+
return benchmark;
57+
58+
function benchmark( b ) {
59+
var z;
60+
var i;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
z = dgemv( 'upper', 'transpose', 'non-unit', len, A, len, 1, 0, x, 1, 0 );
65+
if ( isnan( z ) ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
}
69+
b.toc();
70+
if ( isnan( z ) ) {
71+
b.fail( 'should not return NaN' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
}
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var min;
88+
var max;
89+
var len;
90+
var f;
91+
var i;
92+
93+
min = 1; // 10^min
94+
max = 6; // 10^max
95+
96+
for ( i = min; i <= max; i++ ) {
97+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
98+
f = createBenchmark( len );
99+
bench( pkg+':size='+(len*len), opts, f );
100+
}
101+
}
102+
103+
main();

0 commit comments

Comments
 (0)