From 70b1ce11c6b32cfe4ed1cedcef5e96a43659d15a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 19 Jul 2010 23:31:08 +0200 Subject: * fix SelfCwiseBinaryOp traits and handling of mixed types * improve compilation error in case of type mismatch --- Eigen/src/Core/SelfCwiseBinaryOp.h | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'Eigen/src/Core/SelfCwiseBinaryOp.h') diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h index acdbb8658..de8c4e740 100644 --- a/Eigen/src/Core/SelfCwiseBinaryOp.h +++ b/Eigen/src/Core/SelfCwiseBinaryOp.h @@ -39,14 +39,19 @@ * * \sa class SwapWrapper for a similar trick. */ -template -struct ei_traits > : ei_traits +template +struct ei_traits > + : ei_traits > { - + enum { + Flags = ei_traits >::Flags | (Lhs::Flags&DirectAccessBit), + OuterStrideAtCompileTime = Lhs::OuterStrideAtCompileTime, + InnerStrideAtCompileTime = Lhs::InnerStrideAtCompileTime + }; }; -template class SelfCwiseBinaryOp - : public ei_dense_xpr_base< SelfCwiseBinaryOp >::type +template class SelfCwiseBinaryOp + : public ei_dense_xpr_base< SelfCwiseBinaryOp >::type { public: @@ -57,7 +62,7 @@ template class SelfCwiseBinaryOp using Base::operator=; - inline SelfCwiseBinaryOp(MatrixType& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {} + inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {} inline Index rows() const { return m_matrix.rows(); } inline Index cols() const { return m_matrix.cols(); } @@ -122,12 +127,8 @@ template class SelfCwiseBinaryOp template EIGEN_STRONG_INLINE SelfCwiseBinaryOp& lazyAssign(const DenseBase& rhs) { - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(MatrixType,RhsDerived) - - EIGEN_STATIC_ASSERT((ei_functor_allows_mixing_real_and_complex::ret - ? int(ei_is_same_type::ret) - : int(ei_is_same_type::ret)), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs,RhsDerived) + EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename RhsDerived::Scalar); #ifdef EIGEN_DEBUG_ASSIGN ei_assign_traits::debug(); @@ -141,7 +142,7 @@ template class SelfCwiseBinaryOp } protected: - MatrixType& m_matrix; + Lhs& m_matrix; const BinaryOp& m_functor; private: @@ -151,8 +152,8 @@ template class SelfCwiseBinaryOp template inline Derived& DenseBase::operator*=(const Scalar& other) { - SelfCwiseBinaryOp, Derived> tmp(derived()); typedef typename Derived::PlainObject PlainObject; + SelfCwiseBinaryOp, Derived, typename PlainObject::ConstantReturnType> tmp(derived()); tmp = PlainObject::Constant(rows(),cols(),other); return derived(); } @@ -160,10 +161,11 @@ inline Derived& DenseBase::operator*=(const Scalar& other) template inline Derived& DenseBase::operator/=(const Scalar& other) { - SelfCwiseBinaryOp::IsInteger, + typedef typename ei_meta_if::IsInteger, ei_scalar_quotient_op, - ei_scalar_product_op >::ret, Derived> tmp(derived()); + ei_scalar_product_op >::ret BinOp; typedef typename Derived::PlainObject PlainObject; + SelfCwiseBinaryOp tmp(derived()); tmp = PlainObject::Constant(rows(),cols(), NumTraits::IsInteger ? other : Scalar(1)/other); return derived(); } -- cgit v1.2.3