aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2013-08-19 16:40:50 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2013-08-19 16:40:50 +0200
commit2b15e001068f548b852d58472b9b29f1a7bf1a2c (patch)
tree086ad5d158ff13b80bba632f72c3506efca65c8b
parent127d7f2071c9be2a62f881d53d0b696f43053453 (diff)
Make ArrayBase operator+=(scalar) and -=(scalar) use SelfCwiseBinaryOp optimization
-rw-r--r--Eigen/Core2
-rw-r--r--Eigen/src/Core/ArrayBase.h6
-rw-r--r--Eigen/src/Core/SelfCwiseBinaryOp.h18
3 files changed, 21 insertions, 5 deletions
diff --git a/Eigen/Core b/Eigen/Core
index 97aa581e2..a508b97f6 100644
--- a/Eigen/Core
+++ b/Eigen/Core
@@ -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
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,