具有特征类型输出的特征二进制 Expr
Eigen binaryExpr with eigen type output
我在尝试使用binaryExpr时遇到问题。这是我第一次使用它,所以我一直在关注 Eigen 文档
对于我的使用,我需要一个具有特征类型输入和输出的函子,但这不想编译,我不明白为什么。我已经在代码中查找了解释,但我认为这不适用于这里,因为我使用浮点数和浮点数组
// We require Lhs and Rhs to have "compatible" scalar types.
// It is tempting to always allow mixing different types but remember that this is often impossible in the vectorized paths.
// So allowing mixing different types gives very unexpected errors when enabling vectorization, when the user tries to
// add together a float matrix and a double matrix.
下面是我需要的使用的一个简短示例,它使我遇到相同的编译错误:
#include <eigen3/Eigen/Dense>
using namespace std;
using namespace Eigen;
struct myBinaryFunctor {
EIGEN_EMPTY_STRUCT_CTOR(myBinaryFunctor)
typedef Vector2f result_type;
Vector2f operator()(const Matrix<float,9,1>& a,const float& f) const
{
float x = a.head(4).sum()*f;
float y = a.tail(5).sum()/f;
return Vector2f(x,y);
}
};
int main()
{
constexpr int n = 3;
Matrix<Matrix<float,9,1>,n,n> Ma;
Matrix<float,n,n> F;
Matrix<Vector2f,n,n> R;
for(size_t i = 0, sizeMa = Ma.size(); i<sizeMa; i++)
{
Ma(i).setOnes();
}
F.setConstant(n,n,2);
R = Ma.binaryExpr(F,myBinaryFunctor());
return 0;
}
编译输出为:
/usr/local/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h:107: erreur : static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
^
如果你有一个解决方案可以使这项工作,这对我:)如果没有,我仍然会喜欢解释以了解正在发生的事情。多谢。
添加:
namespace Eigen {
template<>
struct ScalarBinaryOpTraits<Matrix<float,9,1>,float,myBinaryFunctor> {
typedef Vector2f ReturnType;
};
}
会做这项工作。这是因为隐式标量转换在 Eigen 中是明确不允许的,因此您必须明确表示两种不同的标量类型是兼容的。例如,不允许向VectorXf
添加VectorXd
。
尽管如此,在我看来,你在这里滥用了艾根的特征。
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 有根的二进制搜索树.保留与其父级的链接
- 多态二进制函数
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 正在读取二进制文件(is_open)
- visual在c++中将十进制数转换为二进制数
- C++十进制到二进制,如何转换
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 为什么二进制搜索在我的测试中不起作用
- 重载==不适用于二进制树
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 正在尝试重载二进制搜索树分配运算符
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 在C++中将类(带有Vector成员)保存为二进制文件
- c ++:如何为每个特征制作特定的二进制文件(可执行文件)?
- 具有特征类型输出的特征二进制 Expr
- 如何从二进制文件中写入/读取特征矩阵
- 特征:t 1 的随机二进制向量