diff options
Diffstat (limited to 'src/internal')
-rw-r--r-- | src/internal/Eval.h | 52 | ||||
-rw-r--r-- | src/internal/Matrix.h | 8 | ||||
-rw-r--r-- | src/internal/Object.h | 11 | ||||
-rw-r--r-- | src/internal/Util.h | 1 |
4 files changed, 61 insertions, 11 deletions
diff --git a/src/internal/Eval.h b/src/internal/Eval.h new file mode 100644 index 000000000..2b79866ed --- /dev/null +++ b/src/internal/Eval.h @@ -0,0 +1,52 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr> +// +// Eigen is free software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along +// with Eigen; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. This exception does not invalidate any other reasons why a work +// based on this file might be covered by the GNU General Public License. + +#ifndef EI_EVAL_H +#define EI_EVAL_H + +template<typename Expression> class EiEval + : public EiMatrix< typename Expression::Scalar, + Expression::Derived::RowsAtCompileTime, + Expression::Derived::ColsAtCompileTime > +{ + public: + typedef typename Expression::Scalar Scalar; + typedef typename Expression::Derived Derived; + typedef EiMatrix< Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> MatrixType; + typedef Expression Base; + friend class EiObject<Scalar, Derived>; + + EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval) + + EiEval(const Expression& expression) : MatrixType(expression) {} +}; + +template<typename Scalar, typename Derived> +EiEval<EiObject<Scalar, Derived> > EiObject<Scalar, Derived>::eval() const +{ + return EiEval<EiObject<Scalar, Derived> >(*this); +} + +#endif // EI_EVAL_H diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h index d56ac455a..738cc9f6b 100644 --- a/src/internal/Matrix.h +++ b/src/internal/Matrix.h @@ -97,13 +97,6 @@ class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >, ~EiMatrix() {} }; -template<typename Scalar, typename Derived> -EiMatrix<Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> -eval(const EiObject<Scalar, Derived>& expression) -{ - return EiMatrix<Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime>(expression); -} - #define EI_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ typedef EiMatrix<Type, Size, Size> EiMatrix##SizeSuffix##TypeSuffix; \ typedef EiMatrix<Type, Size, 1> EiVector##SizeSuffix##TypeSuffix; @@ -124,6 +117,7 @@ EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd) #undef EI_MAKE_TYPEDEFS_ALL_SIZES #undef EI_MAKE_TYPEDEFS +#include "Eval.h" #include "MatrixOps.h" #include "ScalarOps.h" #include "RowAndCol.h" diff --git a/src/internal/Object.h b/src/internal/Object.h index 6bf86f87a..fde835001 100644 --- a/src/internal/Object.h +++ b/src/internal/Object.h @@ -28,13 +28,14 @@ #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; public: - typedef typename EiForwardDecl<Derived>::Ref Ref; + typedef typename EiForwardDecl<_Derived>::Ref Ref; typedef _Scalar Scalar; + typedef _Derived Derived; int rows() const { return static_cast<const Derived *>(this)->_rows(); } int cols() const { return static_cast<const Derived *>(this)->_cols(); } @@ -109,6 +110,8 @@ template<typename _Scalar, typename Derived> class EiObject Scalar& operator()(int row, int col = 0) { return write(row, col); } + + EiEval<EiObject> eval() const; }; template<typename Scalar, typename Derived> diff --git a/src/internal/Util.h b/src/internal/Util.h index 05ebbe163..c7730d6fb 100644 --- a/src/internal/Util.h +++ b/src/internal/Util.h @@ -51,6 +51,7 @@ template<typename Lhs, typename Rhs> class EiSum; template<typename Lhs, typename Rhs> class EiDifference; template<typename Lhs, typename Rhs> class EiMatrixProduct; template<typename MatrixType> class EiScalarProduct; +template<typename ExpressionType> class EiEval; template<typename T> struct EiForwardDecl { |