使用具有自定义标量类型的特征::几何模块

Using Eigen::Geometry module with custom scalar type

本文关键字:何模块 模块 特征 自定义 类型 标量      更新时间:2023-10-16

II想在我目前正在从事的几何项目中使用本征进行线性代数。这是一个很棒的图书馆,相对较小,易于使用且足够受欢迎。

但是,我还想使用自定义的"Double"类来比较计算机精度中的两个浮点值(类似于两者之间的差异必须小于给定的精度)。对于我的自定义类型,我已经实现了大多数 std::math c++11 函数和所有运算符(包括一元 -、conj、imag、abs2...)。我做了这些链接中列出的所有内容:

http://eigen.tuxfamily.org/dox-devel/TopicCustomizingEigen.html

https://forum.kde.org/viewtopic.php?f=74&t=26631

但是,我仍然在 Eigen Jacobi.h 文件中收到编译错误,更具体地说是在第 340,341 行,它们是:

x[i] =  c * xi + numext::conj(s) * yi;
y[i] = -s * xi + numext::conj(c) * yi;

我从编译器收到以下错误(与 2012、Win32、发布和调试配置)

eigensrc/Jacobi/Jacobi.h(341): error C3767: '*': candidate function(s) not accessible

运算符*在我的自定义类型中为以下情况定义:

CustomType operator*(CustomType const &_other);
CustomType operator*(double const &_other);
double operator*(CustomType const &_other);

我试图以下列方式定义 conj:

CustomType conj(CustomType const &_type){return _type;}
double conj(customType const &_type){return _type.get();}

我尝试在 Eigen::numext 命名空间以及我的 CustomType 命名空间中定义 conj,但没有成功。任何人都有提示,链接,建议或知道Eigen需要的东西,我可能已经忘记了?

很可能

是因为您的代码不正确。

您的操作员重载应为:

CustomType operator*(CustomType const &_other) **const**;
CustomType operator*(double const &_other) **const**;
double operator*(CustomType const &_other) **const**;

如果 eigen 具有对类型 CustomType 对象的 const 引用,则它无法调用运算符,因为它们不是 const 声明的。

void foo(const CustomType& x, const CustomType& y){
    x * y; // Compile error, cannot call non-const operator * on const object.
}

不确定这是否是这里的问题,但你必须专门Eigen::NumTraits<T>.请参阅此手册页。

我也不明白你怎么能有两个conj函数,它们具有返回不同类型的相同参数。