| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

MagMat Class Reference

#include <MagMat.h>

List of all members.


Public Member Functions

 MagMat (int N, int M)
 MagMat ()
 MagMat (const MagMat &m)
 ~MagMat ()
MagMat_row operator[] (int)
MagMat_row_const operator[] (int) const
MagMatoperator= (const MagMat &m)
MagMat operator+ (const MagMat &m)
MagMat operator+ (const MagMat &m) const
MagMatoperator+= (const MagMat &m)
MagMat operator- (const MagMat &m)
MagMat operator- (const MagMat &m) const
MagMatoperator-= (const MagMat &m)
MagMat operator * (const MagMat &m)
MagMat operator * (const MagMat &m) const
MagMatoperator *= (const double &d)
MagMat T () const
int nrow () const
int ncol () const
void reSize (int Nnew, int Mnew)

Private Member Functions

void copy (const MagMat &m)

Private Attributes

int Ncol
int Nrow
int Nele
double * ptr_data

Friends

class MagMat_row
class MagMat_row_const

Classes

class  MagMat_row
class  MagMat_row_const

Detailed Description

Definition at line 10 of file MagMat.h.


Constructor & Destructor Documentation

MagMat::MagMat ( int  N,
int  M 
)

Definition at line 14 of file MagMat.cpp.

00014                            {
00015 
00016   Nrow = N; Ncol = M; Nele = N*M; 
00017   ptr_data = new double[Nele];
00018 
00019   for( int i=0; i<Nrow; i++ ) {
00020     for( int j=0; j<Ncol; j++ ) {
00021 
00022       *(ptr_data+i*Ncol+j) = 0.;
00023 
00024     } 
00025   }
00026 
00027 }

MagMat::MagMat (  ) 

Definition at line 6 of file MagMat.cpp.

00006                {
00007 
00008   Ncol = 0; Nrow = 0; Nele = 0; 
00009   ptr_data = 0;  // set pointer to null
00010 
00011 }

MagMat::MagMat ( const MagMat m  ) 

Definition at line 29 of file MagMat.cpp.

00029                               {
00030   Nrow = m.Nrow; Ncol = m.Ncol; Nele = Nrow*Ncol; 
00031   ptr_data = new double[Nele];
00032   copy(m);
00033 }

MagMat::~MagMat (  ) 

Definition at line 36 of file MagMat.cpp.

00037 {delete [] ptr_data;}


Member Function Documentation

MagMat::MagMat_row MagMat::operator[] ( int   )  [inline]

Definition at line 93 of file MagMat.h.

00094 {
00095   MagMat_row b(*this,r);
00096   return b;
00097 }

MagMat::MagMat_row_const MagMat::operator[] ( int   )  const [inline]

Definition at line 99 of file MagMat.h.

00101 {
00102   const MagMat_row_const b(*this,r);
00103 
00104   return b;
00105 }

MagMat & MagMat::operator= ( const MagMat m  ) 

Definition at line 58 of file MagMat.cpp.

00058                                           {
00059 
00060   if(( Nrow!=0 || Ncol!=0) && (Nrow != m.Nrow || Ncol != m.Ncol ))
00061      { std::cerr << "MagMat MagMat Assignment: size do not match!" << std::endl; return *this; }
00062 
00063   if ( ptr_data != m.ptr_data ) {
00064     reSize(m.Nrow, m.Ncol);
00065     copy(m);
00066   };
00067   return (*this);
00068 
00069 }

MagMat MagMat::operator+ ( const MagMat m  ) 

Definition at line 73 of file MagMat.cpp.

00073                                         {
00074 
00075   if( Nrow != m.Nrow || Ncol != m.Ncol )
00076     { std::cerr << "operator+: size do not match!" << std::endl; return *this; }
00077 
00078   MagMat b( Nrow, Ncol );
00079 
00080   for( int i=0; i<Nrow; i++ ) {
00081     for( int j=0; j<Ncol; j++ ) {
00082 
00083       *(b.ptr_data+i*b.Ncol+j) = *(ptr_data+i*Ncol+j)+m[i][j];
00084 
00085     }
00086   }
00087 
00088   return b;
00089 } 

MagMat MagMat::operator+ ( const MagMat m  )  const

Definition at line 91 of file MagMat.cpp.

00091                                               {
00092 
00093   if( Nrow != m.Nrow || Ncol != m.Ncol )
00094     { std::cerr << "operator+: size do not match!" << std::endl; return *this; }
00095 
00096   MagMat b( Nrow, Ncol );
00097 
00098   for( int i=0; i<Nrow; i++ ) {
00099     for( int j=0; j<Ncol; j++ ) {
00100 
00101       *(b.ptr_data+i*b.Ncol+j) = *(ptr_data+i*Ncol+j)+m[i][j];
00102 
00103     }
00104   }
00105 
00106   return b;
00107 } 

MagMat & MagMat::operator+= ( const MagMat m  ) 

Definition at line 109 of file MagMat.cpp.

00109                                            {
00110 
00111  if( Nrow != m.Nrow || Ncol != m.Ncol )
00112    { std::cerr << "operator+=: size do not match!" << std::endl; return *this; }
00113 
00114   for( int i=0; i<Nrow; i++ ) {
00115     for( int j=0; j<Ncol; j++ ) {
00116 
00117      *(ptr_data+i*Ncol+j)  += *(m.ptr_data+i*m.Ncol+j);
00118 
00119     };
00120   };
00121 
00122   return *this;
00123 }

MagMat MagMat::operator- ( const MagMat m  ) 

Definition at line 125 of file MagMat.cpp.

00125                                           {
00126   if( Nrow != m.Nrow || Ncol != m.Ncol )
00127     { std::cerr << "operator-: size do not match!" << std::endl; return *this; }
00128 
00129   MagMat b( Nrow, Ncol );
00130 
00131   for( int i=0; i<Nrow; i++ ) {
00132     for( int j=0; j<Ncol; j++ ) {
00133 
00134       *(b.ptr_data+i*b.Ncol+j) = *(ptr_data+i*Ncol+j)-m[i][j];
00135 
00136     }
00137   }
00138 
00139   return b;
00140 }

MagMat MagMat::operator- ( const MagMat m  )  const

Definition at line 142 of file MagMat.cpp.

00142                                               {
00143   if( Nrow != m.Nrow || Ncol != m.Ncol )
00144     { std::cerr << "operator-: size do not match!" << std::endl; return *this; }
00145 
00146   MagMat b( Nrow, Ncol );
00147 
00148   for( int i=0; i<Nrow; i++ ) {
00149     for( int j=0; j<Ncol; j++ ) {
00150 
00151       *(b.ptr_data+i*b.Ncol+j) = *(ptr_data+i*Ncol+j)-m[i][j];
00152 
00153     }
00154   }
00155 
00156   return b;
00157 }

MagMat & MagMat::operator-= ( const MagMat m  ) 

Definition at line 159 of file MagMat.cpp.

00159                                            {
00160 
00161  if( Nrow != m.Nrow || Ncol != m.Ncol )
00162    { std::cerr << "operator-=: size do not match!" << std::endl; return *this; }
00163 
00164   for( int i=0; i<Nrow; i++ ) {
00165     for( int j=0; j<Ncol; j++ ) {
00166 
00167      *(ptr_data+i*Ncol+j)  -= *(m.ptr_data+i*m.Ncol+j);
00168 
00169     };
00170   };
00171 
00172   return *this;
00173 }

MagMat MagMat::operator * ( const MagMat m  ) 

Definition at line 175 of file MagMat.cpp.

00175                                         {
00176 
00177   if( Ncol != m.Nrow ) {  std::cerr << "operator*: size do not match!" << std::endl;
00178   return m; }
00179 
00180   MagMat b( Nrow, m.Ncol);
00181 
00182 
00183   for( int i=0; i<Nrow; i++ ) {
00184     for( int j=0; j<m.Ncol; j++ ) {
00185       for( int k=0; k<m.Nrow; k++) b[i][j]+= *(ptr_data+i*Ncol+k)*(m[k][j]);
00186     }
00187   }
00188 
00189   return b;
00190 
00191 }

MagMat MagMat::operator * ( const MagMat m  )  const

Definition at line 193 of file MagMat.cpp.

00193                                               {
00194 
00195   if( Ncol != m.Nrow ) {  std::cerr << "operator*: size do not match!" << std::endl;
00196   return m; }
00197 
00198   MagMat b( Nrow, m.Ncol);
00199 
00200 
00201   for( int i=0; i<Nrow; i++ ) {
00202     for( int j=0; j<m.Ncol; j++ ) {
00203       for( int k=0; k<m.Nrow; k++) b[i][j]+= *(ptr_data+i*Ncol+k)*(m[k][j]);
00204     }
00205   }
00206 
00207   return b;
00208 
00209 }

MagMat & MagMat::operator *= ( const double &  d  ) 

Definition at line 213 of file MagMat.cpp.

00213                                             {
00214 
00215  double*  p = ptr_data+Nele;
00216 
00217   while (p > ptr_data) *(--p) *= d;
00218 
00219   return *this;
00220 
00221 }

MagMat MagMat::T (  )  const

Definition at line 228 of file MagMat.cpp.

00228                        {
00229   MagMat b(Ncol,Nrow);
00230   for( int i=0; i<b.Nrow; i++ ) {
00231     for( int j=0; j<b.Ncol; j++ ) {
00232        b[i][j]= *(ptr_data+j*Ncol+i);
00233     }
00234   }
00235   return b;
00236 }

int MagMat::nrow (  )  const

Definition at line 277 of file MagMat.cpp.

00277                        {
00278 
00279   return Nrow;
00280 
00281 }

int MagMat::ncol (  )  const

Definition at line 283 of file MagMat.cpp.

00283                        {
00284 
00285   return Ncol;
00286 
00287 }

void MagMat::reSize ( int  Nnew,
int  Mnew 
)

Definition at line 245 of file MagMat.cpp.

00245                                       {
00246 
00247  
00248   if ( Nnew != Nrow || Mnew != Ncol ) {
00249 
00250     double*  p = ptr_data;
00251     Nele = Nnew*Mnew;
00252     ptr_data = new double[Nele];
00253     int Nrow_old = Nrow;
00254     int Ncol_old = Ncol;
00255 
00256     Nrow = Nnew;
00257     Ncol = Mnew;
00258     int k = Nrow <= Nrow_old ? Nrow : Nrow_old;
00259     int l = Ncol <= Ncol_old ? Ncol : Ncol_old;
00260 
00261     for( int i=0; i<k; i++ ) {
00262       for( int j=0; j<l; j++ ) {
00263         *(ptr_data+i*Ncol+j) = *(p+i*Ncol_old+j);
00264       }
00265     }
00266 
00267 
00268     delete [] p;
00269   }
00270 
00271 
00272 
00273 }

void MagMat::copy ( const MagMat m  )  [private]

Definition at line 40 of file MagMat.cpp.

00040                                   {
00041 
00042   int n = Nrow <= m.Nrow ? Nrow : m.Nrow;
00043   int l = Ncol <= m.Ncol ? Ncol : m.Ncol;
00044 
00045   for( int i=0; i<n; i++ ) {
00046     for( int j=0; j<l; j++ ) {
00047 
00048       *(ptr_data+i*Ncol+j) = *(m.ptr_data+i*m.Ncol+j);
00049 
00050     } 
00051   }
00052 
00053 }


Friends And Related Function Documentation

friend class MagMat_row [friend]

Definition at line 75 of file MagMat.h.

friend class MagMat_row_const [friend]

Definition at line 76 of file MagMat.h.


Member Data Documentation

int MagMat::Ncol [private]

Definition at line 82 of file MagMat.h.

int MagMat::Nrow [private]

Definition at line 82 of file MagMat.h.

int MagMat::Nele [private]

Definition at line 83 of file MagMat.h.

double* MagMat::ptr_data [private]

Definition at line 84 of file MagMat.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:04:55 2011 for Magnet by doxygen 1.4.7