Skip to content

Can't convert product of 3 1x1 matrices to scalar

Submitted by Ruslan

Assigned to Nobody

Link to original bugzilla bug (#1610)
Version: 3.3 (current stable)

Description

The following test compiles successfully with Eigen 3.2.92, but fails in 3.3.4 and 3.3.5:

#include <Eigen/Dense>

int main()

{

const Eigen::Matrix<double,1,1> a(1), b(2), c(3);  

const double prod1 = a*b;  

const double prod2 = a*b*c;  

}

The error given by g++ 7.3.0-27ubuntu1~18.04 is as follows:

test.cpp:6:30: error: cannot convert ‘Eigen::internal::enable_if<true, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 1, 1, 0, 1, 1> >, const Eigen::Matrix<double, 1, 1, 0, 1, 1> > >::type {aka const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 1, 1, 0, 1, 1> >, const Eigen::Matrix<double, 1, 1, 0, 1, 1> >}’ to ‘const double’ in initialization

 const double prod2 = a*b*c;  

Notice that the prod1 line compiles successfully, unlike the prod2 one.

The workaround is to explicitly take (0,0) element instead of relying on automatic conversion.

Blocking

#1608