00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __MATRIX_H__
00016 #define __MATRIX_H__
00017
00018 #include "magic/mobject.h"
00019 #include "magic/mtable.h"
00020
00023 class Matrix : public PackTable<double> {
00024 public:
00025 Matrix () : PackTable<double> () {;}
00026 Matrix (int rows, int cols) : PackTable<double> (rows, cols) {}
00027 Matrix (const Matrix& o) : PackTable<double> (o) {;}
00028 ~Matrix () {}
00029
00030 void make (int rs, int cs) {
00031 PackTable<double>::make (rs, cs);
00032 operator= (0.0);
00033 }
00034
00038 void load (const String& filename);
00039
00043 void load (FILE* in);
00044
00045 void save (FILE* out) const;
00046
00047 const Matrix& transpose ();
00048 const Matrix& multiplyToSum (double s);
00049 double sum () const;
00050
00051 void splitVertical (Matrix& a, Matrix& b, int column) const;
00052 void splitHorizontal (Matrix& a, Matrix& b, int column) const;
00053
00054 Matrix sub (int row0, int row1, int col0, int col1) const;
00055 void insertColumn (int cols);
00056
00057 enum iters {end=-1};
00058
00059 void joinVertical (const Matrix& a, const Matrix& b);
00060 void joinHorizontal (const Matrix& a, const Matrix& b);
00061
00062 const Matrix& operator= (double x);
00063 const Matrix& operator+= (const Matrix& other);
00064 const Matrix& operator+ (const Matrix& other) const {return Matrix(*this)+=other;}
00065 const Matrix& operator+= (double k);
00066 const Matrix& operator+ (double k) const {return Matrix(*this)+=k;}
00067 const Matrix& operator*= (const Matrix& other);
00068 const Matrix& operator* (const Matrix& other) const {return Matrix(*this)*=other;}
00069 const Matrix& operator*= (double k);
00070 const Matrix& operator* (double k) const {return Matrix(*this)*=k;}
00071 const Matrix& operator/ (double k) const {return Matrix(*this)*=1/k;}
00072 const Matrix& operator/= (double k) {return operator *= (1/k);}
00073
00074 void operator>> (OStream& out) const;
00075 const Matrix& operator= (const Matrix& other);
00076
00077 private:
00078 };
00079
00080 inline Matrix transpose (const Matrix& m) {
00081 Matrix res = m;
00082 res.transpose ();
00083 return res;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 #endif