00001 #ifndef _SMATRIX_H_
00002 #define _SMATRIX_H_
00003
00004 #include <iostream>
00005 #include "vuSimpleTypes.h"
00006
00007 #include "vuColour.h"
00008 #include "vuMatrix.h"
00009 #include "Coool/DensMatrix.hh"
00010 #include "LinAlg/LinAlg.h"
00011
00012
00013 class SVector;
00014
00029 class SMatrix
00030 {
00031 public:
00033 SMatrix(const dword nrows=1, const dword ncols=1);
00035 SMatrix(const dword nrows, const dword ncols, const double s);
00037 SMatrix(const SMatrix& m);
00039 SMatrix(const vuColourN& col);
00041 SMatrix(const vuMatrix& m);
00043 SMatrix(dword nrows, dword ncols, const double* data);
00045 SMatrix(dword nrows, dword ncols, const float* data);
00047 SMatrix(const linalg::Matrix& m);
00049 SMatrix(const linalg::Vector& m);
00051 SMatrix(const coool::DensMatrix<double>& m);
00053 SMatrix(const coool::Vector<double>& m);
00054
00056 ~SMatrix();
00057
00059 SMatrix& operator=(const SMatrix& m);
00061 SMatrix& operator=(const double s);
00063 SMatrix& operator=(const float* fdata);
00065 SMatrix& operator=(const double* fdata);
00067 SMatrix& operator=(const vuMatrix& m);
00069 SMatrix& operator=(const linalg::Matrix& m);
00071 SMatrix& operator=(const coool::DensMatrix<double>& m);
00072
00074 operator linalg::Matrix() const;
00076 operator coool::DensMatrix<double>() const;
00077
00081 double* operator[](unsigned int index);
00082
00084 const double* operator[](unsigned int index) const;
00085
00087
00089 double* getData(void);
00090 double const * getData(void) const;
00091
00098 void resize(dword nrows, dword ncols);
00099
00101 dword getNCols() const {return m_NCols;};
00103 dword getNRows() const {return m_NRows;};
00104
00106 SMatrix& makeIdentity(void);
00108 SMatrix& makeZero(void);
00110 SMatrix& makeDiag(const SVector& diag);
00112 SMatrix& makeToeplitz(const SVector& v, bool symmetric=false);
00113
00115 SMatrix& insert(const SMatrix& m, dword i=0, dword j=0);
00116
00117
00118
00119
00121 SMatrix horizCat(const SMatrix& m) const;
00123 SMatrix vertCat(const SMatrix& m) const;
00124
00126 double norm() const;
00127
00129 double norm2() const;
00130
00132 SMatrix operator+(const SMatrix& m) const;
00133
00135 SMatrix operator-(const SMatrix& m) const;
00136
00138 friend SMatrix operator*(double s, const SMatrix& m);
00139
00141 SMatrix operator*(const SMatrix& m) const;
00142
00144 SMatrix operator*(double s) const;
00145
00147 SMatrix& operator+=(const SMatrix& m);
00149 SMatrix& operator-=(const SMatrix& m);
00151 SMatrix& operator*=(const SMatrix& m);
00153 SMatrix& operator*=(double s);
00154
00155
00156 friend ostream& operator<< (ostream& os, const SMatrix& A);
00157
00158 friend istream& operator>> (istream& is, SMatrix& A);
00159
00160 private:
00162 void init(dword nrows, dword ncols);
00164 void free();
00165
00166 protected:
00168 dword m_NRows, m_NCols;
00170 double *m_Data;
00171 };
00172
00174 class SVector : public SMatrix
00175 {
00176 public:
00178 SVector(dword N=1) : SMatrix(N,1) {};
00180 SVector(dword N, double s) : SMatrix(N,1,s) {};
00182 SVector(dword N, const double* src) : SMatrix(N,1,src) {};
00184 SVector(dword N, const float* src) : SMatrix(N,1,src) {};
00186 SVector(const vuColourN& col) : SMatrix(col) {};
00188 SVector(const SVector& v) : SMatrix(v) {};
00190 SVector(const SMatrix& m) : SMatrix(m)
00191 { if(m.getNCols() != 1)
00192 throw "SVector: error, can't convert matrix with ncols != 1";
00193 };
00194 SVector(const coool::Vector<double> v) : SMatrix(v) {};
00195
00197 dword getSize() const { return m_NRows;};
00198
00200 double& operator[] (dword index) { return m_Data[index]; };
00202 const double operator[] (dword index) const { return m_Data[index]; };
00203
00205 operator linalg::Vector() const;
00207 operator coool::Vector<double>() const;
00208 };
00209
00210 #endif
00211
00212
00213
00214
00215
00216
00217
00218