a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
gslpp::matrix< complex > Class Template Reference

A class for constructing and defining operations on complex matrices. More...

#include <gslpp_matrix_complex.h>

Detailed Description

template<>
class gslpp::matrix< complex >

A class for constructing and defining operations on complex matrices.

Author
HEPfit Collaboration

This class defines some common operations on complex matrices using the GSL.

Definition at line 45 of file gslpp_matrix_complex.h.

Public Member Functions

gsl_matrix_complex & as_gsl_type ()
 
const gsl_matrix_complex & as_gsl_type () const
 
gsl_matrix_complex * as_gsl_type_ptr () const
 
void assign (const size_t &i, const size_t &j, const complex &z)
 
void assign (const size_t &i, const size_t &j, const double &a)
 
void assign (const size_t &i, const size_t &j, const matrix< complex > &z)
 
void assign (const size_t &i, const size_t &j, const matrix< double > &a)
 
void assignim (const size_t &i, const size_t &j, const double &a)
 
void assignre (const size_t &i, const size_t &j, const double &a)
 
void eigensystem (matrix< complex > &U, vector< double > &S) const
 
matrix< complexhconjugate () const
 
matrix< double > imag () const
 
matrix< complexinverse () const
 
bool isSingular ()
 
 matrix (const gsl_matrix_complex &m)
 
 matrix (const gsl_matrix_complex *m)
 
 matrix (const matrix< complex > &m)
 
 matrix (const matrix< double > &m)
 
 matrix (const size_t &size_i, const complex &z)
 
 matrix (const size_t &size_i, const double &a)
 
 matrix (const size_t &size_i, const size_t &size_j, const complex &z)
 Constructor. More...
 
 matrix (const size_t &size_i, const size_t &size_j, const double &a)
 Constructor. More...
 
 matrix (const vector< complex > &v)
 
 matrix (const vector< double > &v)
 
bool operator!= (const matrix< complex > &a) const
 
const complex operator() (const size_t &i, const size_t &j) const
 
matrix< complexoperator* (const complex &z) const
 
matrix< complexoperator* (const double &a) const
 
matrix< complexoperator* (const matrix< complex > &m) const
 
matrix< complexoperator* (const matrix< double > &m) const
 
vector< complexoperator* (const vector< complex > &v) const
 
vector< complexoperator* (const vector< double > &v) const
 
matrix< complex > & operator*= (const complex &z)
 
matrix< complex > & operator*= (const double &a)
 
matrix< complex > & operator*= (const matrix< complex > &m)
 
matrix< complexoperator+ (const complex &z) const
 
matrix< complexoperator+ (const double &a) const
 
matrix< complexoperator+ (const matrix< complex > &m) const
 
matrix< complexoperator+ (const matrix< double > &m) const
 
matrix< complex > & operator+= (const complex &z)
 
matrix< complex > & operator+= (const double &a)
 
matrix< complex > & operator+= (const matrix< complex > &m)
 
matrix< complexoperator- () const
 
matrix< complexoperator- (const complex &z) const
 
matrix< complexoperator- (const double &a) const
 
matrix< complexoperator- (const matrix< complex > &m) const
 
matrix< complexoperator- (const matrix< double > &m) const
 
matrix< complex > & operator-= (const complex &z)
 
matrix< complex > & operator-= (const double &a)
 
matrix< complex > & operator-= (const matrix< complex > &m)
 
matrix< complexoperator/ (const complex &z) const
 
matrix< complexoperator/ (const double &a) const
 
matrix< complex > & operator/= (const complex &z)
 
matrix< complex > & operator/= (const double &a)
 
matrix< complex > & operator= (const matrix< complex > &m)
 
bool operator== (const matrix< complex > &a) const
 
matrix< double > real () const
 
void reset ()
 
void singularvalue (matrix< complex > &U, matrix< complex > &V, vector< double > &S) const
 
size_t size () const
 
size_t size_i () const
 
size_t size_j () const
 
matrix< complextranspose () const
 
 ~matrix ()
 

Static Public Member Functions

static matrix< complexId (size_t size)
 

Private Attributes

gsl_matrix_complex * _matrix
 

Friends

std::ostream & operator<< (std::ostream &output, const matrix< complex > &v)
 
Operations on matrix<complex>
matrix< complexoperator+ (matrix< double > m1, const matrix< complex > m2)
 
matrix< complexoperator- (matrix< double > m1, const matrix< complex > m2)
 
matrix< complexoperator+ (const complex &z, const matrix< complex > m)
 
matrix< complexoperator- (const complex &z, const matrix< complex > m)
 
matrix< complexoperator* (const complex &z, const matrix< complex > m)
 
vector< complexoperator* (const vector< complex > &v, const matrix< complex > m)
 
vector< complexoperator* (const vector< double > &v, const matrix< complex > m)
 
matrix< complexoperator+ (const double &a, const matrix< complex > m)
 
matrix< complexoperator- (const double &a, const matrix< complex > m)
 
matrix< complexoperator* (const double &a, const matrix< complex > m)
 

Constructor & Destructor Documentation

◆ matrix() [1/10]

gslpp::matrix< complex >::matrix ( const size_t &  size_i,
const size_t &  size_j,
const complex z 
)

Constructor.

Parameters
size_inumber of rows
size_jnumber of columns
zinitial value of entries (complex)

Constructor

Definition at line 25 of file gslpp_matrix_complex.cpp.

26  {
27  _matrix = gsl_matrix_complex_alloc(size_i, size_j);
28  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
29  }

◆ matrix() [2/10]

gslpp::matrix< complex >::matrix ( const size_t &  size_i,
const complex z 
)

Definition at line 31 of file gslpp_matrix_complex.cpp.

32  {
33  _matrix = gsl_matrix_complex_alloc(size_i, size_i);
34  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
35  }

◆ matrix() [3/10]

gslpp::matrix< complex >::matrix ( const size_t &  size_i,
const size_t &  size_j,
const double &  a 
)

Constructor.

Parameters
size_inumber of rows
size_jnumber of columns
ainitial value of entries (double)

Definition at line 37 of file gslpp_matrix_complex.cpp.

38  {
39  complex z(a);
40  _matrix = gsl_matrix_complex_alloc(size_i, size_j);
41  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
42  }

◆ matrix() [4/10]

gslpp::matrix< complex >::matrix ( const size_t &  size_i,
const double &  a 
)

Definition at line 44 of file gslpp_matrix_complex.cpp.

45  {
46  complex z(a);
47  _matrix = gsl_matrix_complex_alloc(size_i, size_i);
48  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
49  }

◆ matrix() [5/10]

gslpp::matrix< complex >::matrix ( const matrix< complex > &  m)

Copy constructor

Copy constructor

Definition at line 52 of file gslpp_matrix_complex.cpp.

53  {
54  _matrix = gsl_matrix_complex_alloc(m.size_i(), m.size_j());
55  gsl_matrix_complex_memcpy(_matrix, m.as_gsl_type_ptr());
56  }

◆ matrix() [6/10]

gslpp::matrix< complex >::matrix ( const matrix< double > &  m)

Definition at line 58 of file gslpp_matrix_complex.cpp.

59  {
60  size_t i, j, size_i, size_j;
61  size_i = m.size_i();
62  size_j = m.size_j();
63  _matrix = gsl_matrix_complex_alloc(size_i, size_j);
64  for (i = 0; i < size_i; ++i)
65  for (j = 0; j < size_j; ++j)
66  gsl_matrix_complex_set(_matrix, i, j, m(i, j) + 0. * complex::i());
67  }

◆ matrix() [7/10]

gslpp::matrix< complex >::matrix ( const vector< complex > &  v)

Definition at line 69 of file gslpp_matrix_complex.cpp.

70  {
71  size_t i, size = v.size();
72  complex z(0, 0, false);
73  _matrix = gsl_matrix_complex_alloc(size, size);
74  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
75  for (i = 0; i < size; ++i)
76  gsl_matrix_complex_set(_matrix, i, i, v(i));
77  }

◆ matrix() [8/10]

gslpp::matrix< complex >::matrix ( const vector< double > &  v)

Definition at line 79 of file gslpp_matrix_complex.cpp.

80  {
81  size_t i, size = v.size();
82  complex z(0, 0, false);
83  _matrix = gsl_matrix_complex_alloc(size, size);
84  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
85  for (i = 0; i < size; ++i)
86  gsl_matrix_complex_set(_matrix, i, i, v(i) + 0. * complex::i());
87  }

◆ matrix() [9/10]

gslpp::matrix< complex >::matrix ( const gsl_matrix_complex &  m)

Definition at line 89 of file gslpp_matrix_complex.cpp.

90  {
91  _matrix = gsl_matrix_complex_alloc(m.size1, m.size2);
92  gsl_matrix_complex_memcpy(_matrix, &m);
93  }

◆ matrix() [10/10]

gslpp::matrix< complex >::matrix ( const gsl_matrix_complex *  m)

Definition at line 95 of file gslpp_matrix_complex.cpp.

96  {
97  _matrix = gsl_matrix_complex_alloc(m->size1, m->size2);
98  gsl_matrix_complex_memcpy(_matrix, m);
99  }

◆ ~matrix()

Destructor

Definition at line 102 of file gslpp_matrix_complex.cpp.

103  {
104  gsl_matrix_complex_free(_matrix);
105  }

Member Function Documentation

◆ as_gsl_type() [1/2]

gsl_matrix_complex & gslpp::matrix< complex >::as_gsl_type ( )

Definition at line 389 of file gslpp_matrix_complex.cpp.

390  {
391  return const_cast<gsl_matrix_complex&> (*_matrix);
392  }

◆ as_gsl_type() [2/2]

const gsl_matrix_complex & gslpp::matrix< complex >::as_gsl_type ( ) const

Definition at line 394 of file gslpp_matrix_complex.cpp.

395  {
396  return const_cast<gsl_matrix_complex&> (*_matrix);
397  }

◆ as_gsl_type_ptr()

gsl_matrix_complex * gslpp::matrix< complex >::as_gsl_type_ptr ( ) const

Conversion

Conversion

Definition at line 384 of file gslpp_matrix_complex.cpp.

385  {
386  return _matrix;
387  }

◆ assign() [1/4]

void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const complex z 
)

Assign element

Definition at line 140 of file gslpp_matrix_complex.cpp.

141  {
142  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
143  *x = z.as_gsl_type();
144  }

◆ assign() [2/4]

void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const double &  a 
)

Definition at line 146 of file gslpp_matrix_complex.cpp.

147  {
148  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
149  *x = complex(a).as_gsl_type();
150  }

◆ assign() [3/4]

void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const matrix< complex > &  z 
)

Assign submatrix

Definition at line 165 of file gslpp_matrix_complex.cpp.

166  {
167  size_t ki, kj;
168  gsl_complex *x;
169  if (i + z.size_i() <= size_i() && j + z.size_j() <= size_j())
170  for (ki = i; ki < i + z.size_i(); ki++)
171  for (kj = j; kj < j + z.size_j(); kj++)
172  {
173  x = gsl_matrix_complex_ptr(_matrix, ki, kj);
174  *x = z(ki - i, kj - j).as_gsl_type();
175  } else
176  {
177  std::cout << "\n ** Wrong size assign in matrix<complex> assign submatrix" << std::endl;
178  exit(EXIT_FAILURE);
179  }
180  }

◆ assign() [4/4]

void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const matrix< double > &  a 
)

Definition at line 182 of file gslpp_matrix_complex.cpp.

183  {
184  matrix<complex> z(a);
185  assign(i, j, z);
186  }

◆ assignim()

void gslpp::matrix< complex >::assignim ( const size_t &  i,
const size_t &  j,
const double &  a 
)

Definition at line 158 of file gslpp_matrix_complex.cpp.

159  {
160  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
161  GSL_SET_IMAG(x, a);
162  }

◆ assignre()

void gslpp::matrix< complex >::assignre ( const size_t &  i,
const size_t &  j,
const double &  a 
)

Definition at line 152 of file gslpp_matrix_complex.cpp.

153  {
154  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
155  GSL_SET_REAL(x, a);
156  }

◆ eigensystem()

void gslpp::matrix< complex >::eigensystem ( matrix< complex > &  U,
vector< double > &  S 
) const

Eigenvalues and eigenvectors

Parameters
Umatrix<complex>& eigenvectors
Svector<double>& eigenvalues

Definition at line 347 of file gslpp_matrix_complex.cpp.

348  {
349  matrix<complex> m(*this);
350 
351  gsl_eigen_hermv_workspace *ws;
352 
353  ws = gsl_eigen_hermv_alloc(size_i());
354 
355  gsl_eigen_hermv(m.as_gsl_type_ptr(), S.as_gsl_type_ptr(), U.as_gsl_type_ptr(), ws);
356 
357  gsl_eigen_hermv_sort(S.as_gsl_type_ptr(), U.as_gsl_type_ptr(),
358  GSL_EIGEN_SORT_VAL_ASC);
359 
360  gsl_eigen_hermv_free(ws);
361  }

◆ hconjugate()

matrix< complex > gslpp::matrix< complex >::hconjugate ( ) const

Hermitean conjugate matrix

Definition at line 229 of file gslpp_matrix_complex.cpp.

230  {
231  matrix<complex> m1(*this);
232  gsl_complex z1, z2;
233 
234  GSL_SET_COMPLEX(&z1, 1., 0.);
235  GSL_SET_COMPLEX(&z2, 0., 0.);
236 
237  if (gsl_blas_zgemm(CblasConjTrans, CblasNoTrans, z1, _matrix,
238  Id(size_j()).as_gsl_type_ptr(), z2, m1.as_gsl_type_ptr()) != 0)
239  {
240  std::cout << "\n ** Error in matrix<complex> conjugate" << std::endl;
241  exit(EXIT_FAILURE);
242  }
243 
244  return m1;
245  }

◆ Id()

matrix< complex > gslpp::matrix< complex >::Id ( size_t  size)
static

Identity matrix

Definition at line 211 of file gslpp_matrix_complex.cpp.

212  {
213  return matrix<double>::Id(size) * (1. + 0. * complex::i());
214  }

◆ imag()

matrix< double > gslpp::matrix< complex >::imag ( ) const

Get matrix of imaginary parts

Definition at line 335 of file gslpp_matrix_complex.cpp.

336  {
337  matrix<double> res(size_i(), size_j());
338  for (size_t i = 0; i < size_i(); i++)
339  {
340  gsl_vector_complex_view tmp = gsl_matrix_complex_row(_matrix, i);
341  gsl_vector_view tmpd = gsl_vector_complex_imag(&tmp.vector);
342  gsl_matrix_set_row(res.as_gsl_type_ptr(), i, &tmpd.vector);
343  }
344  return res;
345  }

◆ inverse()

matrix< complex > gslpp::matrix< complex >::inverse ( ) const

Inverse matrix

Definition at line 248 of file gslpp_matrix_complex.cpp.

249  {
250  matrix<complex> m1(_matrix);
251  matrix<complex> m2(_matrix);
252  int signum;
253  gsl_permutation *p;
254 
255  if (size_j() != size_i())
256  {
257  std::cout << "\n ** Size mismatch in matrix<complex> inverse" << std::endl;
258  exit(EXIT_FAILURE);
259  }
260 
261  if ((p = gsl_permutation_alloc(size_i())) == NULL)
262  {
263  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
264  exit(EXIT_FAILURE);
265  }
266 
267  if (gsl_linalg_complex_LU_decomp(m1.as_gsl_type_ptr(), p, &signum))
268  {
269  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
270  gsl_permutation_free(p);
271  exit(EXIT_FAILURE);
272  }
273 
274  if (gsl_linalg_complex_LU_invert(m1.as_gsl_type_ptr(), p,
275  m2.as_gsl_type_ptr()))
276  {
277  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
278  gsl_permutation_free(p);
279  exit(EXIT_FAILURE);
280  }
281  gsl_permutation_free(p);
282  return m2;
283  }

◆ isSingular()

bool gslpp::matrix< complex >::isSingular ( )

Check is matrix is singular to avoid errors in luc.c

Check if matrix is singular (This is to avoid error checking by luc.c)

Definition at line 287 of file gslpp_matrix_complex.cpp.

288  {
289  matrix<complex> m1(_matrix);
290  int signum;
291  gsl_permutation *p;
292 
293  if (size_j() != size_i())
294  {
295  std::cout << "\n ** Size mismatch in bool isSingular" << std::endl;
296  exit(EXIT_FAILURE);
297  }
298 
299  if ((p = gsl_permutation_alloc(size_i())) == NULL)
300  {
301  std::cout << "\n ** Error in bool isSingular" << std::endl;
302  exit(EXIT_FAILURE);
303  }
304 
305  if (gsl_linalg_complex_LU_decomp(m1.as_gsl_type_ptr(), p, &signum))
306  {
307  std::cout << "\n ** Error in bool isSingular" << std::endl;
308  gsl_permutation_free(p);
309  exit(EXIT_FAILURE);
310  }
311 
312  size_t i, n = m1.size_i();
313 
314  for (i = 0; i < n; i++) {
315  gsl_complex u = gsl_matrix_complex_get(m1.as_gsl_type_ptr(), i, i);
316  if (GSL_REAL(u) == 0 && GSL_IMAG(u) == 0) return 1;
317  }
318  return 0;
319  }

◆ operator!=()

bool gslpp::matrix< complex >::operator!= ( const matrix< complex > &  a) const
inline

Definition at line 182 of file gslpp_matrix_complex.h.

183  {
184  return(!(*this == a));
185  }

◆ operator()()

const complex gslpp::matrix< complex >::operator() ( const size_t &  i,
const size_t &  j 
) const

Get i-th element

Definition at line 108 of file gslpp_matrix_complex.cpp.

109  {
110  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
111  return complex(x);
112  }

◆ operator*() [1/6]

matrix< complex > gslpp::matrix< complex >::operator* ( const complex z) const

Multiplication operator

Multiplication operator (complex)

Definition at line 581 of file gslpp_matrix_complex.cpp.

582  {
583  matrix<complex> m1(_matrix);
584  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z.as_gsl_type()))
585  {
586  std::cout << "\n ** Error in matrix<complex> * (complex)" << std::endl;
587  exit(EXIT_FAILURE);
588  }
589  return m1;
590  }

◆ operator*() [2/6]

matrix< complex > gslpp::matrix< complex >::operator* ( const double &  a) const

Multiplication operator

Multiplication operator (double)

Definition at line 647 of file gslpp_matrix_complex.cpp.

648  {
649  complex z(a);
650  return *this * z;
651  }

◆ operator*() [3/6]

matrix< complex > gslpp::matrix< complex >::operator* ( const matrix< complex > &  m) const

Multiplication operator

Multiplication operator (matrix complex)

Definition at line 443 of file gslpp_matrix_complex.cpp.

444  {
445  matrix<complex> m1(_matrix);
446  gsl_complex z1, z2;
447 
448  if (size_j() != m.size_i())
449  {
450  std::cout << "\n ** Size mismatch in matrix<complex> *" << std::endl;
451  exit(EXIT_FAILURE);
452  }
453  GSL_SET_COMPLEX(&z1, 1., 0.);
454  GSL_SET_COMPLEX(&z2, 0., 0.);
455  if (gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, z1, _matrix,
456  m.as_gsl_type_ptr(), z2, m1.as_gsl_type_ptr()))
457  {
458  std::cout << "\n ** Error in matrix<complex> *" << std::endl;
459  exit(EXIT_FAILURE);
460  }
461  return m1;
462  }

◆ operator*() [4/6]

matrix< complex > gslpp::matrix< complex >::operator* ( const matrix< double > &  m) const

Multiplication operator

Multiplication operator (matrix double)

Definition at line 491 of file gslpp_matrix_complex.cpp.

492  {
493  matrix<complex> m1(m);
494  return *this * m1;
495  }

◆ operator*() [5/6]

vector< complex > gslpp::matrix< complex >::operator* ( const vector< complex > &  v) const

Multiplication operator

Multiplication operator (vector complex)

Definition at line 498 of file gslpp_matrix_complex.cpp.

499  {
500  gsl_complex z1, z2;
501  vector<complex> v1(size_i(), 0.);
502 
503  if (size_j() != v.size())
504  {
505  std::cout << "\n ** Size mismatch in matrix<complex> * (vector complex)"
506  << std::endl;
507  exit(EXIT_FAILURE);
508  }
509  GSL_SET_COMPLEX(&z1, 1., 0.);
510  GSL_SET_COMPLEX(&z2, 0., 0.);
511  if (gsl_blas_zgemv(CblasNoTrans, z1, _matrix, v.as_gsl_type_ptr(),
512  z2, v1.as_gsl_type_ptr()))
513  {
514  std::cout << "\n ** Error in matrix<complex> * (vector complex)"
515  << std::endl;
516  exit(EXIT_FAILURE);
517  }
518  return v1;
519  }

◆ operator*() [6/6]

vector< complex > gslpp::matrix< complex >::operator* ( const vector< double > &  v) const

Multiplication operator (vector double)

Definition at line 522 of file gslpp_matrix_complex.cpp.

523  {
524  vector<complex> v1(v);
525  return *this * v1;
526  }

◆ operator*=() [1/3]

matrix< complex > & gslpp::matrix< complex >::operator*= ( const complex z)

Multiplication assignment

Multiplication assignment (complex)

Definition at line 619 of file gslpp_matrix_complex.cpp.

620  {
621  *this = *this * z;
622  return *this;
623  }

◆ operator*=() [2/3]

matrix< complex > & gslpp::matrix< complex >::operator*= ( const double &  a)

Multiplication assignment

Multiplication assignment (double)

Definition at line 675 of file gslpp_matrix_complex.cpp.

676  {
677  *this = *this * a;
678  return *this;
679  }

◆ operator*=() [3/3]

matrix< complex > & gslpp::matrix< complex >::operator*= ( const matrix< complex > &  m)

Multiplication assignment

Multiplication assignment (matrix)

Definition at line 543 of file gslpp_matrix_complex.cpp.

544  {
545  if (!((size_i() == size_j()) && (size_i() == m.size_i()) &&
546  (size_j() == m.size_j())))
547  {
548  std::cout << "\n ** Size mismatch in matrix<complex> *= (matrix)"
549  << std::endl;
550  exit(EXIT_FAILURE);
551  }
552  *this = *this * m;
553  return *this;
554  }

◆ operator+() [1/4]

matrix< complex > gslpp::matrix< complex >::operator+ ( const complex z) const

Addition operator

Addition operator (complex)

Definition at line 557 of file gslpp_matrix_complex.cpp.

558  {
559  matrix<complex> m1(_matrix);
560  if (gsl_matrix_complex_add_constant(m1.as_gsl_type_ptr(), z.as_gsl_type()))
561  {
562  std::cout << "\n ** Error in matrix<complex> + (complex)" << std::endl;
563  exit(EXIT_FAILURE);
564  }
565  return m1;
566  }

◆ operator+() [2/4]

matrix< complex > gslpp::matrix< complex >::operator+ ( const double &  a) const

Addition operator

Addition operator (double)

Definition at line 633 of file gslpp_matrix_complex.cpp.

634  {
635  complex z(a);
636  return *this +z;
637  }

◆ operator+() [3/4]

matrix< complex > gslpp::matrix< complex >::operator+ ( const matrix< complex > &  m) const

Addition operator

Addition operator (matrix)

Definition at line 418 of file gslpp_matrix_complex.cpp.

419  {
420  matrix<complex> m1(_matrix);
421  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m.as_gsl_type_ptr()))
422  {
423  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
424  exit(EXIT_FAILURE);
425  }
426  return m1;
427  }

◆ operator+() [4/4]

matrix< complex > gslpp::matrix< complex >::operator+ ( const matrix< double > &  m) const

Addition operator

Addition operator (matrix)

Definition at line 465 of file gslpp_matrix_complex.cpp.

466  {
467  matrix<complex> m1(_matrix);
468  matrix<complex> m2(m);
469  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
470  {
471  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
472  exit(EXIT_FAILURE);
473  }
474  return m1;
475  }

◆ operator+=() [1/3]

matrix< complex > & gslpp::matrix< complex >::operator+= ( const complex z)

Addition assignment

Addition assignment (complex)

Definition at line 605 of file gslpp_matrix_complex.cpp.

606  {
607  *this = *this +z;
608  return *this;
609  }

◆ operator+=() [2/3]

matrix< complex > & gslpp::matrix< complex >::operator+= ( const double &  a)

Addition assignment

Addition assignment (double)

Definition at line 661 of file gslpp_matrix_complex.cpp.

662  {
663  *this = *this +a;
664  return *this;
665  }

◆ operator+=() [3/3]

matrix< complex > & gslpp::matrix< complex >::operator+= ( const matrix< complex > &  m)

Addition assignment

Addition assignment (matrix)

Definition at line 529 of file gslpp_matrix_complex.cpp.

530  {
531  *this = *this +m;
532  return *this;
533  }

◆ operator-() [1/5]

matrix< complex > gslpp::matrix< complex >::operator- ( ) const

check whether two matrices are equal Unary minus

Unary minus

Definition at line 404 of file gslpp_matrix_complex.cpp.

405  {
406  matrix<complex> m1(_matrix);
407  gsl_complex z1;
408  GSL_SET_COMPLEX(&z1, -1., 0.);
409  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z1))
410  {
411  std::cout << "\n ** Error in matrix<complex> unary -" << std::endl;
412  exit(EXIT_FAILURE);
413  }
414  return m1;
415  }

◆ operator-() [2/5]

matrix< complex > gslpp::matrix< complex >::operator- ( const complex z) const

Subtraction operator

Subtraction operator (complex)

Definition at line 569 of file gslpp_matrix_complex.cpp.

570  {
571  matrix<complex> m1(_matrix);
572  if (gsl_matrix_complex_add_constant(m1.as_gsl_type_ptr(), (-z).as_gsl_type()))
573  {
574  std::cout << "\n ** Error in matrix<complex> - (complex)" << std::endl;
575  exit(EXIT_FAILURE);
576  }
577  return m1;
578  }

◆ operator-() [3/5]

matrix< complex > gslpp::matrix< complex >::operator- ( const double &  a) const

Subtraction operator

Subtraction assignment (double)

Definition at line 640 of file gslpp_matrix_complex.cpp.

641  {
642  complex z(a);
643  return *this -z;
644  }

◆ operator-() [4/5]

matrix< complex > gslpp::matrix< complex >::operator- ( const matrix< complex > &  m) const

Subtraction operator

Subtraction operator (matrix)

Definition at line 430 of file gslpp_matrix_complex.cpp.

431  {
432  matrix<complex> m1(_matrix);
433  matrix<complex> m2 = -m;
434  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
435  {
436  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
437  exit(EXIT_FAILURE);
438  }
439  return m1;
440  }

◆ operator-() [5/5]

matrix< complex > gslpp::matrix< complex >::operator- ( const matrix< double > &  m) const

Subtraction operator

Subtraction operator (matrix)

Definition at line 478 of file gslpp_matrix_complex.cpp.

479  {
480  matrix<complex> m1(_matrix);
481  matrix<complex> m2(-m);
482  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
483  {
484  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
485  exit(EXIT_FAILURE);
486  }
487  return m1;
488  }

◆ operator-=() [1/3]

matrix< complex > & gslpp::matrix< complex >::operator-= ( const complex z)

Subtraction assignment

Subtraction assignment (complex)

Definition at line 612 of file gslpp_matrix_complex.cpp.

613  {
614  *this = *this -z;
615  return *this;
616  }

◆ operator-=() [2/3]

matrix< complex > & gslpp::matrix< complex >::operator-= ( const double &  a)

Subtraction assignment

Subtraction assignment (double)

Definition at line 668 of file gslpp_matrix_complex.cpp.

669  {
670  *this = *this -a;
671  return *this;
672  }

◆ operator-=() [3/3]

matrix< complex > & gslpp::matrix< complex >::operator-= ( const matrix< complex > &  m)

Subtraction assignment

Subtraction assignment (matrix)

Definition at line 536 of file gslpp_matrix_complex.cpp.

537  {
538  *this = *this -m;
539  return *this;
540  }

◆ operator/() [1/2]

matrix< complex > gslpp::matrix< complex >::operator/ ( const complex z) const

Division operator

Division operator (complex)

Definition at line 593 of file gslpp_matrix_complex.cpp.

594  {
595  matrix<complex> m1(_matrix);
596  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z.inverse().as_gsl_type()))
597  {
598  std::cout << "\n ** Error in matrix<complex> / (complex)" << std::endl;
599  exit(EXIT_FAILURE);
600  }
601  return m1;
602  }

◆ operator/() [2/2]

matrix< complex > gslpp::matrix< complex >::operator/ ( const double &  a) const

Division operator

Division operator (double)

Definition at line 654 of file gslpp_matrix_complex.cpp.

655  {
656  complex z(a);
657  return *this / z;
658  }

◆ operator/=() [1/2]

matrix< complex > & gslpp::matrix< complex >::operator/= ( const complex z)

Division assignment

Division assignment (complex)

Definition at line 626 of file gslpp_matrix_complex.cpp.

627  {
628  *this = *this / z;
629  return *this;
630  }

◆ operator/=() [2/2]

matrix< complex > & gslpp::matrix< complex >::operator/= ( const double &  a)

Division assignment

Division assignment (double)

Definition at line 682 of file gslpp_matrix_complex.cpp.

683  {
684  *this = *this / a;
685  return *this;
686  }

◆ operator=()

matrix< complex > & gslpp::matrix< complex >::operator= ( const matrix< complex > &  m)

Set i-th element Assign

Definition at line 127 of file gslpp_matrix_complex.cpp.

128  {
129  if (size_i() == m.size_i() && size_j() == m.size_j())
130  gsl_matrix_complex_memcpy(_matrix, m.as_gsl_type_ptr());
131  else
132  {
133  std::cout << "\n ** Wrong size assign in matrix<complex> operator =" << std::endl;
134  exit(EXIT_FAILURE);
135  }
136  return *this;
137  }

◆ operator==()

bool gslpp::matrix< complex >::operator== ( const matrix< complex > &  a) const

Comparison == (matrix)

Definition at line 689 of file gslpp_matrix_complex.cpp.

690  {
691  if (a.size_i() != size_i() || a.size_j() != size_j())
692  {
693  std::cout << "\n Error in matrix<complex>::operator== (matrix): cannot compare matrices of different size" << std::endl;
694  exit(EXIT_FAILURE);
695  }
696  for (size_t i = 0; i < size_i(); i++)
697  for (size_t j = 0; j < size_j(); j++)
698  if (a(i, j) != (*this)(i, j)) return (false);
699  return (true);
700  }

◆ real()

matrix< double > gslpp::matrix< complex >::real ( ) const

Get matrix of real parts

Definition at line 322 of file gslpp_matrix_complex.cpp.

323  {
324  matrix<double> res(size_i(), size_j());
325  for (size_t i = 0; i < size_i(); i++)
326  {
327  gsl_vector_complex_view tmp = gsl_matrix_complex_row(_matrix, i);
328  gsl_vector_view tmpd = gsl_vector_complex_real(&tmp.vector);
329  gsl_matrix_set_row(res.as_gsl_type_ptr(), i, &tmpd.vector);
330  }
331  return res;
332  }

◆ reset()

void gslpp::matrix< complex >::reset ( )

Assign element

Set i-th element Assign

Definition at line 122 of file gslpp_matrix_complex.cpp.

123  {
124  gsl_matrix_complex_set_zero(_matrix);
125  }

◆ singularvalue()

void gslpp::matrix< complex >::singularvalue ( matrix< complex > &  U,
matrix< complex > &  V,
vector< double > &  S 
) const

Singular Value Decomposition as U diagonalmatrix(S) V^+

Parameters
Umatrix<complex>&
Vmatrix<complex>&
Svector<double>&

Definition at line 363 of file gslpp_matrix_complex.cpp.

365  {
366  size_t i;
367  matrix<complex> m(*this);
368  vector<complex> v1(size_i(), 0.);
369 
370  m = (*this) * hconjugate();
371  m.eigensystem(U, S);
372  m = hconjugate()*(*this);
373  m.eigensystem(V, S);
374  m = U.hconjugate()*(*this) * V;
375  for (i = 0; i < m.size_i(); i++)
376  {
377  v1.assign(i, complex(1., -m(i, i).arg(), true));
378  S(i) = m(i, i).abs();
379  }
380  V = V * matrix<complex>(v1);
381  }

◆ size()

size_t gslpp::matrix< complex >::size ( ) const

Definition at line 199 of file gslpp_matrix_complex.cpp.

200  {
201  if (_matrix->size1 == _matrix->size2)
202  return _matrix->size2;
203  else
204  {
205  std::cout << "\n ** Non square matrix" << std::endl;
206  exit(EXIT_FAILURE);
207  }
208  }

◆ size_i()

size_t gslpp::matrix< complex >::size_i ( ) const

Get matrix size

Definition at line 189 of file gslpp_matrix_complex.cpp.

190  {
191  return _matrix->size1;
192  }

◆ size_j()

size_t gslpp::matrix< complex >::size_j ( ) const

Definition at line 194 of file gslpp_matrix_complex.cpp.

195  {
196  return _matrix->size2;
197  }

◆ transpose()

matrix< complex > gslpp::matrix< complex >::transpose ( ) const

Transpose matrix

Definition at line 217 of file gslpp_matrix_complex.cpp.

218  {
219  matrix<complex> m1(size_j(), size_i(), 0.);
220  if (gsl_matrix_complex_transpose_memcpy(m1.as_gsl_type_ptr(), _matrix))
221  {
222  std::cout << "\n ** Error in matrix<complex> transpose" << std::endl;
223  exit(EXIT_FAILURE);
224  }
225  return m1;
226  }

Friends And Related Function Documentation

◆ operator* [1/4]

matrix<complex> operator* ( const complex z,
const matrix< complex m 
)
friend

Multiply a complex number by complex matrix

Parameters
zComplex number
mComplex matrix
Returns
\( z*m \)

Definition at line 737 of file gslpp_matrix_complex.cpp.

738  {
739  return m * z;
740  }

◆ operator* [2/4]

matrix<complex> operator* ( const double &  a,
const matrix< complex m 
)
friend

Multiply a real number by a complex matrix

Parameters
aReal number
mComplex matrix
Returns
\( z*m \)

Definition at line 762 of file gslpp_matrix_complex.cpp.

763  {
764  return m * a;
765  }

◆ operator* [3/4]

vector<complex> operator* ( const vector< complex > &  v,
const matrix< complex m 
)
friend

Multiply a complex vector by a complex matrix

Parameters
vComplex vector
mComplex matrix
Returns
\( v*m \)

Definition at line 742 of file gslpp_matrix_complex.cpp.

743  {
744  return m.transpose() * v;
745  }

◆ operator* [4/4]

vector<complex> operator* ( const vector< double > &  v,
const matrix< complex m 
)
friend

Multiply a real vector by a complex matrix

Parameters
vReal vector
mComplex matrix
Returns
\( v*m \)

Definition at line 747 of file gslpp_matrix_complex.cpp.

748  {
749  return m.transpose() * v;
750  }

◆ operator+ [1/3]

matrix<complex> operator+ ( const complex z,
const matrix< complex m 
)
friend

Add a complex number to a complex matrix

Parameters
zComplex number
mComplex matrix
Returns
\( z + m \)

Definition at line 727 of file gslpp_matrix_complex.cpp.

728  {
729  return m + z;
730  }

◆ operator+ [2/3]

matrix<complex> operator+ ( const double &  a,
const matrix< complex m 
)
friend

Add a real number to a complex matrix

Parameters
aReal number
mComplex matrix
Returns
\( a + m \)

Definition at line 752 of file gslpp_matrix_complex.cpp.

753  {
754  return m + a;
755  }

◆ operator+ [3/3]

matrix<complex> operator+ ( matrix< double >  m1,
const matrix< complex m2 
)
friend

Add a double matrix to a complex matrix

Parameters
m1Double matrix
m2Complex matrix
Returns
\( m2 + m1 \)

Definition at line 717 of file gslpp_matrix_complex.cpp.

718  {
719  return m2 + m1;
720  }

◆ operator- [1/3]

matrix<complex> operator- ( const complex z,
const matrix< complex m 
)
friend

Subtract a complex number from a complex matrix

Parameters
zComplex number
mComplex matrix
Returns
\( z - m \)

Definition at line 732 of file gslpp_matrix_complex.cpp.

733  {
734  return -m + z;
735  }

◆ operator- [2/3]

matrix<complex> operator- ( const double &  a,
const matrix< complex m 
)
friend

Subtract a complex matrix from a real number

Parameters
aReal number
mComplex matrix
Returns
\( a - m \)

Definition at line 757 of file gslpp_matrix_complex.cpp.

758  {
759  return -m + a;
760  }

◆ operator- [3/3]

matrix<complex> operator- ( matrix< double >  m1,
const matrix< complex m2 
)
friend

Subtract a double matrix to a complex matrix

Parameters
m1Double matrix
m2Complex matrix
Returns
\( -m2 + m1 \)

Definition at line 722 of file gslpp_matrix_complex.cpp.

723  {
724  return -m2 + m1;
725  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  output,
const matrix< complex > &  v 
)
friend

friend functions

Definition at line 703 of file gslpp_matrix_complex.cpp.

704  {
705  size_t i, j;
706  for (i = 0; i < m.size_i(); i++)
707  {
708  output << std::endl;
709  output << "\t(";
710  for (j = 0; j < m.size_j() - 1; j++)
711  output << m(i, j) << ",";
712  output << m(i, j) << ")";
713  }
714  return output;
715  }

Member Data Documentation

◆ _matrix

gsl_matrix_complex* gslpp::matrix< complex >::_matrix
private

Definition at line 47 of file gslpp_matrix_complex.h.


The documentation for this class was generated from the following files:
gslpp::matrix< complex >::as_gsl_type
gsl_matrix_complex & as_gsl_type()
Definition: gslpp_matrix_complex.cpp:389
gslpp::matrix< complex >::hconjugate
matrix< complex > hconjugate() const
Definition: gslpp_matrix_complex.cpp:229
gslpp::matrix< double >::Id
static matrix< double > Id(size_t size)
Definition: gslpp_matrix_double.cpp:154
gslpp::matrix< complex >::size
size_t size() const
Definition: gslpp_matrix_complex.cpp:199
gslpp::matrix< complex >::_matrix
gsl_matrix_complex * _matrix
Definition: gslpp_matrix_complex.h:47
gslpp::matrix< complex >::assign
void assign(const size_t &i, const size_t &j, const complex &z)
Definition: gslpp_matrix_complex.cpp:140
gslpp::matrix< complex >::size_j
size_t size_j() const
Definition: gslpp_matrix_complex.cpp:194
gslpp::matrix< complex >::size_i
size_t size_i() const
Definition: gslpp_matrix_complex.cpp:189
gslpp::matrix< complex >::eigensystem
void eigensystem(matrix< complex > &U, vector< double > &S) const
Definition: gslpp_matrix_complex.cpp:347
gslpp::complex::i
static const complex & i()
Definition: gslpp_complex.cpp:154
gslpp::matrix< complex >::as_gsl_type_ptr
gsl_matrix_complex * as_gsl_type_ptr() const
Definition: gslpp_matrix_complex.cpp:384
S
A class for the form factor in .
Definition: MVllObservables.h:1436
gslpp::matrix< complex >::Id
static matrix< complex > Id(size_t size)
Definition: gslpp_matrix_complex.cpp:211