Avoid module level lookup in _dtype
@@ -24,19 +24,20 @@ all_type_chars = '?bhilqBHILQefdFD'
# D ... complex128
cdef dict _dtype_dict = {}
+cdef _dtype = numpy.dtype
cdef _init_dtype_dict():
for i in six.integer_types + (float, bool, complex, None):
- dtype = numpy.dtype(i)
+ dtype = _dtype(i)
_dtype_dict[i] = (dtype, dtype.itemsize)
for i in all_type_chars:
- dtype = numpy.dtype(i)
+ dtype = _dtype(i)
item = (dtype, dtype.itemsize)
_dtype_dict[i] = item
_dtype_dict[dtype.type] = item
- for i in {str(numpy.dtype(i)) for i in all_type_chars}:
- dtype = numpy.dtype(i)
+ for i in {str(_dtype(i)) for i in all_type_chars}:
+ dtype = _dtype(i)
_dtype_dict[i] = (dtype, dtype.itemsize)
@@ -45,20 +46,20 @@ _init_dtype_dict()
@cython.profile(False)
cpdef get_dtype(t):
- if type(t) is numpy.dtype: # Exact type check
+ if type(t) is _dtype: # Exact type check
return t
ret = _dtype_dict.get(t, None)
if ret is None:
- return numpy.dtype(t)
+ return _dtype(t)
return ret[0]
@cython.profile(False)
cpdef tuple get_dtype_with_itemsize(t):
- if type(t) is numpy.dtype: # Exact type check
+ if type(t) is _dtype: # Exact type check
return t, t.itemsize
ret = _dtype_dict.get(t, None)
if ret is None:
- t = numpy.dtype(t)
+ t = _dtype(t)
return t, t.itemsize
return ret
