diff options
author | mattip <matti.picus@gmail.com> | 2022-08-11 10:19:02 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2022-08-21 18:26:10 +0300 |
commit | c35cb18f3e20c3b072adfc2f1bed86e6ca89d172 (patch) | |
tree | 0726433fcc22563fe5e04e0435d0c714b2585988 /numpy/core | |
parent | aceba280d9484e5f7e66967bbf7c047aa6ded3fe (diff) | |
download | numpy-c35cb18f3e20c3b072adfc2f1bed86e6ca89d172.tar.gz |
restore HAVE_LOG2 for cygwin blocklistingw
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/setup.py | 1 | ||||
-rw-r--r-- | numpy/core/setup_common.py | 13 | ||||
-rw-r--r-- | numpy/core/src/npymath/npy_math_internal.h.src | 54 |
3 files changed, 61 insertions, 7 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 571d067e0..9fc7c2f29 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -189,6 +189,7 @@ def check_math_capabilities(config, ext, moredefs, mathlibs): if config.check_decl(fname2def(f), headers=["Python.h"]): OPTIONAL_FILE_FUNCS.remove(f) + check_funcs(OPTIONAL_STDFUNCS) check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"]) check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"]) diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index d618fac69..141b62e76 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -122,13 +122,16 @@ for file in [ # Mandatory functions: if not found, fail the build MANDATORY_FUNCS = ["sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs", "floor", "ceil", "sqrt", "log10", "log", "exp", "asin", - "acos", "atan", "fmod", 'modf', 'frexp', 'ldexp'] - -# Some of these are C99 functions. -MANDATORY_FUNCS += ["expm1", "log1p", "acosh", "asinh", "atanh", - "rint", "trunc", "exp2", "log2", "hypot", "atan2", "pow", + "acos", "atan", "fmod", 'modf', 'frexp', 'ldexp', + "expm1", "log1p", "acosh", "asinh", "atanh", + "rint", "trunc", "exp2", "hypot", "atan2", "pow", "copysign", "nextafter", "strtoll", "strtoull", "cbrt"] +OPTIONAL_STDFUNCS = [ + # cygwin + "log2", +] + OPTIONAL_LOCALE_FUNCS = ["strtold_l"] OPTIONAL_FILE_FUNCS = ["ftello", "fseeko", "fallocate"] OPTIONAL_MISC_FUNCS = ["backtrace", "madvise"] diff --git a/numpy/core/src/npymath/npy_math_internal.h.src b/numpy/core/src/npymath/npy_math_internal.h.src index 5d2f4f078..ab5576a0b 100644 --- a/numpy/core/src/npymath/npy_math_internal.h.src +++ b/numpy/core/src/npymath/npy_math_internal.h.src @@ -94,6 +94,41 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul * classification instead of calling npy_isinf/npy_isnan: we should have some * macros for this, though, instead of doing it manually */ +#ifndef HAVE_LOG2 +NPY_INPLACE double npy_log2(double x) +{ +#ifdef HAVE_FREXP + if (!npy_isfinite(x) || x <= 0.) { + /* special value result */ + return npy_log(x); + } + else { + /* + * fallback implementation copied from python3.4 math.log2 + * provides int(log(2**i)) == i for i 1-64 in default rounding mode. + * + * We want log2(m * 2**e) == log(m) / log(2) + e. Care is needed when + * x is just greater than 1.0: in that case e is 1, log(m) is negative, + * and we get significant cancellation error from the addition of + * log(m) / log(2) to e. The slight rewrite of the expression below + * avoids this problem. + */ + int e; + double m = frexp(x, &e); + if (x >= 1.0) { + return log(2.0 * m) / log(2.0) + (e - 1); + } + else { + return log(m) / log(2.0) + e; + } + } +#else + /* does not provide int(log(2**i)) == i */ + return NPY_LOG2E * npy_log(x); +#endif +} +#endif + /* * * sin, cos, tan @@ -140,10 +175,12 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul #define WORKAROUND_APPLE_TRIG_BUG 0 #endif +/* mandatory C99 functions */ + /**begin repeat1 * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, - * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# - * #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22# + * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2# + * #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*21# */ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x) { @@ -156,6 +193,19 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x) } /**end repeat1**/ +/* Optional C99 functions */ +/**begin repeat1 + * #kind = log2# + * #KIND = LOG2# + */ +#ifdef HAVE_@KIND@@C@ +NPY_INPLACE @type@ npy_@kind@@c@(@type@ x) +{ + return NPY__FP_SFX(@kind@)(x); +} +#endif + +/**end repeat1**/ #undef WORKAROUND_APPLE_TRIG_BUG |