50 #ifndef MERCURYDPM_SMALLMATRIX_H
51 #define MERCURYDPM_SMALLMATRIX_H
66 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
80 logger.assert_debug(numberOfColumns == 1,
"Trying to construct a matrix with more than 1 columns from a vector");
81 std::copy(other.
data(), other.
data() + numberOfRows,
data_.begin());
94 logger.assert_debug(entries.size() == numberOfColumns,
"expected a matrix with % "
95 "columns, but got a matrix with % columns", numberOfColumns,
97 unsigned int column = 0;
100 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
102 (*this)(
i, column) = entry[
i];
119 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
121 for (
unsigned int j = 0; j < numberOfColumns; ++j)
123 (*this)(
i, j) = entries[j][
i];
137 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
138 logger.assert_debug(m < numberOfColumns,
"Requested column number % for a matrix with only % columns", m,
140 return data_[
n + m * numberOfRows];
146 logger.assert_debug(
n < numberOfRows,
"Requested row number % for a matrix with only % rows",
n, numberOfRows);
147 logger.assert_debug(m < numberOfColumns,
"Requested column number % for a matrix with only % columns", m,
149 return data_[
n + m * numberOfRows];
155 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
156 numberOfRows * numberOfColumns);
162 logger.assert_debug(
n < numberOfRows * numberOfColumns,
"Requested entry % for a matrix with only % entries",
n,
163 numberOfRows * numberOfColumns);
177 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, right));
182 template<
unsigned int K>
185 template<
unsigned int K>
190 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(),
data_.begin(), std::plus<Mdouble>());
196 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(),
data_.begin(), std::minus<Mdouble>());
203 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(), result.
data_.begin(), std::plus<Mdouble>());
210 std::transform(
data_.begin(),
data_.end(), other.
data_.begin(), result.
data_.begin(), std::minus<Mdouble>());
223 std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, scalar));
235 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
244 std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
258 std::move(right.data_.begin(), right.data_.end(),
data_.begin());
268 for (
unsigned int i = 0;
i < numberOfRows * numberOfColumns; ++
i)
277 return numberOfRows * numberOfColumns;
295 return numberOfColumns;
306 logger.assert_debug(j < numberOfColumns,
"Asked for column %, but there are only % columns", j, numberOfColumns);
313 logger.assert_debug(
i < numberOfRows,
"Asked for row %, but there are only % rows",
i, numberOfRows);
315 for (
unsigned int j = 0; j < numberOfColumns; ++j)
317 result[j] = (*this)(
i, j);
333 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
335 for (
unsigned int j = 0; j < numberOfColumns; ++j)
337 result(j,
i) = (*this)(
i, j);
344 template<
unsigned int numberOfRightHandS
ideColumns>
363 std::array<Mdouble, numberOfRows * numberOfColumns>
data_;
367 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
370 for (
unsigned int i = 0;
i < numberOfRows; ++
i)
372 os <<
A.getRow(
i) << std::endl;
378 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
386 template<
unsigned int numberOfRows,
unsigned int numberOfColumns>
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
double Mdouble
Definition: GeneralDefine.h:34
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
SmallMatrix< numberOfRows, numberOfColumns > operator*(const Mdouble d, const SmallMatrix< numberOfRows, numberOfColumns > &mat)
Multiplies a matrix with a Mdouble.
Definition: SmallMatrix.h:380
std::ostream & operator<<(std::ostream &os, const SmallMatrix< numberOfRows, numberOfColumns > &A)
Writes nicely formatted entries of the Matrix A to the stream os.
Definition: SmallMatrix.h:368
@ A
Definition: StatisticsVector.h:42
Data type for small dense matrix.
Definition: SmallMatrix.h:68
SmallMatrix(const std::initializer_list< SmallVector< numberOfRows >> &entries)
Definition: SmallMatrix.h:91
std::array< Mdouble, numberOfRows *numberOfColumns > data_
The actually data of the matrix class.
Definition: SmallMatrix.h:363
SmallVector< numberOfRows > getColumn(unsigned int j) const
get the j^th column
Definition: SmallMatrix.h:304
Mdouble & operator[](const unsigned int n)
Access the n linear element in the matrix.
Definition: SmallMatrix.h:153
Mdouble determinant() const
Definition: SmallMatrix_impl.h:261
unsigned int getNCols() const
Definition: SmallMatrix.h:298
SmallMatrix< numberOfColumns, numberOfRows > transpose() const
Definition: SmallMatrix.h:330
SmallMatrix & operator+=(const SmallMatrix &other)
Definition: SmallMatrix.h:188
SmallMatrix operator/(const Mdouble &scalar) const
this does element by divided by a scalar
Definition: SmallMatrix.h:240
SmallMatrix & operator/=(const Mdouble &scalar)
Does matrix A_ij=scalar*A_ij.
Definition: SmallMatrix.h:232
SmallMatrix operator*(const Mdouble &right) const
Does matrix A_ij=scalar*B_ij.
Definition: SmallMatrix.h:173
SmallMatrix operator-(const SmallMatrix &other) const
Definition: SmallMatrix.h:207
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:109
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
unsigned int size() const
Get total number of Matrix entries.
Definition: SmallMatrix.h:275
SmallVector< numberOfColumns > getRow(unsigned int i) const
get the i^th row
Definition: SmallMatrix.h:311
unsigned int getNRows() const
Definition: SmallMatrix.h:287
SmallVector< numberOfRows > computeWedgeStuffVector() const
computeWedgeStuffVector.
Definition: SmallMatrix_impl.h:201
const Mdouble & operator[](const unsigned int n) const
Definition: SmallMatrix.h:160
SmallMatrix(SmallMatrix &&other)
Move Matrix from another Matrix.
Definition: SmallMatrix.h:129
unsigned int getNumberOfColumns() const
Get the number of columns.
Definition: SmallMatrix.h:293
SmallMatrix & operator=(const SmallMatrix &right)
Assigns one matrix to another.
Definition: SmallMatrix.h:249
SmallMatrix(const Mdouble &c)
Constructs a matrix of size n-rows by m-columns and initialises all entry to a constant.
Definition: SmallMatrix.h:85
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:135
SmallMatrix & operator-=(const SmallMatrix &other)
Definition: SmallMatrix.h:194
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
SmallMatrix(const SmallVector< numberOfRows > &other)
Definition: SmallMatrix.h:77
SmallMatrix operator-() const
Definition: SmallMatrix.h:214
const Mdouble * data() const
Definition: SmallMatrix.h:356
SmallMatrix(std::array< SmallVector< numberOfRows >, numberOfColumns > entries)
Glues one or more vectors with the same number of rows together.
Definition: SmallMatrix.h:116
SmallMatrix operator+(const SmallMatrix &other) const
Definition: SmallMatrix.h:200
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
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:144
SmallMatrix inverse() const
return the inverse in the vector result. The size of result matches the matrix.
Definition: SmallMatrix_impl.h:305
SmallMatrix()
Constructs a matrix of size n-rows by m-columns.
Definition: SmallMatrix.h:72
SmallMatrix & operator=(SmallMatrix &&right)
Assigns one matrix to another.
Definition: SmallMatrix.h:256
unsigned int getNumberOfRows() const
Get the number of rows.
Definition: SmallMatrix.h:281
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:266
Definition: SmallVector.h:62
const Mdouble * data() const
Definition: SmallVector.h:238
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51