diff options
author | 2007-09-28 11:20:29 +0000 | |
---|---|---|
committer | 2007-09-28 11:20:29 +0000 | |
commit | 51e29ae4bd9d725c3a68fe94766c73ba8c717688 (patch) | |
tree | 65bd0d0e0e6fc6e9f6f668ff14652a34ae4a1eb0 | |
parent | aa3294f14e33ae5078fcdbedc9df241a674a9f2e (diff) |
some reorganization leading to simpler expression trees
-rw-r--r-- | src/internal/Block.h | 4 | ||||
-rw-r--r-- | src/internal/Eval.h | 13 | ||||
-rw-r--r-- | src/internal/Minor.h | 4 | ||||
-rw-r--r-- | src/internal/Object.h | 38 | ||||
-rw-r--r-- | src/internal/RowAndCol.h | 8 |
5 files changed, 34 insertions, 33 deletions
diff --git a/src/internal/Block.h b/src/internal/Block.h index ca2c67465..0664abb58 100644 --- a/src/internal/Block.h +++ b/src/internal/Block.h @@ -75,10 +75,10 @@ template<typename MatrixType> class EiBlock }; template<typename Scalar, typename Derived> -EiBlock<EiObject<Scalar, Derived> > +EiBlock<Derived> EiObject<Scalar, Derived>::block(int startRow, int endRow, int startCol, int endCol) { - return EiBlock<EiObject>(ref(), startRow, endRow, startCol, endCol); + return EiBlock<Derived>(static_cast<Derived*>(this)->ref(), startRow, endRow, startCol, endCol); } #endif // EI_BLOCK_H diff --git a/src/internal/Eval.h b/src/internal/Eval.h index 2b79866ed..2d792d822 100644 --- a/src/internal/Eval.h +++ b/src/internal/Eval.h @@ -28,15 +28,14 @@ template<typename Expression> class EiEval : public EiMatrix< typename Expression::Scalar, - Expression::Derived::RowsAtCompileTime, - Expression::Derived::ColsAtCompileTime > + Expression::RowsAtCompileTime, + Expression::ColsAtCompileTime > { public: typedef typename Expression::Scalar Scalar; - typedef typename Expression::Derived Derived; - typedef EiMatrix< Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> MatrixType; + typedef EiMatrix< Scalar, Expression::RowsAtCompileTime, Expression::ColsAtCompileTime> MatrixType; typedef Expression Base; - friend class EiObject<Scalar, Derived>; + friend class EiObject<Scalar, Expression>; EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval) @@ -44,9 +43,9 @@ template<typename Expression> class EiEval }; template<typename Scalar, typename Derived> -EiEval<EiObject<Scalar, Derived> > EiObject<Scalar, Derived>::eval() const +EiEval<Derived> EiObject<Scalar, Derived>::eval() const { - return EiEval<EiObject<Scalar, Derived> >(*this); + return EiEval<Derived>(*static_cast<const Derived*>(this)); } #endif // EI_EVAL_H diff --git a/src/internal/Minor.h b/src/internal/Minor.h index 77fa4b9c8..abd8fe03c 100644 --- a/src/internal/Minor.h +++ b/src/internal/Minor.h @@ -71,10 +71,10 @@ template<typename MatrixType> class EiMinor }; template<typename Scalar, typename Derived> -EiMinor<EiObject<Scalar, Derived> > +EiMinor<Derived> EiObject<Scalar, Derived>::minor(int row, int col) { - return EiMinor<EiObject>(ref(), row, col); + return EiMinor<Derived>(static_cast<Derived*>(this)->ref(), row, col); } #endif // EI_MINOR_H diff --git a/src/internal/Object.h b/src/internal/Object.h index fde835001..fefa15897 100644 --- a/src/internal/Object.h +++ b/src/internal/Object.h @@ -28,14 +28,21 @@ #include "Util.h" -template<typename _Scalar, typename _Derived> class EiObject +template<typename Scalar, typename Derived> class EiObject { - static const int RowsAtCompileTime = _Derived::RowsAtCompileTime, - ColsAtCompileTime = _Derived::ColsAtCompileTime; + static const int RowsAtCompileTime = Derived::RowsAtCompileTime, + ColsAtCompileTime = Derived::ColsAtCompileTime; + + template<typename OtherDerived> + void _copy_helper(const EiObject<Scalar, OtherDerived>& other) + { + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + write(i, j) = other.read(i, j); + } + public: - typedef typename EiForwardDecl<_Derived>::Ref Ref; - typedef _Scalar Scalar; - typedef _Derived Derived; + typedef typename EiForwardDecl<Derived>::Ref Ref; int rows() const { return static_cast<const Derived *>(this)->_rows(); } int cols() const { return static_cast<const Derived *>(this)->_cols(); } @@ -61,9 +68,7 @@ template<typename _Scalar, typename _Derived> class EiObject Derived& operator=(const EiObject<Scalar, OtherDerived>& other) { assert(rows() == other.rows() && cols() == other.cols()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); + _copy_helper(other); return *static_cast<Derived*>(this); } @@ -72,17 +77,14 @@ template<typename _Scalar, typename _Derived> class EiObject Derived& operator=(const EiObject& other) { assert(rows() == other.rows() && cols() == other.cols()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); + _copy_helper(other); return *static_cast<Derived*>(this); } - EiRow<EiObject> row(int i); - EiColumn<EiObject> col(int i); - EiMinor<EiObject> minor(int row, int col); - EiBlock<EiObject> - block(int startRow, int endRow, int startCol= 0, int endCol = 0); + EiRow<Derived> row(int i); + EiColumn<Derived> col(int i); + EiMinor<Derived> minor(int row, int col); + EiBlock<Derived> block(int startRow, int endRow, int startCol= 0, int endCol = 0); template<typename OtherDerived> Derived& operator+=(const EiObject<Scalar, OtherDerived>& other); @@ -111,7 +113,7 @@ template<typename _Scalar, typename _Derived> class EiObject Scalar& operator()(int row, int col = 0) { return write(row, col); } - EiEval<EiObject> eval() const; + EiEval<Derived> eval() const; }; template<typename Scalar, typename Derived> diff --git a/src/internal/RowAndCol.h b/src/internal/RowAndCol.h index 0bfc361b0..00079c81f 100644 --- a/src/internal/RowAndCol.h +++ b/src/internal/RowAndCol.h @@ -128,17 +128,17 @@ template<typename MatrixType> class EiColumn }; template<typename Scalar, typename Derived> -EiRow<EiObject<Scalar, Derived> > +EiRow<Derived> EiObject<Scalar, Derived>::row(int i) { - return EiRow<EiObject>(ref(), i); + return EiRow<Derived>(static_cast<Derived*>(this)->ref(), i); } template<typename Scalar, typename Derived> -EiColumn<EiObject<Scalar, Derived> > +EiColumn<Derived> EiObject<Scalar, Derived>::col(int i) { - return EiColumn<EiObject>(ref(), i); + return EiColumn<Derived>(static_cast<Derived*>(this)->ref(), i); } #endif // EI_ROWANDCOL_H |