9 #include <gsl/gsl_blas.h>
11 #ifndef __GSL_LINALG_H__
12 #include <gsl/gsl_linalg.h>
14 #ifndef __GSL_EIGEN_H__
15 #include <gsl/gsl_eigen.h>
17 #ifndef GSLPP_MATRIX_DOUBLE_H
26 _matrix = gsl_matrix_alloc(size_i, size_j);
27 gsl_matrix_set_all(_matrix, a);
32 _matrix = gsl_matrix_alloc(size_i, size_i);
33 gsl_matrix_set_all(_matrix, a);
45 _matrix = gsl_matrix_alloc(m.size1,m.size2);
46 gsl_matrix_memcpy(_matrix, &m);
51 _matrix = gsl_matrix_alloc(m->size1,m->size2);
52 gsl_matrix_memcpy(_matrix, m);
57 size_t i, size = v.
size();
58 _matrix = gsl_matrix_alloc(size, size);
59 gsl_matrix_set_all(_matrix, 0.);
61 gsl_matrix_set(_matrix, i, i, v(i));
67 gsl_matrix_free(_matrix);
73 const double *x = gsl_matrix_const_ptr(_matrix, i, j);
80 double *x = gsl_matrix_ptr(_matrix, i, j);
91 std::cout <<
"\n ** Wrong size assign in matrix<complex> operator =" << std::endl;
99 gsl_matrix_set_all(_matrix, a);
105 gsl_matrix_set(_matrix, i, j, a);
113 if(i+a.
size_i() <= size_i() && j+a.
size_j() <= size_j())
114 for(ki=i;ki<i+a.
size_i();ki++)
115 for(kj=j;kj<j+a.
size_j();kj++)
117 x = gsl_matrix_ptr(_matrix, ki, kj);
122 std::cout <<
"\n ** Wrong size assign in matrix<double> assign submatrix" << std::endl;
130 return _matrix->size1;
135 return _matrix->size2;
144 std::cout <<
"\n Error in matrix<double> Id" << std::endl;
156 std::cout <<
"\n Error in matrix<double> transpose" << std::endl;
170 if (size_j() != size_i())
172 std::cout <<
"\n ** Size mismatch in matrix<double> inverse" << std::endl;
176 if ((p = gsl_permutation_alloc(size_i())) == NULL)
178 std::cout <<
"\n ** Error in matrix<double> inverse" << std::endl;
184 std::cout <<
"\n ** Error in matrix<double> inverse" << std::endl;
185 gsl_permutation_free(p);
191 std::cout <<
"\n ** Error in matrix<double> inverse" << std::endl;
192 gsl_permutation_free(p);
195 gsl_permutation_free(p);
206 if (size_j() != size_i())
208 std::cout <<
"\n ** Size mismatch in matrix<double> determinant" << std::endl;
212 if ((p = gsl_permutation_alloc(size_i())) == NULL)
214 std::cout <<
"\n ** Error in matrix<double> determinant" << std::endl;
220 std::cout <<
"\n ** Error in matrix<double> determinant" << std::endl;
221 gsl_permutation_free(p);
224 gsl_permutation_free(p);
231 gsl_eigen_nonsymmv_workspace *ws;
233 ws = gsl_eigen_nonsymmv_alloc(size_i());
238 gsl_eigen_nonsymmv_free(ws);
249 return const_cast<gsl_matrix&
>(*_matrix);
254 return const_cast<gsl_matrix&
>(*_matrix);
267 std::cout <<
"\n Error in matrix<double> unary -" << std::endl;
278 std::cout <<
"\n Error in matrix<double> +" << std::endl;
289 std::cout <<
"\n Error in matrix<double> -" << std::endl;
300 if (size_j() != m.
size_i())
302 std::cout <<
"\n Error in matrix<double> *" << std::endl;
306 for(i=0; i<size_i(); i++)
307 for(j=0; j<m.
size_j(); j++)
308 for(k=0; k<m.
size_i(); k++)
309 m1(i,j)+=(*this)(i,k)*m(k,j);
319 if (size_j() != v.
size())
321 std::cout <<
"\n ** Size mismatch in matrix<double> * (vector double)"
328 std::cout <<
"\n ** Error in matrix<double> * (vector double)"
358 if (!((size_i() == size_j()) && (size_i() == m.
size_i()) && (size_j() == m.
size_j())))
360 std::cout <<
"\n Error in matrix<double> *= (matrix)" << std::endl;
373 std::cout <<
"\n Error in matrix<double> + (double)" << std::endl;
384 std::cout <<
"\n Error in matrix<double> - (double)" << std::endl;
395 std::cout <<
"\n Error in matrix<double> * (double)" << std::endl;
406 std::cout <<
"\n Error in matrix<double> / (double)" << std::endl;
461 std::ostream& operator<<(std::ostream& output, const matrix<double>& m)
464 for (i=0; i<m.size_i(); i++)
468 for (j=0; j<m.size_j()-1; j++)
469 output << m(i,j) <<
",";
470 output << m(i,j) <<
")";
complex operator*(const double &x1, const complex &z2)
A class for the form factor in .
A class for constructing and defining operations on real matrices.
A base class for defining operations on matrices, both real and complex.
gsl_matrix * as_gsl_type_ptr() const
matrix< complex > operator+(const complex &z, matrix< double > m)
A class for constructing and defining operations on complex vectors.
matrix< double > transpose()
A class for constructing and defining operations on complex matrices.
matrix< complex > operator*(const complex &z, matrix< double > m)
gsl_matrix_complex * as_gsl_type_ptr() const
complex operator/(const double &x1, const complex &z2)
matrix< complex > operator-(const complex &z, matrix< double > m)
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