Commit 8406b3ea authored by Stefan Behnel's avatar Stefan Behnel

reduce some unnecessary overhead in fused types runtime dispatch code

parent 37264625
...@@ -404,12 +404,15 @@ class FusedCFuncDefNode(StatListNode): ...@@ -404,12 +404,15 @@ class FusedCFuncDefNode(StatListNode):
if pyx_code.indenter(u"while 1:"): if pyx_code.indenter(u"while 1:"):
pyx_code.put_chunk( pyx_code.put_chunk(
u""" u"""
if numpy is not None: if ndarray is not None:
if isinstance(arg, numpy.ndarray): if isinstance(arg, ndarray):
dtype = arg.dtype dtype = arg.dtype
elif (__pyx_memoryview_check(arg) and elif __pyx_memoryview_check(arg):
isinstance(arg.base, numpy.ndarray)): arg_base = arg.base
dtype = arg.base.dtype if isinstance(arg_base, ndarray):
dtype = arg_base.dtype
else:
dtype = None
else: else:
dtype = None dtype = None
...@@ -417,7 +420,7 @@ class FusedCFuncDefNode(StatListNode): ...@@ -417,7 +420,7 @@ class FusedCFuncDefNode(StatListNode):
if dtype is not None: if dtype is not None:
itemsize = dtype.itemsize itemsize = dtype.itemsize
kind = ord(dtype.kind) kind = ord(dtype.kind)
dtype_signed = kind == ord('i') dtype_signed = kind == 'i'
""") """)
pyx_code.indent(2) pyx_code.indent(2)
pyx_code.named_insertion_point("numpy_dtype_checks") pyx_code.named_insertion_point("numpy_dtype_checks")
...@@ -462,10 +465,12 @@ class FusedCFuncDefNode(StatListNode): ...@@ -462,10 +465,12 @@ class FusedCFuncDefNode(StatListNode):
pyx_code.imports.put_chunk( pyx_code.imports.put_chunk(
u""" u"""
cdef type ndarray
try: try:
import numpy import numpy
except ImportError: ndarray = numpy.ndarray
numpy = None except (ImportError, AttributeError, TypeError):
ndarray = None
""") """)
seen_int_dtypes = set() seen_int_dtypes = set()
...@@ -519,7 +524,7 @@ class FusedCFuncDefNode(StatListNode): ...@@ -519,7 +524,7 @@ class FusedCFuncDefNode(StatListNode):
elif '{{arg.name}}' in kwargs: elif '{{arg.name}}' in kwargs:
arg = kwargs['{{arg.name}}'] arg = kwargs['{{arg.name}}']
else: else:
{{if arg.default:}} {{if arg.default}}
arg = defaults[{{default_idx}}] arg = defaults[{{default_idx}}]
{{else}} {{else}}
raise TypeError("Expected at least %d arguments" % len(args)) raise TypeError("Expected at least %d arguments" % len(args))
...@@ -556,7 +561,9 @@ class FusedCFuncDefNode(StatListNode): ...@@ -556,7 +561,9 @@ class FusedCFuncDefNode(StatListNode):
pyx_code.put_chunk( pyx_code.put_chunk(
u""" u"""
def __pyx_fused_cpdef(signatures, args, kwargs, defaults): def __pyx_fused_cpdef(dict signatures not None,
tuple args not None, dict kwargs, tuple defaults not None):
dest_sig = [{{for _ in range(n_fused)}}None,{{endfor}}] dest_sig = [{{for _ in range(n_fused)}}None,{{endfor}}]
if kwargs is None: if kwargs is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment