aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-11 20:48:56 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-11 20:48:56 +0000
commita30b498ab449df1ab51fc389bc2d9f6334e31f84 (patch)
tree81b9618f9b4bf3c1b884dc51be176ed8e2828a6f
parent28e15574df883e2f917d6fa0d2e099bb549ca54a (diff)
add cwise operator *= and /=.
Keir says hi!!
-rw-r--r--Eigen/src/Array/CwiseOperators.h37
-rw-r--r--Eigen/src/Core/Cwise.h6
-rw-r--r--doc/snippets/Cwise_slash_equal.cpp4
-rw-r--r--doc/snippets/Cwise_times_equal.cpp4
4 files changed, 51 insertions, 0 deletions
diff --git a/Eigen/src/Array/CwiseOperators.h b/Eigen/src/Array/CwiseOperators.h
index 4b6346daa..81e51f8d9 100644
--- a/Eigen/src/Array/CwiseOperators.h
+++ b/Eigen/src/Array/CwiseOperators.h
@@ -418,6 +418,43 @@ inline ExpressionType& Cwise<ExpressionType>::operator+=(const Scalar& scalar)
return m_matrix.const_cast_derived() = *this + scalar;
}
+
+//=============
+
+/** \array_module
+ *
+ * Replaces this expression by its coefficient-wise product with \a other.
+ *
+ * Example: \include Cwise_times_equal.cpp
+ * Output: \verbinclude Cwise_times_equal.out
+ *
+ * \sa operator*(), operator/=()
+ */
+template<typename ExpressionType>
+template<typename OtherDerived>
+inline ExpressionType& Cwise<ExpressionType>::operator*=(const MatrixBase<OtherDerived> &other)
+{
+ return m_matrix.const_cast_derived() = *this * other;
+}
+
+/** \array_module
+ *
+ * Replaces this expression by its coefficient-wise quotient with \a other.
+ *
+ * Example: \include Cwise_slash_equal.cpp
+ * Output: \verbinclude Cwise_slash_equal.out
+ *
+ * \sa operator/(), operator*=()
+ */
+template<typename ExpressionType>
+template<typename OtherDerived>
+inline ExpressionType& Cwise<ExpressionType>::operator/=(const MatrixBase<OtherDerived> &other)
+{
+ return m_matrix.const_cast_derived() = *this / other;
+}
+
+//=============
+
/** \array_module
*
* \returns an expression of \c *this with each coeff decremented by the constant \a scalar
diff --git a/Eigen/src/Core/Cwise.h b/Eigen/src/Core/Cwise.h
index a04fff3db..eef7ef02c 100644
--- a/Eigen/src/Core/Cwise.h
+++ b/Eigen/src/Core/Cwise.h
@@ -128,6 +128,12 @@ template<typename ExpressionType> class Cwise
ExpressionType& operator-=(const Scalar& scalar);
+ template<typename OtherDerived>
+ inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
+
template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
operator<(const MatrixBase<OtherDerived>& other) const;
diff --git a/doc/snippets/Cwise_slash_equal.cpp b/doc/snippets/Cwise_slash_equal.cpp
new file mode 100644
index 000000000..10c4f4acc
--- /dev/null
+++ b/doc/snippets/Cwise_slash_equal.cpp
@@ -0,0 +1,4 @@
+Vector3d v(3,2,4);
+Vector3d w(5,4,2);
+v.cwise() /= w;
+cout << v << endl;
diff --git a/doc/snippets/Cwise_times_equal.cpp b/doc/snippets/Cwise_times_equal.cpp
new file mode 100644
index 000000000..7db95b03b
--- /dev/null
+++ b/doc/snippets/Cwise_times_equal.cpp
@@ -0,0 +1,4 @@
+Vector3d v(1,2,3);
+Vector3d w(2,3,0);
+v.cwise() *= w;
+cout << v << endl;