Transpose.h

00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 // Forward declaration
00024 template<class Rep> class ConstTransView;
00025 
00027 template<class Rep>
00028 class TransView : public TransposeViewTag
00029 {
00030 public:
00031     typedef TransView<Rep>      self_type;
00032     typedef TransposeViewTag    exp_tag;
00033     typedef NullTag             extra_param_type;
00034     typedef ConstTransView<Rep> const_view_type;
00035     COMMON_VIEW_TYPEDEFS();
00036 
00037     enum {
00038         ROWS = super_type::COLS,
00039         COLS = super_type::ROWS,
00040         IsLinear = false,
00041         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00042         TNOP = Rep::TNOP,
00043         ENOP = Rep::ENOP,
00044         EXPLevel = Rep::EXPLevel + 1
00045     };
00046 
00048     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00049 
00050     /************************************************/
00051     // Constructors
00052     EXMAT_INLINE2 TransView(const self_type& self)
00053         : rep(self.rep) {}
00054     EXMAT_INLINE2 TransView(super_type& mat)
00055         : rep(mat) {}
00057     template<class Rep2> EXMAT_INLINE2
00058     TransView(const Rep2& self, super_type& mat)
00059         : rep(mat) {}
00060 
00062     EXMAT_INLINE2 self_type operator=(const_param_type s) {
00063         rep = s;
00064         return *this;
00065     }
00066     /************************************************/
00067     // Dimension information
00068     EXMAT_INLINE2 size_t size() const { return rep.size(); }
00069     EXMAT_INLINE2 size_t rows() const { return rep.cols(); }
00070     EXMAT_INLINE2 size_t cols() const { return rep.rows(); }
00071     /************************************************/
00072     // Index function (for internal use, no error checking applied)
00073     EXMAT_INLINE2 reference setAt(index_type i) {
00074         if(ROWS == 1 || COLS == 1)
00075             return rep.setAt(i);
00076         else
00077             return rep.setAt(i%rep.cols(), i/rep.cols());
00078     }
00079     EXMAT_INLINE2 const_reference getAt(index_type i) const {
00080         if(ROWS == 1 || COLS == 1)
00081             return rep.getAt(i);
00082         else
00083             return rep.getAt(i%rep.cols(), i/rep.cols());
00084     }
00085     EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00086     {   return rep.setAt(j, i); }
00087     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00088     {   return rep.getAt(j, i); }
00089 };
00093 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00094 Mat<ExpMat<TransView<typename Rep::rep_type> >, ErrChk>
00095 trans(Mat<Rep, ErrChk>& mat) {
00096     return ExpMat<TransView<TTYPENAME Rep::rep_type> >(mat);
00097 }
00102 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00103 Vec<ExpMat<TransView<typename Rep::rep_type> >, ErrChk>
00104 trans(Vec<Rep, ErrChk>& vec) {
00105     return ExpMat<TransView<TTYPENAME Rep::rep_type> >(vec);
00106 }
00107 #if HAVE_TT_PARAMETER
00108 
00112 template<class Rep, class ErrChk, template<class Rep, class ErrChk> class RepT, template<class RepT> class MathClass > EXMAT_INLINE2
00113 static MathClass<RepT<ExpMat<ConstTransView<Rep> >, ErrChk> >
00114 trans(MathClass<RepT<Rep, ErrChk> >& vec) {
00115     return MathClass<RepT<ExpMat<ConstTransView<Rep> >, ErrChk> >(ExpMat<ConstTransView<Rep> >(vec));
00116 }
00117 #endif  // HAVE_TT_PARAMETER
00118 
00119 
00121 template<class Rep>
00122 class ConstTransView : public TransposeViewTag
00123 {
00124 public:
00125     typedef ConstTransView<Rep> self_type;
00126     typedef TransposeViewTag        exp_tag;
00127     typedef NullTag             extra_param_type;
00128     COMMON_CONST_VIEW_TYPEDEFS();
00129 
00130     enum {
00131         ROWS = super_type::COLS,
00132         COLS = super_type::ROWS,
00133         IsLinear = false,
00134         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00135         TNOP = Rep::TNOP,
00136         ENOP = Rep::ENOP,
00137         EXPLevel = Rep::EXPLevel +1
00138     };
00139 
00141     typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00142 
00143     /************************************************/
00144     // Constructors
00145     EXMAT_INLINE2 ConstTransView(const self_type& self)
00146         : rep(self.rep) {}
00147     EXMAT_INLINE2 ConstTransView(const super_type& mat)
00148         : rep(mat) {}
00150     template<class Rep2> EXMAT_INLINE2
00151     ConstTransView(const Rep2& self, const super_type& mat)
00152         : rep(mat) {}
00153 
00154     /************************************************/
00155     // Dimension information
00156     EXMAT_INLINE2 size_t size() const { return rep.size(); }
00157     EXMAT_INLINE2 size_t rows() const { return rep.cols(); }
00158     EXMAT_INLINE2 size_t cols() const { return rep.rows(); }
00159     /************************************************/
00160     // Index function (for internal use, no error checking applied)
00161     EXMAT_INLINE2 const_reference getAt(index_type i) const {
00162         if(ROWS == 1 || COLS == 1)
00163             return rep.getAt(i);
00164         else
00165             return rep.getAt(i%rep.cols(), i/rep.cols());
00166     }
00167     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00168     {   return rep.getAt(j, i); }
00169 };
00173 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00174 const Mat<ExpMat<ConstTransView<typename Rep::rep_type> >, ErrChk>
00175 trans(const Mat<Rep, ErrChk>& mat) {
00176     return ExpMat<ConstTransView<TTYPENAME Rep::rep_type> >(mat);
00177 }
00182 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00183 const Vec<ExpMat<ConstTransView<typename Rep::rep_type> >, ErrChk>
00184 trans(const Vec<Rep, ErrChk>& vec) {
00185     return ExpMat<ConstTransView<TTYPENAME Rep::rep_type> >(vec);
00186 }
00187 #if HAVE_TT_PARAMETER
00188 
00192 template<class Rep, class ErrChk, template<class Rep, class ErrChk> class RepT, template<class RepT> class MathClass > EXMAT_INLINE2
00193 static const MathClass<RepT<ExpMat<ConstTransView<Rep> >, ErrChk> >
00194 trans(const MathClass<RepT<Rep, ErrChk> >& vec) {
00195     return ExpMat<ConstTransView<Rep> >(vec);
00196 }
00197 #endif  // HAVE_TT_PARAMETER

Generated on Sat May 6 23:12:03 2006 for Exmat by  doxygen 1.4.6-NO