Peano
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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
20template <int Rows, int Cols, typename Scalar>
22 const Matrix<Rows, Cols, Scalar>& matrix,
23 const Vector<Cols, Scalar>& vector
24) {
25 return multiply(matrix, vector);
26}
27
28#ifdef UseOpenblas
29template <int Rows, int Cols>
31 const Matrix<Rows, Cols, double>& matrix,
32 const Vector<Cols, double>& vector
33) {
35 cblas_dgemv(
36 CblasRowMajor,
37 CblasNoTrans,
38 Rows,
39 Cols,
40 1,
41 matrix.data(),
42 Rows,
43 vector.data(),
44 1,
45 0,
46 output.data(),
47 1
48 );
49 return output;
50}
51#endif
52
53template <int Size, typename Scalar>
55 const Vector<Size, Scalar>& lhs,
56 const Vector<Size, Scalar>& rhs
57) {
59 for (int i = 0; i < Size; i++) {
60 for (int j = 0; j < Size; j++) {
61 result(j, i) = lhs(j) * rhs(i);
62 }
63 }
64 return result;
65}
Definition vec.h:7
Static (i.e.
Definition Matrix.h:31
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.
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:134