将 libquadmath 与特征一起使用
Using libquadmath with eigen
我想将__float128与 eigen 的 erf(( 函数一起使用,但发现目前它只支持浮点数和双精度:
此函数仅支持 c++11 中的浮点数和双标量类型 模式。支持其他标量类型,或在非 c++11 中支持浮点/双精度 模式,用户必须为任何标量提供 erf(T( 的实现 键入要支持的 T。
由于我想使用__float128,如果可能的话,我想依靠libquadmath
erfq
实现。但是怎么做呢?我目前能想到的唯一(丑陋的?(方法是使用特征unaryExpr()
。还有其他可能性吗?
您可以专门化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.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002.76326390168236932985068267764815703534647315720851e-01 5.20499877813046537682746653891964513119913394193564e-01 7.11155633653515131598937834591410814324096358715387e-01
相关文章:
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 如何将enable-if与模板参数和参数包一起使用
- 如何将PERF_AMPLE_READ与mmap一起使用
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将C++中的库和头与MinGW一起使用
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 为什么我不能将 rand() 与数组的大小一起使用?
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 不能将复制初始化与隐式转换的多个步骤一起使用
- 将fold表达式与std::一起用于两个元组
- 将帕迪索求解器与特征一起使用
- 如何将 stl 迭代器与特征一起使用?
- 如何将特征与 Pybind11 一起使用
- 我可以将特征定义的变量与函数adjacent_difference一起使用吗?
- 将特征与cmake一起使用
- 将 libquadmath 与特征一起使用
- 将特征类型与 boost::bind 一起使用是否会自动违反 Eigen 的"only pass by reference"规则?
- 将std与特征库中的Vectorxd一起使用