aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-06-20 00:35:33 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-06-20 00:35:33 +0200
commite3853353fb12e243b13a324da8ab1d3f47a87786 (patch)
tree34fd406e4215b93839a6e790f9375c1a8bb5890b
parent7fd8418b199cda8b7facb37fccbe871375c5b6d2 (diff)
fix array_comp *= array_real
-rw-r--r--Eigen/src/Core/SelfCwiseBinaryOp.h28
-rw-r--r--test/mixingtypes.cpp7
2 files changed, 34 insertions, 1 deletions
diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h
index 4a85e1140..7ec2a90e9 100644
--- a/Eigen/src/Core/SelfCwiseBinaryOp.h
+++ b/Eigen/src/Core/SelfCwiseBinaryOp.h
@@ -39,7 +39,10 @@
* \sa class SwapWrapper for a similar trick.
*/
template<typename BinaryOp, typename MatrixType>
-struct ei_traits<SelfCwiseBinaryOp<BinaryOp,MatrixType> > : ei_traits<MatrixType> {};
+struct ei_traits<SelfCwiseBinaryOp<BinaryOp,MatrixType> > : ei_traits<MatrixType>
+{
+
+};
template<typename BinaryOp, typename MatrixType> class SelfCwiseBinaryOp
: public ei_dense_xpr_base< SelfCwiseBinaryOp<BinaryOp, MatrixType> >::type
@@ -113,6 +116,29 @@ template<typename BinaryOp, typename MatrixType> class SelfCwiseBinaryOp
m_functor.packetOp(m_matrix.template packet<StoreMode>(index),_other.template packet<LoadMode>(index)) );
}
+ // reimplement lazyAssign to handle complex *= real
+ // see CwiseBinaryOp ctor for details
+ template<typename RhsDerived>
+ EIGEN_STRONG_INLINE SelfCwiseBinaryOp& lazyAssign(const DenseBase<RhsDerived>& rhs)
+ {
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(MatrixType,RhsDerived)
+
+ EIGEN_STATIC_ASSERT((ei_functor_allows_mixing_real_and_complex<BinaryOp>::ret
+ ? int(ei_is_same_type<typename MatrixType::RealScalar, typename RhsDerived::RealScalar>::ret)
+ : int(ei_is_same_type<typename MatrixType::Scalar, typename RhsDerived::Scalar>::ret)),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+
+ #ifdef EIGEN_DEBUG_ASSIGN
+ ei_assign_traits<SelfCwiseBinaryOp, RhsDerived>::debug();
+ #endif
+ ei_assert(rows() == rhs.rows() && cols() == rhs.cols());
+ ei_assign_impl<SelfCwiseBinaryOp, RhsDerived>::run(*this,rhs.derived());
+ #ifndef EIGEN_NO_DEBUG
+ checkTransposeAliasing(rhs.derived());
+ #endif
+ return *this;
+ }
+
protected:
MatrixType& m_matrix;
const BinaryOp& m_functor;
diff --git a/test/mixingtypes.cpp b/test/mixingtypes.cpp
index c6cf00d28..0465f3059 100644
--- a/test/mixingtypes.cpp
+++ b/test/mixingtypes.cpp
@@ -97,6 +97,13 @@ template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
// check outer product
VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());
+
+ // coeff wise product
+
+ VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());
+
+ Mat_cd mcd2 = mcd;
+ VERIFY_IS_APPROX(mcd.array() *= md.array(), mcd2.array() *= md.array().template cast<std::complex<double> >());
}