Improve kind score operation
@@ -52,13 +52,14 @@ cpdef _get_simple_elementwise_kernel(
return module.get_function(name)
-cdef dict _kind_score = {
- 'b': 0,
- 'u': 1,
- 'i': 1,
- 'f': 2,
- 'c': 2,
-}
+cdef inline int get_kind_score(int kind):
+ if b'b' == kind:
+ return 0
+ if b'u' == kind or b'i' == kind:
+ return 1
+ if b'f' == kind or b'c' == kind:
+ return 2
+ return -1
cpdef list _preprocess_args(args, bint use_c_scalar=False):
@@ -657,7 +658,7 @@ cdef inline bint _check_should_use_min_scalar(list in_args) except? -1:
max_array_kind = -1
max_scalar_kind = -1
for i in in_args:
- kind = _kind_score[i.dtype.kind]
+ kind = get_kind_score(ord(i.dtype.kind))
if isinstance(i, ndarray):
all_scalars = False
max_array_kind = max(max_array_kind, kind)
