From f23dc5b971d1c11bc0fcb7068788a30e4bd7cbf1 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Thu, 3 Dec 2020 14:32:45 -0800 Subject: Revert "Add log2() operator to Eigen" This reverts commit 4d91519a9be061da5d300079fca17dd0b9328050. --- Eigen/src/Core/arch/Default/BFloat16.h | 3 -- .../Core/arch/Default/GenericPacketMathFunctions.h | 63 ++++------------------ .../arch/Default/GenericPacketMathFunctionsFwd.h | 12 ----- Eigen/src/Core/arch/Default/Half.h | 4 -- 4 files changed, 11 insertions(+), 71 deletions(-) (limited to 'Eigen/src/Core/arch/Default') diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h index 616dcf667..351f451a3 100644 --- a/Eigen/src/Core/arch/Default/BFloat16.h +++ b/Eigen/src/Core/arch/Default/BFloat16.h @@ -512,9 +512,6 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log1p(const bfloat16& a) { EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log10(const bfloat16& a) { return bfloat16(::log10f(float(a))); } -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log2(const bfloat16& a) { - return bfloat16(static_cast(M_LOG2E) * ::logf(float(a))); -} EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sqrt(const bfloat16& a) { return bfloat16(::sqrtf(float(a))); } diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index c6bb89b05..60db2e12f 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -59,16 +59,16 @@ pldexp_double(Packet a, Packet exponent) return pmul(a, preinterpret(plogical_shift_left<52>(ei))); } -// Natural or base 2 logarithm. +// Natural logarithm // Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) // and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can // be easily approximated by a polynomial centered on m=1 for stability. // TODO(gonnet): Further reduce the interval allowing for lower-degree // polynomial interpolants -> ... -> profit! -template +template EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet plog_impl_float(const Packet _x) +Packet plog_float(const Packet _x) { Packet x = _x; @@ -131,13 +131,8 @@ Packet plog_impl_float(const Packet _x) x = padd(x, y); // Add the logarithm of the exponent back to the result of the interpolation. - if (base2) { - const Packet cst_log2e = pset1(static_cast(M_LOG2E)); - x = pmadd(x, cst_log2e, e); - } else { - const Packet cst_ln2 = pset1(static_cast(M_LN2)); - x = pmadd(e, cst_ln2, x); - } + const Packet cst_ln2 = pset1(M_LN2); + x = pmadd(e, cst_ln2, x); Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x)); Packet iszero_mask = pcmp_eq(_x,pzero(_x)); @@ -150,23 +145,8 @@ Packet plog_impl_float(const Packet _x) por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask)); } -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog_float(const Packet _x) -{ - return plog_impl_float(_x); -} - -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog2_float(const Packet _x) -{ - return plog_impl_float(_x); -} -/* Returns the base e (2.718...) or base 2 logarithm of x. +/* Returns the base e (2.718...) logarithm of x. * The argument is separated into its exponent and fractional parts. * The logarithm of the fraction in the interval [sqrt(1/2), sqrt(2)], * is approximated by @@ -175,16 +155,16 @@ Packet plog2_float(const Packet _x) * * for more detail see: http://www.netlib.org/cephes/ */ -template +template EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED -Packet plog_impl_double(const Packet _x) +Packet plog_double(const Packet _x) { Packet x = _x; const Packet cst_1 = pset1(1.0); const Packet cst_neg_half = pset1(-0.5); - // The smallest non denormalized double. + // The smallest non denormalized float number. const Packet cst_min_norm_pos = pset1frombits( static_cast(0x0010000000000000ull)); const Packet cst_minus_inf = pset1frombits( static_cast(0xfff0000000000000ull)); const Packet cst_pos_inf = pset1frombits( static_cast(0x7ff0000000000000ull)); @@ -252,13 +232,8 @@ Packet plog_impl_double(const Packet _x) x = padd(x, y); // Add the logarithm of the exponent back to the result of the interpolation. - if (base2) { - const Packet cst_log2e = pset1(M_LOG2E); - x = pmadd(x, cst_log2e, e); - } else { - const Packet cst_ln2 = pset1(M_LN2); - x = pmadd(e, cst_ln2, x); - } + const Packet cst_ln2 = pset1(M_LN2); + x = pmadd(e, cst_ln2, x); Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x)); Packet iszero_mask = pcmp_eq(_x,pzero(_x)); @@ -271,22 +246,6 @@ Packet plog_impl_double(const Packet _x) por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask)); } -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog_double(const Packet _x) -{ - return plog_impl_double(_x); -} - -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog2_double(const Packet _x) -{ - return plog_impl_double(_x); -} - /** \internal \returns log(1 + x) computed using W. Kahan's formula. See: http://www.plunk.org/~hatch/rightway.php */ diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h index b0f0b78fc..0e02a1b20 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h @@ -32,24 +32,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet plog_float(const Packet _x); -/** \internal \returns log2(x) for single precision float */ -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog2_float(const Packet _x); - /** \internal \returns log(x) for single precision float */ template EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet plog_double(const Packet _x); -/** \internal \returns log2(x) for single precision float */ -template -EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS -EIGEN_UNUSED -Packet plog2_double(const Packet _x); - /** \internal \returns log(1 + x) */ template Packet generic_plog1p(const Packet& x); diff --git a/Eigen/src/Core/arch/Default/Half.h b/Eigen/src/Core/arch/Default/Half.h index db85f4edf..7029c500d 100644 --- a/Eigen/src/Core/arch/Default/Half.h +++ b/Eigen/src/Core/arch/Default/Half.h @@ -622,10 +622,6 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(const half& a) { EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) { return half(::log10f(float(a))); } -EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(const half& a) { - return half(static_cast(M_LOG2E) * ::logf(float(a))); -} - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) { #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \ defined(EIGEN_HIP_DEVICE_COMPILE) -- cgit v1.2.3