diff options
author | Srinivas Vasudevan <srvasude@google.com> | 2019-08-12 19:26:29 -0400 |
---|---|---|
committer | Srinivas Vasudevan <srvasude@google.com> | 2019-08-12 19:26:29 -0400 |
commit | e38dd48a27b59b59a924b66a9486c3c2856acdf9 (patch) | |
tree | dbf29396db64c008ce982a4e3fe48c9ca53ff061 /Eigen | |
parent | f59bed7a133322955dac03f3654def706aff3ba6 (diff) |
PR 681: Add ndtri function, the inverse of the normal distribution function.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/GenericPacketMath.h | 21 | ||||
-rw-r--r-- | Eigen/src/Core/GlobalFunctions.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/arch/AVX/PacketMath.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/arch/AVX512/PacketMath.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h | 55 | ||||
-rw-r--r-- | Eigen/src/Core/arch/GPU/PacketMath.h | 2 | ||||
-rwxr-xr-x | Eigen/src/Core/arch/SSE/PacketMath.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/arch/SYCL/InteropHeaders.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/util/ForwardDeclarations.h | 1 | ||||
-rw-r--r-- | Eigen/src/plugins/ArrayCwiseUnaryOps.h | 28 |
10 files changed, 103 insertions, 9 deletions
diff --git a/Eigen/src/Core/GenericPacketMath.h b/Eigen/src/Core/GenericPacketMath.h index 6ab38994f..651e3f7b3 100644 --- a/Eigen/src/Core/GenericPacketMath.h +++ b/Eigen/src/Core/GenericPacketMath.h @@ -83,6 +83,7 @@ struct default_packet_traits HasPolygamma = 0, HasErf = 0, HasErfc = 0, + HasNdtri = 0, HasI0e = 0, HasI1e = 0, HasIGamma = 0, @@ -257,12 +258,32 @@ pldexp(const Packet &a, const Packet &exponent) { return std::ldexp(a,exponent); template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pzero(const Packet& a) { return pxor(a,a); } +template<> EIGEN_DEVICE_FUNC inline float pzero<float>(const float& a) { + EIGEN_UNUSED_VARIABLE(a); + return 0.; +} + +template<> EIGEN_DEVICE_FUNC inline double pzero<double>(const double& a) { + EIGEN_UNUSED_VARIABLE(a); + return 0.; +} + /** \internal \returns bits of \a or \b according to the input bit mask \a mask */ template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pselect(const Packet& mask, const Packet& a, const Packet& b) { return por(pand(a,mask),pandnot(b,mask)); } +template<> EIGEN_DEVICE_FUNC inline float pselect<float>( + const float& mask, const float& a, const float&b) { + return mask == 0 ? b : a; +} + +template<> EIGEN_DEVICE_FUNC inline double pselect<double>( + const double& mask, const double& a, const double& b) { + return mask == 0 ? b : a; +} + /** \internal \returns a <= b as a bit mask */ template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pcmp_le(const Packet& a, const Packet& b) { return a<=b ? ptrue(a) : pzero(a); } diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 71377cee5..7f132bdd0 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -76,6 +76,7 @@ namespace Eigen EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op,complement error function,\sa ArrayBase::erfc) + EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ndtri,scalar_ndtri_op,inverse normal distribution function,\sa ArrayBase::ndtri) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op,exponential,\sa ArrayBase::exp) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(expm1,scalar_expm1_op,exponential of a value minus 1,\sa ArrayBase::expm1) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op,natural logarithm,\sa Eigen::log10 DOXCOMMA ArrayBase::log) diff --git a/Eigen/src/Core/arch/AVX/PacketMath.h b/Eigen/src/Core/arch/AVX/PacketMath.h index 020f6c276..e3363d006 100644 --- a/Eigen/src/Core/arch/AVX/PacketMath.h +++ b/Eigen/src/Core/arch/AVX/PacketMath.h @@ -72,6 +72,7 @@ template<> struct packet_traits<float> : default_packet_traits HasLog1p = 1, HasExpm1 = 1, HasExp = 1, + HasNdtri = 1, HasSqrt = 1, HasRsqrt = 1, HasTanh = EIGEN_FAST_MATH, diff --git a/Eigen/src/Core/arch/AVX512/PacketMath.h b/Eigen/src/Core/arch/AVX512/PacketMath.h index e37855693..11c8dae02 100644 --- a/Eigen/src/Core/arch/AVX512/PacketMath.h +++ b/Eigen/src/Core/arch/AVX512/PacketMath.h @@ -97,6 +97,7 @@ template<> struct packet_traits<float> : default_packet_traits HasLog = 1, HasLog1p = 1, HasExpm1 = 1, + HasNdtri = 1, #endif HasExp = 1, HasSqrt = EIGEN_FAST_MATH, diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 0fc673e12..13351d5ec 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -512,5 +512,60 @@ Packet pcos_float(const Packet& x) return psincos_float<false>(x); } +/* polevl (modified for Eigen) + * + * Evaluate polynomial + * + * + * + * SYNOPSIS: + * + * int N; + * Scalar x, y, coef[N+1]; + * + * y = polevl<decltype(x), N>( x, coef); + * + * + * + * DESCRIPTION: + * + * Evaluates polynomial of degree N: + * + * 2 N + * y = C + C x + C x +...+ C x + * 0 1 2 N + * + * Coefficients are stored in reverse order: + * + * coef[0] = C , ..., coef[N] = C . + * N 0 + * + * The function p1evl() assumes that coef[N] = 1.0 and is + * omitted from the array. Its calling arguments are + * otherwise the same as polevl(). + * + * + * The Eigen implementation is templatized. For best speed, store + * coef as a const array (constexpr), e.g. + * + * const double coef[] = {1.0, 2.0, 3.0, ...}; + * + */ +template <typename Packet, int N> +struct ppolevl { + static EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) { + EIGEN_STATIC_ASSERT((N > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); + return pmadd(ppolevl<Packet, N-1>::run(x, coeff), x, pset1<Packet>(coeff[N])); + } +}; + +template <typename Packet> +struct ppolevl<Packet, 0> { + static EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) { + EIGEN_UNUSED_VARIABLE(x); + return pset1<Packet>(coeff[0]); + } +}; + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/arch/GPU/PacketMath.h b/Eigen/src/Core/arch/GPU/PacketMath.h index d1df26e57..bdbaa5362 100644 --- a/Eigen/src/Core/arch/GPU/PacketMath.h +++ b/Eigen/src/Core/arch/GPU/PacketMath.h @@ -44,6 +44,7 @@ template<> struct packet_traits<float> : default_packet_traits HasPolygamma = 1, HasErf = 1, HasErfc = 1, + HasNdtri = 1, HasI0e = 1, HasI1e = 1, HasIGamma = 1, @@ -78,6 +79,7 @@ template<> struct packet_traits<double> : default_packet_traits HasPolygamma = 1, HasErf = 1, HasErfc = 1, + HasNdtri = 1, HasI0e = 1, HasI1e = 1, HasIGamma = 1, diff --git a/Eigen/src/Core/arch/SSE/PacketMath.h b/Eigen/src/Core/arch/SSE/PacketMath.h index b59e2c602..61500c06d 100755 --- a/Eigen/src/Core/arch/SSE/PacketMath.h +++ b/Eigen/src/Core/arch/SSE/PacketMath.h @@ -112,6 +112,7 @@ template<> struct packet_traits<float> : default_packet_traits HasLog = 1, HasLog1p = 1, HasExpm1 = 1, + HasNdtri = 1, HasExp = 1, HasSqrt = 1, HasRsqrt = 1, diff --git a/Eigen/src/Core/arch/SYCL/InteropHeaders.h b/Eigen/src/Core/arch/SYCL/InteropHeaders.h index ef66fc7de..d76030419 100644 --- a/Eigen/src/Core/arch/SYCL/InteropHeaders.h +++ b/Eigen/src/Core/arch/SYCL/InteropHeaders.h @@ -54,6 +54,7 @@ struct sycl_packet_traits : default_packet_traits { HasPolygamma = 0, HasErf = 0, HasErfc = 0, + HasNdtri = 0, HasIGamma = 0, HasIGammac = 0, HasBetaInc = 0, diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 050d15e96..18889fcf4 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -214,6 +214,7 @@ template<typename Scalar> struct scalar_lgamma_op; template<typename Scalar> struct scalar_digamma_op; template<typename Scalar> struct scalar_erf_op; template<typename Scalar> struct scalar_erfc_op; +template<typename Scalar> struct scalar_ndtri_op; template<typename Scalar> struct scalar_igamma_op; template<typename Scalar> struct scalar_igammac_op; template<typename Scalar> struct scalar_zeta_op; diff --git a/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/Eigen/src/plugins/ArrayCwiseUnaryOps.h index 2f99ee0b2..4aef72d92 100644 --- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h +++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h @@ -536,14 +536,12 @@ typedef CwiseUnaryOp<internal::scalar_lgamma_op<Scalar>, const Derived> LgammaRe typedef CwiseUnaryOp<internal::scalar_digamma_op<Scalar>, const Derived> DigammaReturnType; typedef CwiseUnaryOp<internal::scalar_erf_op<Scalar>, const Derived> ErfReturnType; typedef CwiseUnaryOp<internal::scalar_erfc_op<Scalar>, const Derived> ErfcReturnType; +typedef CwiseUnaryOp<internal::scalar_ndtri_op<Scalar>, const Derived> NdtriReturnType; /** \cpp11 \returns an expression of the coefficient-wise ln(|gamma(*this)|). * * \specialfunctions_module * - * Example: \include Cwise_lgamma.cpp - * Output: \verbinclude Cwise_lgamma.out - * * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, * or float/double in non c++11 mode, the user has to provide implementations of lgamma(T) for any scalar * type T to be supported. @@ -579,9 +577,6 @@ digamma() const * * \specialfunctions_module * - * Example: \include Cwise_erf.cpp - * Output: \verbinclude Cwise_erf.out - * * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, * or float/double in non c++11 mode, the user has to provide implementations of erf(T) for any scalar * type T to be supported. @@ -600,9 +595,6 @@ erf() const * * \specialfunctions_module * - * Example: \include Cwise_erfc.cpp - * Output: \verbinclude Cwise_erfc.out - * * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, * or float/double in non c++11 mode, the user has to provide implementations of erfc(T) for any scalar * type T to be supported. @@ -615,3 +607,21 @@ erfc() const { return ErfcReturnType(derived()); } + +/** \cpp11 \returns an expression of the coefficient-wise Complementary error + * function of *this. + * + * \specialfunctions_module + * + * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types, + * or float/double in non c++11 mode, the user has to provide implementations of ndtri(T) for any scalar + * type T to be supported. + * + * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ndtri">Math functions</a>, erf() + */ +EIGEN_DEVICE_FUNC +inline const NdtriReturnType +ndtri() const +{ + return NdtriReturnType(derived()); +} |