Skip to content

Commit f90d065

Browse files
committed
chore: add implementation
--- 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: na - task: lint_repl_help status: na - 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: na - 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: na - 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 1220dd4 commit f90d065

File tree

10 files changed

+1499
-42
lines changed

10 files changed

+1499
-42
lines changed

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

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

96+
<!-- lint disable maximum-heading-length -->
97+
9698
#### sgemv.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/sgemv.h"
200202
```
201203

202-
#### TODO
204+
#### c_sgemv( order, trans, M, N, alpha, \*A, LDA, \*X, strideX, beta, \*Y, strideY )
205+
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.
207+
208+
```c
209+
#include "stdlib/blas/base/shared.h"
210+
211+
float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
212+
const float x[] = { 1.0f, 2.0f, 3.0f };
213+
const float y[] = { 1.0f, 2.0f, 3.0f };
214+
215+
c_sgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0f, A, 3, x, 1, 1.0f, y, 1 );
216+
```
217+
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] float` scalar.
225+
- **A**: `[inout] float*` 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] float*` first input vector.
228+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
229+
- **beta**: `[in] float` scalar.
230+
- **Y**: `[in] float*` second input vector.
231+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
232+
233+
```c
234+
void c_sgemv( const CBLAS_LAYOUT order, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT LDA, const float *x, const CBLAS_INT strideX, const float beta, float *y, const CBLAS_INT strideY )
235+
```
236+
237+
#### c_sgemv_ndarray( trans, M, N, alpha, \*A, sa1, sa2, oa, \*X, sx, ox, beta, \*Y, sy, oy )
203238

204-
TODO.
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.
205240

206241
```c
207-
TODO
242+
#include "stdlib/blas/base/shared.h"
243+
244+
float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
245+
const float x[] = { 1.0f, 2.0f, 3.0f };
246+
const float y[] = { 1.0f, 2.0f, 3.0f };
247+
248+
c_sgemv_ndarray( CblasNoTrans, 3, 3, 1.0f, A, 1, 3, 0, x, 1, 0, 1.0f, y, 1, 0 );
208249
```
209250
210-
TODO
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] float` scalar.
257+
- **A**: `[inout] float*` 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] float*` first input vector.
262+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
263+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
264+
- **beta**: `[in] float` scalar.
265+
- **Y**: `[in] float*` second input vector.
266+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
267+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
211268
212269
```c
213-
TODO
270+
void c_sgemv_ndarray( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const float *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float beta, float *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/sgemv.h"
293+
#include "stdlib/blas/base/shared.h"
294+
#include <stdio.h>
295+
296+
int main( void ) {
297+
// Create a strided array:
298+
const float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
299+
const float x[] = { 1.0f, 2.0f, 3.0f };
300+
float 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_sgemv( 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 ] = %f\n", i, y[ i ] );
312+
}
313+
314+
// Perform the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`:
315+
c_sgemv_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 ] = %f\n", i, y[ i ] );
320+
}
321+
}
236322
```
237323
238324
</section>

lib/node_modules/@stdlib/blas/base/sgemv/examples/c/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ int main( void ) {
3131
const int N = 3;
3232

3333
// Perform the matrix-vector operations `y = α*A*x + β*y`:
34-
c_sgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0f, A, 1, x, 1, 1.0f, y, 1 );
34+
c_sgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0f, A, M, x, 1, 1.0f, y, 1 );
3535

3636
// Print the result:
3737
for ( int i = 0; i < N; i++ ) {
3838
printf( "y[ %i ] = %f\n", i, y[ i ] );
3939
}
4040

4141
// Perform the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`:
42-
c_sgemv_ndarray( CblasNoTrans, M, N, 1.0f, A, 1, 1, 0, x, 1, 0, 1.0f, y, 1, 0 );
42+
c_sgemv_ndarray( CblasNoTrans, 3, 3, 1.0f, A, 3, 1, 0, x, 1, 0, 1.0f, y, 1, 0 );
4343

4444
// Print the result:
4545
for ( int i = 0; i < N; i++ ) {

lib/node_modules/@stdlib/blas/base/sgemv/examples/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ var A = discreteUniform( M*N, 0, 255, opts );
3232
var x = discreteUniform( N, 0, 255, opts );
3333
var y = discreteUniform( M, 0, 255, opts );
3434

35-
sgemv( 'row-major', 'no-transpose', M, N, 1.0, A, N, x, -1, 1.0, y, -1 );
35+
sgemv( 'row-major', 'no-transpose', M, N, 1.0, A, N, x, 1, 1.0, y, 1 );
36+
console.log( y );
37+
38+
sgemv.ndarray( 'no-transpose', M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
3639
console.log( y );

lib/node_modules/@stdlib/blas/base/sgemv/lib/ndarray.native.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ var addon = require( './../src/addon.node' );
5656
*
5757
* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
5858
* var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
59-
* var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );
59+
* var y = new Float32Array( [ 1.0, 1.0 ] );
6060
*
6161
* sgemv( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
62-
* // y => <Float32Array>[ 6.0, 8.0, 1.0 ]
62+
* // y => <Float32Array>[ 7.0, 16.0 ]
6363
*/
6464
function sgemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
65-
return addon.ndarray( resolveTrans( trans ), M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len
65+
addon.ndarray( resolveTrans( trans ), M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len
66+
return y;
6667
}
6768

6869

lib/node_modules/@stdlib/blas/base/sgemv/lib/sgemv.native.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ var addon = require( './../src/addon.node' );
5656
*
5757
* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
5858
* var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
59-
* var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );
59+
* var y = new Float32Array( [ 1.0, 1.0 ] );
6060
*
6161
* sgemv( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 );
62-
* // y => <Float32Array>[ 6.0, 8.0, 1.0 ]
62+
* // y => <Float32Array>[ 7.0, 16.0 ]
6363
*/
6464
function sgemv( order, trans, M, N, alpha, A, LDA, x, strideX, beta, y, strideY ) { // eslint-disable-line max-params, max-len
65-
return addon( resolveOrder( order ), resolveTrans( trans ), M, N, alpha, A, LDA, x, strideX, beta, y, strideY ); // eslint-disable-line max-len
65+
addon( resolveOrder( order ), resolveTrans( trans ), M, N, alpha, A, LDA, x, strideX, beta, y, strideY ); // eslint-disable-line max-len
66+
return y;
6667
}
6768

6869

lib/node_modules/@stdlib/blas/base/sgemv/src/addon.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,29 @@ static napi_value addon( napi_env env, napi_callback_info info ) {
4949
STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 4 );
5050
STDLIB_NAPI_ARGV_FLOAT( env, beta, argv, 9 );
5151

52-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 7 );
53-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 10 );
54-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, M, N, LDA, 1, argv, 5 );
52+
CBLAS_INT xlen;
53+
CBLAS_INT ylen;
54+
CBLAS_INT sa1;
55+
CBLAS_INT sa2;
56+
57+
if ( trans == CblasNoTrans ) {
58+
xlen = N;
59+
ylen = M;
60+
} else {
61+
xlen = M;
62+
ylen = N;
63+
}
64+
if ( order == CblasColMajor ) {
65+
sa1 = 1;
66+
sa2 = LDA;
67+
} else { // order === 'row-major'
68+
sa1 = LDA;
69+
sa2 = 1;
70+
}
71+
72+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, xlen, strideX, argv, 7 );
73+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, ylen, strideY, argv, 10 );
74+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, M, N, sa1, sa2, argv, 5 );
5575

5676
API_SUFFIX(c_sgemv)( order, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY );
5777

@@ -83,8 +103,19 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) {
83103
STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 3 );
84104
STDLIB_NAPI_ARGV_FLOAT( env, beta, argv, 11 );
85105

86-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 8 );
87-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 12 );
106+
CBLAS_INT xlen;
107+
CBLAS_INT ylen;
108+
109+
if ( trans == CblasNoTrans ) {
110+
xlen = N;
111+
ylen = M;
112+
} else {
113+
xlen = M;
114+
ylen = N;
115+
}
116+
117+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, xlen, strideX, argv, 8 );
118+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, ylen, strideY, argv, 12 );
88119
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, M, N, strideA1, strideA2, argv, 4 );
89120

90121
API_SUFFIX(c_sgemv_ndarray)( trans, M, N, alpha, A, strideA1, strideA2, offsetA, X, strideX, offsetX, beta, Y, strideY, offsetY );

lib/node_modules/@stdlib/blas/base/sgemv/src/sgemv.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@
3838
* @return output value
3939
*/
4040
void API_SUFFIX(c_sgemv)( const CBLAS_LAYOUT order, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT LDA, const float *x, const CBLAS_INT strideX, const float beta, float *y, const CBLAS_INT strideY ) {
41+
CBLAS_INT xlen;
42+
CBLAS_INT ylen;
4143
CBLAS_INT sa1;
4244
CBLAS_INT sa2;
4345
CBLAS_INT ox;
4446
CBLAS_INT oy;
4547

46-
if ( M == 0 || N == 0 || ( alpha == 0.0f && beta == 1.0f ) ) {
47-
return;
48+
if ( trans == CblasNoTrans ) {
49+
xlen = N;
50+
ylen = M;
51+
} else {
52+
xlen = M;
53+
ylen = N;
4854
}
4955
if ( order == CblasColMajor ) {
5056
sa1 = 1;
@@ -53,8 +59,8 @@ void API_SUFFIX(c_sgemv)( const CBLAS_LAYOUT order, const CBLAS_TRANSPOSE trans,
5359
sa1 = LDA;
5460
sa2 = 1;
5561
}
56-
ox = stdlib_strided_stride2offset( N, strideX );
57-
oy = stdlib_strided_stride2offset( N, strideY );
62+
ox = stdlib_strided_stride2offset( xlen, strideX );
63+
oy = stdlib_strided_stride2offset( ylen, strideY );
5864
API_SUFFIX(c_sgemv_ndarray)( trans, M, N, alpha, A, sa1, sa2, 0, x, strideX, ox, beta, y, strideY, oy );
5965
return;
6066
}

lib/node_modules/@stdlib/blas/base/sgemv/src/sgemv_ndarray.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ void API_SUFFIX(c_sgemv_ndarray)( const CBLAS_TRANSPOSE trans, const CBLAS_INT M
5858
// Note on variable naming convention: sa#, ix#, i# where # corresponds to the loop number, with `0` being the innermost loop...
5959

6060
int64_t strides[] = { strideA1, strideA2 };
61+
isrm = stdlib_ndarray_is_row_major( 2, strides );
6162
if ( M == 0 || N == 0 || ( alpha == 0.0f && beta == 1.0f ) ) {
6263
return;
6364
}
64-
isrm = stdlib_ndarray_is_row_major( 2, strides );
6565
if ( isrm ) {
66-
// For row-major matrices, the last dimension has the fastest changing index...
67-
sa0 = strideA2; // stride for innermost loop
68-
sa1 = strideA1; // stride for outermost loop
69-
} else { // isColMajor
70-
// For column-major matrices, the first dimension has the fastest changing index...
71-
sa0 = strideA1; // stride for innermost loop
72-
sa1 = strideA2; // stride for outermost loop
66+
sa0 = strideA2;
67+
sa1 = strideA1;
68+
} else {
69+
sa0 = strideA1;
70+
sa1 = strideA2;
7371
}
74-
if ( CblasNoTrans ) {
72+
73+
if ( trans == CblasNoTrans ) {
7574
xlen = N;
7675
ylen = M;
7776
} else {
7877
xlen = M;
7978
ylen = N;
8079
}
81-
// y = beta*y
80+
81+
// y = beta * y
8282
if ( beta != 1.0f ) {
8383
if ( beta == 0.0f ) {
8484
stdlib_strided_sfill_ndarray( ylen, 0.0f, y, strideY, offsetY );
@@ -90,17 +90,14 @@ void API_SUFFIX(c_sgemv_ndarray)( const CBLAS_TRANSPOSE trans, const CBLAS_INT M
9090
return;
9191
}
9292
// Form: y = α*A*x + y
93-
if (
94-
( isrm && CblasNoTrans ) ||
95-
( !isrm && CblasTrans )
96-
) {
93+
if ( ( !isrm && trans == CblasNoTrans ) || ( isrm && trans != CblasNoTrans ) ) {
9794
ix1 = offsetX;
9895
for ( i1 = 0; i1 < xlen; i1++ ) {
9996
tmp = alpha * x[ ix1 ];
100-
oa = offsetA + (sa1*i1);
97+
oa = offsetA + sa1 * i1;
10198
iy1 = offsetY;
10299
for ( i0 = 0; i0 < ylen; i0++ ) {
103-
y[ iy1 ] += A[ oa+(sa0*i0) ] * tmp;
100+
y[ iy1 ] += A[ oa + sa0 * i0 ] * tmp;
104101
iy1 += strideY;
105102
}
106103
ix1 += strideX;
@@ -114,9 +111,9 @@ void API_SUFFIX(c_sgemv_ndarray)( const CBLAS_TRANSPOSE trans, const CBLAS_INT M
114111
for ( i1 = 0; i1 < ylen; i1++ ) {
115112
tmp = 0.0f;
116113
ix1 = offsetX;
117-
oa = offsetA + (sa1*i1);
114+
oa = offsetA + sa1 * i1;
118115
for ( i0 = 0; i0 < xlen; i0++ ) {
119-
tmp += A[ oa+(sa0*i0) ] * x[ ix1 ];
116+
tmp += A[ oa + sa0 * i0 ] * x[ ix1 ];
120117
ix1 += strideX;
121118
}
122119
y[ iy1 ] += alpha * tmp;

0 commit comments

Comments
 (0)