Skip to content

Commit 26fc04d

Browse files
committed
feat: add c implementation for blas/base/dgemv
--- 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 70d6643 commit 26fc04d

23 files changed

+3578
-6
lines changed

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

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 );
9393
// y0 => <Float64Array>[ 0.0, 8.0, 4.0 ]
9494
```
9595

96+
<!-- lint disable maximum-heading-length -->
97+
9698
#### dgemv.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy )
9799

98100
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A**T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
@@ -199,18 +201,73 @@ console.log( y );
199201
#include "stdlib/blas/base/dgemv.h"
200202
```
201203

202-
#### TODO
204+
#### c_dgemv( order, trans, M, N, alpha, \*A, LDA, \*X, strideX, beta, \*Y, strideY )
203205

204-
TODO.
206+
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
205207

206208
```c
207-
TODO
209+
#include "stdlib/blas/base/shared.h"
210+
211+
double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
212+
const double x[] = { 1.0, 2.0, 3.0 };
213+
const double y[] = { 1.0, 2.0, 3.0 };
214+
215+
c_dgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0, A, 3, x, 1, 1.0, y, 1 );
208216
```
209217
210-
TODO
218+
The function accepts the following arguments:
219+
220+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
221+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
222+
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
223+
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
224+
- **alpha**: `[in] double` scalar.
225+
- **A**: `[inout] double*` input matrix.
226+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
227+
- **X**: `[in] double*` first input vector.
228+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
229+
- **beta**: `[in] double` scalar.
230+
- **Y**: `[in] double*` second input vector.
231+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
211232
212233
```c
213-
TODO
234+
void c_dgemv( const CBLAS_LAYOUT order, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *x, const CBLAS_INT strideX, const double beta, double *y, const CBLAS_INT strideY )
235+
```
236+
237+
#### c_dgemv_ndarray( trans, M, N, alpha, \*A, sa1, sa2, oa, \*X, sx, ox, beta, \*Y, sy, oy )
238+
239+
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix using indexing alternative semantics.
240+
241+
```c
242+
#include "stdlib/blas/base/shared.h"
243+
244+
double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
245+
const double x[] = { 1.0, 2.0, 3.0 };
246+
const double y[] = { 1.0, 2.0, 3.0 };
247+
248+
c_dgemv_ndarray( CblasNoTrans, 3, 3, 1.0, A, 1, 3, 0, x, 1, 0, 1.0, y, 1, 0 );
249+
```
250+
251+
The function accepts the following arguments:
252+
253+
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
254+
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
255+
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
256+
- **alpha**: `[in] double` scalar.
257+
- **A**: `[inout] double*` input matrix.
258+
- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
259+
- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
260+
- **oa**: `[in] CBLAS_INT` starting index for `A`.
261+
- **X**: `[in] double*` first input vector.
262+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
263+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
264+
- **beta**: `[in] double` scalar.
265+
- **Y**: `[in] double*` second input vector.
266+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
267+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
268+
269+
```c
270+
void c_dgemv_ndarray( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *y, const CBLAS_INT strideY, const CBLAS_INT offsetY )
214271
```
215272

216273
</section>
@@ -232,7 +289,36 @@ TODO
232289
### Examples
233290

234291
```c
235-
TODO
292+
#include "stdlib/blas/base/dgemv.h"
293+
#include "stdlib/blas/base/shared.h"
294+
#include <stdio.h>
295+
296+
int main( void ) {
297+
// Create a strided array:
298+
const double A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
299+
const double x[] = { 1.0f, 2.0f, 3.0f };
300+
double y[] = { 1.0f, 2.0f, 3.0f };
301+
302+
// Specify the number of elements along each dimension of `A`:
303+
const int M = 3;
304+
const int N = 3;
305+
306+
// Perform the matrix-vector operations `y = α*A*x + β*y`:
307+
c_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0f, A, M, x, 1, 1.0f, y, 1 );
308+
309+
// Print the result:
310+
for ( int i = 0; i < N; i++ ) {
311+
printf( "y[ %i ] = %lf\n", i, y[ i ] );
312+
}
313+
314+
// Perform the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`:
315+
c_dgemv_ndarray( CblasNoTrans, 3, 3, 1.0f, A, 3, 1, 0, x, 1, 0, 1.0f, y, 1, 0 );
316+
317+
// Print the result:
318+
for ( int i = 0; i < N; i++ ) {
319+
printf( "y[ %i ] = %lf\n", i, y[ i ] );
320+
}
321+
}
236322
```
237323
238324
</section>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 y = ones( len, options.dtype );
56+
var A = ones( len*len, options.dtype );
57+
return benchmark;
58+
59+
function benchmark( b ) {
60+
var z;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
z = dgemv( 'row-major', 'no-transpose', len, len, 1.0, A, len, x, 1, 1.0, y, 1 );
66+
if ( isnan( z ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnan( z ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var min;
89+
var max;
90+
var len;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
99+
f = createBenchmark( len );
100+
bench( pkg+':size='+(len*len), opts, f );
101+
}
102+
}
103+
104+
main();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 y = ones( len, options.dtype );
56+
var A = ones( len*len, options.dtype );
57+
return benchmark;
58+
59+
function benchmark( b ) {
60+
var z;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
z = dgemv( 'no-transpose', len, len, 1.0, A, len, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
66+
if ( isnan( z ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnan( z ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var min;
89+
var max;
90+
var len;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
99+
f = createBenchmark( len );
100+
bench( pkg+':size='+(len*len), opts, f );
101+
}
102+
}
103+
104+
main();

0 commit comments

Comments
 (0)