Implement evaluators for sparse coeff-wise views

This commit is contained in:
Gael Guennebaud 2014-06-25 17:21:04 +02:00
parent e3ba5329ff
commit 199ac3f2e7
2 changed files with 83 additions and 61 deletions

View File

@ -93,6 +93,17 @@ class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename in
ViewOp m_functor; ViewOp m_functor;
}; };
#ifdef EIGEN_TEST_EVALUATORS
// Generic API dispatcher
template<typename ViewOp, typename XprType, typename StorageKind>
class CwiseUnaryViewImpl
: public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
{
public:
typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
};
#endif
template<typename ViewOp, typename MatrixType> template<typename ViewOp, typename MatrixType>
class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
: public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type

View File

@ -216,67 +216,78 @@ class unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::ReverseInne
}; };
// template<typename ViewOp, typename MatrixType>
// class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
// : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
// { template<typename ViewOp, typename ArgType>
// public: struct unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>
// : public evaluator_base<CwiseUnaryView<ViewOp,ArgType> >
// class InnerIterator; {
// class ReverseInnerIterator; public:
// typedef CwiseUnaryView<ViewOp, ArgType> XprType;
// typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
// EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) class InnerIterator;
// class ReverseInnerIterator;
// protected:
// typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested; enum {
// typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<ViewOp>::Cost,
// typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator; Flags = XprType::Flags
// }; };
//
// template<typename ViewOp, typename MatrixType> unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) {}
// class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
// : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator protected:
// { typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
// typedef typename CwiseUnaryViewImpl::Scalar Scalar; typedef typename evaluator<ArgType>::ReverseInnerIterator EvalReverseIterator;
// typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator Base;
// public: const ViewOp m_functor;
// typename evaluator<ArgType>::nestedType m_argImpl;
// EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer) };
// : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
// {} template<typename ViewOp, typename ArgType>
// class unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::InnerIterator
// EIGEN_STRONG_INLINE InnerIterator& operator++() : public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator
// { Base::operator++(); return *this; } {
// typedef typename XprType::Scalar Scalar;
// EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); } typedef typename unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator Base;
// EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); } public:
//
// protected: EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, typename XprType::Index outer)
// const ViewOp m_functor; : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
// }; {}
//
// template<typename ViewOp, typename MatrixType> EIGEN_STRONG_INLINE InnerIterator& operator++()
// class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::ReverseInnerIterator { Base::operator++(); return *this; }
// : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator
// { EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
// typedef typename CwiseUnaryViewImpl::Scalar Scalar; EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(Base::valueRef()); }
// typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
// public: protected:
// const ViewOp m_functor;
// EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer) };
// : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
// {} template<typename ViewOp, typename ArgType>
// class unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::ReverseInnerIterator
// EIGEN_STRONG_INLINE ReverseInnerIterator& operator--() : public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalReverseIterator
// { Base::operator--(); return *this; } {
// typedef typename XprType::Scalar Scalar;
// EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); } typedef typename unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalReverseIterator Base;
// EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); } public:
//
// protected: EIGEN_STRONG_INLINE ReverseInnerIterator(const XprType& unaryOp, typename XprType::Index outer)
// const ViewOp m_functor; : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
// }; {}
EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
{ Base::operator--(); return *this; }
EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(Base::valueRef()); }
protected:
const ViewOp m_functor;
};
} // end namespace internal } // end namespace internal