SmallMatrix< numberOfRows, numberOfColumns > Class Template Reference

Data type for small dense matrix. More...

#include <SmallMatrix.h>

Public Member Functions

 SmallMatrix ()
 Constructs a matrix of size n-rows by m-columns. More...
 
 SmallMatrix (const SmallVector< numberOfRows > &other)
 
 SmallMatrix (const Mdouble &c)
 Constructs a matrix of size n-rows by m-columns and initialises all entry to a constant. More...
 
 SmallMatrix (const std::initializer_list< SmallVector< numberOfRows >> &entries)
 
 SmallMatrix (const SmallMatrix &other)
 Construct and copy Matrix from another Matrix i.e. B(A) where B and A are both matrices. More...
 
 SmallMatrix (std::array< SmallVector< numberOfRows >, numberOfColumns > entries)
 Glues one or more vectors with the same number of rows together. More...
 
 SmallMatrix (SmallMatrix &&other)
 Move Matrix from another Matrix. More...
 
Mdoubleoperator() (unsigned int n, unsigned int m)
 defines the operator(n,m) to access the element on row n and column m More...
 
const Mdoubleoperator() (unsigned int n, unsigned int m) const
 defines the operator(n,m) to access the element on row n and column m More...
 
Mdoubleoperator[] (const unsigned int n)
 Access the n linear element in the matrix. More...
 
const Mdoubleoperator[] (const unsigned int n) const
 
SmallVector< numberOfRows > operator* (SmallVector< numberOfColumns > &right)
 Defines Matrix A times vector B and return vector C i.e. C_,j= A_ij B_,j. More...
 
SmallVector< numberOfRows > operator* (SmallVector< numberOfColumns > &right) const
 
SmallMatrix operator* (const Mdouble &right) const
 Does matrix A_ij=scalar*B_ij. More...
 
template<unsigned int K>
SmallMatrix< numberOfRows, K > operator* (const SmallMatrix< numberOfColumns, K > &other)
 Does matrix A_ij = B_ik * C_kj. More...
 
template<unsigned int K>
SmallMatrix< numberOfRows, K > operator* (const SmallMatrix< numberOfColumns, K > &other) const
 
SmallMatrixoperator+= (const SmallMatrix &other)
 
SmallMatrixoperator-= (const SmallMatrix &other)
 
SmallMatrix operator+ (const SmallMatrix &other) const
 
SmallMatrix operator- (const SmallMatrix &other) const
 
SmallMatrix operator- () const
 
SmallMatrixoperator*= (const Mdouble &scalar)
 Does matrix A_ij=scalar*A_ij. More...
 
SmallMatrixoperator*= (const SmallMatrix< numberOfColumns, numberOfColumns > &other)
 Does matrix A_ij = A_ik * B_kj note that other must be square because this is a fixed-size matrix. More...
 
SmallMatrixoperator/= (const Mdouble &scalar)
 Does matrix A_ij=scalar*A_ij. More...
 
SmallMatrix operator/ (const Mdouble &scalar) const
 this does element by divided by a scalar More...
 
SmallMatrixoperator= (const SmallMatrix &right)
 Assigns one matrix to another. More...
 
SmallMatrixoperator= (SmallMatrix &&right)
 Assigns one matrix to another. More...
 
SmallVector< numberOfRows > computeWedgeStuffVector () const
 computeWedgeStuffVector. More...
 
void axpy (Mdouble a, const SmallMatrix &x)
 Applies the matrix y=ax + y, where x is another matrix and a is a scalar. More...
 
unsigned int size () const
 Get total number of Matrix entries. More...
 
unsigned int getNumberOfRows () const
 Get the number of rows. More...
 
unsigned int getNRows () const
 
unsigned int getNumberOfColumns () const
 Get the number of columns. More...
 
unsigned int getNCols () const
 
SmallVector< numberOfRows > getColumn (unsigned int j) const
 get the j^th column More...
 
SmallVector< numberOfColumns > getRow (unsigned int i) const
 get the i^th row More...
 
SmallMatrix LUfactorisation () const
 Return the LUfactorisation of the matrix. More...
 
Mdouble determinant () const
 
SmallMatrix inverse () const
 return the inverse in the vector result. The size of result matches the matrix. More...
 
SmallMatrix< numberOfColumns, numberOfRows > transpose () const
 
template<unsigned int numberOfRightHandSideColumns>
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. More...
 
void solve (SmallVector< numberOfRows > &b) const
 solves Ax=b where A is the current matrix and NumericalVector b is the input parameter. The result is returned in b. More...
 
Mdoubledata ()
 
const Mdoubledata () const
 

Private Attributes

std::array< Mdouble, numberOfRows *numberOfColumns > data_
 The actually data of the matrix class. More...
 

Detailed Description

template<unsigned int numberOfRows, unsigned int numberOfColumns>
class SmallMatrix< numberOfRows, numberOfColumns >

Data type for small dense matrix.

Stores small dense matrix efficiently. It only store Mdoubles as this is the main type linear algebra is done on in hpGEM It stores the matrix in fortran style (column-major) to give quicker access to extern BLAS libraries. For example, the order they are stored in a 2x2 matrix is 0 2 1 3

Constructor & Destructor Documentation

◆ SmallMatrix() [1/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( )
inline

Constructs a matrix of size n-rows by m-columns.

53  : data_()
54  {
55  }
std::array< Mdouble, numberOfRows *numberOfColumns > data_
The actually data of the matrix class.
Definition: SmallMatrix.h:343

◆ SmallMatrix() [2/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( const SmallVector< numberOfRows > &  other)
inline
58  : data_()
59  {
60  logger.assert_debug(numberOfColumns == 1, "Trying to construct a matrix with more than 1 columns from a vector");
61  std::copy(other.data(), other.data() + numberOfRows, data_.begin());
62  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
const Mdouble * data() const
Definition: SmallVector.h:218
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32

References copy(), SmallVector< numberOfRows >::data(), SmallMatrix< numberOfRows, numberOfColumns >::data_, and logger.

◆ SmallMatrix() [3/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( const Mdouble c)
inline

Constructs a matrix of size n-rows by m-columns and initialises all entry to a constant.

66  : data_()
67  {
68  data_.fill(c);
69  }
int c
Definition: calibrate.py:100

References calibrate::c, and SmallMatrix< numberOfRows, numberOfColumns >::data_.

◆ SmallMatrix() [4/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( const std::initializer_list< SmallVector< numberOfRows >> &  entries)
inline
72  : data_()
73  {
74  logger.assert_debug(entries.size() == numberOfColumns, "expected a matrix with % "
75  "columns, but got a matrix with % columns", numberOfColumns,
76  entries.size());
77  unsigned int column = 0;
78  for (const SmallVector<numberOfRows>& entry : entries)
79  {
80  for (unsigned int i = 0; i < numberOfRows; ++i)
81  {
82  (*this)(i, column) = entry[i];
83  }
84  ++column;
85  }
86  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: SmallVector.h:42

References i, and logger.

◆ SmallMatrix() [5/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( const SmallMatrix< numberOfRows, numberOfColumns > &  other)
inline

Construct and copy Matrix from another Matrix i.e. B(A) where B and A are both matrices.

90  : data_()
91  {
92  std::copy(other.data_.begin(), other.data_.end(), data_.begin());
93  }

References copy(), and SmallMatrix< numberOfRows, numberOfColumns >::data_.

◆ SmallMatrix() [6/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( std::array< SmallVector< numberOfRows >, numberOfColumns >  entries)
inline

Glues one or more vectors with the same number of rows together.

97  : data_()
98  {
99  for (unsigned int i = 0; i < numberOfRows; ++i)
100  {
101  for (unsigned int j = 0; j < numberOfColumns; ++j)
102  {
103  (*this)(i, j) = entries[j][i];
104  }
105  }
106  }
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, and j.

◆ SmallMatrix() [7/7]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns >::SmallMatrix ( SmallMatrix< numberOfRows, numberOfColumns > &&  other)
inline

Move Matrix from another Matrix.

110  : data_(std::move(other.data_))
111  {
112  }

Member Function Documentation

◆ axpy()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
void SmallMatrix< numberOfRows, numberOfColumns >::axpy ( Mdouble  a,
const SmallMatrix< numberOfRows, numberOfColumns > &  x 
)
inline

Applies the matrix y=ax + y, where x is another matrix and a is a scalar.

247  {
248  for (unsigned int i = 0; i < numberOfRows * numberOfColumns; ++i)
249  {
250  data_[i] += a * x[i];
251  }
252  }
const Scalar * a
Definition: level2_cplx_impl.h:32
list x
Definition: plotDoE.py:28

References a, SmallMatrix< numberOfRows, numberOfColumns >::data_, i, and plotDoE::x.

Referenced by main().

◆ computeWedgeStuffVector()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallVector< numberOfRows > SmallMatrix< numberOfRows, numberOfColumns >::computeWedgeStuffVector

computeWedgeStuffVector.

182 {
183  //copied from MiddleSizeMatrix to prevent constructing a temporary MiddleSizeMatrix
184  logger.assert_debug(numberOfColumns == numberOfRows - 1,
185  "Matrix has wrong dimensions to construct the wedge stuff vector");
187 
188  switch (numberOfRows)
189  {
190  case 2:
191  result[0] = -(*this)(1, 0);
192  result[1] = +(*this)(0, 0);
193  break;
194  case 3:
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); // includes minus sign already!
197  result[2] = (*this)(0, 0) * (*this)(1, 1) - (*this)(1, 0) * (*this)(0, 1);
198  break;
199  case 4:
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));
203 
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));
213  break;
214  default:
215  logger(ERROR, "Wedge product not implemented for this dimension");
216  } //end switch
217 
218  return (result);
219 }
@ ERROR

References ERROR, and logger.

◆ data() [1/2]

◆ data() [2/2]

◆ determinant()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
Mdouble SmallMatrix< numberOfRows, numberOfColumns >::determinant
242 {
243  logger.assert_debug(numberOfRows == numberOfColumns, "Matrix should be square to have a determinant!");
244 
245  switch (numberOfRows)
246  {
247  case 0:
248  return 1;
249  case 1:
250  return (*this)(0, 0);
251  case 2:
252  return (*this)(0, 0) * (*this)(1, 1) - (*this)(0, 1) * (*this)(1, 0);
253 
254  case 3:
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));
258 
259  case 4:
260  return ((*this)(3, 0) * (*this)(2, 1) * (*this)(0, 3) - (*this)(2, 0) * (*this)(3, 1) * (*this)(0, 3)) *
261  (*this)(1, 2) +
262  (-(*this)(3, 0) * (*this)(0, 3) * (*this)(2, 2) + (*this)(2, 0) * (*this)(0, 3) * (*this)(3, 2)) *
263  (*this)(1, 1) +
264  ((*this)(3, 1) * (*this)(0, 3) * (*this)(2, 2) - (*this)(2, 1) * (*this)(0, 3) * (*this)(3, 2)) *
265  (*this)(1, 0) +
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);
275  // ... says Maple; this can possibly be done more efficiently,
276  // maybe even with LU (with pivoting, though...)
277  default:
278  logger(ERROR, "Computing the Determinant for size % is not implemented", numberOfRows);
279  break;
280  }
281  return 0;
282 }

References ERROR, and logger.

◆ getColumn()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallVector<numberOfRows> SmallMatrix< numberOfRows, numberOfColumns >::getColumn ( unsigned int  j) const
inline

get the j^th column

285  {
286  logger.assert_debug(j < numberOfColumns, "Asked for column %, but there are only % columns", j, numberOfColumns);
287  return SmallVector<numberOfRows>(data() + j * numberOfRows);
288  }
Mdouble * data()
Definition: SmallMatrix.h:331

References SmallMatrix< numberOfRows, numberOfColumns >::data(), j, and logger.

◆ getNCols()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
unsigned int SmallMatrix< numberOfRows, numberOfColumns >::getNCols ( ) const
inline
279  {
280  return getNumberOfColumns();
281  }
unsigned int getNumberOfColumns() const
Get the number of columns.
Definition: SmallMatrix.h:273

References SmallMatrix< numberOfRows, numberOfColumns >::getNumberOfColumns().

Referenced by main().

◆ getNRows()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
unsigned int SmallMatrix< numberOfRows, numberOfColumns >::getNRows ( ) const
inline
Deprecated:
Does not conform naming convention, please use getNumberOfRows instead.
268  {
269  return getNumberOfRows();
270  }
unsigned int getNumberOfRows() const
Get the number of rows.
Definition: SmallMatrix.h:261

References SmallMatrix< numberOfRows, numberOfColumns >::getNumberOfRows().

◆ getNumberOfColumns()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
unsigned int SmallMatrix< numberOfRows, numberOfColumns >::getNumberOfColumns ( ) const
inline

Get the number of columns.

274  {
275  return numberOfColumns;
276  }

Referenced by SmallMatrix< numberOfRows, numberOfColumns >::getNCols().

◆ getNumberOfRows()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
unsigned int SmallMatrix< numberOfRows, numberOfColumns >::getNumberOfRows ( ) const
inline

Get the number of rows.

262  {
263  return numberOfRows;
264  }

Referenced by SmallMatrix< numberOfRows, numberOfColumns >::getNRows(), and main().

◆ getRow()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallVector<numberOfColumns> SmallMatrix< numberOfRows, numberOfColumns >::getRow ( unsigned int  i) const
inline

get the i^th row

292  {
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)
296  {
297  result[j] = (*this)(i, j);
298  }
299  return result;
300  }

References i, j, and logger.

◆ inverse()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns > SmallMatrix< numberOfRows, numberOfColumns >::inverse

return the inverse in the vector result. The size of result matches the matrix.

286 {
287  logger.assert_debug(numberOfRows == numberOfColumns, "Cannot invert a non-square matrix");
289 
290  int nr = numberOfRows;
291  int nc = numberOfColumns;
292 
293  int nPivot = numberOfRows;
294  int iPivot[nPivot];
295 
296  int info = 0;
297 
298  dgetrf_(&nr, &nc, result.data(), &nr, iPivot, &info);
299 
300  int lwork = numberOfRows * numberOfColumns;
301  SmallMatrix work;
302  dgetri_(&nc, result.data(), &nc, iPivot, work.data(), &lwork, &info);
303 
304  return result;
305 }
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 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...
Data type for small dense matrix.
Definition: SmallMatrix.h:48
int info
Definition: level2_cplx_impl.h:39

References SmallMatrix< numberOfRows, numberOfColumns >::data(), dgetrf_(), dgetri_(), info, and logger.

Referenced by main().

◆ LUfactorisation()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns > SmallMatrix< numberOfRows, numberOfColumns >::LUfactorisation

Return the LUfactorisation of the matrix.

223 {
224  int nr = numberOfRows;
225  int nc = numberOfColumns;
226  int nPivot = std::min(numberOfRows, numberOfColumns);
227  int iPivot[nPivot];
228 
229  SmallMatrix result(*this);
230 
231  int info;
232 
233  dgetrf_(&nr, &nc, result.data(), &nr, iPivot, &info);
234 
235  return result;
236 }
#define min(a, b)
Definition: datatypes.h:22

References SmallMatrix< numberOfRows, numberOfColumns >::data(), dgetrf_(), info, and min.

◆ operator()() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
Mdouble& SmallMatrix< numberOfRows, numberOfColumns >::operator() ( unsigned int  n,
unsigned int  m 
)
inline

defines the operator(n,m) to access the element on row n and column m

116  {
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,
119  numberOfColumns);
120  return data_[n + m * numberOfRows];
121  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
int * m
Definition: level2_cplx_impl.h:294

References SmallMatrix< numberOfRows, numberOfColumns >::data_, logger, m, and n.

◆ operator()() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
const Mdouble& SmallMatrix< numberOfRows, numberOfColumns >::operator() ( unsigned int  n,
unsigned int  m 
) const
inline

defines the operator(n,m) to access the element on row n and column m

125  {
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,
128  numberOfColumns);
129  return data_[n + m * numberOfRows];
130  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, logger, m, and n.

◆ operator*() [1/5]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix SmallMatrix< numberOfRows, numberOfColumns >::operator* ( const Mdouble right) const
inline

Does matrix A_ij=scalar*B_ij.

154  {
155  SmallMatrix result;
156  std::transform(data_.begin(), data_.end(), result.data_.begin(),
157  std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, right));
158  return result;
159  }
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator*() [2/5]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
template<unsigned int K>
SmallMatrix< numberOfRows, K > SmallMatrix< numberOfRows, numberOfColumns >::operator* ( const SmallMatrix< numberOfColumns, K > &  other)

Does matrix A_ij = B_ik * C_kj.

122 {
123  int i = numberOfRows;
124  int j = numberOfColumns;
125  int k = K;
126 
127  if (numberOfColumns == 0)
128  {
129  logger(WARN, "Trying to multiply a matrix with a matrix without any columns.");
131  }
132  //The result of the matrix is left.numberOfRows, right.numberOfColumns()
134 
135  double d_one = 1.0;
136  double d_zero = 0.0;
137 
138  //Let the actual multiplication be done by Fortran
139  dgemm_("N", "N", &i, &k, &j, &d_one, this->data(), &i, const_cast<double*>(other.data()), &j, &d_zero, C.data(),
140  &i);
141 
142  return C;
143 }
@ WARN
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.
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
Definition: matrices.h:74
char char char int int * k
Definition: level2_impl.h:374
double K
Wave number.
Definition: sphere_scattering.cc:115

References SmallMatrix< numberOfRows, numberOfColumns >::data(), data, dgemm_(), i, j, k, PlanarWave::K, logger, and WARN.

◆ operator*() [3/5]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
template<unsigned int K>
SmallMatrix< numberOfRows, K > SmallMatrix< numberOfRows, numberOfColumns >::operator* ( const SmallMatrix< numberOfColumns, K > &  other) const
149 {
150  int i = numberOfRows;
151  int j = numberOfColumns;
152  int k = K;
153 
154  if (numberOfColumns == 0)
155  {
156  logger(WARN, "Trying to multiply a matrix with a matrix without any columns.");
158  }
159  //The result of the matrix is left.Nrows, right.NCols()
161 
162  double d_one = 1.0;
163  double d_zero = 0.0;
164 
165  //Let the actual multiplication be done by Fortran
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);
168 
169  return C;
170 }

References SmallMatrix< numberOfRows, numberOfColumns >::data(), data, dgemm_(), i, j, k, PlanarWave::K, logger, and WARN.

◆ operator*() [4/5]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallVector< numberOfRows > SmallMatrix< numberOfRows, numberOfColumns >::operator* ( SmallVector< numberOfColumns > &  right)

Defines Matrix A times vector B and return vector C i.e. C_,j= A_ij B_,j.

62 {
63  if (numberOfRows == 0)
64  {
65  logger(WARN, "Trying to multiply a vector with a matrix without any rows.");
67  }
68  if (numberOfColumns == 0)
69  {
70  logger(WARN, "Trying to multiply a vector with a matrix without any columns.");
72  }
73  int nr = numberOfRows;
74  int nc = numberOfColumns;
75 
76  int i_one = 1;
77  double d_one = 1.0;
78  double d_zero = 0.0;
79 
81 
82  logger(DEBUG, "Matrix size: % x % \n Vector size: %", nr, nc, right.size());
83 
84  dgemv_("N", &nr, &nc, &d_one, this->data(), &nr, right.data(), &i_one, &d_zero, result.data(), &i_one);
85  return result;
86 }
@ DEBUG
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.
unsigned int size() const
Definition: SmallVector.h:213

References SmallVector< numberOfRows >::data(), data, DEBUG, dgemv_(), logger, SmallVector< numberOfRows >::size(), and WARN.

◆ operator*() [5/5]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallVector< numberOfRows > SmallMatrix< numberOfRows, numberOfColumns >::operator* ( SmallVector< numberOfColumns > &  right) const
91 {
92  if (numberOfRows == 0)
93  {
94  logger(WARN, "Trying to multiply a vector with a matrix without any rows.");
96  }
97  if (numberOfColumns == 0)
98  {
99  logger(WARN, "Trying to multiply a vector with a matrix without any columns.");
100  return SmallVector<numberOfRows>();
101  }
102  int nr = numberOfRows;
103  int nc = numberOfColumns;
104 
105  int i_one = 1;
106  double d_one = 1.0;
107  double d_zero = 0.0;
108 
110 
111  logger(DEBUG, "Matrix size: % x % \n Vector size: %", nr, nc, right.size());
112 
113  dgemv_("N", &nr, &nc, &d_one, (const_cast<double*>(this->data())), &nr, right.data(), &i_one, &d_zero,
114  result.data(), &i_one);
115  return result;
116 }

References SmallVector< numberOfRows >::data(), data, DEBUG, dgemv_(), logger, SmallVector< numberOfRows >::size(), and WARN.

◆ operator*=() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator*= ( const Mdouble scalar)
inline

Does matrix A_ij=scalar*A_ij.

201  {
202  std::transform(data_.begin(), data_.end(), data_.begin(),
203  std::bind(std::multiplies<Mdouble>(), std::placeholders::_1, scalar));
204  return *this;
205  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator*=() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix< numberOfRows, numberOfColumns > & SmallMatrix< numberOfRows, numberOfColumns >::operator*= ( const SmallMatrix< numberOfColumns, numberOfColumns > &  other)

Does matrix A_ij = A_ik * B_kj note that other must be square because this is a fixed-size matrix.

175 {
176  //blas does not support in-place multiply
177  return (*this) = (*this) * other;
178 }

◆ operator+()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix SmallMatrix< numberOfRows, numberOfColumns >::operator+ ( const SmallMatrix< numberOfRows, numberOfColumns > &  other) const
inline
181  {
182  SmallMatrix result;
183  std::transform(data_.begin(), data_.end(), other.data_.begin(), result.data_.begin(), std::plus<Mdouble>());
184  return result;
185  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator+=()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator+= ( const SmallMatrix< numberOfRows, numberOfColumns > &  other)
inline
169  {
170  std::transform(data_.begin(), data_.end(), other.data_.begin(), data_.begin(), std::plus<Mdouble>());
171  return *this;
172  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator-() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix SmallMatrix< numberOfRows, numberOfColumns >::operator- ( void  ) const
inline
195  {
196  return *this * -1.;
197  }

◆ operator-() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix SmallMatrix< numberOfRows, numberOfColumns >::operator- ( const SmallMatrix< numberOfRows, numberOfColumns > &  other) const
inline
188  {
189  SmallMatrix result;
190  std::transform(data_.begin(), data_.end(), other.data_.begin(), result.data_.begin(), std::minus<Mdouble>());
191  return result;
192  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator-=()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator-= ( const SmallMatrix< numberOfRows, numberOfColumns > &  other)
inline
175  {
176  std::transform(data_.begin(), data_.end(), other.data_.begin(), data_.begin(), std::minus<Mdouble>());
177  return *this;
178  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator/()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix SmallMatrix< numberOfRows, numberOfColumns >::operator/ ( const Mdouble scalar) const
inline

this does element by divided by a scalar

221  {
222  SmallMatrix result;
223  std::transform(data_.begin(), data_.end(), result.data_.begin(),
224  std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
225  return result;
226  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator/=()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator/= ( const Mdouble scalar)
inline

Does matrix A_ij=scalar*A_ij.

213  {
214  std::transform(data_.begin(), data_.end(), data_.begin(),
215  std::bind(std::divides<Mdouble>(), std::placeholders::_1, scalar));
216  return *this;
217  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, and transform().

◆ operator=() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator= ( const SmallMatrix< numberOfRows, numberOfColumns > &  right)
inline

Assigns one matrix to another.

230  {
231  std::copy(right.data_.begin(), right.data_.end(), data_.begin());
232  return *this;
233  }

References copy(), and SmallMatrix< numberOfRows, numberOfColumns >::data_.

◆ operator=() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix& SmallMatrix< numberOfRows, numberOfColumns >::operator= ( SmallMatrix< numberOfRows, numberOfColumns > &&  right)
inline

Assigns one matrix to another.

237  {
238  std::move(right.data_.begin(), right.data_.end(), data_.begin());
239  return *this;
240  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_.

◆ operator[]() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
Mdouble& SmallMatrix< numberOfRows, numberOfColumns >::operator[] ( const unsigned int  n)
inline

Access the n linear element in the matrix.

134  {
135  logger.assert_debug(n < numberOfRows * numberOfColumns, "Requested entry % for a matrix with only % entries", n,
136  numberOfRows * numberOfColumns);
137  return data_[n];
138  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, logger, and n.

◆ operator[]() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
const Mdouble& SmallMatrix< numberOfRows, numberOfColumns >::operator[] ( const unsigned int  n) const
inline
141  {
142  logger.assert_debug(n < numberOfRows * numberOfColumns, "Requested entry % for a matrix with only % entries", n,
143  numberOfRows * numberOfColumns);
144  return data_[n];
145  }

References SmallMatrix< numberOfRows, numberOfColumns >::data_, logger, and n.

◆ size()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
unsigned int SmallMatrix< numberOfRows, numberOfColumns >::size ( ) const
inline

Get total number of Matrix entries.

256  {
257  return numberOfRows * numberOfColumns;
258  }

Referenced by main().

◆ solve() [1/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
template<unsigned int numberOfRightHandSideColumns>
void SmallMatrix< numberOfRows, numberOfColumns >::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.

310 {
311  logger.assert_debug(numberOfRows == numberOfColumns, "can only solve for square matrixes");
312 
313  int n = numberOfRows;
314  int nrhs = numberOfRightHandSideColumns;
315  int info;
316 
317  int IPIV[numberOfRows];
319  dgesv_(&n, &nrhs, matThis.data(), &n, IPIV, B.data(), &n, &info);
320 }
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.

References SmallMatrix< numberOfRows, numberOfColumns >::data(), dgesv_(), info, logger, and n.

Referenced by SuperQuadricParticle::computeContactPoint(), and main().

◆ solve() [2/2]

template<unsigned int numberOfRows, unsigned int numberOfColumns>
void SmallMatrix< numberOfRows, numberOfColumns >::solve ( SmallVector< numberOfRows > &  b) const

solves Ax=b where A is the current matrix and NumericalVector b is the input parameter. The result is returned in b.

324 {
325  logger.assert_debug(numberOfRows == numberOfColumns, "can only solve for square matrixes");
326 
327  int n = numberOfRows;
328  int nrhs = 1;
329  int info;
330 
331  int IPIV[numberOfRows];
332  SmallMatrix matThis = *this;
333  dgesv_(&n, &nrhs, matThis.data(), &n, IPIV, b.data(), &n, &info);
334 }
Scalar * b
Definition: benchVecAdd.cpp:17

References b, SmallMatrix< numberOfRows, numberOfColumns >::data(), dgesv_(), info, logger, and n.

◆ transpose()

template<unsigned int numberOfRows, unsigned int numberOfColumns>
SmallMatrix<numberOfColumns, numberOfRows> SmallMatrix< numberOfRows, numberOfColumns >::transpose ( ) const
inline
311  {
313  for (unsigned int i = 0; i < numberOfRows; ++i)
314  {
315  for (unsigned int j = 0; j < numberOfColumns; ++j)
316  {
317  result(j, i) = (*this)(i, j);
318  }
319  }
320  return result;
321  }

References i, and j.

Referenced by SuperQuadricParticle::getCurvature(), main(), ShapeGradientHessianTester::testCushion(), ShapeGradientHessianTester::testEllipsoid(), and ShapeGradientHessianTester::testRoundedBeam().

Member Data Documentation

◆ data_


The documentation for this class was generated from the following files: