|
23 | 23 | #include "stdlib/ndarray/base/min_view_buffer_index.h" |
24 | 24 |
|
25 | 25 | /** |
26 | | -* 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. |
| 26 | +* 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. |
27 | 27 | * |
28 | 28 | * @param order storage layout |
29 | 29 | * @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed |
|
32 | 32 | * @param alpha scalar constant |
33 | 33 | * @param A input matrix |
34 | 34 | * @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) |
35 | | -* @param X first input vector |
36 | | -* @param strideX `X` stride length |
| 35 | +* @param x first input vector |
| 36 | +* @param strideX `x` stride length |
37 | 37 | * @param beta scalar constant |
38 | | -* @param Y second input vector |
39 | | -* @param strideY `Y` stride length |
| 38 | +* @param y second input vector |
| 39 | +* @param strideY `y` stride length |
40 | 40 | * @return output value |
41 | 41 | */ |
42 | | -double API_SUFFIX(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, const double *Y, const CBLAS_INT strideY ) { |
43 | | - return API_SUFFIX(cblas_dgemv)( order, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY ); |
| 42 | +double API_SUFFIX(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, const double *y, const CBLAS_INT strideY ) { |
| 43 | + CBLAS_INT sx = strideX; |
| 44 | + CBLAS_INT sy = strideY; |
| 45 | + if ( sx < 0 ) { |
| 46 | + sx = -sx; |
| 47 | + } |
| 48 | + if ( sy < 0 ) { |
| 49 | + sy = -sy; |
| 50 | + } |
| 51 | + return API_SUFFIX(cblas_dgemv)( order, trans, M, N, alpha, A, LDA, x, sx, beta, y, sy ); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | +* 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. |
| 56 | +* |
| 57 | +* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed |
| 58 | +* @param M number of rows in the matrix `A` |
| 59 | +* @param N number of columns in the matrix `A` |
| 60 | +* @param alpha scalar constant |
| 61 | +* @param A input matrix |
| 62 | +* @param strideA1 stride of the first dimension of `A` |
| 63 | +* @param strideA1 stride of the second dimension of `A` |
| 64 | +* @param offsetA starting index for `A` |
| 65 | +* @param x first input vector |
| 66 | +* @param strideX `x` stride length |
| 67 | +* @param offsetX starting index for `x` |
| 68 | +* @param beta scalar constant |
| 69 | +* @param y second input vector |
| 70 | +* @param strideY `y` stride length |
| 71 | +* @param offsetY starting index for `Y` |
| 72 | +* @return output value |
| 73 | +*/ |
| 74 | +double API_SUFFIX(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, const double *y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { |
| 75 | + CBLAS_INT sx = strideX; |
| 76 | + CBLAS_INT sy = strideY; |
| 77 | + if ( sx < 0 ) { |
| 78 | + sx = -sx; |
| 79 | + } |
| 80 | + if ( sy < 0 ) { |
| 81 | + sy = -sy; |
| 82 | + } |
| 83 | + x += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer |
| 84 | + y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer |
| 85 | + const int64_t shape[] = { M, N }; |
| 86 | + const int64_t strides[] = { strideA1, strideA2 }; |
| 87 | + A += stdlib_ndarray_min_view_buffer_index( 2, shape, strides, offsetA ); // adjust array pointer |
| 88 | + return API_SUFFIX(cblas_dgemv)( order, trans, M, N, alpha, A, LDA, x, sx, beta, y, sy ); |
44 | 89 | } |
0 commit comments