如何解决Eigen 中的自定义标量类型:运算符的二义性重载* 编辑
我正在尝试将 FloatX (https://github.com/oprecomp/FloatX) 集成到 Eigen 中,但在进行任何矩阵乘法时都会出错:
error: ambiguous overload for 'operator*'
根据在 Eigen 中添加自定义标量类型的文档,我有以下内容:
namespace Eigen {
template<int E,int M>
struct NumTraits<flx::floatx<E,M>> : NumTraits<double>
{
typedef flx::floatx<E,M> Real;
typedef flx::floatx<E,M> NonInteger;
typedef flx::floatx<E,M> Nested;
enum {
IsComplex = 0,IsInteger = 0,IsSigned = 1,RequireInitialization = 0,ReadCost = 1,AddCost = 3,MulCost = 3
};
};
template<typename BinaryOp,typename A,int E,int M>
struct ScalarBinaryOpTraits<A,flx::floatx<E,M>,BinaryOp> { typedef flx::floatx<E,M> ReturnType; };
template<typename BinaryOp,int M>
struct ScalarBinaryOpTraits<flx::floatx<E,A,M> ReturnType; };
template <int E,int M>
struct ScalarBinaryOpTraits<
flx::floatx<E,internal::scalar_product_op<flx::floatx<E,M>>> {
typedef flx::floatx<E,M> ReturnType;
};
}
在底部包含 ScalarBinaryOpTraits
似乎无济于事。无论我是否包含它们,我都会收到相同的错误。任何帮助表示赞赏!
编辑
这是一个重现错误的简单示例(需要从 https://github.com/oprecomp/FloatX/blob/master/src/floatx.hpp 下载 floatx.hpp
):
#include <Eigen/Eigen>
#include "floatx.hpp"
using fx = flx::floatx<8,23>;
// support for eigen library
namespace Eigen {
template<int E,M> Nested;
enum {
IsComplex = 0,MulCost = 3
};
};
}
int main() {
Eigen::Matrix<fx,3,3> m;
m << fx(1),fx(2),fx(3),fx(4),fx(5),fx(6),fx(7),fx(8),fx(9);
Eigen::Matrix<fx,3> m2 = m * m;
std::cout << m;
std::cout << m2;
}
输出:
g++ -I /usr/include/eigen3 floatx.hpp test.cpp -o floatx_test
test.cpp: In function ‘int main()’:
test.cpp:35:34: error: ambiguous overload for ‘operator*’ (operand types are ‘Eigen::Matrix<flx::floatx<8,23>,3>’ and ‘Eigen::Matrix<flx::floatx<8,3>’)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。