微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 operator+ 对于 rowwise Eigen 数组不是可交换的?

如何解决为什么 operator+ 对于 rowwise Eigen 数组不是可交换的?

给定两个特征数组:

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

为什么 n.rowwise() + m; 可以编译,而 m + n.rowwise(); 不能?

这是一个显示编译错误demonstration with Compiler Explorer,其中包括

invalid operands to binary expression ('Eigen::Array<double,2>' and 'Eigen::DenseBase<Eigen::Array<double,2,2>>::RowwiseReturnType' (aka 'VectorwiSEOp<Eigen::Array<double,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,Horizontal>') to 'const Eigen::ArrayBase<Eigen::Array<double,2>>::StorageBaseType' (aka 'const Eigen::ArrayBase<Eigen::Array<double,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,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,1>]: no type named 'type' in 'Eigen::internal::promote_scalar_arg<double,Eigen::VectorwiSEOp<Eigen::Array<double,1>,false>'

一个表达式使用的 operator+ 是编译的表达式,它是 on this line of VectorwiseOp.h

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。