00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 struct RowReMapTag : public UnaExpTag, public ViewTag {
00025 EXMAT_INLINE2 RowReMapTag() {}
00026 static char* name()
00027 { return "Row remapped"; }
00028 };
00029
00031 template<class Rep>
00032 class RowReMapView : public RowReMapTag
00033 {
00034 public:
00035 typedef RowReMapView<Rep> self_type;
00036 typedef RowReMapTag exp_tag;
00037 typedef NullTag extra_param_type;
00038 COMMON_VIEW_TYPEDEFS();
00039
00040 enum {
00041 ROWS = super_type::COLS,
00042 COLS = super_type::ROWS,
00043 IsLinear = false,
00044 IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00045 TNOP = 0,
00046 ENOP = 0,
00047 EXPLevel = Rep::EXPLevel + 1
00048 };
00049
00051 typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00052
00053
00054
00055 EXMAT_INLINE2 RowReMapView(super_type& mat)
00056 : rep(mat)
00057 {
00058 InitTable();
00059 }
00061 template<class Rep2> EXMAT_INLINE2
00062 RowReMapView(const Rep2& self, super_type& mat)
00063 : rep(mat)
00064 {
00065 memcpy(rowMap, self.rowMap, sizeof(rowMap));
00066 }
00067
00069 EXMAT_INLINE2 self_type operator=(const_param_type s) {
00070 rep = s;
00071 return *this;
00072 }
00073
00074
00075 EXMAT_INLINE2 size_t size() const { return rep.size(); }
00076 EXMAT_INLINE2 size_t rows() const { return rep.cols(); }
00077 EXMAT_INLINE2 size_t cols() const { return rep.rows(); }
00078
00079
00080 EXMAT_INLINE2 reference setAt(index_type i) {
00081 if(ROWS == 1)
00082 return rep.setAt(i);
00083 else
00084 return rep.setAt(rowMap[i/rep.cols()], i%rep.cols());
00085 }
00086 EXMAT_INLINE2 const_reference getAt(index_type i) const {
00087 if(ROWS == 1)
00088 return rep.getAt(i);
00089 else
00090 return rep.getAt(rowMap[i/rep.cols()], i%rep.cols());
00091 }
00092 EXMAT_INLINE2 reference setAt(index_type i, index_type j) {
00093 return rep.setAt(rowMap[i], j);
00094 }
00095 EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00096 { return rep.getAt(rowMap[i], j); }
00097
00098
00099
00100 EXMAT_INLINE2 void exchange(index_type r1, index_type r2) {
00101
00102 index_type tmp = rowMap[r2];
00103 rowMap[r2] = rowMap[r1];
00104 rowMap[r1] = tmp;
00105 }
00106
00107 private:
00108 EXMAT_INLINE2 void InitTable() {
00109 for(index_type i=0; i<ROWS; ++i)
00110 rowMap[i] = i;
00111 }
00112 private:
00113 index_type rowMap[ROWS];
00114 };
00115
00116 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00117 Mat<ExpMat<RowReMapView<typename Rep::rep_type> >, ErrChk>
00118 rowremap(Mat<Rep, ErrChk>& mat) {
00119 return ExpMat<RowReMapView<TTYPENAME Rep::rep_type> >(mat);
00120 }