39 double*
y,
int*
incy);
43 dgemm_(
const char* transA,
const char* transB,
int*
M,
int*
N,
int*
k,
double*
alpha,
double*
A,
int* LDA,
double*
B,
44 int*
LDB,
double*
beta,
double*
C,
int* LDC);
47 int daxpy_(
int*
N,
double* DA,
double* DX,
int* INCX,
double* DY,
int* INCY);
53 void dgetri_(
int*
N,
double*
A,
int*
lda,
int* IPIV,
double* WORK,
int* lwork,
int*
INFO);
60 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
63 if (numberOfRows == 0)
65 logger(
WARN,
"Trying to multiply a vector with a matrix without any rows.");
68 if (numberOfColumns == 0)
70 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
73 int nr = numberOfRows;
74 int nc = numberOfColumns;
82 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, right.
size());
84 dgemv_(
"N", &nr, &nc, &d_one, this->
data(), &nr, right.
data(), &i_one, &d_zero, result.
data(), &i_one);
88 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
92 if (numberOfRows == 0)
94 logger(
WARN,
"Trying to multiply a vector with a matrix without any rows.");
97 if (numberOfColumns == 0)
99 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
102 int nr = numberOfRows;
103 int nc = numberOfColumns;
111 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, right.
size());
113 dgemv_(
"N", &nr, &nc, &d_one, (
const_cast<double*
>(this->
data())), &nr, right.
data(), &i_one, &d_zero,
114 result.
data(), &i_one);
118 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
119 template<
unsigned int K>
123 int i = numberOfRows;
124 int j = numberOfColumns;
127 if (numberOfColumns == 0)
129 logger(
WARN,
"Trying to multiply a matrix with a matrix without any columns.");
139 dgemm_(
"N",
"N", &
i, &
k, &
j, &d_one, this->
data(), &i,
const_cast<double*
>(other.
data()), &
j, &d_zero,
C.data(),
145 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
146 template<
unsigned int K>
150 int i = numberOfRows;
151 int j = numberOfColumns;
154 if (numberOfColumns == 0)
156 logger(
WARN,
"Trying to multiply a matrix with a matrix without any columns.");
166 dgemm_(
"N",
"N", &
i, &
k, &
j, &d_one,
const_cast<double*
>(this->
data()), &i,
const_cast<double*
>(other.
data()), &
j,
167 &d_zero,
C.data(), &
i);
172 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
177 return (*
this) = (*this) * other;
180 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
184 logger.assert_debug(numberOfColumns == numberOfRows - 1,
185 "Matrix has wrong dimensions to construct the wedge stuff vector");
188 switch (numberOfRows)
191 result[0] = -(*this)(1, 0);
192 result[1] = +(*this)(0, 0);
195 result[0] = (*this)(1, 0) * (*
this)(2, 1) - (*
this)(2, 0) * (*
this)(1, 1);
196 result[1] = (*this)(0, 1) * (*
this)(2, 0) - (*
this)(0, 0) * (*
this)(2, 1);
197 result[2] = (*this)(0, 0) * (*
this)(1, 1) - (*
this)(1, 0) * (*
this)(0, 1);
200 result[0] = (*this)(1, 0) * (-(*
this)(2, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(2, 2)) +
201 (*this)(2, 0) * ((*
this)(1, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(1, 2)) +
202 (*this)(3, 0) * (-(*
this)(1, 1) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(1, 2));
204 result[1] = (*this)(0, 0) * ((*
this)(2, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(2, 2)) +
205 (*this)(2, 0) * (-(*
this)(0, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(0, 2)) +
206 (*this)(3, 0) * ((*
this)(0, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(0, 2));
207 result[2] = (*this)(0, 0) * (-(*
this)(1, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(1, 2)) +
208 (*this)(1, 0) * ((*
this)(0, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(0, 2)) +
209 (*this)(3, 0) * (-(*
this)(0, 1) * (*
this)(1, 2) + (*
this)(1, 1) * (*
this)(0, 2));
210 result[3] = (*this)(0, 0) * ((*
this)(1, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(1, 2)) +
211 (*this)(1, 0) * (-(*
this)(0, 1) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(0, 2)) +
212 (*this)(2, 0) * ((*
this)(0, 1) * (*
this)(1, 2) - (*
this)(1, 1) * (*
this)(0, 2));
215 logger(
ERROR,
"Wedge product not implemented for this dimension");
221 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
224 int nr = numberOfRows;
225 int nc = numberOfColumns;
226 int nPivot =
std::min(numberOfRows, numberOfColumns);
240 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
243 logger.assert_debug(numberOfRows == numberOfColumns,
"Matrix should be square to have a determinant!");
245 switch (numberOfRows)
250 return (*
this)(0, 0);
252 return (*
this)(0, 0) * (*
this)(1, 1) - (*
this)(0, 1) * (*
this)(1, 0);
255 return (*
this)(0, 0) * ((*
this)(1, 1) * (*
this)(2, 2) - (*
this)(1, 2) * (*
this)(2, 1)) -
256 (*this)(0, 1) * ((*
this)(1, 0) * (*
this)(2, 2) - (*
this)(2, 0) * (*
this)(1, 2)) +
257 (*this)(0, 2) * ((*
this)(1, 0) * (*
this)(2, 1) - (*
this)(2, 0) * (*
this)(1, 1));
260 return ((*
this)(3, 0) * (*
this)(2, 1) * (*
this)(0, 3) - (*
this)(2, 0) * (*
this)(3, 1) * (*
this)(0, 3)) *
262 (-(*
this)(3, 0) * (*
this)(0, 3) * (*
this)(2, 2) + (*
this)(2, 0) * (*
this)(0, 3) * (*
this)(3, 2)) *
264 ((*
this)(3, 1) * (*
this)(0, 3) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(0, 3) * (*
this)(3, 2)) *
266 (-(*
this)(3, 0) * (*
this)(2, 1) * (*
this)(1, 3) + (*
this)(2, 0) * (*
this)(3, 1) * (*
this)(1, 3) +
267 (-(*
this)(2, 0) * (*
this)(3, 3) + (*
this)(3, 0) * (*
this)(2, 3)) * (*this)(1, 1) +
268 ((*
this)(2, 1) * (*
this)(3, 3) - (*
this)(3, 1) * (*
this)(2, 3)) * (*this)(1, 0)) * (*this)(0, 2) +
269 ((*
this)(3, 0) * (*
this)(1, 3) * (*
this)(2, 2) - (*
this)(2, 0) * (*
this)(1, 3) * (*
this)(3, 2) +
270 ((*
this)(2, 0) * (*
this)(3, 3) - (*
this)(3, 0) * (*
this)(2, 3)) * (*this)(1, 2) +
271 (-(*
this)(2, 2) * (*
this)(3, 3) + (*
this)(2, 3) * (*
this)(3, 2)) * (*this)(1, 0)) * (*this)(0, 1) +
272 (-(*
this)(3, 1) * (*
this)(1, 3) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(1, 3) * (*
this)(3, 2) +
273 ((*
this)(3, 1) * (*
this)(2, 3) - (*
this)(2, 1) * (*
this)(3, 3)) * (*this)(1, 2) +
274 (*
this)(1, 1) * ((*
this)(2, 2) * (*
this)(3, 3) - (*
this)(2, 3) * (*
this)(3, 2))) * (*
this)(0, 0);
278 logger(
ERROR,
"Computing the Determinant for size % is not implemented", numberOfRows);
284 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
287 logger.assert_debug(numberOfRows == numberOfColumns,
"Cannot invert a non-square matrix");
290 int nr = numberOfRows;
291 int nc = numberOfColumns;
293 int nPivot = numberOfRows;
300 int lwork = numberOfRows * numberOfColumns;
307 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
308 template<
unsigned int numberOfRightHandS
ideColumns>
311 logger.assert_debug(numberOfRows == numberOfColumns,
"can only solve for square matrixes");
313 int n = numberOfRows;
314 int nrhs = numberOfRightHandSideColumns;
317 int IPIV[numberOfRows];
322 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
325 logger.assert_debug(numberOfRows == numberOfColumns,
"can only solve for square matrixes");
327 int n = numberOfRows;
331 int IPIV[numberOfRows];
336 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
339 if (numberOfColumns == 0)
341 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
344 int nr = numberOfRows;
345 int nc = numberOfColumns;
353 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, vec.
size());
355 dgemv_(
"T", &nr, &nc, &d_one,
mat.
data(), &nr, vec.
data(), &i_one, &d_zero, result.
data(), &i_one);
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:32
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:33
int data[]
Definition: Map_placement_new.cpp:1
int daxpy_(int *N, double *DA, double *DX, int *INCX, double *DY, int *INCY)
This is the gerneral scalar times vector + vector from blas, hence from blas level 1....
void dgemv_(const char *trans, int *m, int *n, double *alpha, double *A, int *LDA, double *x, int *incx, double *beta, double *y, int *incy)
This does matrix times vector and is from blas level 2.
void dgetrf_(int *M, int *N, double *A, int *lda, int *IPIV, int *INFO)
This is LU factorisation of the matrix A. This has been taken from LAPACK.
void dgesv_(int *N, int *NRHS, double *A, int *lda, int *IPIV, double *B, int *LDB, int *INFO)
This is used for solve Ax=B for x. Again this is from LAPACK.
int dgemm_(const char *transA, const char *transB, int *M, int *N, int *k, double *alpha, double *A, int *LDA, double *B, int *LDB, double *beta, double *C, int *LDC)
This is the gernal matrix multiplication from blas level 3.
void dgetri_(int *N, double *A, int *lda, int *IPIV, double *WORK, int *lwork, int *INFO)
This is the inverse calulation also from LAPACK. Calculates inverse if you pass it the LU factorisati...
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
constexpr Storage & data()
Definition: SparseMatrix.h:205
Data type for small dense matrix.
Definition: SmallMatrix.h:48
Mdouble determinant() const
Definition: SmallMatrix_impl.h:241
Mdouble * data()
Definition: SmallMatrix.h:331
void solve(SmallMatrix< numberOfRows, numberOfRightHandSideColumns > &B) const
solves Ax=B where A is the current matrix and B is passed in. The result is returned in B.
Definition: SmallMatrix_impl.h:309
SmallVector< numberOfRows > computeWedgeStuffVector() const
computeWedgeStuffVector.
Definition: SmallMatrix_impl.h:181
SmallMatrix & operator*=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:200
SmallMatrix LUfactorisation() const
Return the LUfactorisation of the matrix.
Definition: SmallMatrix_impl.h:222
SmallVector< numberOfRows > operator*(SmallVector< numberOfColumns > &right)
Defines Matrix A times vector B and return vector C i.e. C_,j= A_ij B_,j.
Definition: SmallMatrix_impl.h:61
SmallMatrix inverse() const
return the inverse in the vector result. The size of result matches the matrix.
Definition: SmallMatrix_impl.h:285
Definition: SmallVector.h:42
unsigned int size() const
Definition: SmallVector.h:213
const Mdouble * data() const
Definition: SmallVector.h:218
Definition: matrices.h:74
@ N
Definition: constructor.cpp:22
#define min(a, b)
Definition: datatypes.h:22
Scalar * y
Definition: level1_cplx_impl.h:128
int RealScalar int RealScalar int * incy
Definition: level1_cplx_impl.h:124
RealScalar alpha
Definition: level1_cplx_impl.h:151
RealScalar RealScalar int * incx
Definition: level1_cplx_impl.h:27
const char const int const RealScalar const RealScalar const int * lda
Definition: level2_cplx_impl.h:20
int * m
Definition: level2_cplx_impl.h:294
int info
Definition: level2_cplx_impl.h:39
Scalar beta
Definition: level2_cplx_impl.h:36
char * trans
Definition: level2_impl.h:240
char char char int int * k
Definition: level2_impl.h:374
#define DEBUG
Definition: main.h:181
#define INFO(i)
Definition: mumps_solver.h:54
double K
Wave number.
Definition: sphere_scattering.cc:115
@ LDB
Definition: octree.h:49
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2