Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50d6720

Browse files
committed
ENH: evaluate c99 complex funcs at build time
For all of the C99 complex function excepting the creal, cimag, cabs and carg (which are either trivial or defined by a C89 function) we now run a set of build time tests to evaluate if we want to use the system version of these functions or our own. These tests involve all of the special values for these functions defined in Annxex G of the C99 standard as well as any tests that were existing in the numpy test suite. These tests do not consider the sign of NAN.
1 parent 2d33f7c commit 50d6720

3 files changed

Lines changed: 1616 additions & 3 deletions

File tree

numpy/core/setup.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,29 @@ def check_prec(prec):
220220
else:
221221
priv.extend([(fname2def(f), 1) for f in flist])
222222

223+
flist = [f + prec for f in C99_COMPLEX_FUNCS_CHECKED]
224+
decl = dict([(f, True) for f in flist])
225+
exists = []
226+
if not config.check_funcs_once(flist, call=decl, decl=decl,
227+
libraries=mathlibs):
228+
for f in C99_COMPLEX_FUNCS_CHECKED:
229+
if config.check_func(f + prec, call=True, decl=True,
230+
libraries=mathlibs):
231+
exists.append(f)
232+
else:
233+
exists.extend(C99_COMPLEX_FUNCS_CHECKED)
234+
235+
if len(exists) > 0:
236+
fp = open('./numpy/core/test_c99complex.c', 'r')
237+
obody = fp.read()
238+
fp.close()
239+
precname = {'f':'FLOAT', '':'DOUBLE', 'l':'LONGDOUBLE'}[prec]
240+
for f in exists:
241+
print("ERIC1")
242+
body = obody.replace('PYTESTPRECISION', precname).replace('PYTESTFUNC', f.upper())
243+
if config.try_run(body, libraries=mathlibs):
244+
priv.append((fname2def(f + prec), 1))
245+
223246
check_prec('')
224247
check_prec('f')
225248
check_prec('l')

numpy/core/setup_common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ def check_api_version(apiversion, codegen_dir):
143143

144144
C99_COMPLEX_TYPES = ['complex double', 'complex float', 'complex long double']
145145

146-
C99_COMPLEX_FUNCS = ['creal', 'cimag', 'cabs', 'carg', 'cexp', 'clog', 'csqrt',
147-
'cpow', 'ccos', 'csin', 'ctan', 'ccosh', 'csinh', 'ctanh',
148-
'cacos', 'casin', 'catan', 'cacosh', 'casinh', 'catanh']
146+
C99_COMPLEX_FUNCS = ['creal', 'cimag', 'cabs', 'carg']
147+
C99_COMPLEX_FUNCS_CHECKED = ['cacos', 'casin', 'catan', 'cacosh', 'casinh',
148+
'catanh', 'ccos', 'csin', 'ctan', 'ccosh', 'csinh',
149+
'ctanh', 'cexp', 'clog', 'cpow', 'csqrt']
149150

150151
def fname2def(name):
151152
return "HAVE_%s" % name.upper()

0 commit comments

Comments
 (0)