aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2019-01-17 16:55:42 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2019-01-17 16:55:42 +0100
commitb57c9787b1b7c7436f95814cab6e3551f49dda6f (patch)
tree2aa52e2587efdb7462b7472eca39aa9c90215d5c
parentbe05d0030d7c2a83a2cc924d9c3aae6ad81cda4f (diff)
Cleanup useless const_cast and add missing broadcast assignment tests
-rw-r--r--Eigen/src/Core/VectorwiseOp.h10
-rw-r--r--test/vectorwiseop.cpp13
2 files changed, 18 insertions, 5 deletions
diff --git a/Eigen/src/Core/VectorwiseOp.h b/Eigen/src/Core/VectorwiseOp.h
index ea0a092a5..db0b9f8c4 100644
--- a/Eigen/src/Core/VectorwiseOp.h
+++ b/Eigen/src/Core/VectorwiseOp.h
@@ -557,7 +557,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
//eigen_assert((m_matrix.isNull()) == (other.isNull())); FIXME
- return const_cast<ExpressionType&>(m_matrix = extendedTo(other.derived()));
+ return m_matrix = extendedTo(other.derived());
}
/** Adds the vector \a other to each subvector of \c *this */
@@ -567,7 +567,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
- return const_cast<ExpressionType&>(m_matrix += extendedTo(other.derived()));
+ return m_matrix += extendedTo(other.derived());
}
/** Substracts the vector \a other to each subvector of \c *this */
@@ -577,7 +577,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
- return const_cast<ExpressionType&>(m_matrix -= extendedTo(other.derived()));
+ return m_matrix -= extendedTo(other.derived());
}
/** Multiples each subvector of \c *this by the vector \a other */
@@ -589,7 +589,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
m_matrix *= extendedTo(other.derived());
- return const_cast<ExpressionType&>(m_matrix);
+ return m_matrix;
}
/** Divides each subvector of \c *this by the vector \a other */
@@ -601,7 +601,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
m_matrix /= extendedTo(other.derived());
- return const_cast<ExpressionType&>(m_matrix);
+ return m_matrix;
}
/** Returns the expression of the sum of the vector \a other to each subvector of \c *this */
diff --git a/test/vectorwiseop.cpp b/test/vectorwiseop.cpp
index 4b9d2d570..8ee58841a 100644
--- a/test/vectorwiseop.cpp
+++ b/test/vectorwiseop.cpp
@@ -150,6 +150,19 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
RealColVectorType rcres;
RealRowVectorType rrres;
+ // test broadcast assignment
+ m2 = m1;
+ m2.colwise() = colvec;
+ for(Index j=0; j<cols; ++j)
+ VERIFY_IS_APPROX(m2.col(j), colvec);
+ m2.rowwise() = rowvec;
+ for(Index i=0; i<rows; ++i)
+ VERIFY_IS_APPROX(m2.row(i), rowvec);
+ if(rows>1)
+ VERIFY_RAISES_ASSERT(m2.colwise() = colvec.transpose());
+ if(cols>1)
+ VERIFY_RAISES_ASSERT(m2.rowwise() = rowvec.transpose());
+
// test addition
m2 = m1;