Eigen::internal::generic_fast_erf< Scalar > Struct Template Reference

#include <SpecialFunctionsImpl.h>

Public Member Functions

EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T run (const T &x)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T run (const T &x)
 

Static Public Member Functions

template<typename T >
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T run (const T &x_in)
 

Member Function Documentation

◆ run() [1/3]

Returns
the error function of a (coeff-wise) This uses a 11/10-degree rational interpolantand is accurate to 3 ulp for normalized floats.

This implementation works on both scalars and SIMD "packets".

479  {
480  // The monomial coefficients of the numerator polynomial (odd).
481  constexpr float alpha[] = {2.123732201653183437883853912353515625e-06f, 2.861979592125862836837768554687500000e-04f,
482  3.658048342913389205932617187500000000e-03f, 5.243302136659622192382812500000000000e-02f,
483  1.874160766601562500000000000000000000e-01f, 1.128379106521606445312500000000000000e+00f};
484 
485  // The monomial coefficients of the denominator polynomial (even).
486  constexpr float beta[] = {3.89185734093189239501953125000e-05f, 1.14329601638019084930419921875e-03f,
487  1.47520881146192550659179687500e-02f, 1.12945675849914550781250000000e-01f,
488  4.99425798654556274414062500000e-01f, 1.0f};
489 
490  // Since the polynomials are odd/even, we need x^2.
491  // Since erf(4) == 1 in float, we clamp x^2 to 16 to avoid
492  // computing Inf/Inf below.
493  const T x2 = pmin(pset1<T>(16.0f), pmul(x, x));
494 
495  // Evaluate the numerator polynomial p.
497  p = pmul(x, p);
498 
499  // Evaluate the denominator polynomial p.
501  const T r = pdiv(p, q);
502 
503  // Clamp to [-1:1].
504  return pmax(pmin(r, pset1<T>(1.0f)), pset1<T>(-1.0f));
505 }
float * p
Definition: Tutorial_Map_using.cpp:9
RealScalar alpha
Definition: level1_cplx_impl.h:151
Scalar beta
Definition: level2_cplx_impl.h:36
EIGEN_DEVICE_FUNC Packet pdiv(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:368
EIGEN_DEVICE_FUNC Packet pmax(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:663
EIGEN_STRONG_INLINE Packet4cf pmul(const Packet4cf &a, const Packet4cf &b)
Definition: AVX/Complex.h:88
EIGEN_DEVICE_FUNC Packet pmin(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:649
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
EIGEN_DEVICE_FUNC const Scalar & x
Definition: SpecialFunctionsImpl.h:2024
Vector< double > x2(const Vector< double > &coord)
Cartesian coordinates centered at the point (1.5,1)
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:102
r
Definition: UniformPSDSelfTest.py:20
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet &x, const typename unpacket_traits< Packet >::type coeff[])
Definition: GenericPacketMathFunctions.h:86

References alpha, beta, p, Eigen::internal::pdiv(), Eigen::internal::pmax(), Eigen::internal::pmin(), Eigen::internal::pmul(), Eigen::numext::q, UniformPSDSelfTest::r, Eigen::internal::ppolevl< Packet, N >::run(), Eigen::numext::x, and Global_parameters::x2().

◆ run() [2/3]

509  {
510  T x2 = pmul(x, x);
511  T erf_small = pmul(x, erf_over_x_double_small(x2));
512 
513  // Return early if we don't need the more expensive approximation for any
514  // entry in a.
515  const T one = pset1<T>(1.0);
516  const T x_abs_gt_one_mask = pcmp_lt(one, x2);
517  if (!predux_any(x_abs_gt_one_mask)) return erf_small;
518 
519  // For |x| > 1, use erf(x) = 1 - erfc(x).
520  const T erf_large = psub(one, erfc_double_large(x, x2));
521  return pselect(x_abs_gt_one_mask, erf_large, erf_small);
522 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T erfc_double_large(const T &x, const T &x2)
Definition: SpecialFunctionsImpl.h:366
EIGEN_STRONG_INLINE bool predux_any(const Packet4f &x)
Definition: AltiVec/PacketMath.h:2751
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T erf_over_x_double_small(const T &x2)
Definition: SpecialFunctionsImpl.h:336
EIGEN_STRONG_INLINE Packet4i pcmp_lt(const Packet4i &a, const Packet4i &b)
Definition: AltiVec/PacketMath.h:1341
EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f &mask, const Packet4f &a, const Packet4f &b)
Definition: AltiVec/PacketMath.h:1474
EIGEN_DEVICE_FUNC Packet psub(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:337

References Eigen::internal::erf_over_x_double_small(), Eigen::internal::erfc_double_large(), Eigen::internal::pcmp_lt(), Eigen::internal::pmul(), Eigen::internal::predux_any(), Eigen::internal::pselect(), Eigen::internal::psub(), Eigen::numext::x, and Global_parameters::x2().

◆ run() [3/3]

template<typename Scalar >
template<typename T >
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T Eigen::internal::generic_fast_erf< Scalar >::run ( const T x_in)
static

The documentation for this struct was generated from the following file: