Make ArrayBase operator+=(scalar) and -=(scalar) use SelfCwiseBinaryOp optimization

This commit is contained in:
Gael Guennebaud 2013-08-19 16:40:50 +02:00
parent 127d7f2071
commit 2b15e00106
3 changed files with 21 additions and 5 deletions

View File

@ -284,6 +284,7 @@ using std::ptrdiff_t;
#include "src/Core/Assign.h"
#endif
#include "src/Core/ArrayBase.h"
#include "src/Core/util/BlasUtil.h"
#include "src/Core/DenseStorage.h"
#include "src/Core/NestByValue.h"
@ -347,7 +348,6 @@ using std::ptrdiff_t;
#include "src/Core/Random.h"
#include "src/Core/Replicate.h"
#include "src/Core/Reverse.h"
#include "src/Core/ArrayBase.h"
#include "src/Core/ArrayWrapper.h"
#ifdef EIGEN_ENABLE_EVALUATORS

View File

@ -123,10 +123,8 @@ template<typename Derived> class ArrayBase
return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
}
Derived& operator+=(const Scalar& scalar)
{ return *this = derived() + scalar; }
Derived& operator-=(const Scalar& scalar)
{ return *this = derived() - scalar; }
Derived& operator+=(const Scalar& scalar);
Derived& operator-=(const Scalar& scalar);
template<typename OtherDerived>
Derived& operator+=(const ArrayBase<OtherDerived>& other);

View File

@ -177,6 +177,24 @@ inline Derived& DenseBase<Derived>::operator*=(const Scalar& other)
return derived();
}
template<typename Derived>
inline Derived& ArrayBase<Derived>::operator+=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, typename PlainObject::ConstantReturnType> tmp(derived());
tmp = PlainObject::Constant(rows(),cols(),other);
return derived();
}
template<typename Derived>
inline Derived& ArrayBase<Derived>::operator-=(const Scalar& other)
{
typedef typename Derived::PlainObject PlainObject;
SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, typename PlainObject::ConstantReturnType> tmp(derived());
tmp = PlainObject::Constant(rows(),cols(),other);
return derived();
}
template<typename Derived>
inline Derived& DenseBase<Derived>::operator/=(const Scalar& other)
{