Bugzilla – Attachment 30 Details for
Bug 99
Expression evaluator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
evaluator proof of concept
evaluator (text/plain), 12.12 KB, created by
Benoit Jacob
on 2010-11-02 16:06:44 UTC
(
hide
)
Description:
evaluator proof of concept
Filename:
MIME Type:
Creator:
Benoit Jacob
Created:
2010-11-02 16:06:44 UTC
Size:
12.12 KB
patch
obsolete
># HG changeset patch ># Parent 8c5eb5b135c542bda13db6d990ea28f8d450179c > >diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h >--- a/Eigen/src/Core/Array.h >+++ b/Eigen/src/Core/Array.h >@@ -41,16 +41,25 @@ > */ > namespace internal { > template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> > struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > > { > typedef ArrayXpr XprKind; > typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase; > }; >+ >+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> >+struct evaluator<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > >+{ >+ typedef Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> xpr_type; >+ typedef xpr_type type; >+ const type& result; >+ evaluator(const xpr_type& xpr) : result(xpr) {} >+}; > } > > template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> > class Array > : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > > { > public: > >diff --git a/Eigen/src/Core/ArrayWrapper.h b/Eigen/src/Core/ArrayWrapper.h >--- a/Eigen/src/Core/ArrayWrapper.h >+++ b/Eigen/src/Core/ArrayWrapper.h >@@ -38,16 +38,25 @@ > > namespace internal { > template<typename ExpressionType> > struct traits<ArrayWrapper<ExpressionType> > > : public traits<typename remove_all<typename ExpressionType::Nested>::type > > { > typedef ArrayXpr XprKind; > }; >+ >+template<typename ExpressionType> >+struct evaluator<ArrayWrapper<ExpressionType> > >+{ >+ typedef ArrayWrapper<ExpressionType> xpr_type; >+ typedef ArrayWrapper<typename evaluator<ExpressionType>::type> type; >+ type result; >+ evaluator(const xpr_type& xpr) : result(xpr.nestedXpr()) {} >+}; > } > > template<typename ExpressionType> > class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > > { > public: > typedef ArrayBase<ArrayWrapper> Base; > EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper) >@@ -104,16 +113,18 @@ class ArrayWrapper : public ArrayBase<Ar > inline void writePacket(Index index, const PacketScalar& x) > { > m_expression.const_cast_derived().template writePacket<LoadMode>(index, x); > } > > template<typename Dest> > inline void evalTo(Dest& dst) const { dst = m_expression; } > >+ const NestedExpressionType nestedXpr() const { return m_expression; } >+ > protected: > const NestedExpressionType m_expression; > }; > > /** \class MatrixWrapper > * \ingroup Core_Module > * > * \brief Expression of an array as a mathematical vector or matrix >@@ -126,16 +137,25 @@ class ArrayWrapper : public ArrayBase<Ar > > namespace internal { > template<typename ExpressionType> > struct traits<MatrixWrapper<ExpressionType> > > : public traits<typename remove_all<typename ExpressionType::Nested>::type > > { > typedef MatrixXpr XprKind; > }; >+ >+template<typename ExpressionType> >+struct evaluator<MatrixWrapper<ExpressionType> > >+{ >+ typedef MatrixWrapper<ExpressionType> xpr_type; >+ typedef MatrixWrapper<typename evaluator<ExpressionType>::type> type; >+ type result; >+ evaluator(const xpr_type& xpr) : result(xpr.nestedXpr()) {} >+}; > } > > template<typename ExpressionType> > class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > > { > public: > typedef MatrixBase<MatrixWrapper<ExpressionType> > Base; > EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper) >@@ -189,13 +209,15 @@ class MatrixWrapper : public MatrixBase< > } > > template<int LoadMode> > inline void writePacket(Index index, const PacketScalar& x) > { > m_expression.const_cast_derived().template writePacket<LoadMode>(index, x); > } > >+ const NestedExpressionType nestedXpr() const { return m_expression; } >+ > protected: > const NestedExpressionType m_expression; > }; > > #endif // EIGEN_ARRAYWRAPPER_H >diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h >--- a/Eigen/src/Core/Assign.h >+++ b/Eigen/src/Core/Assign.h >@@ -513,42 +513,59 @@ EIGEN_STRONG_INLINE Derived& DenseBase<D > checkTransposeAliasing(other.derived()); > #endif > return derived(); > } > > namespace internal { > > template<typename Derived, typename OtherDerived, >+ bool NeedEvaluator = !is_same<OtherDerived, typename evaluator<OtherDerived>::type >::value, > bool EvalBeforeAssigning = (int(OtherDerived::Flags) & EvalBeforeAssigningBit) != 0, > bool NeedToTranspose = Derived::IsVectorAtCompileTime > && OtherDerived::IsVectorAtCompileTime > && ((int(Derived::RowsAtCompileTime) == 1 && int(OtherDerived::ColsAtCompileTime) == 1) > | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&". > // revert to || as soon as not needed anymore. > (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1)) > && int(Derived::SizeAtCompileTime) != 1> > struct assign_selector; > > template<typename Derived, typename OtherDerived> >-struct assign_selector<Derived,OtherDerived,false,false> { >+struct assign_selector<Derived,OtherDerived,false,false,false> { > EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.derived()); } > }; > template<typename Derived, typename OtherDerived> >-struct assign_selector<Derived,OtherDerived,true,false> { >+struct assign_selector<Derived,OtherDerived,false,true,false> { > EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.eval()); } > }; > template<typename Derived, typename OtherDerived> >-struct assign_selector<Derived,OtherDerived,false,true> { >+struct assign_selector<Derived,OtherDerived,false,false,true> { > EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose()); } > }; > template<typename Derived, typename OtherDerived> >-struct assign_selector<Derived,OtherDerived,true,true> { >+struct assign_selector<Derived,OtherDerived,false,true,true> { > EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose().eval()); } > }; >+template<typename Derived, typename OtherDerived> >+struct assign_selector<Derived,OtherDerived,true,false,false> { >+ EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(evaluator<OtherDerived>(other).result); } >+}; >+template<typename Derived, typename OtherDerived> >+struct assign_selector<Derived,OtherDerived,true,true,false> { >+ EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(evaluator<OtherDerived>(other).result.eval()); } >+}; >+template<typename Derived, typename OtherDerived> >+struct assign_selector<Derived,OtherDerived,true,false,true> { >+ EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(evaluator<OtherDerived>(other.transpose()).result); } >+}; >+template<typename Derived, typename OtherDerived> >+struct assign_selector<Derived,OtherDerived,true,true,true> { >+ EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(evaluator<OtherDerived>(other.transpose()).result.eval()); } >+}; > > } // end namespace internal > > template<typename Derived> > template<typename OtherDerived> > EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other) > { > return internal::assign_selector<Derived,OtherDerived>::run(derived(), other.derived()); >diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h >--- a/Eigen/src/Core/Matrix.h >+++ b/Eigen/src/Core/Matrix.h >@@ -125,16 +125,26 @@ struct traits<Matrix<_Scalar, _Rows, _Co > MaxColsAtCompileTime = _MaxCols, > Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret, > CoeffReadCost = NumTraits<Scalar>::ReadCost, > Options = _Options, > InnerStrideAtCompileTime = 1, > OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime > }; > }; >+ >+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> >+struct evaluator<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > >+{ >+ typedef Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> xpr_type; >+ typedef xpr_type type; >+ const type& result; >+ evaluator(const xpr_type& xpr) : result(xpr) {} >+}; >+ > } > > template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> > class Matrix > : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > > { > public: > >diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h >--- a/Eigen/src/Core/PlainObjectBase.h >+++ b/Eigen/src/Core/PlainObjectBase.h >@@ -478,17 +478,17 @@ class PlainObjectBase : public internal: > template<typename OtherDerived> > EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other) > { > // I don't think we need this resize call since the lazyAssign will anyways resize > // and lazyAssign will be called by the assign selector. > //_resize_to_match(other); > // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because > // it wouldn't allow to copy a row-vector into a column-vector. >- return internal::assign_selector<Derived,OtherDerived,false>::run(this->derived(), other.derived()); >+ return internal::assign_selector<Derived,OtherDerived,!internal::is_same<OtherDerived, typename internal::evaluator<OtherDerived>::type>::value,false>::run(this->derived(), other.derived()); > } > > template<typename T0, typename T1> > EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0) > { > eigen_assert(rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) > && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); > m_storage.resize(rows*cols,rows,cols); >diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h >--- a/Eigen/src/Core/Transpose.h >+++ b/Eigen/src/Core/Transpose.h >@@ -55,16 +55,25 @@ struct traits<Transpose<MatrixType> > : > MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, > MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, > Flags = int(_MatrixTypeNested::Flags & ~NestByRefBit) ^ RowMajorBit, > CoeffReadCost = _MatrixTypeNested::CoeffReadCost, > InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret, > OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret > }; > }; >+ >+template<typename ExpressionType> >+struct evaluator<Transpose<ExpressionType> > >+{ >+ typedef Transpose<ExpressionType> xpr_type; >+ typedef Transpose<typename evaluator<ExpressionType>::type> type; >+ type result; >+ evaluator(const xpr_type& xpr) : result(xpr.nestedExpression()) {} >+}; > } > > template<typename MatrixType, typename StorageKind> class TransposeImpl; > > template<typename MatrixType> class Transpose > : public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind> > { > public: >diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h >--- a/Eigen/src/Core/util/ForwardDeclarations.h >+++ b/Eigen/src/Core/util/ForwardDeclarations.h >@@ -22,22 +22,26 @@ > // You should have received a copy of the GNU Lesser General Public > // License and a copy of the GNU General Public License along with > // Eigen. If not, see <http://www.gnu.org/licenses/>. > > #ifndef EIGEN_FORWARDDECLARATIONS_H > #define EIGEN_FORWARDDECLARATIONS_H > > namespace internal { >+ > template<typename T> struct traits; > > template<typename Derived> struct has_direct_access > { > enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 }; > }; >+ >+template<typename T> struct evaluator {}; >+ > } // end namespace internal > > template<typename T> struct NumTraits; > > template<typename Derived> struct EigenBase; > template<typename Derived> class DenseBase; > template<typename Derived, > AccessorLevels Level = (internal::traits<Derived>::Flags & DirectAccessBit) ? DirectAccessors
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 99
:
28
| 30 |
143
|
156
|
165
|
295
|
400