aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Eigen/src/Core/DiagonalProduct.h6
-rw-r--r--test/mixingtypes.cpp28
2 files changed, 22 insertions, 12 deletions
diff --git a/Eigen/src/Core/DiagonalProduct.h b/Eigen/src/Core/DiagonalProduct.h
index b838d1b31..7eaa380eb 100644
--- a/Eigen/src/Core/DiagonalProduct.h
+++ b/Eigen/src/Core/DiagonalProduct.h
@@ -29,7 +29,7 @@
template<typename MatrixType, typename DiagonalType, int ProductOrder>
struct ei_traits<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> >
{
- typedef typename MatrixType::Scalar Scalar;
+ typedef typename ei_scalar_product_traits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar;
enum {
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
@@ -62,7 +62,7 @@ class DiagonalProduct : ei_no_assignment_operator,
{
return m_diagonal.diagonal().coeff(ProductOrder == DiagonalOnTheLeft ? row : col) * m_matrix.coeff(row, col);
}
-
+
template<int LoadMode>
EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const
{
@@ -72,7 +72,7 @@ class DiagonalProduct : ei_no_assignment_operator,
DiagonalVectorPacketLoadMode = (LoadMode == Aligned && ((InnerSize%16) == 0)) ? Aligned : Unaligned
};
const int indexInDiagonalVector = ProductOrder == DiagonalOnTheLeft ? row : col;
-
+
if((int(StorageOrder) == RowMajor && int(ProductOrder) == DiagonalOnTheLeft)
||(int(StorageOrder) == ColMajor && int(ProductOrder) == DiagonalOnTheRight))
{
diff --git a/test/mixingtypes.cpp b/test/mixingtypes.cpp
index 690442a02..6280c3b6e 100644
--- a/test/mixingtypes.cpp
+++ b/test/mixingtypes.cpp
@@ -33,6 +33,7 @@
#include "main.h"
+using namespace std;
template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
{
@@ -45,14 +46,14 @@ template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf;
typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd;
- Mat_f mf(size,size);
- Mat_d md(size,size);
- Mat_cf mcf(size,size);
- Mat_cd mcd(size,size);
- Vec_f vf(size,1);
- Vec_d vd(size,1);
- Vec_cf vcf(size,1);
- Vec_cd vcd(size,1);
+ Mat_f mf = Mat_f::Random(size,size);
+ Mat_d md = mf.template cast<double>();
+ Mat_cf mcf = Mat_cf::Random(size,size);
+ Mat_cd mcd = mcf.template cast<complex<double> >();
+ Vec_f vf = Vec_f::Random(size,1);
+ Vec_d vd = vf.template cast<double>();
+ Vec_cf vcf = Vec_cf::Random(size,1);
+ Vec_cd vcd = vcf.template cast<complex<double> >();
mf+mf;
VERIFY_RAISES_ASSERT(mf+md);
@@ -64,7 +65,16 @@ template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
vf.dot(vf);
VERIFY_RAISES_ASSERT(vd.dot(vf));
VERIFY_RAISES_ASSERT(vcf.dot(vf)); // yeah eventually we should allow this but i'm too lazy to make that change now in Dot.h
-} // especially as that might be rewritten as cwise product .sum() which would make that automatic.
+ // especially as that might be rewritten as cwise product .sum() which would make that automatic.
+
+ VERIFY_IS_APPROX(vf.asDiagonal() * mcf, vf.template cast<complex<float> >().asDiagonal() * mcf);
+ VERIFY_IS_APPROX(vcd.asDiagonal() * md, vcd.asDiagonal() * md.template cast<complex<double> >());
+ VERIFY_IS_APPROX(mcf * vf.asDiagonal(), mcf * vf.template cast<complex<float> >().asDiagonal());
+ VERIFY_IS_APPROX(md * vcd.asDiagonal(), md.template cast<complex<double> >() * vcd.asDiagonal());
+
+// vd.asDiagonal() * mf; // does not even compile
+// vcd.asDiagonal() * mf; // does not even compile
+}
void mixingtypes_large(int size)