10000 BUILD: convert HAVE_ macros to BLOCK_, cleanup · numpy/numpy@d1cbf3f · GitHub
[go: up one dir, main page]

Skip to content

Commit d1cbf3f

Browse files
committed
BUILD: convert HAVE_ macros to BLOCK_, cleanup
1 parent b6d52fc commit d1cbf3f

File tree

4 files changed

+98
-81
lines changed

4 files changed

+98
-81
lines changed

numpy/core/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ 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)
193192
check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"])
194193
check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"])
195194

numpy/core/setup_common.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,31 @@ def set_sig(sig):
127127
"expm1", "log1p", "acosh", "asinh", "atanh",
128128
"rint", "trunc", "exp2",
129129
"copysign", "nextafter", "strtoll", "strtoull", "cbrt",
130+
"log2", "pow", "hypot", "atan2",
130131
]
131132

132-
OPTIONAL_STDFUNCS_BASE = [
133-
# cygwin
134-
"log2",
135-
# macos for powl
136-
"pow",
137-
# 32-bit windows
138-
"hypot",
139-
# 32-bit mingw, visual studio 2015
140-
"atan2",
141-
]
142-
143-
OPTIONAL_STDFUNCS = OPTIONAL_STDFUNCS_BASE[:]
144-
OPTIONAL_STDFUNCS += [f + 'f' for f in OPTIONAL_STDFUNCS_BASE]
145-
OPTIONAL_STDFUNCS += [f + 'l' for f in OPTIONAL_STDFUNCS_BASE]
146-
147133
OPTIONAL_LOCALE_FUNCS = ["strtold_l"]
148134
OPTIONAL_FILE_FUNCS = ["ftello", "fseeko", "fallocate"]
149135
OPTIONAL_MISC_FUNCS = ["backtrace", "madvise"]
150136

137+
# variable attributes tested via "int %s a" % attribute
138+
OPTIONAL_VARIABLE_ATTRIBUTES = ["__thread", "__declspec(thread)"]
139+
140+
# Subset of OPTIONAL_*_FUNCS which may already have HAVE_* defined by Python.h
141+
OPTIONAL_FUNCS_MAYBE = [
142+
"ftello", "fseeko"
143+
]
144+
145+
# TODO: make these mandatory and use BLOCK_ macros rather than HAVE_ macros
146+
# in npy_config.h and throughout the code
147+
C99_COMPLEX_TYPES = [
148+
'complex double', 'complex float', 'complex long double'
149+
]
150+
C99_COMPLEX_FUNCS = [
151+
"cabs", "cacos", "cacosh", "carg", "casin", "casinh", "catan",
152+
"catanh", "ccos", "ccosh", "cexp", "cimag", "clog", "conj", "cpow",
153+
"cproj", "creal", "csin", "csinh", "csqrt", "ctan", "ctanh"
154+
]
151155

152156
OPTIONAL_HEADERS = [
153157
# sse headers only enabled automatically on amd64/x32 builds
@@ -238,23 +242,6 @@ def set_sig(sig):
238242
'immintrin.h'),
239243
]
240244

241-
# variable attributes tested via "int %s a" % attribute
242-
OPTIONAL_VARIABLE_ATTRIBUTES = ["__thread", "__declspec(thread)"]
243-
244-
# Subset of OPTIONAL_*_FUNCS which may already have HAVE_* defined by Python.h
245-
OPTIONAL_FUNCS_MAYBE = [
246-
"ftello", "fseeko"
247-
]
248-
249-
C99_COMPLEX_TYPES = [
250-
'complex double', 'complex float', 'complex long double'
251-
]
252-
C99_COMPLEX_FUNCS = [
253-
"cabs", "cacos", "cacosh", "carg", "casin", "casinh", "catan",
254-
"catanh", "ccos", "ccosh", "cexp", "cimag", "clog", "conj", "cpow",
255-
"cproj", "creal", "csin", "csinh", "csqrt", "ctan", "ctanh"
256-
]
257-
258245
def fname2def(name):
259246
return "HAVE_%s" % name.upper()
260247

numpy/core/src/common/npy_config.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
/* Disable broken functions on z/OS */
1212
#if defined (__MVS__)
1313

14-
#undef HAVE_POWF
15-
#undef HAVE_EXPF
14+
#define BLOCK_POWF
15+
#define BLOCK_EXPF
1616
#undef HAVE___THREAD
1717

1818
#endif
1919

2020
/* Disable broken MS math functions */
2121
#if defined(__MINGW32_VERSION)
2222

23-
#undef HAVE_ATAN2
24-
#undef HAVE_ATAN2F
25-
#undef HAVE_ATAN2L
23+
#define BLOCK_ATAN2
24+
#define BLOCK_ATAN2F
25+
#define BLOCK_ATAN2L
2626

27-
#undef HAVE_HYPOT
28-
#undef HAVE_HYPOTF
29-
#undef HAVE_HYPOTL
27+
#define BLOCK_HYPOT
28+
#define BLOCK_HYPOTF
29+
#define BLOCK_HYPOTL
3030

3131
#endif
3232

@@ -66,23 +66,23 @@
6666
#undef HAVE_CABSF
6767
#undef HAVE_CABSL
6868

69-
#undef HAVE_HYPOT
70-
#undef HAVE_HYPOTF
71-
#undef HAVE_HYPOTL
69+
#define BLOCK_HYPOT
70+
#define BLOCK_HYPOTF
71+
#define BLOCK_HYPOTL
7272

7373
#endif
7474

7575

7676
/* Intel C for Windows uses POW for 64 bits longdouble*/
7777
#if defined(_MSC_VER) && defined(__INTEL_COMPILER)
78-
#if defined(HAVE_POWL) && (NPY_SIZEOF_LONGDOUBLE == 8)
79-
#undef HAVE_POWL
78+
#if NPY_SIZEOF_LONGDOUBLE == 8
79+
#define BLOCK_POWL
8080
#endif
8181
#endif /* defined(_MSC_VER) && defined(__INTEL_COMPILER) */
8282

8383
/* powl gives zero division warning on OS X, see gh-8307 */
84-
#if defined(HAVE_POWL) && defined(NPY_OS_DARWIN)
85-
#undef HAVE_POWL
84+
#if defined(NPY_OS_DARWIN)
85+
#define BLOCK_POWL
8686
#endif
8787

8888
#ifdef __CYGWIN__
@@ -119,7 +119,7 @@
119119
#undef HAVE_CACOS
120120

121121
/* log2(exp2(i)) off by a few eps */
122-
#undef HAVE_LOG2
122+
#define BLOCK_LOG2
123123

124124
/* np.power(..., dtype=np.complex256) doesn't report overflow */
125125
#undef HAVE_CPOWL

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

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,33 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul
8383

8484
/*
8585
*****************************************************************************
86-
** BASIC MATH FUNCTIONS **
86+
** BLOCKLIST-ABLE BASIC MATH FUNCTIONS **
8787
*****************************************************************************
8888
*/
8989

90+
/* The double variant for these functions are never blocked */
91+
92+
NPY_INPLACE double npy_exp(double x){
93+
return exp(x);
94+
}
95+
96+
NPY_INPLACE double npy_pow(double x, double y)
97+
{
98+
return pow(x, y);
99+
}
100+
101+
NPY_INPLACE double npy_sqrt(double x)
102+
{
103+
return sqrt(x);
104+
}
105+
106+
NPY_INPLACE double npy_modf(double x, double *iptr)
107+
{
108+
return modf(x, iptr);
109+
}
110+
111+
/* The following functions can be blocked, even for doubles */
112+
90113
/* Original code by Konrad Hinsen. */
91114
/* Taken from FreeBSD mlib, adapted for numpy
92115
*
@@ -96,7 +119,7 @@ static const npy_uint64 MAGIC64[] = {0x5555555555555555ull, 0x3333333333333333ul
96119
*/
97120
NPY_INPLACE double npy_log2(double x)
98121
{
99-
#ifdef HAVE_LOG2
122+
#ifndef BLOCK_LOG2
100123
return log2(x);
101124
#else
102125
if (!npy_isfinite(x) || x <= 0.) {
@@ -136,7 +159,7 @@ NPY_INPLACE double npy_log2(double x)
136159
#define NPY_DBL_EPSILON 1.2246467991473531772E-16
137160
NPY_INPLACE double npy_atan2(double y, double x)
138161
{
139-
#ifdef HAVE_ATAN2
162+
#ifndef BLOCK_ATAN2
140163
return atan2(y, x);
141164
#else
142165
npy_int32 k, m, iy, ix, hx, hy;
@@ -220,7 +243,7 @@ NPY_INPLACE double npy_atan2(double y, double x)
220243

221244
NPY_INPLACE double npy_hypot(double x, double y)
222245
{
223-
#ifdef HAVE_HYPOT
246+
#ifndef BLOCK_HYPOT
224247
return hypot(x, y);
225248
#else
226249
double yx;
@@ -296,12 +319,10 @@ NPY_INPLACE double npy_hypot(double x, double y)
296319
#define WORKAROUND_APPLE_TRIG_BUG 0
297320
#endif
298321

299-
/* mandatory C99 functions */
300-
301322
/**begin repeat1
302-
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
303-
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2#
304-
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*21#
323+
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,log10,
324+
* log,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2#
325+
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*19#
305326
*/
306327
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
307328
{
@@ -329,12 +350,6 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
329350
}
330351
/**end repeat1**/
331352

332-
333-
NPY_INPLACE @type@ npy_modf@c@(@type@ x, @type@ *iptr)
334-
{
335-
return NPY__FP_SFX(modf)(x, iptr);
336-
}
337-
338353
NPY_INPLACE @type@ npy_ldexp@c@(@type@ x, int exp)
339354
{
340355
return NPY__FP_SFX(ldexp)(x, exp);
@@ -352,13 +367,13 @@ NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
352367

353368
/**end repeat**/
354369

355-
/* Optional C99 functions */
370+
/* Blocklist-able C99 functions */
356371

357372
/**begin repeat
358-
* #type = npy_longdouble, npy_float#
359-
* #TYPE = LONGDOUBLE, FLOAT#
360-
* #c = l,f#
361-
* #C = L,F#
373+
* #type = npy_float,npy_longdouble#
374+
* #TYPE = FLOAT,LONGDOUBLE#
375+
* #c = f,l#
376+
* #C = F,L#
362377
*/
363378
#undef NPY__FP_SFX
364379
#if NPY_SIZEOF_@TYPE@ == NPY_SIZEOF_DOUBLE
@@ -368,21 +383,21 @@ NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
368383
#endif
369384

370385
/**begin repeat1
371-
* #kind = log2#
372-
* #KIND = LOG2#
386+
* #kind = exp,log2,sqrt#
387+
* #KIND = EXP,LOG2,SQRT#
373388
*/
374389

375390
#ifdef @kind@@c@
376391
#undef @kind@@c@
377392
#endif
378-
#ifndef HAVE_@KIND@@C@
393+
#ifdef BLOCK_@KIND@@C@
379394
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
380395
{
381396
return (@type@) npy_@kind@((double)x);
382397
}
383398
#endif
384399

385-
#ifdef HAVE_@KIND@@C@
400+
#ifndef BLOCK_@KIND@@C@
386401
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
387402
{
388403
return NPY__FP_SFX(@kind@)(x);
@@ -399,20 +414,42 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
399414
#ifdef @kind@@c@
400415
#undef @kind@@c@
401416
#endif
402-
#ifndef HAVE_@KIND@@C@
417+
#ifdef BLOCK_@KIND@@C@
403418
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
404419
{
405420
return (@type@) npy_@kind@((double)x, (double) y);
406421
}
407422
#endif
408423

409-
#ifdef HAVE_@KIND@@C@
424+
#ifndef BLOCK_@KIND@@C@
410425
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
411426
{
412427
return NPY__FP_SFX(@kind@)(x, y);
413428
}
414429
#endif
415430
/**end repeat1**/
431+
432+
#ifdef modf@c@
433+
#undef modf@c@
434+
#endif
435+
#ifdef BLOCK_MODF@C@
436+
NPY_INPLACE @type@ npy_modf@c@(@type@ x, @type@ *iptr)
437+
{
438+
double niptr;
439+
double y = npy_modf((double)x, &niptr);
440+
*iptr = (@type@) niptr;
441+
return (@type@) y;
442+
}
443+
#endif
444+
445+
#ifndef BLOCK_MODF@C@
446+
NPY_INPLACE @type@ npy_modf@c@(@type@ x, @type@ *iptr)
447+
{
448+
return NPY__FP_SFX(modf)(x, iptr);
449+
}
450+
#endif
451+
452+
416453
/**end repeat**/
417454

418455

@@ -753,9 +790,3 @@ npy_popcount@c@(npy_@type@ a)
753790
}
754791
/**end repeat**/
755792

756-
/* XXX: will moving this to a define break anything? */
757-
758-
NPY_INPLACE double npy_pow(double x, double y)
759-
{
760-
return pow(x, y);
761-
}

0 commit comments

Comments
 (0)
0