Peano
Loading...
Searching...
No Matches
MatrixVectorOperations.cpph
Go to the documentation of this file.
1#ifdef UseOpenblas
2#include <cblas.h>
3#endif
4
5template <int Rows, int Cols, typename Scalar>
7 const Matrix<Rows, Cols, Scalar>& matrix,
8 const Vector<Cols, Scalar>& vector
9) {
10 tarch::la::Vector<Rows, Scalar> result(Scalar(0));
11 for (int i = 0; i < Rows; i++) {
12 for (int j = 0; j < Cols; j++) {
13 result(i) += matrix(i, j) * vector(j);
14 }
15 }
16 return result;
17}
18
19
23template <int Rows, int Cols, typename Scalar>
25 const Matrix<Rows, Cols, Scalar>& matrix,
26 Scalar alpha,
27 const Vector<Cols, Scalar>& v,
29) {
30 for (int i = 0; i < Rows; i++) {
31 for (int j = 0; j < Cols; j++) {
32 r(i) += alpha * matrix(i, j) * v(j);
33 }
34 }
35}
36
37
38template <int Rows, int Cols, typename Scalar>
40 const Matrix<Rows, Cols, Scalar>& matrix,
41 const Vector<Cols, Scalar>& vector
42) {
43 return multiply(matrix, vector);
44}
45
46#ifdef UseOpenblas
47template <int Rows, int Cols>
49 const Matrix<Rows, Cols, double>& matrix,
50 const Vector<Cols, double>& vector
51) {
53 cblas_dgemv(
54 CblasRowMajor,
55 CblasNoTrans,
56 Rows,
57 Cols,
58 1,
59 matrix.data(),
60 Rows,
61 vector.data(),
62 1,
63 0,
64 output.data(),
65 1
66 );
67 return output;
68}
69#endif
70
71template <int Size, typename Scalar>
73 const Vector<Size, Scalar>& lhs,
74 const Vector<Size, Scalar>& rhs
75) {
77 for (int i = 0; i < Size; i++) {
78 for (int j = 0; j < Size; j++) {
79 result(j, i) = lhs(j) * rhs(i);
80 }
81 }
82 return result;
83}
Definition vec.h:7
Static (i.e.
Definition Matrix.h:42
const float r
Definition hydro_iact.h:68
j
Definition euler.py:99
Matrix< Rows, Cols, Scalar > multiply(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Performs a matrix x matrix multiplication.
void matVec(const Matrix< Rows, Cols, Scalar > &matrix, Scalar alpha, const Vector< Cols, Scalar > &v, Vector< Rows, Scalar > &r)
Compute r = r + alpha * M * v in-situ.
Matrix< Size, Size, Scalar > outerDot(const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
Outer dot product.
Matrix< Rows, Cols, Scalar > operator*(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Simple vector class.
Definition Vector.h:150