我想在__float128的erf()函数中使用找出,但目前它只支持浮点数和双倍的找出:
此函数只支持c++11模式下的浮动和双标量类型。为了支持其他标量类型,或非c++11模式下的浮动/双值,用户必须为支持的任何标量类型T提供erf(T)的实现。
由于我想使用__float128,所以如果可能的话,我希望依赖于libquadmath的erfq 实现。但怎么做呢?唯一(丑陋的?)我现在能想到的方法是使用unaryExpr()。还有其他的可能性吗?
发布于 2017-05-12 15:52:28
您可以专门化Eigen::internal::erf_impl (当然,对于任何其他功能也是如此):
#include <quadmath.h>
#include <iostream>
#include <unsupported/Eigen/SpecialFunctions>
namespace Eigen { namespace internal {
template<>
struct erf_impl<__float128> {
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE __float128 run(__float128 x) { return ::erfq(x); }
};
}}
int main()
{
typedef Eigen::Array<__float128, Eigen::Dynamic, 1> ArrayXF;
ArrayXF a(4); a << 0, 0.25, 0.5, 0.75;
ArrayXF b = a.erf();
for(int i=0; i<4; ++i){
char buf[100];
quadmath_snprintf(buf, 100, "%.50Qe", b[i]); std::cout << buf << '\n';
}
}输出:
0.00000000000000000000000000000000000000000000000000e+00 2.76326390168236932985068267764815703534647315720851e-01 5.20499877813046537682746653891964513119913394193564e-01 7.11155633653515131598937834591410814324096358715387e-01
https://stackoverflow.com/questions/43941416
复制相似问题