00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __MCLASSES_HH
00021 #define __MCLASSES_HH
00022
00023
00024
00025 template <int Rows, int Cols, class Layout>
00026 class Matrix : public FixedMatrix<Rows, Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> > {
00027 public:
00028 inline Matrix(){}
00029
00030
00031 inline Matrix(const double d[Rows*Cols]){*this = (reinterpret_cast<const FixedMatrix<Rows,Cols,FixedMAccessor<Rows,Cols,RowMajor,Stack<Rows*Cols> > >&>(*d));}
00032 inline Matrix(const double d[Rows][Cols]){*this = (reinterpret_cast<const FixedMatrix<Rows,Cols,FixedMAccessor<Rows,Cols,RowMajor,Stack<Rows*Cols> > >&>(*d));}
00033
00034
00035 template <class Accessor>
00036 inline Matrix(const FixedMatrix<Rows,Cols,Accessor>& m){
00037 FixedMatrix<Rows,Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> >::operator=(m);
00038 }
00039
00040
00041 template <class Accessor>
00042 inline Matrix(const DynamicMatrix<Accessor>& m){
00043 assert(m.num_rows()==Rows && m.num_cols() == Cols);
00044 FixedMatrix<Rows,Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> >::operator=(m);
00045 }
00046
00047
00048 template <class Arg, class Op>
00049 Matrix(const Arg& arg, const Operator<Op>&){Op::eval(*this,arg);}
00050
00051
00052 template <class LHS, class RHS, class Op>
00053 Matrix(const LHS& lhs, const RHS& rhs, const Operator<Op>&){Op::eval(*this,lhs,rhs);}
00054
00055
00056
00057 };
00058
00059 template <class Layout>
00060 class Matrix<General, General, Layout> : public DynamicMatrix<DynamicMAccessor<Layout> > {
00061 friend class MSizer;
00062 public:
00063 inline Matrix(){
00064 this->my_num_rows = 0;
00065 this->my_num_cols = 0;
00066 this->my_values = NULL;
00067 }
00068
00069 inline Matrix(int num_rows, int num_cols){
00070 this->my_num_rows = num_rows;
00071 this->my_num_cols = num_cols;
00072 this->my_values = new double[num_rows*num_cols];
00073 }
00074
00075 inline ~Matrix(){
00076 delete[] this->my_values;}
00077
00078
00079 inline Matrix(int num_rows, int num_cols, const double* data){
00080 this->my_num_rows=num_rows;
00081 this->my_num_cols = num_cols;
00082 this->my_values = new double[num_rows*num_cols];
00083 RefMatrix<RowMajor> temp (num_rows,num_cols,data);
00084 DynamicMatrix<DynamicMAccessor<Layout> >::operator=(temp);
00085 }
00086
00087
00088 template <class Accessor>
00089 inline Matrix(const MatrixBase<Accessor>& from){
00090 this->my_num_rows = from.num_rows();
00091 this->my_num_cols = from.num_cols();
00092 this->my_values = new double [this->my_num_rows*this->my_num_cols];
00093 DynamicMatrix<DynamicMAccessor<Layout> >::operator=(from);
00094 }
00095
00096 inline void resize(int rows, int cols)
00097 {
00098 if(rows != this->my_num_rows || cols != this->my_num_cols)
00099 {
00100 delete[] this->my_values;
00101 this->my_num_rows = rows;
00102 this->my_num_cols = cols;
00103 this->my_values = new double[this->my_num_rows*this->my_num_cols];
00104 }
00105 }
00106
00107 template <class Accessor> inline void assign(const MatrixBase<Accessor>& m) {
00108 resize(m.num_rows(),m.num_cols());
00109 DynamicMatrix<DynamicMAccessor<Layout> >::operator=(m);
00110 }
00111
00112
00113 inline Matrix(const Matrix<General,General,Layout>& from){
00114 this->my_num_rows = from.my_num_rows;
00115 this->my_num_cols = from.my_num_cols;
00116 this->my_values = new double[this->my_num_rows*this->my_num_cols];
00117 DynamicMatrix<DynamicMAccessor<Layout> >::operator=(from);
00118 }
00119
00120
00121 template <class Arg, class Op>
00122 Matrix(const Arg& arg, const Operator<Op>&){
00123 Op::eval(*this,arg);
00124 }
00125
00126
00127 template <class LHS, class RHS, class Op>
00128 Matrix(const LHS& lhs, const RHS& rhs, const Operator<Op>&){
00129 Op::eval(*this,lhs,rhs);
00130 }
00131 };
00132
00133
00134
00135 struct MSizer {
00136 template<class Layout>
00137 static inline void set_size(Matrix<General,General,Layout>& ret, int rows, int cols){
00138 ret.my_num_rows=rows;
00139 ret.my_num_cols=cols;
00140 ret.my_values = new double[rows*cols];
00141 }
00142 };
00143
00144
00145 #endif