00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _Matrix_matrix_h_
00028 #define _Matrix_matrix_h_
00029
00030
00031 #include <iostream>
00032 #include "matrix_global.hh"
00033 #include "barray2d.hh"
00034 #include "vector.hh"
00035
00036
00037
00038
00039
00042 namespace PLib {
00043 template <class T> class Matrix ;
00044
00045 template <class T> PLib::Matrix<T> operator+(const PLib::Matrix<T>&,const PLib::Matrix<T>&);
00046 template <class T> PLib::Matrix<T> operator-(const PLib::Matrix<T>&,const PLib::Matrix<T>&);
00047 template <class T> PLib::Matrix<T> operator*(const PLib::Matrix<T>&,const PLib::Matrix<T>&);
00048 template <class T> PLib::Matrix<T> operator*(const double,const PLib::Matrix<T>&);
00049 template <class T> PLib::Matrix<T> operator*(const Complex&,const PLib::Matrix<T>&);
00050 template <class T> PLib::Vector<T> operator*(const PLib::Matrix<T>&,const PLib::Vector<T>&);
00051 template <class T> int operator==(const PLib::Matrix<T>&,const PLib::Matrix<T>&);
00052 template <class T> int operator!=(const PLib::Matrix<T>& a,const PLib::Matrix<T>& b) ;
00053
00054 template <> PLib::Matrix<Complex> operator*(const double d, const PLib::Matrix<Complex> &a);
00055 template <> PLib::Matrix<Complex> operator*(const Complex &d, const PLib::Matrix<Complex> &a);
00056
00057
00067 template<class T>
00068 class Matrix : public Basic2DArray<T>
00069 {
00070 public:
00071 Matrix(const int r,const int c) : Basic2DArray<T>(r,c) {}
00072 Matrix() : Basic2DArray<T>() {}
00073 Matrix(const Matrix<T>& M) : Basic2DArray<T>(M) {}
00074 Matrix(T* p, const int r, const int c) : Basic2DArray<T>(p,r,c) {}
00075
00076
00077 Matrix<T>& operator=(const Matrix<T>&);
00078 T operator=(const T v)
00079 { reset((T)0);
00080 diag(v);
00081 return v; }
00082 void submatrix(int i, int j, Matrix<T>&);
00083 void as(int rw, int cl, Matrix<T>&) ;
00084 Matrix<T> get(int rw, int cl, int nr, int nc) const ;
00085
00086
00087 Matrix<T>& operator+=(const Matrix<T>&);
00088 Matrix<T>& operator-=(const Matrix<T>&);
00089 Matrix<T>& operator+=(double d) ;
00090 Matrix<T>& operator-=(double d) ;
00091 Matrix<T>& operator*=(double d) ;
00092 Matrix<T>& operator/=(double d) ;
00093
00094 #ifdef HAVE_ISO_FRIEND_DECL
00095 friend Matrix<T> operator+ <>(const Matrix<T>&,
00096 const Matrix<T>&);
00097 friend Matrix<T> operator- <>(const Matrix<T>&,
00098 const Matrix<T>&);
00099 friend Matrix<T> operator* <>(const Matrix<T>&,
00100 const Matrix<T>&);
00101 friend Matrix<T> operator* <>(const double,
00102 const Matrix<T>&);
00103 friend Matrix<T> operator* <>(const Complex&,
00104 const Matrix<T>&);
00105 friend Vector<T> operator* <>(const Matrix<T>&,
00106 const Vector<T>&);
00107 friend int operator== <>(const Matrix<T>&,
00108 const Matrix<T>&);
00109 friend int operator!= <>(const Matrix<T>& a,
00110 const Matrix<T>& b) ;
00111
00112 #else
00113 friend Matrix<T> operator+ (const Matrix<T>&,
00114 const Matrix<T>&);
00115 friend Matrix<T> operator- (const Matrix<T>&,
00116 const Matrix<T>&);
00117 friend Matrix<T> operator* (const Matrix<T>&,
00118 const Matrix<T>&);
00119 friend Matrix<T> operator* (const double,
00120 const Matrix<T>&);
00121 friend Matrix<T> operator* (const Complex&,
00122 const Matrix<T>&);
00123 friend Vector<T> operator* (const Matrix<T>&,
00124 const Vector<T>&);
00125 friend int operator== (const Matrix<T>&,
00126 const Matrix<T>&);
00127 friend int operator!= (const Matrix<T>& a,
00128 const Matrix<T>& b) ;
00129 #endif
00130
00131 Matrix<T> herm() const ;
00132 Matrix<T> transpose() const ;
00133 Matrix<T> flop() const ;
00134 T trace() const ;
00135
00136 double norm(void) ;
00137 void diag(const T fv);
00138 Vector<T> getDiag();
00139
00140 void qSort() ;
00141
00142
00143
00144 int read(char* filename) ;
00145 int read(char* filename, int rows, int cols) ;
00146 int write(char* filename) ;
00147 int writeRaw(char* filename) ;
00148
00149
00150 friend class LAPACK ;
00151 };
00152
00153 }
00154
00155
00156 template <class T>
00157 PLib::Matrix<T> comm( const PLib::Matrix<T>& a, const PLib::Matrix<T>& b);
00158
00159 template <class T>
00160 inline PLib::Matrix<T> herm( const PLib::Matrix<T>& a) {
00161 return a.herm() ;
00162 }
00163
00164 template <class T>
00165 inline PLib::Matrix<T> transpose( const PLib::Matrix<T>& a) {
00166 return a.transpose() ;
00167 }
00168
00169 template <class T>
00170 inline T trace( const PLib::Matrix<T>& a) {
00171 return a.trace() ;
00172 }
00173
00174 template <class T>
00175 inline int operator!=(const PLib::Matrix<T>& a, const PLib::Matrix<T>& b) {
00176 return a==b?0:1 ;
00177 }
00178
00179
00180 typedef PLib::Matrix<int> Matrix_INT ;
00181 typedef PLib::Matrix<char> Matrix_BYTE ;
00182 typedef PLib::Matrix<float> Matrix_FLOAT ;
00183 typedef PLib::Matrix<double> Matrix_DOUBLE ;
00184 typedef PLib::Matrix<Complex> Matrix_COMPLEX ;
00185 typedef PLib::Matrix<unsigned char> Matrix_UBYTE ;
00186 typedef PLib::Matrix<PLib::Point3Df> Matrix_Point3Df ;
00187 typedef PLib::Matrix<PLib::HPoint3Df> Matrix_HPoint3Df ;
00188 typedef PLib::Matrix<PLib::Point3Dd> Matrix_Point3Dd ;
00189 typedef PLib::Matrix<PLib::HPoint3Dd> Matrix_HPoint3Dd ;
00190 typedef PLib::Matrix<PLib::Point2Df> Matrix_Point2Df ;
00191 typedef PLib::Matrix<PLib::HPoint2Df> Matrix_HPoint2Df ;
00192 typedef PLib::Matrix<PLib::Point2Dd> Matrix_Point2Dd ;
00193 typedef PLib::Matrix<PLib::HPoint2Dd> Matrix_HPoint2Dd ;
00194
00195 typedef PLib::Matrix<int> PlMatrix_int ;
00196 typedef PLib::Matrix<char> PlMatrix_byte ;
00197 typedef PLib::Matrix<float> PlMatrix_float ;
00198 typedef PLib::Matrix<double> PlMatrix_double ;
00199 typedef PLib::Matrix<Complex> PlMatrix_complex ;
00200 typedef PLib::Matrix<unsigned char> PlMatrix_ubyte ;
00201 typedef PLib::Matrix<PLib::Point3Df> PlMatrix_Point3Df ;
00202 typedef PLib::Matrix<PLib::HPoint3Df> PlMatrix_HPoint3Df ;
00203 typedef PLib::Matrix<PLib::Point3Dd> PlMatrix_Point3Dd ;
00204 typedef PLib::Matrix<PLib::HPoint3Dd> PlMatrix_HPoint3Dd ;
00205 typedef PLib::Matrix<PLib::Point3Df> PlMatrix_Point2Df ;
00206 typedef PLib::Matrix<PLib::HPoint3Df> PlMatrix_HPoint2Df ;
00207 typedef PLib::Matrix<PLib::Point3Dd> PlMatrix_Point2Dd ;
00208 typedef PLib::Matrix<PLib::HPoint3Dd> PlMatrix_HPoint2Dd ;
00209
00210 #ifdef INCLUDE_TEMPLATE_SOURCE
00211 #include "matrix.cc"
00212 #endif
00213
00214 #endif