Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENH: special/generate_ufuncs: more consistent special function cast r…

…ules
  • Loading branch information...
commit 7c10c58b8622833f5f28197a8a415cce5084d018 1 parent 0dfe2b6
@pv pv authored
Showing with 22 additions and 4 deletions.
  1. +22 −4 scipy/special/generate_ufuncs.py
View
26 scipy/special/generate_ufuncs.py
@@ -486,10 +486,28 @@ def iter_variants(inputs, outputs):
Also the original input/output pair is yielded.
"""
- yield inputs.replace('d', 'f').replace('D', 'F'), outputs.replace('d', 'f').replace('D', 'F')
- yield inputs, outputs
- yield inputs.replace('i', 'l'), outputs.replace('i', 'l')
- yield inputs.replace('i', 'd'), outputs.replace('i', 'd')
+ maps = [
+ # always use long instead of int (more common type on 64-bit)
+ ('i', 'l'),
+ ]
+
+ # allow doubles in integer args
+ if 'd' in inputs+outputs or 'D' in inputs+outputs:
+ maps.append(('il', 'dd'))
+ if 'f' in inputs+outputs or 'F' in inputs+outputs:
+ maps.append(('il', 'ff'))
+
+ # float32-preserving signatures
+ maps = [(a + 'dD', b + 'fF') for a, b in maps] + maps
+
+ # do the replacements
+ for src, dst in maps:
+ new_inputs = inputs
+ new_outputs = outputs
+ for a, b in zip(src, dst):
+ new_inputs = new_inputs.replace(a, b)
+ new_outputs = new_outputs.replace(a, b)
+ yield new_inputs, new_outputs
class Ufunc(object):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.