Why is operator+ not commutative for rowwise Eigen arrays?

Viewed 64

Given two Eigen arrays:

Eigen::Array<double, 1, 2> m(1);
Eigen::Array<double, 3, 2> n(2);

why does n.rowwise() + m; compile, but not m + n.rowwise();?

Here is a demonstration with Compiler Explorer that shows the compilation error, which includes

invalid operands to binary expression ('Eigen::Array<double, 1, 2>' and 'Eigen::DenseBase<Eigen::Array<double, 3, 2, 0, 3, 2>>::RowwiseReturnType' (aka 'VectorwiseOp<Eigen::Array<double, 3, 2, 0, 3, 2>, Horizontal>'))
    m + n.rowwise(); // does not compile
    ~ ^ ~~~~~~~~~~~
[...]/Eigen/src/Core/../plugins/ArrayCwiseBinaryOps.h:241:29: note: candidate function template not viable: no known conversion from 'Eigen::DenseBase<Eigen::Array<double, 3, 2, 0, 3, 2>>::RowwiseReturnType' (aka 'VectorwiseOp<Eigen::Array<double, 3, 2, 0, 3, 2>, Horizontal>') to 'const Eigen::ArrayBase<Eigen::Array<double, 1, 2, 1, 1, 2>>::StorageBaseType' (aka 'const Eigen::ArrayBase<Eigen::Array<double, 1, 2, 1, 1, 2>>') for 2nd argument
[...]/Eigen/src/Core/../plugins/ArrayCwiseBinaryOps.h:241:29: note: candidate function template not viable: no known conversion from 'Eigen::DenseBase<Eigen::Array<double, 3, 2, 0, 3, 2>>::RowwiseReturnType' (aka 'VectorwiseOp<Eigen::Array<double, 3, 2, 0, 3, 2>, Horizontal>') to 'const Eigen::ArrayBase<Eigen::Array<double, 3, 2, 0, 3, 2>>::StorageBaseType' (aka 'const Eigen::ArrayBase<Eigen::Array<double, 3, 2, 0, 3, 2>>') for 2nd argument
[...]/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:27:28: note: candidate template ignored: could not match 'ArrayBase' against 'VectorwiseOp'
[...]/Eigen/src/Core/../plugins/ArrayCwiseBinaryOps.h:241:29: note: candidate template ignored: substitution failure [with T = Eigen::VectorwiseOp<Eigen::Array<double, 3, 2, 0, 3, 2>, 1>]: no type named 'type' in 'Eigen::internal::promote_scalar_arg<double, Eigen::VectorwiseOp<Eigen::Array<double, 3, 2, 0, 3, 2>, 1>, false>'

The operator+ being used by the first expression, the one that does compile, is on this line of VectorwiseOp.h.

0 Answers
Related