summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-12-27 14:53:54 -0700
committerGitHub <noreply@github.com>2017-12-27 14:53:54 -0700
commit0131a3b95461d38846e25c8d132f0323699a766d (patch)
tree7df8bf63ac3fbd72ab47ea27810fa9fc48c8128b
parent6c4b09259c04630d7bfaceb3ae7c67c9ea2e7386 (diff)
parent2adb9298e4bad5b961143293d9ba19dbd10a2786 (diff)
downloadnumpy-0131a3b95461d38846e25c8d132f0323699a766d.tar.gz
Merge pull request #10284 from eric-wieser/tidy-gen-math
MAINT/BUG: Tidy gen_umath
-rw-r--r--numpy/core/code_generators/generate_umath.py99
1 files changed, 51 insertions, 48 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 9287be095..9470e882a 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -789,7 +789,7 @@ defdict = {
docstrings.get('numpy.core.umath.divmod'),
None,
TD(intflt),
- TD(O, f='PyNumber_Divmod'),
+ # TD(O, f='PyNumber_Divmod'), # gh-9730
),
'hypot':
Ufunc(2, 1, Zero,
@@ -942,16 +942,42 @@ def make_arrays(funcdict):
k = 0
sub = 0
- if uf.nin > 1:
- assert uf.nin == 2
- thedict = chartotype2 # two inputs and one output
- else:
- thedict = chartotype1 # one input and one output
-
for t in uf.type_descriptions:
- if (t.func_data not in (None, FullTypeDescr) and
- not isinstance(t.func_data, FuncNameSuffix)):
+ if t.func_data is FullTypeDescr:
+ tname = english_upper(chartoname[t.type])
+ datalist.append('(void *)NULL')
+ funclist.append(
+ '%s_%s_%s_%s' % (tname, t.in_, t.out, name))
+ elif isinstance(t.func_data, FuncNameSuffix):
+ datalist.append('(void *)NULL')
+ tname = english_upper(chartoname[t.type])
+ funclist.append(
+ '%s_%s_%s' % (tname, name, t.func_data.suffix))
+ elif t.func_data is None:
+ datalist.append('(void *)NULL')
+ tname = english_upper(chartoname[t.type])
+ funclist.append('%s_%s' % (tname, name))
+ if t.simd is not None:
+ for vt in t.simd:
+ code2list.append(textwrap.dedent("""\
+ #ifdef HAVE_ATTRIBUTE_TARGET_{ISA}
+ if (NPY_CPU_SUPPORTS_{ISA}) {{
+ {fname}_functions[{idx}] = {type}_{fname}_{isa};
+ }}
+ #endif
+ """).format(
+ ISA=vt.upper(), isa=vt,
+ fname=name, type=tname, idx=k
+ ))
+ else:
funclist.append('NULL')
+ if (uf.nin, uf.nout) == (2, 1):
+ thedict = chartotype2
+ elif (uf.nin, uf.nout) == (1, 1):
+ thedict = chartotype1
+ else:
+ raise ValueError("Could not handle {}[{}]".format(name, t.type))
+
astype = ''
if not t.astype is None:
astype = '_As_%s' % thedict[t.astype]
@@ -972,29 +998,6 @@ def make_arrays(funcdict):
datalist.append('(void *)NULL')
#datalist.append('(void *)%s' % t.func_data)
sub += 1
- elif t.func_data is FullTypeDescr:
- tname = english_upper(chartoname[t.type])
- datalist.append('(void *)NULL')
- funclist.append(
- '%s_%s_%s_%s' % (tname, t.in_, t.out, name))
- elif isinstance(t.func_data, FuncNameSuffix):
- datalist.append('(void *)NULL')
- tname = english_upper(chartoname[t.type])
- funclist.append(
- '%s_%s_%s' % (tname, name, t.func_data.suffix))
- else:
- datalist.append('(void *)NULL')
- tname = english_upper(chartoname[t.type])
- funclist.append('%s_%s' % (tname, name))
- if t.simd is not None:
- for vt in t.simd:
- code2list.append("""\
-#ifdef HAVE_ATTRIBUTE_TARGET_{ISA}
-if (NPY_CPU_SUPPORTS_{ISA}) {{
- {fname}_functions[{idx}] = {type}_{fname}_{isa};
-}}
-#endif
-""".format(ISA=vt.upper(), isa=vt, fname=name, type=tname, idx=k))
for x in t.in_ + t.out:
siglist.append('NPY_%s' % (english_upper(chartoname[x]),))
@@ -1032,10 +1035,10 @@ def make_ufuncs(funcdict):
# string literal in C code. We split at endlines because textwrap.wrap
# do not play well with \n
docstring = '\\n\"\"'.join(docstring.split(r"\n"))
- mlist.append(\
-r"""f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,
- %d, %d, %s, "%s",
- "%s", 0);""" % (name, name, name,
+ mlist.append(textwrap.dedent("""\
+ f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,
+ %d, %d, %s, "%s",
+ "%s", 0);""") % (name, name, name,
len(uf.type_descriptions),
uf.nin, uf.nout,
uf.identity,
@@ -1054,23 +1057,23 @@ def make_code(funcdict, filename):
code3 = make_ufuncs(funcdict)
code2 = indent(code2, 4)
code3 = indent(code3, 4)
- code = r"""
+ code = textwrap.dedent(r"""
-/** Warning this file is autogenerated!!!
+ /** Warning this file is autogenerated!!!
- Please make changes to the code generator program (%s)
-**/
+ Please make changes to the code generator program (%s)
+ **/
-%s
+ %s
-static void
-InitOperators(PyObject *dictionary) {
- PyObject *f;
+ static void
+ InitOperators(PyObject *dictionary) {
+ PyObject *f;
-%s
-%s
-}
-""" % (filename, code1, code2, code3)
+ %s
+ %s
+ }
+ """) % (filename, code1, code2, code3)
return code