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.
I'm not sure, if we actually want to fix this -- we also don't allow assigning "products with one factor" (i.e., 1x1 matrices) to a scalar. Assigning products 1xN * Nx1 directly to a scalar already is a hack, which usually is better expressed by using a `.dot()` product, IMO, i.e.: a.adjoint().dot(b*c); This of course also works if the inner dimensions of the products are not 1. I would actually prefer to deprecate the auto-conversion (and remove it at some point).
Allowing any 1x1 expression to be convertible to a Scalar is not possible. I've tried that a while back and this yield to countless ambiguous calls. This is why we decided to enable it for inner products only. This is especially useful when dealing for complexes as it makes which operands gets conjugated explicit. Regarding this precise issue, that is: some_inner_prod * 1x1_mat the problem is that the compiler prefers to convert the lhs to a scalar instead of calling the matrix-product operator*. I tried to add more specialized overload of operator* to either Product<> or MatrixBase<>, but at bet I get an ambiguous call error. One possibility would be to have a single generic operator* for MatrixBase that would return a scalar multiple or matrix product depending on the argument. But that sounds overkill.
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1610.