30 #ifndef MERCURYDPM_SMALLMATRIX_H
31 #define MERCURYDPM_SMALLMATRIX_H
46 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
60 logger.assert_debug(numberOfColumns == 1,
"Trying to construct a matrix with more than 1 columns from a vector");
74 logger.assert_debug(entries.size() == numberOfColumns,
"expected a matrix with % "
75 "columns, but got a matrix with % columns", numberOfColumns,
77 unsigned int column = 0;
80 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
82 (*this)(
i, column) = entry[
i];
99 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
101 for (
unsigned int j = 0;
j < numberOfColumns; ++
j)
103 (*this)(
i,
j) = entries[
j][
i];
117 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
118 logger.assert_debug(
m < numberOfColumns,
"Requested column number % for a matrix with only % columns",
m,
120 return data_[
n +
m * numberOfRows];
126 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
127 logger.assert_debug(
m < numberOfColumns,
"Requested column number % for a matrix with only % columns",
m,
129 return data_[
n +
m * numberOfRows];
135 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
136 numberOfRows * numberOfColumns);
142 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
143 numberOfRows * numberOfColumns);
157 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, right));
162 template<
unsigned int K>
165 template<
unsigned int K>
203 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, scalar));
215 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
224 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
238 std::move(right.data_.begin(), right.data_.end(),
data_.begin());
248 for (
unsigned int i = 0;
i < numberOfRows * numberOfColumns; ++
i)
257 return numberOfRows * numberOfColumns;
275 return numberOfColumns;
286 logger.assert_debug(
j < numberOfColumns,
"Asked for column %, but there are only % columns",
j, numberOfColumns);
293 logger.assert_debug(
i < numberOfRows,
"Asked for row %, but there are only % rows",
i, numberOfRows);
295 for (
unsigned int j = 0;
j < numberOfColumns; ++
j)
297 result[
j] = (*this)(
i,
j);
313 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
315 for (
unsigned int j = 0;
j < numberOfColumns; ++
j)
317 result(
j,
i) = (*this)(
i,
j);
324 template<
unsigned int numberOfRightHandS
ideColumns>
343 std::array<Mdouble, numberOfRows * numberOfColumns>
data_;
347 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
350 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
352 os <<
A.getRow(
i) << std::endl;
358 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
366 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
double Mdouble
Definition: GeneralDefine.h:13
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
std::ostream & operator<<(std::ostream &s, const DenseBase< Derived > &m)
Definition: IO.h:222
Data type for small dense matrix.
Definition: SmallMatrix.h:48
SmallMatrix(const std::initializer_list< SmallVector< numberOfRows >> &entries)
Definition: SmallMatrix.h:71
std::array< Mdouble, numberOfRows *numberOfColumns > data_
The actually data of the matrix class.
Definition: SmallMatrix.h:343
SmallVector< numberOfRows > getColumn(unsigned int j) const
get the j^th column
Definition: SmallMatrix.h:284
Mdouble & operator[](const unsigned int n)
Access the n linear element in the matrix.
Definition: SmallMatrix.h:133
Mdouble determinant() const
Definition: SmallMatrix_impl.h:241
unsigned int getNCols() const
Definition: SmallMatrix.h:278
SmallMatrix< numberOfColumns, numberOfRows > transpose() const
Definition: SmallMatrix.h:310
SmallMatrix & operator+=(const SmallMatrix &other)
Definition: SmallMatrix.h:168
SmallMatrix operator/(const Mdouble &scalar) const
this does element by divided by a scalar
Definition: SmallMatrix.h:220
SmallMatrix & operator/=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:212
SmallMatrix operator*(const Mdouble &right) const
Does matrix A_ij=scalar*B_ij.
Definition: SmallMatrix.h:153
SmallMatrix operator-(const SmallMatrix &other) const
Definition: SmallMatrix.h:187
SmallMatrix(const SmallMatrix &other)
Construct and copy Matrix from another Matrix i.e. B(A) where B and A are both matrices.
Definition: SmallMatrix.h:89
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
unsigned int size() const
Get total number of Matrix entries.
Definition: SmallMatrix.h:255
SmallVector< numberOfColumns > getRow(unsigned int i) const
get the i^th row
Definition: SmallMatrix.h:291
unsigned int getNRows() const
Definition: SmallMatrix.h:267
SmallVector< numberOfRows > computeWedgeStuffVector() const
computeWedgeStuffVector.
Definition: SmallMatrix_impl.h:181
const Mdouble & operator[](const unsigned int n) const
Definition: SmallMatrix.h:140
SmallMatrix(SmallMatrix &&other)
Move Matrix from another Matrix.
Definition: SmallMatrix.h:109
unsigned int getNumberOfColumns() const
Get the number of columns.
Definition: SmallMatrix.h:273
SmallMatrix & operator=(const SmallMatrix &right)
Assigns one matrix to another.
Definition: SmallMatrix.h:229
SmallMatrix(const Mdouble &c)
Constructs a matrix of size n-rows by m-columns and initialises all entry to a constant.
Definition: SmallMatrix.h:65
Mdouble & operator()(unsigned int n, unsigned int m)
defines the operator(n,m) to access the element on row n and column m
Definition: SmallMatrix.h:115
SmallMatrix & operator-=(const SmallMatrix &other)
Definition: SmallMatrix.h:174
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
SmallMatrix(const SmallVector< numberOfRows > &other)
Definition: SmallMatrix.h:57
SmallMatrix operator-() const
Definition: SmallMatrix.h:194
const Mdouble * data() const
Definition: SmallMatrix.h:336
SmallMatrix(std::array< SmallVector< numberOfRows >, numberOfColumns > entries)
Glues one or more vectors with the same number of rows together.
Definition: SmallMatrix.h:96
SmallMatrix operator+(const SmallMatrix &other) const
Definition: SmallMatrix.h:180
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
const Mdouble & operator()(unsigned int n, unsigned int m) const
defines the operator(n,m) to access the element on row n and column m
Definition: SmallMatrix.h:124
SmallMatrix inverse() const
return the inverse in the vector result. The size of result matches the matrix.
Definition: SmallMatrix_impl.h:285
SmallMatrix()
Constructs a matrix of size n-rows by m-columns.
Definition: SmallMatrix.h:52
SmallMatrix & operator=(SmallMatrix &&right)
Assigns one matrix to another.
Definition: SmallMatrix.h:236
unsigned int getNumberOfRows() const
Get the number of rows.
Definition: SmallMatrix.h:261
void axpy(Mdouble a, const SmallMatrix &x)
Applies the matrix y=ax + y, where x is another matrix and a is a scalar.
Definition: SmallMatrix.h:246
Definition: SmallVector.h:42
const Mdouble * data() const
Definition: SmallVector.h:218
Definition: matrices.h:74
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
std::array< T, N > array
Definition: EmulateArray.h:231
int c
Definition: calibrate.py:100
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2