Matrix< T > Class Template Reference

#include <Matrix.h>

List of all members.


Detailed Description

template<class T>
class Matrix< T >

2-D Matrix class.

Definition at line 111 of file Matrix.h.

Public Member Functions

 Matrix ()
 Matrix (const int rows, const int columns)
 Matrix (const int rows, const int columns, T init)
 Matrix (Matrix< T > &m)
 ~Matrix ()
void Clean ()
void Set (const int rows, const int columns, T *_data)
const T * DataPtr ()
T * Data ()
Matrix< T > Clone () const
void SwitchColumns (int i, int j)
void SyncData2Columns ()
 reorganizes data array such that matrix elements are ordered in column major ordering. Calling this function will allocate new memory with correct ordering of elements and old memory is freed.
SubMatrix< T > Slice (int row1, int row2, int col1, int col2)
const int Columns () const
const int Rows () const
const int XDim () const
const int YDim () const
const int * Dims () const
const List< int, 2 > Size () const
const int Length () const
const int NDims () const
void Init (const T init)
Matrix< T > & Rand ()
Matrix< T > & Rand (const double max)
void ReadFromMatrix (const Matrix< T > &m)
void ReadFromMatrix (const Matrix< T > &m, const int rowStart, const int colStart)
Matrix< T > & Transpose ()
 Transpose of a matrix. Does not allocate a new Matrix. Creates transpose inline.
Matrix< T > & Add (Matrix< T > &m)
Matrix< T > & Subtract (Matrix< T > &m)
Matrix< T > & Multiply (Matrix< T > &m)
Matrix< T > & Divide (Matrix< T > &m)
Matrix< T > & Add (T v)
Matrix< T > & Subtract (T v)
Matrix< T > & Multiply (T v)
Matrix< T > & Divide (T v)
Matrix< T > & operator= (Matrix< T > &m)
Matrix< T > & operator= (Array< T > &m)
Matrix< T > & operator= (Vector< T > &m)
Matrix< T > operator+ ()
 Unary +. Does not have any effect. Returns the same matrix.
Matrix< T > operator- ()
 Unary -.
Matrix< int > operator! ()
Matrix< T > operator~ ()
 Transpose ~.
T & Coor (const int x, const int y)
 Matrix element access using coordinates (x,y). Bounds are checked.
T & CoorNC (const int x, const int y)
 Matrix element access using coordinates (x,y). Bounds are not checked.
T & Elem (const int _row, const int _col)
 Matrix element access (row,col). Bounds are checked.
T & ElemNC (const int _row, const int _col)
 Matrix element access (row,col). Bounds are not checked.
T & Elem (const int i)
 Matrix element access (sequential: column scan). Bounds are checked.
T & ElemNC (const int i)
 Matrix element access (sequential: column scan). Bounds are not checked.
T & operator() (const int i)
 Matrix element access (sequential: column scan). Bounds are checked (See ElemNC() for element access with no bounds check).
T & operator() (const int i, const int j)
 Matrix element access (row,col). Bounds are checked (See ElemNC() for element access with no bounds check).
Vector< T > & operator[] (const int i)
 Returns a pointer to the beginning of a column.
Matrix< T > operator() (const int row1, const int row2, const int col1, const int col2)
 returns a new Matrix using the slice rectangle.
Matrix< T > & operator+= (Matrix< T > &m)
Matrix< T > & operator-= (Matrix< T > &m)
Matrix< T > & operator *= (Matrix< T > &m)
Matrix< T > & operator/= (Matrix< T > &m)
Matrix< T > & operator+= (T v)
Matrix< T > & operator-= (T v)
Matrix< T > & operator *= (T v)
Matrix< T > & operator/= (T v)
 Matrix (Array< T > &m)
 Matrix (Vector< T > &m)

Static Public Member Functions

Matrix< T > Rand (const int rows, const int cols)
Matrix< T > Rand (const int rows, const int cols, const double max)
bool IsSquare (Matrix< T > &m)
bool IsM2MCompatible (Matrix< T > &m1, Matrix< T > &m2)
 are these matrices (and in this order) are compatible for matrix multiplication
Matrix< T > MMultiply (Matrix< T > &m1, Matrix< T > &m2)
 Matrix multiplication. Also used to overload & operator.
Matrix< T > MMultiply (Matrix< T > &m1, Vector< T > &m2)
 Matrix to Vector multiplication. Vector is taken as a column vector.
Matrix< T > MMultiply (Vector< T > &m1, Matrix< T > &m2)
 Vector to Matrix multiplication. Vector is taken as a row vector.
Matrix< T > Transpose (Matrix< T > &m)
 Transpose of a matrix. Allocates a new Matrix.
bool IsCompatible (Matrix< T > &m1, Matrix< T > &m2)
 Check if two matrices have the same sizes.
Matrix< int > And (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise AND operator. Returns 1 or 0 for each element.
Matrix< int > Or (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise OR operator. Returns 1 or 0 for each element.
Matrix< int > Lt (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise < (less than) operator. Returns 1 or 0 for each element.
Matrix< int > Gt (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise > (greater than) operator. Returns 1 or 0 for each element.
Matrix< int > Le (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise <= (less than or equal) operator. Returns 1 or 0 for each element.
Matrix< int > Ge (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise >= (greater than or equal) operator. Returns 1 or 0 for each element.
Matrix< int > Eq (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise == operator. Returns 1 or 0 for each element.
Matrix< int > Ne (Matrix< T > &m1, Matrix< T > &m2)
 Elementwise != (not equal) operator. Returns 1 or 0 for each element.
Matrix< int > And (Matrix< T > &m, T v)
 AND operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Or (Matrix< T > &m, T v)
 OR operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Lt (Matrix< T > &m, T v)
 < (Less than) operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Gt (Matrix< T > &m, T v)
 > (Greater than) operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Le (Matrix< T > &m, T v)
 <= (Less than or equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Ge (Matrix< T > &m, T v)
 <= (Greater than or equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Eq (Matrix< T > &m, T v)
 == operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< int > Ne (Matrix< T > &m, T v)
 != (Not equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.
Matrix< T > Add (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > Subtract (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > Multiply (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > Divide (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > Add (Matrix< T > &m1, T v2)
Matrix< T > Subtract (Matrix< T > &m1, T v2)
Matrix< T > Subtract (T v2, Matrix< T > &m1)
Matrix< T > Multiply (Matrix< T > &m1, T v2)
Matrix< T > Divide (Matrix< T > &m1, T v2)
Matrix< T > Divide (T v2, Matrix< T > &m1)

Protected Attributes

T * data
int ndims
int length
int xDim
int yDim
Cleaner< T > * clean
Vector< T > * columns

Friends

class Array<T>
class Vector<T>
class SubMatrix<T>
ostream & operator<< (ostream &output, Matrix< T > &m)
Matrix< T > operator & (Matrix< T > &m1, Matrix< T > &m2)
 Matrix to Matrix multiplication.
Matrix< T > operator & (Matrix< T > &m1, Vector< T > &m2)
 Matrix to column Vector multiplication.
Matrix< T > operator & (Vector< T > &m1, Matrix< T > &m2)
 Row Vector to Matrix multiplication.
Matrix< int > operator && (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator|| (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator< (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator> (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator<= (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator>= (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator== (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator!= (Matrix< T > &m1, Matrix< T > &m2)
Matrix< int > operator && (Matrix< T > &m, T v)
Matrix< int > operator && (T v, Matrix< T > &m)
Matrix< int > operator|| (Matrix< T > &m, T v)
Matrix< int > operator|| (T v, Matrix< T > &m)
Matrix< int > operator< (Matrix< T > &m, T v)
Matrix< int > operator< (T v, Matrix< T > &m)
Matrix< int > operator> (Matrix< T > &m, T v)
Matrix< int > operator> (T v, Matrix< T > &m)
Matrix< int > operator<= (Matrix< T > &m, T v)
Matrix< int > operator<= (T v, Matrix< T > &m)
Matrix< int > operator>= (Matrix< T > &m, T v)
Matrix< int > operator>= (T v, Matrix< T > &m)
Matrix< int > operator== (Matrix< T > &m, T v)
Matrix< int > operator== (T v, Matrix< T > &m)
Matrix< int > operator!= (Matrix< T > &m, T v)
Matrix< int > operator!= (T v, Matrix< T > &m)
Matrix< T > operator+ (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > operator- (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > operator * (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > operator/ (Matrix< T > &m1, Matrix< T > &m2)
Matrix< T > operator+ (Matrix< T > &m, T v)
Matrix< T > operator+ (T v, Matrix< T > &m)
Matrix< T > operator- (Matrix< T > &m, T v)
Matrix< T > operator- (T v, Matrix< T > &m)
Matrix< T > operator * (Matrix< T > &m, T v)
Matrix< T > operator * (T v, Matrix< T > &m)
Matrix< T > operator/ (Matrix< T > &m, T v)
Matrix< T > operator/ (T v, Matrix< T > &m)


Constructor & Destructor Documentation

template<class T>
Matrix< T >::Matrix  ) 
 

Definition at line 63 of file Matrix.inl.

References Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

00064     : ndims(2), length(0)
00065 {
00066     data = 0;
00067     xDim = 0;
00068     yDim = 0;
00069     columns = 0;
00070     clean = 0;
00071 
00072 }

template<class T>
Matrix< T >::Matrix const int  rows,
const int  columns
 

Definition at line 76 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::length, Matrix< T >::ndims, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00077 {
00078     if(rows < 1 || cols < 1)
00079     {
00080         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00081         Utility::RunTimeError("All Matrix dimensions should be larger than 0!");
00082     }
00083 
00084     ndims = 2;
00085     length = rows*cols;
00086     xDim = cols;
00087     yDim = rows;
00088     data = new T[length];
00089     Utility::CheckPointer(data);
00090 
00091     columns = new Vector<T>[cols];
00092     Utility::CheckPointer(columns);
00093     for(int i=0; i<cols; i++)
00094     {
00095         columns[i].Set(&(data[i*rows]), rows);
00096     }
00097     
00098     clean = new Cleaner<T>(data, columns);
00099     
00100 }

template<class T>
Matrix< T >::Matrix const int  rows,
const int  columns,
init
 

Definition at line 103 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::length, Matrix< T >::ndims, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00104 {
00105     if(rows < 1 || cols < 1)
00106     {
00107         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00108         Utility::RunTimeError("All Matrix dimensions should be larger than 0!");
00109     }
00110 
00111     ndims = 2;
00112     length = rows*cols;
00113     xDim = cols;
00114     yDim = rows;
00115     data = new T[length];
00116     Utility::CheckPointer(data);
00117 
00118     columns = new Vector<T>[cols];
00119     Utility::CheckPointer(columns);
00120     for(int i=0; i<cols; i++)
00121     {
00122         columns[i].Set(&(data[i*rows]), rows);
00123     }
00124     
00125     clean = new Cleaner<T>(data, columns);
00126 
00127     for(int i=0;i<length;i++)
00128     {
00129         data[i] = init;
00130     }
00131 
00132 }

template<class T>
Matrix< T >::Matrix Matrix< T > &  m  ) 
 

Definition at line 140 of file Matrix.inl.

References Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::length, Matrix< T >::ndims, Matrix< T >::xDim, and Matrix< T >::yDim.

00141 {
00142     ndims = m.ndims;
00143     length = m.length;
00144     xDim = m.xDim;
00145     yDim = m.yDim;
00146 
00147     data = m.data;
00148     columns = m.columns;
00149 
00150     clean = new Cleaner<T>(data, columns);
00151 
00152 }

template<class T>
Matrix< T >::~Matrix  ) 
 

Definition at line 157 of file Matrix.inl.

References Matrix< T >::clean.

00158 {
00159     
00160     if(clean != 0)
00161     {
00162         delete clean;
00163     }
00164 }

template<class T>
Matrix< T >::Matrix Array< T > &  m  ) 
 

Definition at line 1551 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::Columns(), Matrix< T >::columns, Array< T >::data, Matrix< T >::data, Array< T >::length, Matrix< T >::length, Array< T >::ndims, Matrix< T >::ndims, Matrix< T >::Rows(), Utility::Warning(), Array< T >::XDim(), Matrix< T >::xDim, Array< T >::YDim(), and Matrix< T >::yDim.

01552 {
01553     ndims = 2;
01554     xDim = 0;
01555     yDim = 0;
01556     data = 0;
01557     columns = 0;
01558 
01559     if(m.ndims == 2){
01560         length = m.length;
01561         data = m.data;
01562         xDim = m.XDim();
01563         yDim = m.YDim();
01564         
01565         columns = new Vector<T>[Columns()];
01566         Utility::CheckPointer(columns);
01567         for(int i=0; i<Columns(); i++)
01568         {
01569             columns[i].Set(&(data[i*Rows()]), Rows());
01570         }
01571         clean = new Cleaner<T>(data, columns);
01572 
01573     }
01574     else if(m.ndims > 0)
01575     {
01576         length = m.length;
01577         data = m.data;
01578         xDim = 1;
01579         yDim = length;
01580         
01581         columns = new Vector<T>[1];
01582         Utility::CheckPointer(columns);
01583         columns[0].Set(&(data[0]),length);
01584         clean = new Cleaner<T>(data, columns);
01585         
01586         if(ndims != 1)
01587         {
01588             Utility::Warning("Array (which was not of dimension 2) is converted to a Nx1 (column) Matrix. Dimensionality information is lost.");
01589         }
01590     }
01591 
01592 }

template<class T>
Matrix< T >::Matrix Vector< T > &  m  ) 
 

Definition at line 1596 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::columns, Vector< T >::data, Matrix< T >::data, Vector< T >::length, Matrix< T >::length, Matrix< T >::ndims, Vector< T >::Set(), Matrix< T >::xDim, and Matrix< T >::yDim.

01597 {
01598     ndims = 2;
01599 
01600     length = v.length;
01601     data = v.data;
01602     xDim = 1;
01603     yDim = length;
01604     
01605     columns = new Vector<T>[1];
01606     Utility::CheckPointer(columns);
01607     columns[0].Set(&(data[0]),length);
01608     clean = new Cleaner<T>(data, columns);
01609     
01610 }


Member Function Documentation

template<class T>
Matrix< T > & Matrix< T >::Add v  ) 
 

Definition at line 1171 of file Matrix.inl.

References Matrix< T >::data.

01172 {
01173     for(int i=0;i<this->length;i++)
01174     {
01175         this->data[i] += v;
01176     }
01177     return *this;
01178 }

template<class T>
Matrix< T > & Matrix< T >::Add Matrix< T > &  m  ) 
 

Definition at line 1091 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), and Utility::RunTimeError().

01092 {
01093     if(!Matrix<T>::IsCompatible(*this, m))
01094     {
01095         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01096         Utility::RunTimeError("Matrix sizes are not compatible!");
01097     }
01098 
01099     for(int i=0;i<this->length;i++)
01100     {
01101         this->data[i] += m.data[i];
01102     }
01103     
01104     return *this;
01105 }

template<class T>
Matrix< T > Matrix< T >::Add Matrix< T > &  m1,
v2
[static]
 

Definition at line 1005 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01006 {
01007     Matrix<T> temp(m1.yDim, m1.xDim);
01008     for(int i=0;i<temp.length;i++)
01009     {
01010         temp.data[i] = m1.data[i] + v2;
01011     }
01012     return temp;
01013 }

template<class T>
Matrix< T > Matrix< T >::Add Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Definition at line 918 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::operator+=().

00919 {
00920     if(!Matrix<T>::IsCompatible(m1, m2))
00921     {
00922         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00923         Utility::RunTimeError("Matrix sizes are not compatible!");
00924     }
00925 
00926     Matrix<T> temp(m1.yDim, m1.xDim);
00927     for(int i=0;i<temp.length;i++)
00928     {
00929         temp.data[i] = m1.data[i] + m2.data[i];
00930     }
00931     
00932     return temp;
00933 }

template<class T>
Matrix< int > Matrix< T >::And Matrix< T > &  m,
v
[static]
 

AND operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 793 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00794 {
00795     Matrix<int> temp(m1.yDim, m1.xDim);
00796     for(int i=0;i<temp.Length();i++)
00797     {
00798         temp.Data()[i] = (m1.data[i] != 0 && v != 0) ? 1 : 0;
00799     }
00800     
00801     return temp;
00802 }

template<class T>
Matrix< int > Matrix< T >::And Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise AND operator. Returns 1 or 0 for each element.

Definition at line 632 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00633 {
00634     if(!Matrix<T>::IsCompatible(m1, m2))
00635     {
00636         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00637         Utility::RunTimeError("Matrix sizes are not compatible!");
00638     }
00639 
00640     Matrix<int> temp(m1.yDim, m1.xDim);
00641     for(int i=0;i<temp.Length();i++)
00642     {
00643         temp.Data()[i] = (m1.data[i] != 0 && m2.data[i] != 0) ? 1 : 0;
00644     }
00645     
00646     return temp;
00647 }

template<class T>
void Matrix< T >::Clean  ) 
 

Definition at line 168 of file Matrix.inl.

References Matrix< T >::clean, Matrix< T >::columns, and Matrix< T >::data.

00169 {
00170     if(clean != 0)
00171     {
00172         delete clean;
00173         data = 0;
00174         columns = 0;
00175         clean = 0;
00176     }
00177 }

template<class T>
Matrix< T > Matrix< T >::Clone  )  const
 

Definition at line 221 of file Matrix.inl.

References Matrix< T >::Columns(), Matrix< T >::data, Matrix< T >::length, and Matrix< T >::Rows().

Referenced by Conj().

00222 {
00223     Matrix<T> temp(Rows(), Columns());
00224     
00225     memcpy(temp.data, data, sizeof(T)*temp.length);
00226 
00227     return temp;
00228 }

template<class T>
const int Matrix< T >::Columns  )  const [inline]
 

Definition at line 309 of file Matrix.inl.

Referenced by Matrix< T >::Clone(), Complex(), Imag(), Matrix< T >::Matrix(), Matrix< T >::MMultiply(), Matrix< T >::operator()(), Matrix< T >::operator=(), Real(), ToComplexDouble(), ToComplexFloat(), ToDouble(), and Matrix< T >::Transpose().

00310 {
00311     return xDim;
00312 }

template<class T>
T & Matrix< T >::Coor const int  x,
const int  y
[inline]
 

Matrix element access using coordinates (x,y). Bounds are checked.

Definition at line 1392 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::data, and Utility::RunTimeError().

01393 {
01394     if(i<0 || i>=dims[0] || j<0 || j>=dims[1])
01395     {
01396         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01397         Utility::RunTimeError("Index outside bounds!");
01398     }
01399 
01400     return columns[i].data[j];
01401 
01402 }

template<class T>
T & Matrix< T >::CoorNC const int  x,
const int  y
[inline]
 

Matrix element access using coordinates (x,y). Bounds are not checked.

Definition at line 1407 of file Matrix.inl.

References Matrix< T >::columns, and Matrix< T >::data.

01408 {
01409     return columns[i].data[j];
01410 
01411 }

template<class T>
T * Matrix< T >::Data  )  [inline]
 

Definition at line 214 of file Matrix.inl.

Referenced by Matrix< T >::And(), Conj(), Matrix< T >::Eq(), Matrix< T >::Ge(), Matrix< T >::Gt(), Matrix< T >::Le(), Matrix< T >::Lt(), Matrix< T >::Ne(), Matrix< T >::operator!(), and Matrix< T >::Or().

00215 {
00216     return data;
00217 }

template<class T>
const T * Matrix< T >::DataPtr  )  [inline]
 

Definition at line 208 of file Matrix.inl.

00209 {
00210     return data;
00211 }

template<class T>
const int* Matrix< T >::Dims  )  const
 

template<class T>
Matrix< T > & Matrix< T >::Divide v  ) 
 

Definition at line 1201 of file Matrix.inl.

References Matrix< T >::data, and Utility::RunTimeError().

01202 {
01203     if(v == 0)
01204     {
01205         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01206         Utility::RunTimeError("Divide by zero in matrix by value division!");
01207     }
01208     
01209     for(int i=0;i<this->length;i++)
01210     {
01211         this->data[i] /= v;
01212     }
01213     return *this;
01214 }

template<class T>
Matrix< T > & Matrix< T >::Divide Matrix< T > &  m  ) 
 

Definition at line 1142 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), and Utility::RunTimeError().

01143 {
01144     if(!Matrix<T>::IsCompatible(*this, m))
01145     {
01146         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01147         Utility::RunTimeError("Matrix sizes are not compatible!");
01148     }
01149 
01150     for(int i=0;i<this->length;i++)
01151     {
01152         if(m.data[i] != 0)
01153         {
01154             this->data[i] /= m.data[i];
01155         }
01156         else
01157         {
01158             cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01159             Utility::RunTimeError("Divide by zero in matrix division!");
01160         }
01161     }
01162     
01163     return *this;
01164 }

template<class T>
Matrix< T > Matrix< T >::Divide v2,
Matrix< T > &  m1
[static]
 

Definition at line 1067 of file Matrix.inl.

References Matrix< T >::data, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

01068 {
01069     Matrix<T> temp(m1.yDim, m1.xDim);
01070     for(int i=0;i<temp.length;i++)
01071     {
01072         if(m1.data[i] != 0)
01073         {
01074             temp.data[i] = v2 / m1.data[i];
01075         }
01076         else
01077         {
01078             cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01079             Utility::RunTimeError("Divide by zero in value by matrix division!");
01080         }
01081     }
01082     return temp;
01083 }

template<class T>
Matrix< T > Matrix< T >::Divide Matrix< T > &  m1,
v2
[static]
 

Definition at line 1050 of file Matrix.inl.

References Matrix< T >::data, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

01051 {
01052     if(v2 == 0)
01053     {
01054         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01055         Utility::RunTimeError("Divide by zero in matrix by value division!");
01056     }
01057 
01058     Matrix<T> temp(m1.yDim, m1.xDim);
01059     for(int i=0;i<temp.length;i++)
01060     {
01061         temp.data[i] = m1.data[i] / v2;
01062     }
01063     return temp;
01064 }

template<class T>
Matrix< T > Matrix< T >::Divide Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Definition at line 973 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::operator/=().

00974 {
00975     if(!Matrix<T>::IsCompatible(m1, m2))
00976     {
00977         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00978         Utility::RunTimeError("Matrix sizes are not compatible!");
00979     }
00980 
00981     Matrix<T> temp(m1.yDim, m1.xDim);
00982     for(int i=0;i<temp.length;i++)
00983     {
00984         //FW: catch division exception instead...
00985         if(m2.data[i] != 0)
00986         {
00987             temp.data[i] = m1.data[i] / m2.data[i];
00988         }
00989         else
00990         {
00991             cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00992             Utility::RunTimeError("Divide by zero in matrix division!");
00993         }
00994     }
00995     
00996     return temp;
00997 }

template<class T>
T & Matrix< T >::Elem const int  i  )  [inline]
 

Matrix element access (sequential: column scan). Bounds are checked.

Definition at line 1348 of file Matrix.inl.

References Matrix< T >::data, and Utility::RunTimeError().

01349 {
01350     if(i<0 || i>=length)
01351     {
01352         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01353         Utility::RunTimeError("Index outside bounds!");
01354     }
01355     return data[i];
01356 }

template<class T>
T & Matrix< T >::Elem const int  _row,
const int  _col
[inline]
 

Matrix element access (row,col). Bounds are checked.

Definition at line 1368 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::data, and Utility::RunTimeError().

01369 {
01370     if(i<0 || i>=dims[0] || j<0 || j>=dims[1])
01371     {
01372         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01373         Utility::RunTimeError("Index outside bounds!");
01374     }
01375 
01376     return columns[i].data[j];
01377 
01378 }

template<class T>
T & Matrix< T >::ElemNC const int  i  )  [inline]
 

Matrix element access (sequential: column scan). Bounds are not checked.

Definition at line 1360 of file Matrix.inl.

References Matrix< T >::data.

01361 {
01362     return data[i];
01363 }

template<class T>
T & Matrix< T >::ElemNC const int  _row,
const int  _col
[inline]
 

Matrix element access (row,col). Bounds are not checked.

Definition at line 1383 of file Matrix.inl.

References Matrix< T >::columns, and Matrix< T >::data.

Referenced by Complex(), Imag(), Real(), ToComplexDouble(), ToComplexFloat(), and ToDouble().

01384 {
01385     return columns[i].data[j];
01386 
01387 }

template<class T>
Matrix< int > Matrix< T >::Eq Matrix< T > &  m,
v
[static]
 

== operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 877 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00878 {
00879     Matrix<int> temp(m1.yDim, m1.xDim);
00880     for(int i=0;i<temp.Length();i++)
00881     {
00882         temp.Data()[i] = (m1.data[i] == v) ? 1 : 0;
00883     }
00884     
00885     return temp;
00886 }

template<class T>
Matrix< int > Matrix< T >::Eq Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise == operator. Returns 1 or 0 for each element.

Definition at line 747 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00748 {
00749     if(!Matrix<T>::IsCompatible(m1, m2))
00750     {
00751         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00752         Utility::RunTimeError("Matrix sizes are not compatible!");
00753     }
00754 
00755     Matrix<int> temp(m1.yDim, m1.xDim);
00756     for(int i=0;i<temp.Length();i++)
00757     {
00758         temp.Data()[i] = (m1.data[i] == m2.data[i]) ? 1 : 0;
00759     }
00760     
00761     return temp;
00762 }

template<class T>
Matrix< int > Matrix< T >::Ge Matrix< T > &  m,
v
[static]
 

<= (Greater than or equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 863 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00864 {
00865     Matrix<int> temp(m1.yDim, m1.xDim);
00866     for(int i=0;i<temp.Length();i++)
00867     {
00868         temp.Data()[i] = (m1.data[i] >= v) ? 1 : 0;
00869     }
00870     
00871     return temp;
00872 }

template<class T>
Matrix< int > Matrix< T >::Ge Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise >= (greater than or equal) operator. Returns 1 or 0 for each element.

Definition at line 728 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00729 {
00730     if(!Matrix<T>::IsCompatible(m1, m2))
00731     {
00732         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00733         Utility::RunTimeError("Matrix sizes are not compatible!");
00734     }
00735 
00736     Matrix<int> temp(m1.yDim, m1.xDim);
00737     for(int i=0;i<temp.Length();i++)
00738     {
00739         temp.Data()[i] = (m1.data[i] >= m2.data[i]) ? 1 : 0;
00740     }
00741     
00742     return temp;
00743 }

template<class T>
Matrix< int > Matrix< T >::Gt Matrix< T > &  m,
v
[static]
 

> (Greater than) operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 835 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00836 {
00837     Matrix<int> temp(m1.yDim, m1.xDim);
00838     for(int i=0;i<temp.Length();i++)
00839     {
00840         temp.Data()[i] = (m1.data[i] > v) ? 1 : 0;
00841     }
00842     
00843     return temp;
00844 }

template<class T>
Matrix< int > Matrix< T >::Gt Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise > (greater than) operator. Returns 1 or 0 for each element.

Definition at line 690 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00691 {
00692     if(!Matrix<T>::IsCompatible(m1, m2))
00693     {
00694         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00695         Utility::RunTimeError("Matrix sizes are not compatible!");
00696     }
00697 
00698     Matrix<int> temp(m1.yDim, m1.xDim);
00699     for(int i=0;i<temp.Length();i++)
00700     {
00701         temp.Data()[i] = (m1.data[i] > m2.data[i]) ? 1 : 0;
00702     }
00703     
00704     return temp;
00705 }

template<class T>
void Matrix< T >::Init const T  init  )  [inline]
 

Definition at line 354 of file Matrix.inl.

References Matrix< T >::data.

Referenced by Matrix< T >::MMultiply().

00355 {
00356     for(int i=0;i<length;i++)
00357     {
00358         data[i] = init;
00359     }
00360 }

template<class T>
bool Matrix< T >::IsCompatible Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Check if two matrices have the same sizes.

Definition at line 612 of file Matrix.inl.

References Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::Add(), Matrix< T >::And(), Matrix< T >::Divide(), Matrix< T >::Eq(), Matrix< T >::Ge(), Matrix< T >::Gt(), Matrix< T >::Le(), Matrix< T >::Lt(), Matrix< T >::Multiply(), Matrix< T >::Ne(), Matrix< T >::Or(), and Matrix< T >::Subtract().

00613 {
00614     if(m1.xDim != m2.xDim || m1.yDim != m2.yDim)
00615     {
00616         return false;
00617     }
00618     else
00619     {
00620         return true;
00621     }
00622 
00623 }

template<class T>
bool Matrix< T >::IsM2MCompatible Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

are these matrices (and in this order) are compatible for matrix multiplication

Definition at line 483 of file Matrix.inl.

References Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::MMultiply().

00484 {
00485     if(m1.xDim == m2.yDim)
00486     {
00487         return true;
00488     }
00489     else
00490     {
00491         return false;
00492     }
00493 }

template<class T>
bool Matrix< T >::IsSquare Matrix< T > &  m  )  [static]
 

Definition at line 465 of file Matrix.inl.

References Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::Transpose().

00466 {
00467     if(m.xDim == m.yDim)
00468     {
00469         return true;
00470     }
00471     else
00472     {
00473         return false;
00474     }
00475 }

template<class T>
Matrix< int > Matrix< T >::Le Matrix< T > &  m,
v
[static]
 

<= (Less than or equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 849 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00850 {
00851     Matrix<int> temp(m1.yDim, m1.xDim);
00852     for(int i=0;i<temp.Length();i++)
00853     {
00854         temp.Data()[i] = (m1.data[i] <= v) ? 1 : 0;
00855     }
00856     
00857     return temp;
00858 }

template<class T>
Matrix< int > Matrix< T >::Le Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise <= (less than or equal) operator. Returns 1 or 0 for each element.

Definition at line 709 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00710 {
00711     if(!Matrix<T>::IsCompatible(m1, m2))
00712     {
00713         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00714         Utility::RunTimeError("Matrix sizes are not compatible!");
00715     }
00716 
00717     Matrix<int> temp(m1.yDim, m1.xDim);
00718     for(int i=0;i<temp.Length();i++)
00719     {
00720         temp.Data()[i] = (m1.data[i] <= m2.data[i]) ? 1 : 0;
00721     }
00722     
00723     return temp;
00724 }

template<class T>
const int Matrix< T >::Length  )  const [inline]
 

Definition at line 342 of file Matrix.inl.

Referenced by Complex(), Conj(), Imag(), Real(), ToComplexDouble(), ToComplexFloat(), and ToDouble().

00343 {
00344     return length;
00345 }

template<class T>
Matrix< int > Matrix< T >::Lt Matrix< T > &  m,
v
[static]
 

< (Less than) operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 821 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00822 {
00823     Matrix<int> temp(m1.yDim, m1.xDim);
00824     for(int i=0;i<temp.Length();i++)
00825     {
00826         temp.Data()[i] = (m1.data[i] < v) ? 1 : 0;
00827     }
00828     
00829     return temp;
00830 }

template<class T>
Matrix< int > Matrix< T >::Lt Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise < (less than) operator. Returns 1 or 0 for each element.

Definition at line 671 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00672 {
00673     if(!Matrix<T>::IsCompatible(m1, m2))
00674     {
00675         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00676         Utility::RunTimeError("Matrix sizes are not compatible!");
00677     }
00678 
00679     Matrix<int> temp(m1.yDim, m1.xDim);
00680     for(int i=0;i<temp.Length();i++)
00681     {
00682         temp.Data()[i] = (m1.data[i] < m2.data[i]) ? 1 : 0;
00683     }
00684     
00685     return temp;
00686 }

template<class T>
Matrix< T > Matrix< T >::MMultiply Vector< T > &  m1,
Matrix< T > &  m2
[static]
 

Vector to Matrix multiplication. Vector is taken as a row vector.

Definition at line 548 of file Matrix.inl.

References Matrix< T >::Columns(), Vector< T >::data, Vector< T >::Init(), Vector< T >::length, Matrix< T >::Rows(), and Utility::RunTimeError().

00549 {
00550     if(m2.Rows() != m1.length)
00551     {
00552         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00553         Utility::RunTimeError("Matrix sizes are not compatible for matrix multiplication!");
00554     }
00555 
00556     Matrix<T> temp(1, m2.Columns());
00557     temp.Init(0);
00558     for(int i=0; i<m2.Columns(); i++)
00559     {
00560         for(int j=0; j<m1.length; j++)
00561         {
00562                 temp.data[i] += m2[i][j]*m1[j]; 
00563         }
00564     }
00565     
00566     return temp;
00567 }

template<class T>
Matrix< T > Matrix< T >::MMultiply Matrix< T > &  m1,
Vector< T > &  m2
[static]
 

Matrix to Vector multiplication. Vector is taken as a column vector.

Definition at line 525 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Init(), Vector< T >::length, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00526 {
00527     if(m1.xDim != m2.length)
00528     {
00529         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00530         Utility::RunTimeError("Matrix sizes are not compatible for matrix multiplication!");
00531     }
00532 
00533     Matrix<T> temp(m1.yDim, 1);
00534     temp.Init(0);
00535     for(int i=0; i<m1.yDim; i++)
00536     {
00537         for(int j=0; j<m2.length; j++)
00538         {
00539             temp.data[i] += m1[j][i]*m2[j]; 
00540         }
00541     }
00542     
00543     return temp;
00544 }

template<class T>
Matrix< T > Matrix< T >::MMultiply Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Matrix multiplication. Also used to overload & operator.

Definition at line 498 of file Matrix.inl.

References Matrix< T >::Init(), Matrix< T >::IsM2MCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00499 {
00500     if(!Matrix<T>::IsM2MCompatible(m1, m2))
00501     {
00502         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00503         Utility::RunTimeError("Matrix sizes are not compatible for matrix multiplication!");
00504     }
00505 
00506     Matrix<T> temp(m1.yDim, m2.xDim);
00507     temp.Init(0);
00508     for(int i=0; i<m1.yDim; i++)
00509     {
00510         for(int j=0; j<m2.xDim; j++)
00511         {
00512             for(int k = 0; k<m1.xDim; k++)
00513             {
00514                 temp[j][i] += m1[k][i]*m2[j][k]; 
00515             }
00516         }
00517     }
00518     
00519     return temp;
00520 }

template<class T>
Matrix< T > & Matrix< T >::Multiply v  ) 
 

Definition at line 1191 of file Matrix.inl.

References Matrix< T >::data.

01192 {
01193     for(int i=0;i<this->length;i++)
01194     {
01195         this->data[i] *= v;
01196     }
01197     return *this;
01198 }

template<class T>
Matrix< T > & Matrix< T >::Multiply Matrix< T > &  m  ) 
 

Definition at line 1125 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), and Utility::RunTimeError().

01126 {
01127     if(!Matrix<T>::IsCompatible(*this, m))
01128     {
01129         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01130         Utility::RunTimeError("Matrix sizes are not compatible!");
01131     }
01132 
01133     for(int i=0;i<this->length;i++)
01134     {
01135         this->data[i] *= m.data[i];
01136     }
01137     
01138     return *this;
01139 }

template<class T>
Matrix< T > Matrix< T >::Multiply Matrix< T > &  m1,
v2
[static]
 

Definition at line 1039 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01040 {
01041     Matrix<T> temp(m1.yDim, m1.xDim);
01042     for(int i=0;i<temp.length;i++)
01043     {
01044         temp.data[i] = m1.data[i] * v2;
01045     }
01046     return temp;
01047 }

template<class T>
Matrix< T > Matrix< T >::Multiply Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Definition at line 955 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::operator *=().

00956 {
00957     if(!Matrix<T>::IsCompatible(m1, m2))
00958     {
00959         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00960         Utility::RunTimeError("Matrix sizes are not compatible!");
00961     }
00962 
00963     Matrix<T> temp(m1.yDim, m1.xDim);
00964     for(int i=0;i<temp.length;i++)
00965     {
00966         temp.data[i] = m1.data[i] * m2.data[i];
00967     }
00968     
00969     return temp;
00970 }

template<class T>
const int Matrix< T >::NDims  )  const [inline]
 

Definition at line 348 of file Matrix.inl.

00349 {
00350     return ndims;
00351 }

template<class T>
Matrix< int > Matrix< T >::Ne Matrix< T > &  m,
v
[static]
 

!= (Not equal) operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 891 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00892 {
00893     Matrix<int> temp(m1.yDim, m1.xDim);
00894     for(int i=0;i<temp.Length();i++)
00895     {
00896         temp.Data()[i] = (m1.data[i] != v) ? 1 : 0;
00897     }
00898     
00899     return temp;
00900 }

template<class T>
Matrix< int > Matrix< T >::Ne Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise != (not equal) operator. Returns 1 or 0 for each element.

Definition at line 766 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00767 {
00768     if(!Matrix<T>::IsCompatible(m1, m2))
00769     {
00770         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00771         Utility::RunTimeError("Matrix sizes are not compatible!");
00772     }
00773 
00774     Matrix<int> temp(m1.yDim, m1.xDim);
00775     for(int i=0;i<temp.Length();i++)
00776     {
00777         temp.Data()[i] = (m1.data[i] != m2.data[i]) ? 1 : 0;
00778     }
00779     
00780     return temp;
00781 }

template<class T>
Matrix< T > & Matrix< T >::operator *= v  ) 
 

Definition at line 1536 of file Matrix.inl.

References Matrix< T >::Multiply().

01537 {
01538     return this->Multiply(v);
01539 }

template<class T>
Matrix< T > & Matrix< T >::operator *= Matrix< T > &  m  ) 
 

Definition at line 1511 of file Matrix.inl.

References Matrix< T >::Multiply().

01512 {
01513     return this->Multiply(m);
01514 }

template<class T>
Matrix< int > Matrix< T >::operator!  )  [inline]
 

Definition at line 1317 of file Matrix.inl.

References Matrix< T >::Data(), Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01318 {
01319     Matrix<int> temp(yDim, xDim);
01320     for(int i=0;i<length;i++)
01321     {
01322         if(data[i] == 0)
01323         {
01324             temp.Data()[i] = 1;
01325         }
01326         else
01327         {
01328             temp.Data()[i] = 0;
01329         }
01330     }
01331     return temp;
01332 }

template<class T>
Matrix< T > Matrix< T >::operator() const int  row1,
const int  row2,
const int  col1,
const int  col2
[inline]
 

returns a new Matrix using the slice rectangle.

Definition at line 1456 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::Columns(), Matrix< T >::data, Matrix< T >::Rows(), and Utility::RunTimeError().

01457 {
01458     if(row1<0 || row1>=Rows() || row2<0 || row2>=Rows())
01459     {
01460         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01461         Utility::RunTimeError("Index outside bounds!");
01462     }
01463     if(row1 > row2)
01464     {
01465         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01466         Utility::RunTimeError("Second slice parameter cannot be less than the first parameter!");
01467     }
01468 
01469 
01470     if(col1<0 || col1>=Columns() || col2<0 || col2>=Columns())
01471     {
01472         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01473         Utility::RunTimeError("Index outside bounds!");
01474     }
01475     if(col1 > col2)
01476     {
01477         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01478         Utility::RunTimeError("Second slice parameter cannot be less than the first parameter!");
01479     }
01480 
01481     
01482     Matrix<T> temp(row2-row1+1, col2-col1+1);
01483     
01484     for(int j=col1; j<=col2; j++)
01485     {
01486         memcpy(temp[ j-col1 ].data, &(columns[j].data[row1]), sizeof(T)*temp.Rows());
01487     }
01488 
01489     return temp;
01490 }

template<class T>
T & Matrix< T >::operator() const int  i,
const int  j
[inline]
 

Matrix element access (row,col). Bounds are checked (See ElemNC() for element access with no bounds check).

Definition at line 1431 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::data, Utility::RunTimeError(), and Matrix< T >::xDim.

01432 {
01433     if(i<0 || i>=xDim || j<0 || j>=yDim)
01434     {
01435         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01436         Utility::RunTimeError("Index outside bounds!");
01437     }
01438 
01439     return columns[i].data[j];
01440 
01441 }

template<class T>
T & Matrix< T >::operator() const int  i  )  [inline]
 

Matrix element access (sequential: column scan). Bounds are checked (See ElemNC() for element access with no bounds check).

Definition at line 1419 of file Matrix.inl.

References Matrix< T >::data, and Utility::RunTimeError().

01420 {
01421     if(i<0 || i>=length)
01422     {
01423         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01424         Utility::RunTimeError("Index outside bounds!");
01425     }
01426     return data[i];
01427 }

template<class T>
Matrix< T > Matrix< T >::operator+  )  [inline]
 

Unary +. Does not have any effect. Returns the same matrix.

Definition at line 1296 of file Matrix.inl.

01297 {
01298     return *this;
01299 }

template<class T>
Matrix< T > & Matrix< T >::operator+= v  ) 
 

Definition at line 1524 of file Matrix.inl.

References Matrix< T >::Add().

01525 {
01526     return this->Add(v);
01527 }

template<class T>
Matrix< T > & Matrix< T >::operator+= Matrix< T > &  m  ) 
 

Definition at line 1499 of file Matrix.inl.

References Matrix< T >::Add().

01500 {
01501     return this->Add(m);
01502 }

template<class T>
Matrix< T > Matrix< T >::operator-  )  [inline]
 

Unary -.

Definition at line 1304 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01305 {
01306     Matrix<T> temp(yDim, xDim);
01307     for(int i=0;i<length;i++)
01308     {
01309         temp.data[i] = - data[i];
01310     }
01311     return temp;
01312 }

template<class T>
Matrix< T > & Matrix< T >::operator-= v  ) 
 

Definition at line 1530 of file Matrix.inl.

References Matrix< T >::Subtract().

01531 {
01532     return this->Subtract(v);
01533 }

template<class T>
Matrix< T > & Matrix< T >::operator-= Matrix< T > &  m  ) 
 

Definition at line 1505 of file Matrix.inl.

References Matrix< T >::Subtract().

01506 {
01507     return this->Subtract(m);
01508 }

template<class T>
Matrix< T > & Matrix< T >::operator/= v  ) 
 

Definition at line 1542 of file Matrix.inl.

References Matrix< T >::Divide().

01543 {
01544     return this->Divide(v);
01545 }

template<class T>
Matrix< T > & Matrix< T >::operator/= Matrix< T > &  m  ) 
 

Definition at line 1517 of file Matrix.inl.

References Matrix< T >::Divide().

01518 {
01519     return this->Divide(m);
01520 }

template<class T>
Matrix<T>& Matrix< T >::operator= Vector< T > &  m  ) 
 

template<class T>
Matrix< T > & Matrix< T >::operator= Array< T > &  m  ) 
 

Definition at line 1244 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::Columns(), Matrix< T >::columns, Array< T >::data, Matrix< T >::data, Array< T >::length, Matrix< T >::length, Array< T >::ndims, Matrix< T >::ndims, Matrix< T >::Rows(), Utility::Warning(), Matrix< T >::xDim, and Matrix< T >::yDim.

01245 {
01246     ndims = 2;
01247     xDim = 0;
01248     yDim = 0;
01249     data = 0;
01250     columns = 0;
01251 
01252     if(m.ndims == 2){
01253         length = m.length;
01254         data = m.data;
01255         xDim = m.xDim;
01256         yDim = m.yDim;
01257 
01258         columns = new Vector<T>[Columns()];
01259         Utility::CheckPointer(columns);
01260         for(int i=0; i<Columns(); i++)
01261         {
01262             columns[i].Set(&(data[i*Rows()]), Rows());
01263         }
01264 
01265         delete clean;
01266         clean = new Cleaner<T>(data, columns);
01267     }
01268     else if(m.ndims > 0) // Convert to row matrux
01269     {
01270         length = m.length;
01271         data = m.data;
01272         xDim = length;
01273         yDim = 1;
01274         
01275         columns = new Vector<T>[1];
01276         Utility::CheckPointer(columns);
01277         columns[0].Set(&(data[0]),length);
01278 
01279         delete clean;
01280         clean = new Cleaner<T>(data, columns);
01281         
01282         Utility::Warning("Array (not of dimension 2) is converted to row Matrix. dimensionality information is lost.");
01283     }
01284     
01285 
01286     return *this;
01287 }

template<class T>
Matrix< T > & Matrix< T >::operator= Matrix< T > &  m  ) 
 

Definition at line 1227 of file Matrix.inl.

References Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::length, Matrix< T >::ndims, Matrix< T >::xDim, and Matrix< T >::yDim.

01228 {
01229     ndims = m.ndims;
01230     length = m.length;
01231     xDim = m.xDim;
01232     yDim = m.yDim;
01233     data = m.data;
01234     columns = m.columns;
01235     
01236     delete clean;
01237     clean = new Cleaner<T>(data, columns);
01238     
01239     
01240     return *this;
01241 }

template<class T>
Vector< T > & Matrix< T >::operator[] const int  i  )  [inline]
 

Returns a pointer to the beginning of a column.

Definition at line 1446 of file Matrix.inl.

References Matrix< T >::columns.

01447 {
01448     return columns[i];
01449 }

template<class T>
Matrix< T > Matrix< T >::operator~  )  [inline]
 

Transpose ~.

Definition at line 1337 of file Matrix.inl.

References Matrix< T >::Transpose().

01338 {
01339     return Matrix<T>::Transpose(*this);
01340 }

template<class T>
Matrix< int > Matrix< T >::Or Matrix< T > &  m,
v
[static]
 

OR operator between Matrix elements and a value. Returns 1 or 0 for each element.

Definition at line 807 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::xDim, and Matrix< T >::yDim.

00808 {
00809     Matrix<int> temp(m1.yDim, m1.xDim);
00810     for(int i=0;i<temp.Length();i++)
00811     {
00812         temp.Data()[i] = (m1.data[i] == 0 && v == 0) ? 0 : 1;
00813     }
00814     
00815     return temp;
00816 }

template<class T>
Matrix< int > Matrix< T >::Or Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Elementwise OR operator. Returns 1 or 0 for each element.

Definition at line 652 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::Data(), Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00653 {
00654     if(!Matrix<T>::IsCompatible(m1, m2))
00655     {
00656         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00657         Utility::RunTimeError("Matrix sizes are not compatible!");
00658     }
00659 
00660     Matrix<int> temp(m1.yDim, m1.xDim);
00661     for(int i=0;i<temp.Length();i++)
00662     {
00663         temp.Data()[i] = (m1.data[i] == 0 && m2.data[i] == 0) ? 0 : 1;
00664     }
00665     
00666     return temp;
00667 }

template<class T>
Matrix< T > Matrix< T >::Rand const int  rows,
const int  cols,
const double  max
[static]
 

Definition at line 407 of file Matrix.inl.

References Matrix< T >::data, RandomGen::Initialize(), and RandomGen::Initialized().

00408 {
00409     Matrix<T> m(rows, cols);
00410     if(!RandomGen::Initialized())
00411     {
00412         RandomGen::Initialize();
00413     }
00414     for(int i=0;i<rows*cols;i++)
00415     {
00416         m.data[i] = (T)(rand()/(double)RAND_MAX*max);
00417     }
00418     return m;
00419 }

template<class T>
Matrix< T > Matrix< T >::Rand const int  rows,
const int  cols
[static]
 

Definition at line 392 of file Matrix.inl.

References Matrix< T >::data, RandomGen::Initialize(), and RandomGen::Initialized().

00393 {
00394     Matrix<T> m(rows, cols);
00395     if(!RandomGen::Initialized())
00396     {
00397         RandomGen::Initialize();
00398     }
00399     for(int i=0;i<rows*cols;i++)
00400     {
00401         m.data[i] = (T)rand();
00402     }
00403     return m;
00404 }

template<class T>
Matrix< T > & Matrix< T >::Rand const double  max  )  [inline]
 

Definition at line 377 of file Matrix.inl.

References Matrix< T >::data, RandomGen::Initialize(), and RandomGen::Initialized().

00378 {
00379     if(!RandomGen::Initialized())
00380     {
00381         RandomGen::Initialize();
00382     }
00383     for(int i=0;i<length;i++)
00384     {
00385         data[i] = (T)(rand()/(double)RAND_MAX*max);
00386     }
00387     return *this;
00388 }

template<class T>
Matrix< T > & Matrix< T >::Rand  )  [inline]
 

Definition at line 363 of file Matrix.inl.

References Matrix< T >::data, RandomGen::Initialize(), and RandomGen::Initialized().

00364 {
00365     if(!RandomGen::Initialized())
00366     {
00367         RandomGen::Initialize();
00368     }
00369     for(int i=0;i<length;i++)
00370     {
00371         data[i] = (T)rand();
00372     }
00373     return *this;
00374 }

template<class T>
void Matrix< T >::ReadFromMatrix const Matrix< T > &  m,
const int  rowStart,
const int  colStart
 

Definition at line 443 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::data, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00444 {
00445     if(xDim < m.xDim+colStart || yDim < m.yDim+rowStart)
00446     {
00447         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00448         Utility::RunTimeError("You can't read from a larger Matrix (from the copy start point) to a smaller Matrix!");
00449     }
00450 
00451     for(int i=0;i<m.xDim;i++)
00452     {
00453         for(int j=0;j<m.yDim;j++)
00454         {
00455             columns[i+colStart].data[j+rowStart] = m.columns[i].data[j];
00456         }
00457     }
00458 
00459 }

template<class T>
void Matrix< T >::ReadFromMatrix const Matrix< T > &  m  ) 
 

Definition at line 424 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::data, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00425 {
00426     if(xDim < m.xDim || yDim < m.yDim)
00427     {
00428         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00429         Utility::RunTimeError("You can't read from a larger Matrix to a smaller Matrix!");
00430     }
00431 
00432     for(int i=0;i<m.xDim;i++)
00433     {
00434         for(int j=0;j<m.yDim;j++)
00435         {
00436             columns[i].data[j] = m.columns[i].data[j];
00437         }
00438     }
00439 
00440 }

template<class T>
const int Matrix< T >::Rows  )  const [inline]
 

Definition at line 315 of file Matrix.inl.

Referenced by Matrix< T >::Clone(), Complex(), Imag(), Matrix< T >::Matrix(), Matrix< T >::MMultiply(), Matrix< T >::operator()(), Matrix< T >::operator=(), Real(), ToComplexDouble(), ToComplexFloat(), ToDouble(), and Matrix< T >::Transpose().

00316 {
00317     return yDim;
00318 }

template<class T>
void Matrix< T >::Set const int  rows,
const int  columns,
T *  _data
 

Make sure enough memory is already allocated. Memory is from now on handled by the matrix... Don't free it manually.

Definition at line 181 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, Matrix< T >::length, Matrix< T >::ndims, Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

00182 {
00183     if(rows < 1 || cols < 1)
00184     {
00185         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00186         Utility::RunTimeError("All Matrix dimensions should be larger than 0!");
00187     }
00188 
00189     ndims = 2;
00190     length = rows*cols;
00191     xDim = cols;
00192     yDim = rows;
00193     data = _data;
00194 
00195     columns = new Vector<T>[cols];
00196     Utility::CheckPointer(columns);
00197     for(int i=0; i<cols; i++)
00198     {
00199         columns[i].Set(&(data[i*rows]), rows);
00200     }
00201     
00202     delete clean;
00203     clean = new Cleaner<T>(data, columns);
00204     
00205 }

template<class T>
const List< int, 2 > Matrix< T >::Size  )  const [inline]
 

Definition at line 336 of file Matrix.inl.

References Matrix< T >::xDim, and Matrix< T >::yDim.

00337 {
00338     return List(yDim, xDim);
00339 }

template<class T>
SubMatrix< T > Matrix< T >::Slice int  row1,
int  row2,
int  col1,
int  col2
 

Definition at line 267 of file Matrix.inl.

References SubMatrix< T >::clean, Matrix< T >::columns, SubMatrix< T >::columns, Matrix< T >::data, Utility::RunTimeError(), SubMatrix< T >::xDim, Matrix< T >::XDim(), SubMatrix< T >::yDim, and Matrix< T >::YDim().

00268 {
00269     if(row1<0 || row1>=YDim() || row2<0 || row2>=YDim())
00270     {
00271         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00272         Utility::RunTimeError("Index outside bounds!");
00273     }
00274     if(row1 > row2)
00275     {
00276         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00277         Utility::RunTimeError("Second slice parameter cannot be less than the first parameter!");
00278     }
00279 
00280 
00281     if(col1<0 || col1>=XDim() || col2<0 || col2>=XDim())
00282     {
00283         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00284         Utility::RunTimeError("Index outside bounds!");
00285     }
00286     if(col1 > col2)
00287     {
00288         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00289         Utility::RunTimeError("Second slice parameter cannot be less than the first parameter!");
00290     }
00291 
00292     
00293     SubMatrix<T> temp;
00294     temp.xDim = col2-col1+1;
00295     temp.yDim = row2-row1+1;
00296     temp.columns = new Vector<T>[temp.xDim];
00297     temp.clean = new Cleaner<T>(temp.columns);
00298 
00299     for(int j=col1; j<=col2; j++)
00300     {
00301         temp.columns[j-col1].Set(&(columns[j].data[row1]),  row2-row1+1);
00302     }
00303 
00304     return temp;
00305 }

template<class T>
Matrix< T > & Matrix< T >::Subtract v  ) 
 

Definition at line 1181 of file Matrix.inl.

References Matrix< T >::data.

01182 {
01183     for(int i=0;i<this->length;i++)
01184     {
01185         this->data[i] -= v;
01186     }
01187     return *this;
01188 }

template<class T>
Matrix< T > & Matrix< T >::Subtract Matrix< T > &  m  ) 
 

Definition at line 1108 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), and Utility::RunTimeError().

01109 {
01110     if(!Matrix<T>::IsCompatible(*this, m))
01111     {
01112         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
01113         Utility::RunTimeError("Matrix sizes are not compatible!");
01114     }
01115 
01116     for(int i=0;i<this->length;i++)
01117     {
01118         this->data[i] -= m.data[i];
01119     }
01120     
01121     return *this;
01122 }

template<class T>
Matrix< T > Matrix< T >::Subtract v2,
Matrix< T > &  m1
[static]
 

Definition at line 1027 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01028 {
01029     Matrix<T> temp(m1.yDim, m1.xDim);
01030     for(int i=0;i<temp.length;i++)
01031     {
01032         temp.data[i] = v2 - m1.data[i];
01033     }
01034     return temp;
01035 }

template<class T>
Matrix< T > Matrix< T >::Subtract Matrix< T > &  m1,
v2
[static]
 

Definition at line 1016 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::xDim, and Matrix< T >::yDim.

01017 {
01018     Matrix<T> temp(m1.yDim, m1.xDim);
01019     for(int i=0;i<temp.length;i++)
01020     {
01021         temp.data[i] = m1.data[i] - v2;
01022     }
01023     return temp;
01024 }

template<class T>
Matrix< T > Matrix< T >::Subtract Matrix< T > &  m1,
Matrix< T > &  m2
[static]
 

Definition at line 937 of file Matrix.inl.

References Matrix< T >::data, Matrix< T >::IsCompatible(), Utility::RunTimeError(), Matrix< T >::xDim, and Matrix< T >::yDim.

Referenced by Matrix< T >::operator-=().

00938 {
00939     if(!Matrix<T>::IsCompatible(m1, m2))
00940     {
00941         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00942         Utility::RunTimeError("Matrix sizes are not compatible!");
00943     }
00944 
00945     Matrix<T> temp(m1.yDim, m1.xDim);
00946     for(int i=0;i<temp.length;i++)
00947     {
00948         temp.data[i] = m1.data[i] - m2.data[i];
00949     }
00950     
00951     return temp;
00952 }

template<class T>
void Matrix< T >::SwitchColumns int  i,
int  j
 

Definition at line 232 of file Matrix.inl.

References Matrix< T >::columns, and Matrix< T >::data.

00233 {
00234     T *temp_i = columns[i].data;
00235     columns[i].data = columns[j].data;
00236     columns[j].data = temp_i;
00237 }

template<class T>
void Matrix< T >::SyncData2Columns  ) 
 

reorganizes data array such that matrix elements are ordered in column major ordering. Calling this function will allocate new memory with correct ordering of elements and old memory is freed.

If you created external (manual) pointers to matrix data, you might experience memory/pointer errors after the data is rearranged.

Definition at line 241 of file Matrix.inl.

References Utility::CheckPointer(), Matrix< T >::clean, Matrix< T >::columns, Matrix< T >::data, and Matrix< T >::yDim.

00242 {
00243     T* temp_data = new T[length];
00244     Utility::CheckPointer(temp_data);
00245     
00246     for(int i=0; i<xDim; i++)
00247     {
00248         memcpy(&(temp_data[i*yDim]), columns[i].data, sizeof(T)*yDim);
00249     }
00250     data = temp_data;
00251     
00252     columns = new Vector<T>[xDim];
00253     Utility::CheckPointer(columns);
00254     
00255     for(int i=0; i<xDim; i++)
00256     {
00257         columns[i].data = &(data[i*yDim]);
00258     }
00259     
00260     delete clean;
00261     clean = new Cleaner<T>(data, columns);
00262 }

template<class T>
Matrix< T > & Matrix< T >::Transpose  ) 
 

Transpose of a matrix. Does not allocate a new Matrix. Creates transpose inline.

Definition at line 588 of file Matrix.inl.

References Matrix< T >::columns, Matrix< T >::IsSquare(), and Utility::RunTimeError().

Referenced by Matrix< T >::operator~().

00589 {
00590     if(!Matrix<T>::IsSquare(*this))
00591     {
00592         cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00593         Utility::RunTimeError("Matrix is not square!");
00594     }
00595     
00596     for(int i=0; i<yDim; i++)
00597     {
00598         for(int j=0; j<i; j++)
00599         {
00600             T temp = columns[j][i];
00601             columns[j][i] = columns[i][j];
00602             columns[i][j] = temp;
00603         }
00604     }
00605     return *this;
00606 
00607 }

template<class T>
Matrix< T > Matrix< T >::Transpose Matrix< T > &  m  )  [static]
 

Transpose of a matrix. Allocates a new Matrix.

Definition at line 572 of file Matrix.inl.

References Matrix< T >::Columns(), and Matrix< T >::Rows().

00573 {
00574     Matrix<T> temp(m.Columns(), m.Rows());
00575     for(int i=0; i<m.Rows(); i++)
00576     {
00577         for(int j=0; j<m.Columns(); j++)
00578         {
00579             temp[i][j] = m[j][i]; 
00580         }
00581     }
00582     return temp;
00583 }

template<class T>
const int Matrix< T >::XDim  )  const [inline]
 

Definition at line 322 of file Matrix.inl.

Referenced by Matrix< T >::Slice().

00323 {
00324     return xDim;
00325 }

template<class T>
const int Matrix< T >::YDim  )  const [inline]
 

Definition at line 328 of file Matrix.inl.

Referenced by Matrix< T >::Slice().

00329 {
00330     return yDim;
00331 }


Friends And Related Function Documentation

template<class T>
friend class Array<T> [friend]
 

Definition at line 114 of file Matrix.h.

template<class T>
Matrix<T> operator & Vector< T > &  m1,
Matrix< T > &  m2
[friend]
 

Row Vector to Matrix multiplication.

Definition at line 365 of file Matrix.h.

00366     {
00367         return Matrix<T>::MMultiply(m1, m2);
00368     }

template<class T>
Matrix<T> operator & Matrix< T > &  m1,
Vector< T > &  m2
[friend]
 

Matrix to column Vector multiplication.

Definition at line 359 of file Matrix.h.

00360     {
00361         return Matrix<T>::MMultiply(m1, m2);
00362     }

template<class T>
Matrix<T> operator & Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Matrix to Matrix multiplication.

Definition at line 353 of file Matrix.h.

00354     {
00355         return Matrix<T>::MMultiply(m1, m2);
00356     }

template<class T>
Matrix<int> operator && v,
Matrix< T > &  m
[friend]
 

Definition at line 418 of file Matrix.h.

00419     {
00420         return Matrix<T>::And(m, v);
00421     }

template<class T>
Matrix<int> operator && Matrix< T > &  m,
v
[friend]
 

Definition at line 414 of file Matrix.h.

00415     {
00416         return Matrix<T>::And(m, v);
00417     }

template<class T>
Matrix<int> operator && Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 372 of file Matrix.h.

00373     {
00374         return Matrix<T>::And(m1, m2);
00375     }

template<class T>
Matrix<T> operator * v,
Matrix< T > &  m
[friend]
 

Definition at line 541 of file Matrix.h.

00542     {
00543         return Matrix<T>::Multiply(m, v);
00544     }

template<class T>
Matrix<T> operator * Matrix< T > &  m,
v
[friend]
 

Definition at line 536 of file Matrix.h.

00537     {
00538         return Matrix<T>::Multiply(m, v);
00539     }

template<class T>
Matrix<T> operator * Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 504 of file Matrix.h.

00505     {
00506         return Matrix<T>::Multiply(m1, m2);
00507     }

template<class T>
Matrix<int> operator!= v,
Matrix< T > &  m
[friend]
 

Definition at line 481 of file Matrix.h.

00482     {
00483         return Matrix<T>::Ne(m, v);
00484     }

template<class T>
Matrix<int> operator!= Matrix< T > &  m,
v
[friend]
 

Definition at line 477 of file Matrix.h.

00478     {
00479         return Matrix<T>::Ne(m, v);
00480     }

template<class T>
Matrix<int> operator!= Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 407 of file Matrix.h.

00408     {
00409         return Matrix<T>::Ne(m1, m2);
00410     }

template<class T>
Matrix<T> operator+ v,
Matrix< T > &  m
[friend]
 

Definition at line 521 of file Matrix.h.

00522     {
00523         return Matrix<T>::Add(m, v);
00524     }

template<class T>
Matrix<T> operator+ Matrix< T > &  m,
v
[friend]
 

Definition at line 516 of file Matrix.h.

00517     {
00518         return Matrix<T>::Add(m, v);
00519     }

template<class T>
Matrix<T> operator+ Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 494 of file Matrix.h.

00495     {
00496         return Matrix<T>::Add(m1, m2);
00497     }

template<class T>
Matrix<T> operator- v,
Matrix< T > &  m
[friend]
 

Definition at line 531 of file Matrix.h.

00532     {
00533         return Matrix<T>::Subtract(v, m);
00534     }

template<class T>
Matrix<T> operator- Matrix< T > &  m,
v
[friend]
 

Definition at line 526 of file Matrix.h.

00527     {
00528         return Matrix<T>::Subtract(m, v);
00529     }

template<class T>
Matrix<T> operator- Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 499 of file Matrix.h.

00500     {
00501         return Matrix<T>::Subtract(m1, m2);
00502     }

template<class T>
Matrix<T> operator/ v,
Matrix< T > &  m
[friend]
 

Definition at line 551 of file Matrix.h.

00552     {
00553         return Matrix<T>::Divide(v, m);
00554     }

template<class T>
Matrix<T> operator/ Matrix< T > &  m,
v
[friend]
 

Definition at line 546 of file Matrix.h.

00547     {
00548         return Matrix<T>::Divide(m, v);
00549     }

template<class T>
Matrix<T> operator/ Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 509 of file Matrix.h.

00510     {
00511         return Matrix<T>::Divide(m1, m2);
00512     }

template<class T>
Matrix<int> operator< v,
Matrix< T > &  m
[friend]
 

Definition at line 436 of file Matrix.h.

00437     {
00438         return Matrix<T>::Gt(m, v);
00439     }

template<class T>
Matrix<int> operator< Matrix< T > &  m,
v
[friend]
 

Definition at line 432 of file Matrix.h.

00433     {
00434         return Matrix<T>::Lt(m, v);
00435     }

template<class T>
Matrix<int> operator< Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 382 of file Matrix.h.

00383     {
00384         return Matrix<T>::Lt(m1, m2);
00385     }

template<class T>
ostream& operator<< ostream &  output,
Matrix< T > &  m
[friend]
 

Definition at line 257 of file Matrix.h.

00258     {
00259         int bufferWidth = 80;
00260         int lm = m.Rows();
00261         int rowNoWidth = (int)log10((double)(lm-1))+2;
00262         int infoWidth = 3+rowNoWidth+2;
00263 
00264         int maxLength  = 1;
00265         for(int i=0; i<m.Length(); i++)
00266         {
00267             ostringstream oS;
00268             oS << m.ElemNC(i);
00269             int l = (int)oS.str().length();
00270             if(l>maxLength)
00271             {
00272                 maxLength = l;
00273             }
00274         }
00275 
00276         int columnWidth = maxLength+3;
00277         int columnMax = (bufferWidth-infoWidth)/columnWidth;
00278         
00279         output << typeid(m).name() << " of size " << m.Rows() << "x" << m.Columns() << endl;
00280         output << "=======================" << endl;
00281         if(m.Columns() <= columnMax)
00282         {
00283             for(int i=0;i<m.Rows();i++)
00284             {
00285                 output << "ROW" << right << setw(rowNoWidth) << i+1 << "|";
00286                 for(int j=0;j<m.Columns();j++)
00287                 {
00288                     output << right << setw(columnWidth) << m.ElemNC(i,j);
00289                 }
00290                 output << endl;
00291             }
00292         }
00293         else
00294         {
00295             int groups = m.Columns()/columnMax;
00296             int leftover = m.Columns() % columnMax;
00297             for(int k=0; k<groups; k++)
00298             {
00299                 output << endl;
00300                 output << "----------------------" << endl;
00301                 output << "Columns " << k*columnMax+1 << " through " << k*columnMax+columnMax-1+1 << endl;
00302                 output << "----------------------" << endl;
00303                 for(int i=0;i<m.Rows();i++)
00304                 {
00305                     output << "ROW" << right << setw(rowNoWidth) << i+1 << "|";
00306                     for(int j=columnMax*k;j<columnMax*(k+1);j++)
00307                     {
00308                         output << right << setw(columnWidth) << m.ElemNC(i,j);
00309                     }
00310                     output << endl;
00311                 }
00312             }
00313             if(leftover > 0)
00314             {
00315                 output << endl;
00316                 output << "----------------------" << endl;
00317                 output << "Columns " << groups*columnMax+1 << " through " << groups*columnMax+leftover-1+1 << endl;
00318                 output << "----------------------" << endl;
00319                 for(int i=0;i<m.Rows();i++)
00320                 {
00321                     output << "ROW" << right << setw(rowNoWidth) << i+1 << "|";
00322                     for(int j=groups*columnMax;j<groups*columnMax+leftover;j++)
00323                     {
00324                         output << right << setw(columnWidth) << m.ElemNC(i,j);
00325                     }
00326                     output << endl;
00327                 }
00328             }
00329         }
00330         output << "=======================" << endl;
00331         output << endl;
00332         
00333         return output;
00334     }

template<class T>
Matrix<int> operator<= v,
Matrix< T > &  m
[friend]
 

Definition at line 454 of file Matrix.h.

00455     {
00456         return Matrix<T>::Ge(m, v);
00457     }

template<class T>
Matrix<int> operator<= Matrix< T > &  m,
v
[friend]
 

Definition at line 450 of file Matrix.h.

00451     {
00452         return Matrix<T>::Le(m, v);
00453     }

template<class T>
Matrix<int> operator<= Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 392 of file Matrix.h.

00393     {
00394         return Matrix<T>::Le(m1, m2);
00395     }

template<class T>
Matrix<int> operator== v,
Matrix< T > &  m
[friend]
 

Definition at line 472 of file Matrix.h.

00473     {
00474         return Matrix<T>::Eq(m, v);
00475     }

template<class T>
Matrix<int> operator== Matrix< T > &  m,
v
[friend]
 

Definition at line 468 of file Matrix.h.

00469     {
00470         return Matrix<T>::Eq(m, v);
00471     }

template<class T>
Matrix<int> operator== Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 402 of file Matrix.h.

00403     {
00404         return Matrix<T>::Eq(m1, m2);
00405     }

template<class T>
Matrix<int> operator> v,
Matrix< T > &  m
[friend]
 

Definition at line 445 of file Matrix.h.

00446     {
00447         return Matrix<T>::Lt(m, v);
00448     }

template<class T>
Matrix<int> operator> Matrix< T > &  m,
v
[friend]
 

Definition at line 441 of file Matrix.h.

00442     {
00443         return Matrix<T>::Gt(m, v);
00444     }

template<class T>
Matrix<int> operator> Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 387 of file Matrix.h.

00388     {
00389         return Matrix<T>::Gt(m1, m2);
00390     }

template<class T>
Matrix<int> operator>= v,
Matrix< T > &  m
[friend]
 

Definition at line 463 of file Matrix.h.

00464     {
00465         return Matrix<T>::Le(m, v);
00466     }

template<class T>
Matrix<int> operator>= Matrix< T > &  m,
v
[friend]
 

Definition at line 459 of file Matrix.h.

00460     {
00461         return Matrix<T>::Ge(m, v);
00462     }

template<class T>
Matrix<int> operator>= Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 397 of file Matrix.h.

00398     {
00399         return Matrix<T>::Ge(m1, m2);
00400     }

template<class T>
Matrix<int> operator|| v,
Matrix< T > &  m
[friend]
 

Definition at line 427 of file Matrix.h.

00428     {
00429         return Matrix<T>::Or(m, v);
00430     }

template<class T>
Matrix<int> operator|| Matrix< T > &  m,
v
[friend]
 

Definition at line 423 of file Matrix.h.

00424     {
00425         return Matrix<T>::Or(m, v);
00426     }

template<class T>
Matrix<int> operator|| Matrix< T > &  m1,
Matrix< T > &  m2
[friend]
 

Definition at line 377 of file Matrix.h.

00378     {
00379         return Matrix<T>::Or(m1, m2);
00380     }

template<class T>
friend class SubMatrix<T> [friend]
 

Definition at line 116 of file Matrix.h.

template<class T>
friend class Vector<T> [friend]
 

Definition at line 115 of file Matrix.h.


Member Data Documentation

template<class T>
Cleaner<T>* Matrix< T >::clean [protected]
 

Definition at line 125 of file Matrix.h.

Referenced by Matrix< T >::Clean(), Matrix< T >::Matrix(), Matrix< T >::operator=(), Matrix< T >::Set(), Matrix< T >::SyncData2Columns(), and Matrix< T >::~Matrix().

template<class T>
Vector<T>* Matrix< T >::columns [protected]
 

Definition at line 127 of file Matrix.h.

Referenced by Matrix< T >::Clean(), Matrix< T >::Coor(), Matrix< T >::CoorNC(), Matrix< T >::Elem(), Matrix< T >::ElemNC(), Matrix< T >::Matrix(), Matrix< T >::operator()(), Matrix< T >::operator=(), Matrix< T >::operator[](), Matrix< T >::ReadFromMatrix(), Matrix< T >::Set(), Matrix< T >::Slice(), Matrix< T >::SwitchColumns(), Matrix< T >::SyncData2Columns(), and Matrix< T >::Transpose().

template<class T>
T* Matrix< T >::data [protected]
 

Definition at line 120 of file Matrix.h.

Referenced by Matrix< T >::Add(), Matrix< T >::And(), Array< T >::Array(), Matrix< T >::Clean(), Matrix< T >::Clone(), Matrix< T >::Coor(), Matrix< T >::CoorNC(), Matrix< T >::Divide(), Matrix< T >::Elem(), Matrix< T >::ElemNC(), Matrix< T >::Eq(), Matrix< T >::Ge(), Matrix< T >::Gt(), Matrix< T >::Init(), Matrix< T >::Le(), Matrix< T >::Lt(), Matrix< T >::Matrix(), Matrix< T >::MMultiply(), Matrix< T >::Multiply(), Matrix< T >::Ne(), Matrix< T >::operator!(), Matrix< T >::operator()(), Matrix< T >::operator-(), Array< T >::operator-(), Vector< T >::operator=(), Matrix< T >::operator=(), Array< T >::operator=(), Matrix< T >::Or(), Matrix< T >::Rand(), Matrix< T >::ReadFromMatrix(), Matrix< T >::Set(), Matrix< T >::Slice(), Matrix< T >::Subtract(), Matrix< T >::SwitchColumns(), Matrix< T >::SyncData2Columns(), and Vector< T >::Vector().

template<class T>
int Matrix< T >::length [protected]
 

Definition at line 122 of file Matrix.h.

Referenced by Array< T >::Array(), Matrix< T >::Clone(), Matrix< T >::Matrix(), Vector< T >::operator=(), Matrix< T >::operator=(), Array< T >::operator=(), Matrix< T >::Set(), and Vector< T >::Vector().

template<class T>
int Matrix< T >::ndims [protected]
 

Definition at line 121 of file Matrix.h.

Referenced by Array< T >::Array(), Matrix< T >::Matrix(), Matrix< T >::operator=(), Array< T >::operator=(), and Matrix< T >::Set().

template<class T>
int Matrix< T >::xDim [protected]
 

Definition at line 123 of file Matrix.h.

Referenced by Matrix< T >::Add(), Matrix< T >::And(), Array< T >::Array(), Matrix< T >::Divide(), Matrix< T >::Eq(), Matrix< T >::Ge(), Matrix< T >::Gt(), Matrix< T >::IsCompatible(), Matrix< T >::IsM2MCompatible(), Matrix< T >::IsSquare(), Matrix< T >::Le(), Matrix< T >::Lt(), Matrix< T >::Matrix(), Matrix< T >::MMultiply(), Matrix< T >::Multiply(), Matrix< T >::Ne(), Matrix< T >::operator!(), Matrix< T >::operator()(), Matrix< T >::operator-(), Matrix< T >::operator=(), Array< T >::operator=(), Matrix< T >::Or(), Matrix< T >::ReadFromMatrix(), Matrix< T >::Set(), Matrix< T >::Size(), and Matrix< T >::Subtract().

template<class T>
int Matrix< T >::yDim [protected]
 

Definition at line 124 of file Matrix.h.

Referenced by Matrix< T >::Add(), Matrix< T >::And(), Array< T >::Array(), Matrix< T >::Divide(), Matrix< T >::Eq(), Matrix< T >::Ge(), Matrix< T >::Gt(), Matrix< T >::IsCompatible(), Matrix< T >::IsM2MCompatible(), Matrix< T >::IsSquare(), Matrix< T >::Le(), Matrix< T >::Lt(), Matrix< T >::Matrix(), Matrix< T >::MMultiply(), Matrix< T >::Multiply(), Matrix< T >::Ne(), Matrix< T >::operator!(), Matrix< T >::operator-(), Matrix< T >::operator=(), Array< T >::operator=(), Matrix< T >::Or(), Matrix< T >::ReadFromMatrix(), Matrix< T >::Set(), Matrix< T >::Size(), Matrix< T >::Subtract(), and Matrix< T >::SyncData2Columns().


The documentation for this class was generated from the following files:
CIMPL 0.1 Code Reference. Copyright © 2004, Baris Sumengen. All rights reserved.