Skip to content

Commit c35cb18

Browse files
committed
restore HAVE_LOG2 for cygwin blocklistingw
1 parent aceba28 commit c35cb18

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

numpy/core/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def check_funcs(funcs_name, headers=["feature_detection_math.h"]):
189189
if config.check_decl(fname2def(f), headers=["Python.h"]):
190190
OPTIONAL_FILE_FUNCS.remove(f)
191191

192+
check_funcs(OPTIONAL_STDFUNCS)
192193
check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"])
193194
check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"])
194195

numpy/core/setup_common.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,16 @@ def set_sig(sig):
122122
# Mandatory functions: if not found, fail the build
123123
MANDATORY_FUNCS = ["sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs",
124124
"floor", "ceil", "sqrt", "log10", "log", "exp", "asin",
125-
"acos", "atan", "fmod", 'modf', 'frexp', 'ldexp']
126-
127-
# Some of these are C99 functions.
128-
MANDATORY_FUNCS += ["expm1", "log1p", "acosh", "asinh", "atanh",
129-
"rint", "trunc", "exp2", "log2", "hypot", "atan2", "pow",
125+
"acos", "atan", "fmod", 'modf', 'frexp', 'ldexp',
126+
"expm1", "log1p", "acosh", "asinh", "atanh",
127+
"rint", "trunc", "exp2", "hypot", "atan2", "pow",
130128
"copysign", "nextafter", "strtoll", "strtoull", "cbrt"]
131129

130+
OPTIONAL_STDFUNCS = [
131+
# cygwin
132+
"log2",
133+
]
134+
132135
OPTIONAL_LOCALE_FUNCS = ["strtold_l"]
133136
OPTIONAL_FILE_FUNCS = ["ftello", "fseeko", "fallocate"]
134137
OPTIONAL_MISC_FUNCS = ["backtrace", "madvise"]

numpy/core/src/npymath/npy_math_internal.h.src

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,41 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul
9494
* classification instead of calling npy_isinf/npy_isnan: we should have some
9595
* macros for this, though, instead of doing it manually
9696
*/
97+
#ifndef HAVE_LOG2
98+
NPY_INPLACE double npy_log2(double x)
99+
{
100+
#ifdef HAVE_FREXP
101+
if (!npy_isfinite(x) || x <= 0.) {
102+
/* special value result */
103+
return npy_log(x);
104+
}
105+
else {
106+
/*
107+
* fallback implementation copied from python3.4 math.log2
108+
* provides int(log(2**i)) == i for i 1-64 in default rounding mode.
109+
*
110+
* We want log2(m * 2**e) == log(m) / log(2) + e. Care is needed when
111+
* x is just greater than 1.0: in that case e is 1, log(m) is negative,
112+
* and we get significant cancellation error from the addition of
113+
* log(m) / log(2) to e. The slight rewrite of the expression below
114+
* avoids this problem.
115+
*/
116+
int e;
117+
double m = frexp(x, &e);
118+
if (x >= 1.0) {
119+
return log(2.0 * m) / log(2.0) + (e - 1);
120+
}
121+
else {
122+
return log(m) / log(2.0) + e;
123+
}
124+
}
125+
#else
126+
/* does not provide int(log(2**i)) == i */
127+
return NPY_LOG2E * npy_log(x);
128+
#endif
129+
}
130+
#endif
131+
97132
/*
98133
*
99134
* sin, cos, tan
@@ -140,10 +175,12 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul
140175
#define WORKAROUND_APPLE_TRIG_BUG 0
141176
#endif
142177

178+
/* mandatory C99 functions */
179+
143180
/**begin repeat1
144181
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
145-
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
146-
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22#
182+
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2#
183+
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*21#
147184
*/
148185
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
149186
{
@@ -155,6 +192,19 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
155192
return NPY__FP_SFX(@kind@)(x);
156193
}
157194

195+
/**end repeat1**/
196+
/* Optional C99 functions */
197+
/**begin repeat1
198+
* #kind = log2#
199+
* #KIND = LOG2#
200+
*/
201+
#ifdef HAVE_@KIND@@C@
202+
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
203+
{
204+
return NPY__FP_SFX(@kind@)(x);
205+
}
206+
#endif
207+
158208
/**end repeat1**/
159209

160210
#undef WORKAROUND_APPLE_TRIG_BUG

0 commit comments

Comments
 (0)