8000 Merge pull request #22090 from mattip/simplify-npymath · numpy/numpy@d8c09c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8c09c5

Browse files
authored
Merge pull request #22090 from mattip/simplify-npymath
MAINT: Simplify npymath
2 parents acdd0e3 + 25629dd commit d8c09c5

File tree

13 files changed

+217
-804
lines changed

13 files changed

+217
-804
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ stages:
114114
python3 -m pip install -v . && \
115115
python3 runtests.py -n --debug-info --mode=full -- -rsx --junitxml=junit/test-results.xml && \
116116
python3 tools/openblas_support.py --check_version"
117-
displayName: 'Run 32-bit manylinux2010 Docker Build / Tests'
117+
displayName: 'Run 32-bit manylinux2014 Docker Build / Tests'
118118
- task: PublishTestResults@2
119119
condition: succeededOrFailed()
120120
inputs:

numpy/core/include/numpy/npy_math.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include <numpy/npy_common.h>
55

66
#include <math.h>
7-
#ifdef __SUNPRO_CC
8-
#include <sunmath.h>
9-
#endif
107

118
/* By adding static inline specifiers to npy_math function definitions when
129
appropriate, compiler is given the opportunity to optimize */

numpy/core/setup.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def check_func(
145145
headers=headers,
146146
)
147147

148-
def check_funcs_once(funcs_name, headers=["feature_detection_math.h"]):
148+
def check_funcs_once(funcs_name, headers=["feature_detection_math.h"],
149+
add_to_moredefs=True):
149150
call = dict([(f, True) for f in funcs_name])
150151
call_args = dict([(f, FUNC_CALL_ARGS[f]) for f in funcs_name])
151152
st = config.check_funcs_once(
@@ -156,7 +157,7 @@ def check_funcs_once(funcs_name, headers=["feature_detection_math.h"]):
156157
call_args=call_args,
157158
headers=headers,
158159
)
159-
if st:
160+
if st and add_to_moredefs:
160161
moredefs.extend([(fname2def(f), 1) for f in funcs_name])
161162
return st
162163

@@ -173,7 +174,7 @@ def check_funcs(funcs_name, headers=["feature_detection_math.h" B421 ]):
173174
return 1
174175

175176
#use_msvc = config.check_decl("_MSC_VER")
176-
if not check_funcs_once(MANDATORY_FUNCS):
177+
if not check_funcs_once(MANDATORY_FUNCS, add_to_moredefs=False):
177178
raise SystemError("One of the required function to build numpy is not"
178179
" available (the list is %s)." % str(MANDATORY_FUNCS))
179180

@@ -184,20 +185,12 @@ def check_funcs(funcs_name, headers=["feature_detection_math.h"]):
184185
# config.h in the public namespace, so we have a clash for the common
185186
# functions we test. We remove every function tested by python's
186187
# autoconf, hoping their own test are correct
187-
for f in OPTIONAL_STDFUNCS_MAYBE:
188-
if config.check_decl(fname2def(f),
189-
headers=["Python.h", "math.h"]):
190-
if f in OPTIONAL_STDFUNCS:
191-
OPTIONAL_STDFUNCS.remove(f)
192-
else:
193-
OPTIONAL_FILE_FUNCS.remove(f)
188+
for f in OPTIONAL_FUNCS_MAYBE:
189+
if config.check_decl(fname2def(f), headers=["Python.h"]):
190+
OPTIONAL_FILE_FUNCS.remove(f)
194191

195-
196-
check_funcs(OPTIONAL_STDFUNCS)
197192
check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"])
198193
check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"])
199-
200-
201194

202195
for h in OPTIONAL_HEADERS:
203196
if config.check_func("", decl=False, call=False, headers=[h]):
@@ -249,10 +242,6 @@ def check_funcs(funcs_name, headers=["feature_detection_math.h"]):
249242
m = fn.replace("(", "_").replace(")", "_")
250243
moredefs.append((fname2def(m), 1))
251244

252-
# C99 functions: float and long double versions
253-
check_funcs(C99_FUNCS_SINGLE)
254-
check_funcs(C99_FUNCS_EXTENDED)
255-
256245
def check_complex(config, mathlibs):
257246
priv = []
258247
pub = []

numpy/core/setup_common.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,36 @@ def set_sig(sig):
120120
set_sig(line)
121121

122122
# Mandatory functions: if not found, fail the build
123-
MANDATORY_FUNCS = ["sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs",
124-
"floor", "ceil", "sqrt", "log10", "log", "exp", "asin",
125-
"acos", "atan", "fmod", 'modf', 'frexp', 'ldexp']
126-
127-
# Standard functions which may not be available and for which we have a
128-
# replacement implementation. Note that some of these are C99 functions.
129-
OPTIONAL_STDFUNCS = ["expm1", "log1p", "acosh", "asinh", "atanh",
130-
"rint", "trunc", "exp2", "log2", "hypot", "atan2", "pow",
131-
"copysign", "nextafter", "strtoll", "strtoull", "cbrt"]
123+
MANDATORY_FUNCS = [
124+
"sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs",
125+
"floor", "ceil", "sqrt", "log10", "log", "exp", "asin",
126+
"acos", "atan", "fmod", 'modf', 'frexp', 'ldexp',
127+
"expm1", "log1p", "acosh", "asinh", "atanh",
128+
"rint", "trunc", "exp2",
129+
"copysign", "nextafter", "strtoll", "strtoull", "cbrt",
130+
"log2", "pow", "hypot", "atan2",
131+
]
132132

133133
OPTIONAL_LOCALE_FUNCS = ["strtold_l"]
134134
OPTIONAL_FILE_FUNCS = ["ftello", "fseeko", "fallocate"]
135135
OPTIONAL_MISC_FUNCS = ["backtrace", "madvise"]
136136

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+
C99_COMPLEX_TYPES = [
146+
'complex double', 'complex float', 'complex long double'
147+
]
148+
C99_COMPLEX_FUNCS = [
149+
"cabs", "cacos", "cacosh", "carg", "casin", "casinh", "catan",
150+
"catanh", "ccos", "ccosh", "cexp", "cimag", "clog", "conj", "cpow",
151+
"cproj", "creal", "csin", "csinh", "csqrt", "ctan", "ctanh"
152+
]
137153

138154
OPTIONAL_HEADERS = [
139155
# sse headers only enabled automatically on amd64/x32 builds
@@ -224,34 +240,6 @@ def set_sig(sig):
224240
'immintrin.h'),
225241
]
226242

227-
# variable attributes tested via "int %s a" % attribute
228-
OPTIONAL_VARIABLE_ATTRIBUTES = ["__thread", "__declspec(thread)"]
229-
230-
# Subset of OPTIONAL_STDFUNCS which may already have HAVE_* defined by Python.h
231-
OPTIONAL_STDFUNCS_MAYBE = [
232-
"expm1", "log1p", "acosh", "atanh", "asinh", "hypot", "copysign",
233-
"ftello", "fseeko"
234-
]
235-
236-
# C99 functions: float and long double versions
237-
C99_FUNCS = [
238-
"sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs", "floor", "ceil",
239-
"rint", "trunc", "sqrt", "log10", "log", "log1p", "exp", "expm1",
240-
"asin", "acos", "atan", "asinh", "acosh", "atanh", "hypot", "atan2",
241-
"pow", "fmod", "modf", 'frexp', 'ldexp', "exp2", "log2", "copysign",
242-
"nextafter", "cbrt"
243-
]
244-
C99_FUNCS_SINGLE = [f + 'f' for f in C99_FUNCS]
245-
C99_FUNCS_EXTENDED = [f + 'l' for f in C99_FUNCS]
246-
C99_COMPLEX_TYPES = [
247-
'complex double', 'complex float', 'complex long double'
248-
]
249-
C99_COMPLEX_FUNCS = [
250-
"cabs", "cacos", "cacosh", "carg", "casin", "casinh", "catan",
251-
"catanh", "ccos", "ccosh", "cexp", "cimag", "clog", "conj", "cpow",
252-
"cproj", "creal", "csin", "csinh", "csqrt", "ctan", "ctanh"
253-
]
254-
255243
def fname2def(name):
256244
return "HAVE_%s" % name.upper()
257245

numpy/core/src/_simd/_simd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#include <Python.h>
1616
#include "numpy/npy_common.h"
17+
#include "npy_cpu_features.h"
18+
#include "npy_cpu_dispatch.h"
19+
#include "numpy/npy_cpu.h"
1720

1821
#ifndef NPY_DISABLE_OPTIMIZATION
1922
// autogenerated, required for CPU dispatch macros

numpy/core/src/common/npy_config.h

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,31 @@
22
#define NUMPY_CORE_SRC_COMMON_NPY_CONFIG_H_
33

44
#include "config.h"
5-
#include "npy_cpu_features.h"
6-
#include "npy_cpu_dispatch.h"
75
#include "numpy/numpyconfig.h"
8-
#include "numpy/npy_cpu.h"
6+
#include "numpy/utils.h"
97
#include "numpy/npy_os.h"
108

119
/* blocklist */
1210

13-
/* Disable broken Sun F438 Workshop Pro math functions */
14-
#ifdef __SUNPRO_C
15-
16-
#undef HAVE_ATAN2
17-
#undef HAVE_ATAN2F
18-
#undef HAVE_ATAN2L
19-
20-
#endif
21-
2211
/* Disable broken functions on z/OS */
2312
#if defined (__MVS__)
2413

25-
#undef HAVE_POWF
26-
#undef HAVE_EXPF
14+
#define NPY_BLOCK_POWF
15+
#define NPY_BLOCK_EXPF
2716
#undef HAVE___THREAD
2817

2918
#endif
3019

3120
/* Disable broken MS math functions */
3221
#if defined(__MINGW32_VERSION)
3322

34-
#undef HAVE_ATAN2
35-
#undef HAVE_ATAN2F
36-
#undef HAVE_ATAN2L
23+
#define NPY_BLOCK_ATAN2
24+
#define NPY_BLOCK_ATAN2F
25+
#define NPY_BLOCK_ATAN2L
3726

38-
#undef HAVE_HYPOT
39-
#undef HAVE_HYPOTF
40-
#undef HAVE_HYPOTL
27+
#define NPY_BLOCK_HYPOT
28+
#define NPY_BLOCK_HYPOTF
29+
#define NPY_BLOCK_HYPOTL
4130

4231
#endif
4332

@@ -77,23 +66,23 @@
7766
#undef HAVE_CABSF
7867
#undef HAVE_CABSL
7968

80-
#undef HAVE_HYPOT
81-
#undef HAVE_HYPOTF
82-
#undef HAVE_HYPOTL
69+
#define NPY_BLOCK_HYPOT
70+
#define NPY_BLOCK_HYPOTF
71+
#define NPY_BLOCK_HYPOTL
8372

8473
#endif
8574

8675

8776
/* Intel C for Windows uses POW for 64 bits longdouble*/
8877
#if defined(_MSC_VER) && defined(__INTEL_COMPILER)
89-
#if defined(HAVE_POWL) && (NPY_SIZEOF_LONGDOUBLE == 8)
90-
#undef HAVE_POWL
78+
#if NPY_SIZEOF_LONGDOUBLE == 8
79+
#define NPY_BLOCK_POWL
9180
#endif
9281
#endif /* defined(_MSC_VER) && defined(__INTEL_COMPILER) */
9382

9483
/* powl gives zero division warning on OS X, see gh-8307 */
95-
#if defined(HAVE_POWL) && defined(NPY_OS_DARWIN)
96-
#undef HAVE_POWL
84+
#if defined(NPY_OS_DARWIN)
85+
#define NPY_BLOCK_POWL
9786
#endif
9887

9988
#ifdef __CYGWIN__
@@ -130,7 +119,7 @@
130119
#undef HAVE_CACOS
131120

132121
/* log2(exp2(i)) off by a few eps */
133-
#undef HAVE_LOG2
122+
#define NPY_BLOCK_LOG2
134123

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

numpy/core/src/common/numpyos.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -770,27 +770,12 @@ NumPyOS_ascii_ftoLf(FILE *fp, long double *value)
770770
NPY_NO_EXPORT npy_longlong
771771
NumPyOS_strtoll(const char *str, char **endptr, int base)
772772
{
773-
#if defined HAVE_STRTOLL
774773
return strtoll(str, endptr, base);
775-
#elif defined _MSC_VER
776-
return _strtoi64(str, endptr, base);
777-
#else
778-
/* ok on 64 bit posix */
779-
return PyOS_strtol(str, endptr, base);
780-
#endif
781774
}
782775

783776
NPY_NO_EXPORT npy_ulonglong
784777
NumPyOS_strtoull(const char *str, char **endptr, int base)
785778
{
786-
#if defined HAVE_STRTOULL
787779
return strtoull(str, endptr, base);
788-
#elif defined _MSC_VER
789-
return _strtoui64(str, endptr, base);
790-
#else
791-
/* ok on 64 bit posix */
792-
return PyOS_strtoul(str, endptr, base);
793-
#endif
794780
}
795781

796-

numpy/core/src/multiarray/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <structmember.h>
55
#include "numpy/npy_common.h"
66
#include "numpy/ndarraytypes.h"
7+
#include "npy_cpu_features.h"
8+
#include "npy_cpu_dispatch.h"
9+
#include "numpy/npy_cpu.h"
10+
711
#include "npy_import.h"
812
#include <limits.h>
913

0 commit comments

Comments
 (0)
0