From a30b498ab449df1ab51fc389bc2d9f6334e31f84 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 11 Jan 2009 20:48:56 +0000 Subject: [PATCH] add cwise operator *= and /=. Keir says hi!! --- Eigen/src/Array/CwiseOperators.h | 37 ++++++++++++++++++++++++++++++ Eigen/src/Core/Cwise.h | 6 +++++ doc/snippets/Cwise_slash_equal.cpp | 4 ++++ doc/snippets/Cwise_times_equal.cpp | 4 ++++ 4 files changed, 51 insertions(+) create mode 100644 doc/snippets/Cwise_slash_equal.cpp create mode 100644 doc/snippets/Cwise_times_equal.cpp 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::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 +template +inline ExpressionType& Cwise::operator*=(const MatrixBase &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 +template +inline ExpressionType& Cwise::operator/=(const MatrixBase &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 class Cwise ExpressionType& operator-=(const Scalar& scalar); + template + inline ExpressionType& operator*=(const MatrixBase &other); + + template + inline ExpressionType& operator/=(const MatrixBase &other); + template const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less) operator<(const MatrixBase& 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;