diff options
author | Gael Guennebaud <g.gael@free.fr> | 2013-08-19 16:40:50 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2013-08-19 16:40:50 +0200 |
commit | 2b15e001068f548b852d58472b9b29f1a7bf1a2c (patch) | |
tree | 086ad5d158ff13b80bba632f72c3506efca65c8b /Eigen/src/Core | |
parent | 127d7f2071c9be2a62f881d53d0b696f43053453 (diff) |
Make ArrayBase operator+=(scalar) and -=(scalar) use SelfCwiseBinaryOp optimization
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/ArrayBase.h | 6 | ||||
-rw-r--r-- | Eigen/src/Core/SelfCwiseBinaryOp.h | 18 |
2 files changed, 20 insertions, 4 deletions
diff --git a/Eigen/src/Core/ArrayBase.h b/Eigen/src/Core/ArrayBase.h index 38852600d..b7c4a1c71 100644 --- a/Eigen/src/Core/ArrayBase.h +++ b/Eigen/src/Core/ArrayBase.h @@ -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); diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h index 96012eaf8..3d2deff98 100644 --- a/Eigen/src/Core/SelfCwiseBinaryOp.h +++ b/Eigen/src/Core/SelfCwiseBinaryOp.h @@ -178,6 +178,24 @@ inline Derived& DenseBase<Derived>::operator*=(const Scalar& other) } 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) { typedef typename internal::conditional<NumTraits<Scalar>::IsInteger, |