58 void dgemv_(
const char* trans,
int* m,
int*
n,
double* alpha,
double*
A,
int* LDA,
double* x,
int* incx,
double*
beta,
59 double* y,
int* incy);
63 dgemm_(
const char* transA,
const char* transB,
int*
M,
int* N,
int* k,
double* alpha,
double*
A,
int* LDA,
double* B,
64 int* LDB,
double*
beta,
double* C,
int* LDC);
67 int daxpy_(
int* N,
double* DA,
double* DX,
int* INCX,
double* DY,
int* INCY);
70 void dgetrf_(
int*
M,
int* N,
double*
A,
int* lda,
int* IPIV,
int*
INFO);
73 void dgetri_(
int* N,
double*
A,
int* lda,
int* IPIV,
double* WORK,
int* lwork,
int*
INFO);
76 void dgesv_(
int* N,
int* NRHS,
double*
A,
int* lda,
int* IPIV,
double* B,
int* LDB,
int*
INFO);
80 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
83 if (numberOfRows == 0)
85 logger(
WARN,
"Trying to multiply a vector with a matrix without any rows.");
88 if (numberOfColumns == 0)
90 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
93 int nr = numberOfRows;
94 int nc = numberOfColumns;
102 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, right.
size());
104 dgemv_(
"N", &nr, &nc, &d_one, this->data(), &nr, right.
data(), &i_one, &d_zero, result.
data(), &i_one);
108 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
112 if (numberOfRows == 0)
114 logger(
WARN,
"Trying to multiply a vector with a matrix without any rows.");
117 if (numberOfColumns == 0)
119 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
122 int nr = numberOfRows;
123 int nc = numberOfColumns;
131 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, right.
size());
133 dgemv_(
"N", &nr, &nc, &d_one, (
const_cast<double*
>(this->data())), &nr, right.
data(), &i_one, &d_zero,
134 result.
data(), &i_one);
138 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
139 template<
unsigned int K>
143 int i = numberOfRows;
144 int j = numberOfColumns;
147 if (numberOfColumns == 0)
149 logger(
WARN,
"Trying to multiply a matrix with a matrix without any columns.");
159 dgemm_(
"N",
"N", &
i, &k, &j, &d_one, this->data(), &
i,
const_cast<double*
>(other.
data()), &j, &d_zero, C.
data(),
165 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
166 template<
unsigned int K>
170 int i = numberOfRows;
171 int j = numberOfColumns;
174 if (numberOfColumns == 0)
176 logger(
WARN,
"Trying to multiply a matrix with a matrix without any columns.");
186 dgemm_(
"N",
"N", &
i, &k, &j, &d_one,
const_cast<double*
>(this->data()), &
i,
const_cast<double*
>(other.
data()), &j,
187 &d_zero, C.
data(), &
i);
192 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
197 return (*
this) = (*this) * other;
200 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
204 logger.assert_debug(numberOfColumns == numberOfRows - 1,
205 "Matrix has wrong dimensions to construct the wedge stuff vector");
208 switch (numberOfRows)
211 result[0] = -(*this)(1, 0);
212 result[1] = +(*this)(0, 0);
215 result[0] = (*this)(1, 0) * (*
this)(2, 1) - (*
this)(2, 0) * (*
this)(1, 1);
216 result[1] = (*this)(0, 1) * (*
this)(2, 0) - (*
this)(0, 0) * (*
this)(2, 1);
217 result[2] = (*this)(0, 0) * (*
this)(1, 1) - (*
this)(1, 0) * (*
this)(0, 1);
220 result[0] = (*this)(1, 0) * (-(*
this)(2, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(2, 2)) +
221 (*this)(2, 0) * ((*
this)(1, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(1, 2)) +
222 (*this)(3, 0) * (-(*
this)(1, 1) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(1, 2));
224 result[1] = (*this)(0, 0) * ((*
this)(2, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(2, 2)) +
225 (*this)(2, 0) * (-(*
this)(0, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(0, 2)) +
226 (*this)(3, 0) * ((*
this)(0, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(0, 2));
227 result[2] = (*this)(0, 0) * (-(*
this)(1, 1) * (*
this)(3, 2) + (*
this)(3, 1) * (*
this)(1, 2)) +
228 (*this)(1, 0) * ((*
this)(0, 1) * (*
this)(3, 2) - (*
this)(3, 1) * (*
this)(0, 2)) +
229 (*this)(3, 0) * (-(*
this)(0, 1) * (*
this)(1, 2) + (*
this)(1, 1) * (*
this)(0, 2));
230 result[3] = (*this)(0, 0) * ((*
this)(1, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(1, 2)) +
231 (*this)(1, 0) * (-(*
this)(0, 1) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(0, 2)) +
232 (*this)(2, 0) * ((*
this)(0, 1) * (*
this)(1, 2) - (*
this)(1, 1) * (*
this)(0, 2));
235 logger(
ERROR,
"Wedge product not implemented for this dimension");
241 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
244 int nr = numberOfRows;
245 int nc = numberOfColumns;
246 int nPivot = std::min(numberOfRows, numberOfColumns);
253 dgetrf_(&nr, &nc, result.
data(), &nr, iPivot, &info);
260 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
263 logger.assert_debug(numberOfRows == numberOfColumns,
"Matrix should be square to have a determinant!");
265 switch (numberOfRows)
270 return (*
this)(0, 0);
272 return (*
this)(0, 0) * (*
this)(1, 1) - (*
this)(0, 1) * (*
this)(1, 0);
275 return (*
this)(0, 0) * ((*
this)(1, 1) * (*
this)(2, 2) - (*
this)(1, 2) * (*
this)(2, 1)) -
276 (*this)(0, 1) * ((*
this)(1, 0) * (*
this)(2, 2) - (*
this)(2, 0) * (*
this)(1, 2)) +
277 (*this)(0, 2) * ((*
this)(1, 0) * (*
this)(2, 1) - (*
this)(2, 0) * (*
this)(1, 1));
280 return ((*
this)(3, 0) * (*
this)(2, 1) * (*
this)(0, 3) - (*
this)(2, 0) * (*
this)(3, 1) * (*
this)(0, 3)) *
282 (-(*
this)(3, 0) * (*
this)(0, 3) * (*
this)(2, 2) + (*
this)(2, 0) * (*
this)(0, 3) * (*
this)(3, 2)) *
284 ((*
this)(3, 1) * (*
this)(0, 3) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(0, 3) * (*
this)(3, 2)) *
286 (-(*
this)(3, 0) * (*
this)(2, 1) * (*
this)(1, 3) + (*
this)(2, 0) * (*
this)(3, 1) * (*
this)(1, 3) +
287 (-(*
this)(2, 0) * (*
this)(3, 3) + (*
this)(3, 0) * (*
this)(2, 3)) * (*this)(1, 1) +
288 ((*
this)(2, 1) * (*
this)(3, 3) - (*
this)(3, 1) * (*
this)(2, 3)) * (*this)(1, 0)) * (*this)(0, 2) +
289 ((*
this)(3, 0) * (*
this)(1, 3) * (*
this)(2, 2) - (*
this)(2, 0) * (*
this)(1, 3) * (*
this)(3, 2) +
290 ((*
this)(2, 0) * (*
this)(3, 3) - (*
this)(3, 0) * (*
this)(2, 3)) * (*this)(1, 2) +
291 (-(*
this)(2, 2) * (*
this)(3, 3) + (*
this)(2, 3) * (*
this)(3, 2)) * (*this)(1, 0)) * (*this)(0, 1) +
292 (-(*
this)(3, 1) * (*
this)(1, 3) * (*
this)(2, 2) + (*
this)(2, 1) * (*
this)(1, 3) * (*
this)(3, 2) +
293 ((*
this)(3, 1) * (*
this)(2, 3) - (*
this)(2, 1) * (*
this)(3, 3)) * (*this)(1, 2) +
294 (*
this)(1, 1) * ((*
this)(2, 2) * (*
this)(3, 3) - (*
this)(2, 3) * (*
this)(3, 2))) * (*
this)(0, 0);
298 logger(
ERROR,
"Computing the Determinant for size % is not implemented", numberOfRows);
304 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
307 logger.assert_debug(numberOfRows == numberOfColumns,
"Cannot invert a non-square matrix");
310 int nr = numberOfRows;
311 int nc = numberOfColumns;
313 int nPivot = numberOfRows;
318 dgetrf_(&nr, &nc, result.
data(), &nr, iPivot, &info);
320 int lwork = numberOfRows * numberOfColumns;
327 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
328 template<
unsigned int numberOfRightHandS
ideColumns>
331 logger.assert_debug(numberOfRows == numberOfColumns,
"can only solve for square matrixes");
333 int n = numberOfRows;
334 int nrhs = numberOfRightHandSideColumns;
337 int IPIV[numberOfRows];
342 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
345 logger.assert_debug(numberOfRows == numberOfColumns,
"can only solve for square matrixes");
347 int n = numberOfRows;
351 int IPIV[numberOfRows];
356 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
359 if (numberOfColumns == 0)
361 logger(
WARN,
"Trying to multiply a vector with a matrix without any columns.");
364 int nr = numberOfRows;
365 int nc = numberOfColumns;
373 logger(
DEBUG,
"Matrix size: % x % \n Vector size: %", nr, nc, vec.
size());
375 dgemv_(
"T", &nr, &nc, &d_one, mat.
data(), &nr, vec.
data(), &i_one, &d_zero, result.
data(), &i_one);
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
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:53
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
SmallVector< numberOfColumns > operator*(SmallVector< numberOfRows > &vec, SmallMatrix< numberOfRows, numberOfColumns > &mat)
Multiplies a matrix with a vector.
Definition: SmallMatrix_impl.h:357
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...
@ A
Definition: StatisticsVector.h:42
Data type for small dense matrix.
Definition: SmallMatrix.h:68
Mdouble determinant() const
Definition: SmallMatrix_impl.h:261
Mdouble * data()
Definition: SmallMatrix.h:351
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:329
SmallVector< numberOfRows > computeWedgeStuffVector() const
computeWedgeStuffVector.
Definition: SmallMatrix_impl.h:201
SmallMatrix & operator*=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:220
SmallMatrix LUfactorisation() const
Return the LUfactorisation of the matrix.
Definition: SmallMatrix_impl.h:242
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:81
SmallMatrix inverse() const
return the inverse in the vector result. The size of result matches the matrix.
Definition: SmallMatrix_impl.h:305
Definition: SmallVector.h:62
unsigned int size() const
Definition: SmallVector.h:233
const Mdouble * data() const
Definition: SmallVector.h:238
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Mdouble beta(Mdouble z, Mdouble w)
This is the beta function, returns the approximation based on cmath's implementation of ln(gamma)
Definition: ExtendedMath.cc:164