首页 文章

使用具有自定义标量类型的Eigen :: Geometry模块

提问于
浏览
1

我想在我目前正在研究的几何项目中使用Eigen进行线性代数 . 这是一个相对较小且易于使用且非常受欢迎的优秀图书馆 .

但是,我还想使用自定义的“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;

我从编译器得到以下错误(Vs 2012,Win32,发布和调试配置)

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

operator *在我的自定义类型中定义以下情况:

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需要我可能忘记的东西?

2 回答

  • 1

    很可能是因为您的代码不是const correct .

    您的运算符重载应该是:

    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.
    }
    
  • 0

    不确定这是否是问题,但你必须专门化 Eigen::NumTraits<T> . 见manpage .

    另外,我不明白你如何使用返回不同类型的相同参数的两个 conj 函数 .

相关问题