Main Page   Class Hierarchy   Compound List   File List   Compound Members  

matrix.hh

00001 /*=============================================================================
00002         File: matrix.hh
00003      Purpose:       
00004     Revision: $Id: matrix.hh,v 1.1.1.1 1999/08/05 01:49:16 lavoie Exp $
00005   Created by: Philippe Lavoie          (3 Oct, 1996)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1998 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 // Predefining every friend functions 
00038 // This is required by latest ISO C++ draft
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       //~Matrix() {}    
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       // Mathematical functions
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       // file i/o functions
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       // calls to LAPACK functions are defined in this class
00150       friend class LAPACK ;
00151     };
00152     
00153 } // end namespace
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 

Generated on Sun Jan 27 06:38:07 2002 for NURBS++ by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001