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
 
 matrix (const size_t &size_i, const size_t &size_j, const complex &z)
 Constructor. More...
 
 matrix (const size_t &size_i, const complex &z)
 
 matrix (const size_t &size_i, const size_t &size_j, const double &a)
 Constructor. More...
 
 matrix (const size_t &size_i, const double &a)
 
 matrix (const matrix< complex > &m)
 
 matrix (const matrix< double > &m)
 
 matrix (const vector< complex > &v)
 
 matrix (const vector< double > &v)
 
 matrix (const gsl_matrix_complex &m)
 
 matrix (const gsl_matrix_complex *m)
 
const complex operator() (const size_t &i, const size_t &j) 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< complexoperator* (const complex &z) const
 
matrix< complexoperator* (const double &a) const
 
matrix< complex > & operator*= (const matrix< complex > &m)
 
matrix< complex > & operator*= (const complex &z)
 
matrix< complex > & operator*= (const double &a)
 
matrix< complexoperator+ (const matrix< complex > &m) const
 
matrix< complexoperator+ (const matrix< double > &m) const
 
matrix< complexoperator+ (const complex &z) const
 
matrix< complexoperator+ (const double &a) const
 
matrix< complex > & operator+= (const matrix< complex > &m)
 
matrix< complex > & operator+= (const complex &z)
 
matrix< complex > & operator+= (const double &a)
 
matrix< complexoperator- () const
 
matrix< complexoperator- (const matrix< complex > &m) const
 
matrix< complexoperator- (const matrix< double > &m) const
 
matrix< complexoperator- (const complex &z) const
 
matrix< complexoperator- (const double &a) const
 
matrix< complex > & operator-= (const matrix< complex > &m)
 
matrix< complex > & operator-= (const complex &z)
 
matrix< complex > & operator-= (const double &a)
 
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)
 
matrix< double > real () const
 
void singularvalue (matrix< complex > &U, matrix< complex > &V, vector< double > &S) 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

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  }
gsl_matrix_complex * _matrix
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  }
gsl_matrix_complex * _matrix
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  }
gsl_matrix_complex * _matrix
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  }
gsl_matrix_complex * _matrix
gslpp::matrix< complex >::matrix ( const matrix< complex > &  m)

Copy constructor

Definition at line 51 of file gslpp_matrix_complex.cpp.

52  {
53  _matrix = gsl_matrix_complex_alloc(m.size_i(), m.size_j());
54  gsl_matrix_complex_memcpy(_matrix, m.as_gsl_type_ptr());
55  }
gsl_matrix_complex * _matrix
gslpp::matrix< complex >::matrix ( const matrix< double > &  m)

Definition at line 57 of file gslpp_matrix_complex.cpp.

58  {
59  size_t i, j, size_i, size_j;
60  size_i=m.size_i();
61  size_j=m.size_j();
62  _matrix = gsl_matrix_complex_alloc(size_i, size_j);
63  for(i=0; i<size_i; ++i)
64  for(j=0; j<size_j; ++j)
65  gsl_matrix_complex_set(_matrix, i, j, m(i,j)+0.*complex::i());
66  }
gsl_matrix_complex * _matrix
static const complex & i()
gslpp::matrix< complex >::matrix ( const vector< complex > &  v)

Definition at line 68 of file gslpp_matrix_complex.cpp.

69  {
70  size_t i, size = v.size();
71  complex z(0,0,false);
72  _matrix = gsl_matrix_complex_alloc(size, size);
73  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
74  for(i=0; i<size; ++i)
75  gsl_matrix_complex_set(_matrix, i, i, v(i));
76  }
gsl_matrix_complex * _matrix
gslpp::matrix< complex >::matrix ( const vector< double > &  v)

Definition at line 78 of file gslpp_matrix_complex.cpp.

79  {
80  size_t i, size = v.size();
81  complex z(0,0,false);
82  _matrix = gsl_matrix_complex_alloc(size, size);
83  gsl_matrix_complex_set_all(_matrix, z.as_gsl_type());
84  for(i=0; i<size; ++i)
85  gsl_matrix_complex_set(_matrix, i, i, v(i)+0.*complex::i());
86  }
gsl_matrix_complex * _matrix
static const complex & i()
gslpp::matrix< complex >::matrix ( const gsl_matrix_complex &  m)

Definition at line 88 of file gslpp_matrix_complex.cpp.

89  {
90  _matrix = gsl_matrix_complex_alloc(m.size1, m.size2);
91  gsl_matrix_complex_memcpy(_matrix, &m);
92  }
gsl_matrix_complex * _matrix
gslpp::matrix< complex >::matrix ( const gsl_matrix_complex *  m)

Definition at line 94 of file gslpp_matrix_complex.cpp.

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

Destructor

Definition at line 101 of file gslpp_matrix_complex.cpp.

102  {
103  gsl_matrix_complex_free(_matrix);
104  }
gsl_matrix_complex * _matrix

Member Function Documentation

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

Definition at line 335 of file gslpp_matrix_complex.cpp.

336  {
337  return const_cast<gsl_matrix_complex&>(*_matrix);
338  }
const gsl_matrix_complex & gslpp::matrix< complex >::as_gsl_type ( ) const

Definition at line 340 of file gslpp_matrix_complex.cpp.

341  {
342  return const_cast<gsl_matrix_complex&>(*_matrix);
343  }
gsl_matrix_complex * gslpp::matrix< complex >::as_gsl_type_ptr ( ) const

Conversion

Definition at line 330 of file gslpp_matrix_complex.cpp.

331  {
332  return _matrix;
333  }
gsl_matrix_complex * _matrix
void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const complex z 
)

Assign element

Definition at line 134 of file gslpp_matrix_complex.cpp.

135  {
136  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
137  *x = z.as_gsl_type();
138  }
gsl_matrix_complex * _matrix
void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const double &  a 
)

Definition at line 140 of file gslpp_matrix_complex.cpp.

141  {
142  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
143  *x = complex(a).as_gsl_type();
144  }
gsl_matrix_complex * _matrix
void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const matrix< complex > &  z 
)

Assign submatrix

Definition at line 159 of file gslpp_matrix_complex.cpp.

160  {
161  size_t ki,kj;
162  gsl_complex *x;
163  if(i+z.size_i() <= size_i() && j+z.size_j() <= size_j())
164  for(ki=i;ki<i+z.size_i();ki++)
165  for(kj=j;kj<j+z.size_j();kj++)
166  {
167  x = gsl_matrix_complex_ptr(_matrix, ki, kj);
168  *x = z(ki-i,kj-j).as_gsl_type();
169  }
170  else
171  {
172  std::cout << "\n ** Wrong size assign in matrix<complex> assign submatrix" << std::endl;
173  exit(EXIT_FAILURE);
174  }
175  }
gsl_matrix_complex * _matrix
void gslpp::matrix< complex >::assign ( const size_t &  i,
const size_t &  j,
const matrix< double > &  a 
)

Definition at line 177 of file gslpp_matrix_complex.cpp.

178  {
179  matrix<complex> z(a);
180  assign(i,j,z);
181  }
void assign(const size_t &i, const size_t &j, const complex &z)
void gslpp::matrix< complex >::assignim ( 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_IMAG(x,a);
156  }
gsl_matrix_complex * _matrix
void gslpp::matrix< complex >::assignre ( 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  GSL_SET_REAL(x,a);
150  }
gsl_matrix_complex * _matrix
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 293 of file gslpp_matrix_complex.cpp.

294  {
295  matrix<complex> m(*this);
296 
297  gsl_eigen_hermv_workspace *ws;
298 
299  ws = gsl_eigen_hermv_alloc(size_i());
300 
301  gsl_eigen_hermv(m.as_gsl_type_ptr(), S.as_gsl_type_ptr(), U.as_gsl_type_ptr(), ws);
302 
303  gsl_eigen_hermv_sort(S.as_gsl_type_ptr(), U.as_gsl_type_ptr(),
304  GSL_EIGEN_SORT_VAL_ASC);
305 
306  gsl_eigen_hermv_free(ws);
307  }
A class for the form factor in .
matrix< complex > gslpp::matrix< complex >::hconjugate ( ) const

Hermitean conjugate matrix

Definition at line 213 of file gslpp_matrix_complex.cpp.

214  {
215  matrix<complex> m1(*this);
216  gsl_complex z1, z2;
217 
218  GSL_SET_COMPLEX(&z1,1.,0.);
219  GSL_SET_COMPLEX(&z2,0.,0.);
220 
221  if(gsl_blas_zgemm(CblasConjTrans,CblasNoTrans, z1, _matrix,
222  Id(size_j()).as_gsl_type_ptr(), z2, m1.as_gsl_type_ptr()) != 0)
223  {
224  std::cout << "\n ** Error in matrix<complex> conjugate" << std::endl;
225  exit(EXIT_FAILURE);
226  }
227 
228  return m1;
229  }
gsl_matrix_complex * _matrix
static matrix< complex > Id(size_t size)
gsl_matrix_complex * as_gsl_type_ptr() const
matrix< complex > gslpp::matrix< complex >::Id ( size_t  size)
static

Identity matrix

Definition at line 195 of file gslpp_matrix_complex.cpp.

196  {
197  return matrix<double>::Id(size) * (1.+0.*complex::i());
198  }
static const complex & i()
static matrix< double > Id(size_t size)
matrix< double > gslpp::matrix< complex >::imag ( ) const

Get matrix of imaginary parts

Definition at line 282 of file gslpp_matrix_complex.cpp.

283  {
284  matrix<double> res(size_i(), size_j());
285  for(size_t i = 0; i < size_i(); i++) {
286  gsl_vector_complex_view tmp = gsl_matrix_complex_row(_matrix, i);
287  gsl_vector_view tmpd = gsl_vector_complex_imag(&tmp.vector);
288  gsl_matrix_set_row(res.as_gsl_type_ptr(),i,&tmpd.vector);
289  }
290  return res;
291  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::inverse ( ) const

Inverse matrix

Definition at line 232 of file gslpp_matrix_complex.cpp.

233  {
234  matrix<complex> m1(_matrix);
235  matrix<complex> m2(_matrix);
236  int signum;
237  gsl_permutation *p;
238 
239  if (size_j() != size_i())
240  {
241  std::cout << "\n ** Size mismatch in matrix<complex> inverse" << std::endl;
242  exit(EXIT_FAILURE);
243  }
244 
245  if ((p = gsl_permutation_alloc(size_i())) == NULL)
246  {
247  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
248  exit(EXIT_FAILURE);
249  }
250 
251  if(gsl_linalg_complex_LU_decomp (m1.as_gsl_type_ptr(), p, &signum))
252  {
253  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
254  gsl_permutation_free(p);
255  exit(EXIT_FAILURE);
256  }
257 
258  if(gsl_linalg_complex_LU_invert(m1.as_gsl_type_ptr(), p,
259  m2.as_gsl_type_ptr()))
260  {
261  std::cout << "\n ** Error in matrix<complex> inverse" << std::endl;
262  gsl_permutation_free(p);
263  exit(EXIT_FAILURE);
264  }
265  gsl_permutation_free(p);
266  return m2;
267  }
gsl_matrix_complex * _matrix
const complex gslpp::matrix< complex >::operator() ( const size_t &  i,
const size_t &  j 
) const

Get i-th element

Definition at line 107 of file gslpp_matrix_complex.cpp.

108  {
109  gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
110  return complex(x);
111  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator* ( const matrix< complex > &  m) const

Multiplication operator

Multiplication operator (matrix complex)

Definition at line 388 of file gslpp_matrix_complex.cpp.

389  {
390  matrix<complex> m1(_matrix);
391  gsl_complex z1, z2;
392 
393  if (size_j() != m.size_i())
394  {
395  std::cout << "\n ** Size mismatch in matrix<complex> *" << std::endl;
396  exit(EXIT_FAILURE);
397  }
398  GSL_SET_COMPLEX(&z1,1.,0.);
399  GSL_SET_COMPLEX(&z2,0.,0.);
400  if(gsl_blas_zgemm(CblasNoTrans,CblasNoTrans, z1, _matrix,
401  m.as_gsl_type_ptr(), z2, m1.as_gsl_type_ptr()))
402  {
403  std::cout << "\n ** Error in matrix<complex> *" << std::endl;
404  exit(EXIT_FAILURE);
405  }
406  return m1;
407  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator* ( const matrix< double > &  m) const

Multiplication operator

Multiplication operator (matrix double)

Definition at line 435 of file gslpp_matrix_complex.cpp.

436  {
437  matrix<complex> m1(m);
438  return *this * m1;
439  }
vector< complex > gslpp::matrix< complex >::operator* ( const vector< complex > &  v) const

Multiplication operator

Multiplication operator (vector complex)

Definition at line 442 of file gslpp_matrix_complex.cpp.

443  {
444  gsl_complex z1, z2;
445  vector<complex> v1(size_i(),0.);
446 
447  if (size_j() != v.size())
448  {
449  std::cout << "\n ** Size mismatch in matrix<complex> * (vector complex)"
450  << 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_zgemv(CblasNoTrans, z1, _matrix, v.as_gsl_type_ptr(),
456  z2, v1.as_gsl_type_ptr()))
457  {
458  std::cout << "\n ** Error in matrix<complex> * (vector complex)"
459  << std::endl;
460  exit(EXIT_FAILURE);
461  }
462  return v1;
463  }
gsl_matrix_complex * _matrix
vector< complex > gslpp::matrix< complex >::operator* ( const vector< double > &  v) const

Multiplication operator (vector double)

Definition at line 466 of file gslpp_matrix_complex.cpp.

467  {
468  vector<complex> v1(v);
469  return *this * v1;
470  }
matrix< complex > gslpp::matrix< complex >::operator* ( const complex z) const

Multiplication operator

Multiplication operator (complex)

Definition at line 524 of file gslpp_matrix_complex.cpp.

525  {
526  matrix<complex> m1(_matrix);
527  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z.as_gsl_type()))
528  {
529  std::cout << "\n ** Error in matrix<complex> * (complex)" << std::endl;
530  exit(EXIT_FAILURE);
531  }
532  return m1;
533  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator* ( const double &  a) const

Multiplication operator

Multiplication operator (double)

Definition at line 587 of file gslpp_matrix_complex.cpp.

588  {
589  complex z(a);
590  return *this * z;
591  }
matrix< complex > & gslpp::matrix< complex >::operator*= ( const matrix< complex > &  m)

Multiplication assignment

Multiplication assignment (matrix)

Definition at line 486 of file gslpp_matrix_complex.cpp.

487  {
488  if (!((size_i() == size_j()) && (size_i() == m.size_i()) &&
489  (size_j() == m.size_j())))
490  {
491  std::cout << "\n ** Size mismatch in matrix<complex> *= (matrix)"
492  << std::endl;
493  exit(EXIT_FAILURE);
494  }
495  *this = *this * m;
496  return *this;
497  }
matrix< complex > & gslpp::matrix< complex >::operator*= ( const complex z)

Multiplication assignment

Multiplication assignment (complex)

Definition at line 560 of file gslpp_matrix_complex.cpp.

561  {
562  *this = *this * z;
563  return *this;
564  }
matrix< complex > & gslpp::matrix< complex >::operator*= ( const double &  a)

Multiplication assignment

Multiplication assignment (double)

Definition at line 612 of file gslpp_matrix_complex.cpp.

613  {
614  *this = *this * a;
615  return *this;
616  }
matrix< complex > gslpp::matrix< complex >::operator+ ( const matrix< complex > &  m) const

Addition operator

Addition operator (matrix)

Definition at line 364 of file gslpp_matrix_complex.cpp.

365  {
366  matrix<complex> m1(_matrix);
367  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m.as_gsl_type_ptr()))
368  {
369  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
370  exit(EXIT_FAILURE);
371  }
372  return m1;
373  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator+ ( const matrix< double > &  m) const

Addition operator

Addition operator (matrix)

Definition at line 410 of file gslpp_matrix_complex.cpp.

411  {
412  matrix<complex> m1(_matrix);
413  matrix<complex> m2(m);
414  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
415  {
416  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
417  exit(EXIT_FAILURE);
418  }
419  return m1;
420  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator+ ( const complex z) const

Addition operator

Addition operator (complex)

Definition at line 500 of file gslpp_matrix_complex.cpp.

501  {
502  matrix<complex> m1(_matrix);
503  if (gsl_matrix_complex_add_constant(_matrix, z.as_gsl_type()))
504  {
505  std::cout << "\n ** Error in matrix<complex> + (complex)" << std::endl;
506  exit(EXIT_FAILURE);
507  }
508  return m1;
509  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator+ ( const double &  a) const

Addition operator

Addition operator (double)

Definition at line 573 of file gslpp_matrix_complex.cpp.

574  {
575  complex z(a);
576  return *this + z;
577  }
matrix< complex > & gslpp::matrix< complex >::operator+= ( const matrix< complex > &  m)

Addition assignment

Addition assignment (matrix)

Definition at line 473 of file gslpp_matrix_complex.cpp.

474  {
475  *this = *this + m;
476  return *this;
477  }
matrix< complex > & gslpp::matrix< complex >::operator+= ( const complex z)

Addition assignment

Addition assignment (complex)

Definition at line 548 of file gslpp_matrix_complex.cpp.

549  {
550  *this = *this + z;
551  return *this;
552  }
matrix< complex > & gslpp::matrix< complex >::operator+= ( const double &  a)

Addition assignment

Addition assignment (double)

Definition at line 600 of file gslpp_matrix_complex.cpp.

601  {
602  *this = *this + a;
603  return *this;
604  }
matrix< complex > gslpp::matrix< complex >::operator- ( ) const

check whether two matrices are equal Unary minus

Unary minus

Definition at line 350 of file gslpp_matrix_complex.cpp.

351  {
352  matrix<complex> m1(_matrix);
353  gsl_complex z1;
354  GSL_SET_COMPLEX(&z1,-1.,0.);
355  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z1))
356  {
357  std::cout << "\n ** Error in matrix<complex> unary -" << std::endl;
358  exit(EXIT_FAILURE);
359  }
360  return m1;
361  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator- ( const matrix< complex > &  m) const

Subtraction operator

Subtraction operator (matrix)

Definition at line 375 of file gslpp_matrix_complex.cpp.

376  {
377  matrix<complex> m1(_matrix);
378  matrix<complex> m2 = -m;
379  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
380  {
381  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
382  exit(EXIT_FAILURE);
383  }
384  return m1;
385  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator- ( const matrix< double > &  m) const

Subtraction operator

Subtraction operator (matrix)

Definition at line 422 of file gslpp_matrix_complex.cpp.

423  {
424  matrix<complex> m1(_matrix);
425  matrix<complex> m2(-m);
426  if (gsl_matrix_complex_add(m1.as_gsl_type_ptr(), m2.as_gsl_type_ptr()))
427  {
428  std::cout << "\n ** Error in matrix<complex> +" << std::endl;
429  exit(EXIT_FAILURE);
430  }
431  return m1;
432  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator- ( const complex z) const

Subtraction operator

Subtraction operator (complex)

Definition at line 512 of file gslpp_matrix_complex.cpp.

513  {
514  matrix<complex> m1(_matrix);
515  if (gsl_matrix_complex_add_constant(_matrix, (-z).as_gsl_type()))
516  {
517  std::cout << "\n ** Error in matrix<complex> - (complex)" << std::endl;
518  exit(EXIT_FAILURE);
519  }
520  return m1;
521  }
gsl_matrix_complex * _matrix
gsl_matrix_complex & as_gsl_type()
matrix< complex > gslpp::matrix< complex >::operator- ( const double &  a) const

Subtraction operator

Subtraction assignment (double)

Definition at line 580 of file gslpp_matrix_complex.cpp.

581  {
582  complex z(a);
583  return *this - z;
584  }
matrix< complex > & gslpp::matrix< complex >::operator-= ( const matrix< complex > &  m)

Subtraction assignment

Subtraction assignment (matrix)

Definition at line 479 of file gslpp_matrix_complex.cpp.

480  {
481  *this = *this - m;
482  return *this;
483  }
matrix< complex > & gslpp::matrix< complex >::operator-= ( const complex z)

Subtraction assignment

Subtraction assignment (complex)

Definition at line 554 of file gslpp_matrix_complex.cpp.

555  {
556  *this = *this - z;
557  return *this;
558  }
matrix< complex > & gslpp::matrix< complex >::operator-= ( const double &  a)

Subtraction assignment

Subtraction assignment (double)

Definition at line 606 of file gslpp_matrix_complex.cpp.

607  {
608  *this = *this - a;
609  return *this;
610  }
matrix< complex > gslpp::matrix< complex >::operator/ ( const complex z) const

Division operator

Division operator (complex)

Definition at line 536 of file gslpp_matrix_complex.cpp.

537  {
538  matrix<complex> m1(_matrix);
539  if (gsl_matrix_complex_scale(m1.as_gsl_type_ptr(), z.inverse().as_gsl_type()))
540  {
541  std::cout << "\n ** Error in matrix<complex> / (complex)" << std::endl;
542  exit(EXIT_FAILURE);
543  }
544  return m1;
545  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::operator/ ( const double &  a) const

Division operator

Division operator (double)

Definition at line 594 of file gslpp_matrix_complex.cpp.

595  {
596  complex z(a);
597  return *this / z;
598  }
matrix< complex > & gslpp::matrix< complex >::operator/= ( const complex z)

Division assignment

Division assignment (complex)

Definition at line 566 of file gslpp_matrix_complex.cpp.

567  {
568  *this = *this / z;
569  return *this;
570  }
matrix< complex > & gslpp::matrix< complex >::operator/= ( const double &  a)

Division assignment

Division assignment (double)

Definition at line 618 of file gslpp_matrix_complex.cpp.

619  {
620  *this = *this / a;
621  return *this;
622  }
matrix< complex > & gslpp::matrix< complex >::operator= ( const matrix< complex > &  m)

Set i-th element Assign

Definition at line 121 of file gslpp_matrix_complex.cpp.

122  {
123  if(size_i()==m.size_i() && size_j()==m.size_j())
124  gsl_matrix_complex_memcpy(_matrix, m.as_gsl_type_ptr());
125  else
126  {
127  std::cout << "\n ** Wrong size assign in matrix<complex> operator =" << std::endl;
128  exit(EXIT_FAILURE);
129  }
130  return *this;
131  }
gsl_matrix_complex * _matrix
matrix< double > gslpp::matrix< complex >::real ( ) const

Get matrix of real parts

Definition at line 270 of file gslpp_matrix_complex.cpp.

271  {
272  matrix<double> res(size_i(), size_j());
273  for(size_t i = 0; i < size_i(); i++) {
274  gsl_vector_complex_view tmp = gsl_matrix_complex_row(_matrix, i);
275  gsl_vector_view tmpd = gsl_vector_complex_real(&tmp.vector);
276  gsl_matrix_set_row(res.as_gsl_type_ptr(),i,&tmpd.vector);
277  }
278  return res;
279  }
gsl_matrix_complex * _matrix
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 309 of file gslpp_matrix_complex.cpp.

311  {
312  size_t i;
313  matrix<complex> m(*this);
314  vector<complex> v1(size_i(),0.);
315 
316  m = (*this)*hconjugate();
317  m.eigensystem(U, S);
318  m = hconjugate()*(*this);
319  m.eigensystem(V, S);
320  m = U.hconjugate()*(*this)*V;
321  for(i=0; i<m.size_i(); i++)
322  {
323  v1.assign(i,complex(1.,-m(i,i).arg(),true));
324  S(i)=m(i,i).abs();
325  }
326  V=V*matrix<complex>(v1);
327  }
A class for the form factor in .
matrix< complex > hconjugate() const
void eigensystem(matrix< complex > &U, vector< double > &S) const
size_t gslpp::matrix< complex >::size_i ( ) const

Get matrix size

Definition at line 184 of file gslpp_matrix_complex.cpp.

185  {
186  return _matrix->size1;
187  }
gsl_matrix_complex * _matrix
size_t gslpp::matrix< complex >::size_j ( ) const

Definition at line 189 of file gslpp_matrix_complex.cpp.

190  {
191  return _matrix->size2;
192  }
gsl_matrix_complex * _matrix
matrix< complex > gslpp::matrix< complex >::transpose ( ) const

Transpose matrix

Definition at line 201 of file gslpp_matrix_complex.cpp.

202  {
203  matrix<complex> m1(size_j(), size_i(), 0.);
204  if (gsl_matrix_complex_transpose_memcpy(m1.as_gsl_type_ptr(), _matrix))
205  {
206  std::cout << "\n ** Error in matrix<complex> transpose" << std::endl;
207  exit(EXIT_FAILURE);
208  }
209  return m1;
210  }
gsl_matrix_complex * _matrix

Friends And Related Function Documentation

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 656 of file gslpp_matrix_complex.cpp.

657  {
658  return m * z;
659  }
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 661 of file gslpp_matrix_complex.cpp.

662  {
663  return m.transpose() * v;
664  }
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 666 of file gslpp_matrix_complex.cpp.

667  {
668  return m.transpose() * v;
669  }
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 681 of file gslpp_matrix_complex.cpp.

682  {
683  return m * a;
684  }
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 638 of file gslpp_matrix_complex.cpp.

638  {
639  return m2 + m1;
640  }
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 646 of file gslpp_matrix_complex.cpp.

647  {
648  return m + z;
649  }
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 671 of file gslpp_matrix_complex.cpp.

672  {
673  return m + a;
674  }
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 642 of file gslpp_matrix_complex.cpp.

642  {
643  return -m2 + m1;
644  }
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 651 of file gslpp_matrix_complex.cpp.

652  {
653  return -m + z;
654  }
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 676 of file gslpp_matrix_complex.cpp.

677  {
678  return -m + a;
679  }
std::ostream& operator<< ( std::ostream &  output,
const matrix< complex > &  v 
)
friend

friend functions

Definition at line 624 of file gslpp_matrix_complex.cpp.

625  {
626  size_t i,j;
627  for (i=0; i<m.size_i(); i++)
628  {
629  output << std::endl;
630  output << "\t(";
631  for (j=0; j<m.size_j()-1; j++)
632  output << m(i,j) << ",";
633  output << m(i,j) << ")";
634  }
635  return output;
636  }

Member Data Documentation

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: