Get rid of SeflCwiseBinaryOp

This commit is contained in:
Gael Guennebaud 2014-02-18 10:52:00 +01:00
parent 873401032b
commit 2d136d3d7f
2 changed files with 102 additions and 0 deletions

View File

@ -177,6 +177,59 @@ template<typename Derived> class ArrayBase
{EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
};
#ifdef EIGEN_TEST_EVALUATORS
/** replaces \c *this by \c *this - \a other.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
{
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar>());
return derived();
}
/** replaces \c *this by \c *this + \a other.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
{
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar>());
return derived();
}
/** replaces \c *this by \c *this * \a other coefficient wise.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
{
call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar>());
return derived();
}
/** replaces \c *this by \c *this / \a other coefficient wise.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
{
call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar>());
return derived();
}
#else // EIGEN_TEST_EVALUATORS
/** replaces \c *this by \c *this - \a other.
*
* \returns a reference to \c *this
@ -232,6 +285,7 @@ ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
tmp = other.derived();
return derived();
}
#endif
} // end namespace Eigen

View File

@ -12,6 +12,8 @@
namespace Eigen {
#ifndef EIGEN_TEST_EVALUATORS
/** \class SelfCwiseBinaryOp
* \ingroup Core_Module
*
@ -179,6 +181,51 @@ template<typename BinaryOp, typename Lhs, typename Rhs> class SelfCwiseBinaryOp
SelfCwiseBinaryOp& operator=(const SelfCwiseBinaryOp&);
};
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_TEST_EVALUATORS
template<typename Derived>
inline Derived& DenseBase<Derived>::operator*=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::mul_assign_op<Scalar>());
return derived();
}
template<typename Derived>
inline Derived& ArrayBase<Derived>::operator+=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::add_assign_op<Scalar>());
return derived();
}
template<typename Derived>
inline Derived& ArrayBase<Derived>::operator-=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::sub_assign_op<Scalar>());
return derived();
}
template<typename Derived>
inline Derived& DenseBase<Derived>::operator/=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
typedef typename internal::conditional<NumTraits<Scalar>::IsInteger,
internal::div_assign_op<Scalar>,
internal::mul_assign_op<Scalar> >::type AssignOp;
Scalar actual_other;
if(NumTraits<Scalar>::IsInteger) actual_other = other;
else actual_other = Scalar(1)/other;
internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),actual_other), AssignOp());
return derived();
}
#else
template<typename Derived>
inline Derived& DenseBase<Derived>::operator*=(const Scalar& other)
{
@ -220,6 +267,7 @@ inline Derived& DenseBase<Derived>::operator/=(const Scalar& other)
tmp = PlainObject::Constant(rows(),cols(), actual_other);
return derived();
}
#endif
} // end namespace Eigen