28 #ifndef _SRC_COMMON_CPP_MATHS_MMATRIX_HH_
29 #define _SRC_COMMON_CPP_MATHS_MMATRIX_HH_
34 #include "gsl/gsl_matrix.h"
35 #include "gsl/gsl_blas.h"
61 template <
class Tmplt>
81 MMatrix(
size_t nrows,
size_t ncols, Tmplt* data_beginning );
89 MMatrix(
size_t nrows,
size_t ncols, Tmplt value);
96 MMatrix(
size_t nrows,
size_t ncols);
151 MMatrix<Tmplt> sub(
size_t min_row,
size_t max_row,
size_t min_col,
size_t max_col)
const;
242 if(_matrix)
return ((gsl_matrix*)_matrix)->size1;
248 if(_matrix)
return ((gsl_matrix_complex*)_matrix)->size1;
254 if(_matrix)
return ((gsl_matrix*)_matrix)->size2;
261 if(_matrix)
return ((gsl_matrix_complex*)_matrix)->size2;
266 {gsl_matrix_complex_scale((gsl_matrix_complex*)m.
_matrix,
c);
return m;}
269 {gsl_matrix_scale((gsl_matrix*)m.
_matrix, d);
return m;}
281 gsl_blas_dgemv(CblasNoTrans, 1., (gsl_matrix*)m.
_matrix, (gsl_vector*)v.
_vector, 0., (gsl_vector*)v0.
_vector);
286 {gsl_matrix_complex_add((gsl_matrix_complex*)m1.
_matrix, (gsl_matrix_complex*)m2.
_matrix);
return m1;}
289 {gsl_matrix_add((gsl_matrix*)m1.
_matrix, (gsl_matrix*)m2.
_matrix);
return m1;}
292 {
for(
size_t i=1; i<=m1.
num_row(); i++)
for(
size_t j=1; j<=m1.
num_col(); j++) m1(i,j) = -1.*m1(i,j);
return m1; }
320 {
return *gsl_matrix_ptr((gsl_matrix*)_matrix, i-1, j-1); }
323 {
return *gsl_matrix_complex_ptr((gsl_matrix_complex*)_matrix, i-1, j-1); }
327 {
return *gsl_matrix_ptr((gsl_matrix*)_matrix, i-1, j-1); }
330 {
return *gsl_matrix_complex_ptr((gsl_matrix_complex*)_matrix, i-1, j-1); }
332 template <
class Tmplt>
336 for(
size_t i=1; i<=lhs.
num_row(); i++)
337 for(
size_t j=1; j<=lhs.
num_col(); j++)
338 if(lhs(i,j) != rhs(i,j))
return false;
342 template <
class Tmplt>
346 template <
class Tmplt> std::ostream&
operator<<(std::ostream& out, MMatrix<Tmplt>);
349 template <
class Tmplt>
357 template <
class Tmplt>
362 return (gsl_matrix_complex*)m.
_matrix;
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
MMatrix< Tmplt > operator*(MMatrix< Tmplt >, Tmplt)
MMatrix< Tmplt > operator/(MMatrix< Tmplt >, Tmplt)
Mesh::Iterator & operator+=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
m_complex m_complex_build(double r, double i)
Mesh::Iterator operator+(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Mesh::Iterator operator-(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
bool operator==(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
MMatrix< Tmplt > & operator-=(MMatrix< Tmplt > &m1, MMatrix< Tmplt > m2)
MMatrix< double > & operator+=(MMatrix< double > &m1, const MMatrix< double > &m2)
MMatrix< m_complex > complex(MMatrix< double > real)
bool operator!=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Mesh::Iterator & operator-=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
MVector< m_complex > operator*(MMatrix< m_complex > m, MVector< m_complex > v)
MMatrix< Tmplt > & operator/=(MMatrix< Tmplt > &m, Tmplt t)
MMatrix< double > re(MMatrix< m_complex > mc)
MMatrix< double > & operator*=(MMatrix< double > &m, double d)
std::ostream & operator<<(std::ostream &out, const Mesh::Iterator &it)
MMatrix< double > & operator*=(MMatrix< double > &m1, MMatrix< double > m2)
bool operator!=(const MMatrix< Tmplt > &c1, const MMatrix< Tmplt > &c2)
MMatrix< double > im(MMatrix< m_complex > mc)
MMatrix< Tmplt > operator+(MMatrix< Tmplt >, MMatrix< Tmplt >)
template std::istream & operator>>(std::istream &in, MMatrix< double > &mat)
bool operator==(const MMatrix< Tmplt > &c1, const MMatrix< Tmplt > &c2)
MMatrix< Tmplt > operator-(MMatrix< Tmplt >)
constexpr double c
The velocity of light in m/s.
void build_matrix(size_t i, size_t j, Tmplt *temp)
friend MMatrix< m_complex > & operator+=(MMatrix< m_complex > &m1, const MMatrix< m_complex > &m2)
friend MMatrix< Tmplt2 > operator+(MMatrix< Tmplt2 > m1, const MMatrix< Tmplt2 > m2)
MMatrix< Tmplt > & operator=(const MMatrix< Tmplt > &mm)
void invert()
turns this matrix into its inverse
static gsl_matrix * get_matrix(const MMatrix< double > &m)
MVector< Tmplt > get_mvector(size_t column) const
size_t num_col() const
returns number of columns in the matrix
MVector< m_complex > eigenvalues() const
returns a vector of eigenvalues. Throws an exception if either this matrix is not square or the eigen...
void build_matrix(size_t i, size_t j)
MMatrix(const MMatrix< Tmplt > &mv)
Copy constructor makes a deep copy of mv.
MMatrix< Tmplt > T() const
returns matrix transpose T (such that M(i,j) = T(j,i))
friend MVector< m_complex > operator*(MMatrix< m_complex > m, MVector< m_complex > v)
size_t num_row() const
returns number of rows in the matrix
std::pair< MVector< m_complex >, MMatrix< m_complex > > eigenvectors() const
MMatrix< Tmplt > inverse() const
returns matrix inverse leaving this matrix unchanged
MMatrix< Tmplt > sub(size_t min_row, size_t max_row, size_t min_col, size_t max_col) const
static MMatrix< Tmplt > Diagonal(size_t i, Tmplt diag_value, Tmplt off_diag_value)
Construct a square matrix filling on and off diagonal values.
Tmplt & operator()(size_t row, size_t column)
Tmplt determinant() const
returns matrix determinant; throws an exception if matrix is not square
const Tmplt & operator()(size_t row, size_t column) const
static gsl_matrix_complex * get_matrix(const MMatrix< m_complex > &m)
MMatrix()
default constructor makes an empty MMatrix of size (0,0)
friend MMatrix< m_complex > & operator*=(MMatrix< m_complex > &m, m_complex c)
Tmplt trace() const
returns sum of terms with row == column, even if matrix is not square