diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index aa3297354..9ddbfe286 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -84,6 +84,7 @@ class CwiseBinaryOp : { public: + typedef typename internal::remove_all::type Functor; typedef typename internal::remove_all::type Lhs; typedef typename internal::remove_all::type Rhs; diff --git a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h index aad7b7d79..04cef66fc 100644 --- a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +++ b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h @@ -325,16 +325,79 @@ protected: const XprType &m_expr; }; +template::Kind, + typename RhsKind = typename evaluator_traits::Kind, + typename LhsScalar = typename traits::Scalar, + typename RhsScalar = typename traits::Scalar> struct sparse_conjunction_evaluator; + // "sparse .* sparse" template struct binary_evaluator, Lhs, Rhs>, IteratorBased, IteratorBased> - : evaluator_base, Lhs, Rhs> > + : sparse_conjunction_evaluator, Lhs, Rhs> > +{ + typedef CwiseBinaryOp, Lhs, Rhs> XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; +// "dense .* sparse" +template +struct binary_evaluator, Lhs, Rhs>, IndexBased, IteratorBased> + : sparse_conjunction_evaluator, Lhs, Rhs> > +{ + typedef CwiseBinaryOp, Lhs, Rhs> XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; +// "sparse .* dense" +template +struct binary_evaluator, Lhs, Rhs>, IteratorBased, IndexBased> + : sparse_conjunction_evaluator, Lhs, Rhs> > +{ + typedef CwiseBinaryOp, Lhs, Rhs> XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; + +// "sparse && sparse" +template +struct binary_evaluator, IteratorBased, IteratorBased> + : sparse_conjunction_evaluator > +{ + typedef CwiseBinaryOp XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; +// "dense && sparse" +template +struct binary_evaluator, IndexBased, IteratorBased> + : sparse_conjunction_evaluator > +{ + typedef CwiseBinaryOp XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; +// "sparse && dense" +template +struct binary_evaluator, IteratorBased, IndexBased> + : sparse_conjunction_evaluator > +{ + typedef CwiseBinaryOp XprType; + typedef sparse_conjunction_evaluator Base; + explicit binary_evaluator(const XprType& xpr) : Base(xpr) {} +}; + +// "sparse ^ sparse" +template +struct sparse_conjunction_evaluator + : evaluator_base { protected: - typedef scalar_product_op BinaryOp; + typedef typename XprType::Functor BinaryOp; + typedef typename XprType::Lhs Lhs; + typedef typename XprType::Rhs Rhs; typedef typename evaluator::InnerIterator LhsIterator; typedef typename evaluator::InnerIterator RhsIterator; - typedef CwiseBinaryOp XprType; typedef typename XprType::StorageIndex StorageIndex; typedef typename traits::Scalar Scalar; public: @@ -344,7 +407,7 @@ public: { public: - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) + EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor) { while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index())) @@ -390,7 +453,7 @@ public: Flags = XprType::Flags }; - explicit binary_evaluator(const XprType& xpr) + explicit sparse_conjunction_evaluator(const XprType& xpr) : m_functor(xpr.functor()), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) @@ -409,16 +472,17 @@ protected: evaluator m_rhsImpl; }; -// "dense .* sparse" -template -struct binary_evaluator, Lhs, Rhs>, IndexBased, IteratorBased> - : evaluator_base, Lhs, Rhs> > +// "dense ^ sparse" +template +struct sparse_conjunction_evaluator + : evaluator_base { protected: - typedef scalar_product_op BinaryOp; + typedef typename XprType::Functor BinaryOp; + typedef typename XprType::Lhs Lhs; + typedef typename XprType::Rhs Rhs; typedef evaluator LhsEvaluator; typedef typename evaluator::InnerIterator RhsIterator; - typedef CwiseBinaryOp XprType; typedef typename XprType::StorageIndex StorageIndex; typedef typename traits::Scalar Scalar; public: @@ -430,7 +494,7 @@ public: public: - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) + EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) : m_lhsEval(aEval.m_lhsImpl), m_rhsIter(aEval.m_rhsImpl,outer), m_functor(aEval.m_functor), m_outer(outer) {} @@ -463,7 +527,7 @@ public: Flags = (XprType::Flags & ~RowMajorBit) | (int(Rhs::Flags)&RowMajorBit) }; - explicit binary_evaluator(const XprType& xpr) + explicit sparse_conjunction_evaluator(const XprType& xpr) : m_functor(xpr.functor()), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) @@ -482,16 +546,17 @@ protected: evaluator m_rhsImpl; }; -// "sparse .* dense" -template -struct binary_evaluator, Lhs, Rhs>, IteratorBased, IndexBased> - : evaluator_base, Lhs, Rhs> > +// "sparse ^ dense" +template +struct sparse_conjunction_evaluator + : evaluator_base { protected: - typedef scalar_product_op BinaryOp; + typedef typename XprType::Functor BinaryOp; + typedef typename XprType::Lhs Lhs; + typedef typename XprType::Rhs Rhs; typedef typename evaluator::InnerIterator LhsIterator; typedef evaluator RhsEvaluator; - typedef CwiseBinaryOp XprType; typedef typename XprType::StorageIndex StorageIndex; typedef typename traits::Scalar Scalar; public: @@ -503,7 +568,7 @@ public: public: - EIGEN_STRONG_INLINE InnerIterator(const binary_evaluator& aEval, Index outer) + EIGEN_STRONG_INLINE InnerIterator(const sparse_conjunction_evaluator& aEval, Index outer) : m_lhsIter(aEval.m_lhsImpl,outer), m_rhsEval(aEval.m_rhsImpl), m_functor(aEval.m_functor), m_outer(outer) {} @@ -537,7 +602,7 @@ public: Flags = (XprType::Flags & ~RowMajorBit) | (int(Lhs::Flags)&RowMajorBit) }; - explicit binary_evaluator(const XprType& xpr) + explicit sparse_conjunction_evaluator(const XprType& xpr) : m_functor(xpr.functor()), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs())