10 #include <gsl/gsl_blas.h>
12 #ifndef __GSL_LINALG_H__
13 #include <gsl/gsl_linalg.h>
15 #ifndef __GSL_EIGEN_H__
16 #include <gsl/gsl_eigen.h>
18 #ifndef GSLPP_MATRIX_COMPLEX_H
27 _matrix = gsl_matrix_complex_alloc(size_i, size_j);
28 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
33 _matrix = gsl_matrix_complex_alloc(size_i, size_i);
34 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
40 _matrix = gsl_matrix_complex_alloc(size_i, size_j);
41 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
47 _matrix = gsl_matrix_complex_alloc(size_i, size_i);
48 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
53 _matrix = gsl_matrix_complex_alloc(m.
size_i(), m.
size_j());
59 size_t i, j, size_i, 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());
70 size_t i, size = v.
size();
72 _matrix = gsl_matrix_complex_alloc(size, size);
73 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
75 gsl_matrix_complex_set(_matrix, i, i, v(i));
80 size_t i, size = v.
size();
82 _matrix = gsl_matrix_complex_alloc(size, size);
83 gsl_matrix_complex_set_all(_matrix, z.
as_gsl_type());
85 gsl_matrix_complex_set(_matrix, i, i, v(i)+0.*
complex::i());
90 _matrix = gsl_matrix_complex_alloc(m.size1, m.size2);
91 gsl_matrix_complex_memcpy(_matrix, &m);
96 _matrix = gsl_matrix_complex_alloc(m->size1, m->size2);
97 gsl_matrix_complex_memcpy(_matrix, m);
103 gsl_matrix_complex_free(_matrix);
109 gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
127 std::cout <<
"\n ** Wrong size assign in matrix<complex> operator =" << std::endl;
136 gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
142 gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
148 gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
154 gsl_complex *x = gsl_matrix_complex_ptr(_matrix, i, j);
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++)
167 x = gsl_matrix_complex_ptr(_matrix, ki, kj);
172 std::cout <<
"\n ** Wrong size assign in matrix<complex> assign submatrix" << std::endl;
186 return _matrix->size1;
191 return _matrix->size2;
204 if (gsl_matrix_complex_transpose_memcpy(m1.
as_gsl_type_ptr(), _matrix))
206 std::cout <<
"\n ** Error in matrix<complex> transpose" << std::endl;
218 GSL_SET_COMPLEX(&z1,1.,0.);
219 GSL_SET_COMPLEX(&z2,0.,0.);
221 if(gsl_blas_zgemm(CblasConjTrans,CblasNoTrans, z1, _matrix,
224 std::cout <<
"\n ** Error in matrix<complex> conjugate" << std::endl;
239 if (size_j() != size_i())
241 std::cout <<
"\n ** Size mismatch in matrix<complex> inverse" << std::endl;
245 if ((p = gsl_permutation_alloc(size_i())) == NULL)
247 std::cout <<
"\n ** Error in matrix<complex> inverse" << std::endl;
253 std::cout <<
"\n ** Error in matrix<complex> inverse" << std::endl;
254 gsl_permutation_free(p);
261 std::cout <<
"\n ** Error in matrix<complex> inverse" << std::endl;
262 gsl_permutation_free(p);
265 gsl_permutation_free(p);
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);
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);
297 gsl_eigen_hermv_workspace *ws;
299 ws = gsl_eigen_hermv_alloc(size_i());
304 GSL_EIGEN_SORT_VAL_ASC);
306 gsl_eigen_hermv_free(ws);
316 m = (*this)*hconjugate();
318 m = hconjugate()*(*this);
321 for(i=0; i<m.
size_i(); i++)
337 return const_cast<gsl_matrix_complex&
>(*_matrix);
342 return const_cast<gsl_matrix_complex&
>(*_matrix);
354 GSL_SET_COMPLEX(&z1,-1.,0.);
357 std::cout <<
"\n ** Error in matrix<complex> unary -" << std::endl;
369 std::cout <<
"\n ** Error in matrix<complex> +" << std::endl;
381 std::cout <<
"\n ** Error in matrix<complex> +" << std::endl;
393 if (size_j() != m.
size_i())
395 std::cout <<
"\n ** Size mismatch in matrix<complex> *" << std::endl;
398 GSL_SET_COMPLEX(&z1,1.,0.);
399 GSL_SET_COMPLEX(&z2,0.,0.);
400 if(gsl_blas_zgemm(CblasNoTrans,CblasNoTrans, z1, _matrix,
403 std::cout <<
"\n ** Error in matrix<complex> *" << std::endl;
416 std::cout <<
"\n ** Error in matrix<complex> +" << std::endl;
428 std::cout <<
"\n ** Error in matrix<complex> +" << std::endl;
447 if (size_j() != v.
size())
449 std::cout <<
"\n ** Size mismatch in matrix<complex> * (vector complex)"
453 GSL_SET_COMPLEX(&z1, 1., 0.);
454 GSL_SET_COMPLEX(&z2, 0., 0.);
458 std::cout <<
"\n ** Error in matrix<complex> * (vector complex)"
488 if (!((size_i() == size_j()) && (size_i() == m.
size_i()) &&
489 (size_j() == m.
size_j())))
491 std::cout <<
"\n ** Size mismatch in matrix<complex> *= (matrix)"
503 if (gsl_matrix_complex_add_constant(_matrix, z.
as_gsl_type()))
505 std::cout <<
"\n ** Error in matrix<complex> + (complex)" << std::endl;
515 if (gsl_matrix_complex_add_constant(_matrix, (-z).as_gsl_type()))
517 std::cout <<
"\n ** Error in matrix<complex> - (complex)" << std::endl;
529 std::cout <<
"\n ** Error in matrix<complex> * (complex)" << std::endl;
541 std::cout <<
"\n ** Error in matrix<complex> / (complex)" << std::endl;
624 std::ostream& operator<<(std::ostream& output, const matrix<complex>& m)
627 for (i=0; i<m.size_i(); i++)
631 for (j=0; j<m.size_j()-1; j++)
632 output << m(i,j) <<
",";
633 output << m(i,j) <<
")";
complex operator*(const double &x1, const complex &z2)
A class for the form factor in .
gsl_complex & as_gsl_type()
A class for constructing and defining operations on real matrices.
A base class for defining operations on matrices, both real and complex.
matrix< complex > hconjugate() const
gsl_matrix * as_gsl_type_ptr() const
static const complex & i()
matrix< complex > operator*(const double &a, const matrix< complex > m)
A class for constructing and defining operations on complex vectors.
void assign(const size_t &i, const complex &z)
matrix< complex > operator-(const double &a, const matrix< complex > m)
A class for constructing and defining operations on complex matrices.
gsl_matrix_complex * as_gsl_type_ptr() const
void eigensystem(matrix< complex > &U, vector< double > &S) const
gsl_matrix_complex & as_gsl_type()
matrix< complex > operator+(const double &a, const matrix< complex > m)
complex operator/(const double &x1, const complex &z2)
matrix< complex > transpose() const
gsl_vector_complex * as_gsl_type_ptr() const
A class for constructing and defining operations on real vectors.
complex operator+(const double &x1, const complex &z2)
A class for defining operations on and functions of complex numbers.
complex operator-(const double &x1, const complex &z2)
Complex number, vector and matrix manipulation using GSL.
gsl_vector * as_gsl_type_ptr() const