def supported_ufunc_loop(ufunc, loop): """Return whether the *loop* for the *ufunc* is supported -in nopython-. *loop* should be a UFuncLoopSpec instance, and *ufunc* a numpy ufunc. For ufuncs implemented using the ufunc_db, it is supported if the ufunc_db contains a lowering definition for 'loop' in the 'ufunc' entry. For other ufuncs, it is type based. The loop will be considered valid if it only contains the following letter types: '?bBhHiIlLqQfd'. Note this is legacy and when implementing new ufuncs the ufunc_db should be preferred, as it allows for a more fine-grained incremental support. """ from numba.np import ufunc_db loop_sig = loop.ufunc_sig try: # check if the loop has a codegen description in the # ufunc_db. If so, we can proceed. # note that as of now not all ufuncs have an entry in the # ufunc_db supported_loop = loop_sig in ufunc_db.get_ufunc_info(ufunc) except KeyError: # for ufuncs not in ufunc_db, base the decision of whether the # loop is supported on its types loop_types = [x.char for x in loop.numpy_inputs + loop.numpy_outputs] supported_types = '?bBhHiIlLqQfd' # check if all the types involved in the ufunc loop are # supported in this mode supported_loop = all(t in supported_types for t in loop_types) return supported_loop
def __init__(self, context, builder, outer_sig): super(_KernelImpl, self).__init__(context, builder, outer_sig) loop = ufunc_find_matching_loop( ufunc, outer_sig.args + (outer_sig.return_type, )) self.fn = ufunc_db.get_ufunc_info(ufunc).get(loop.ufunc_sig) self.inner_sig = typing.signature(*(loop.outputs + loop.inputs)) if self.fn is None: msg = "Don't know how to lower ufunc '{0}' for loop '{1}'" raise NotImplementedError(msg.format(ufunc.__name__, loop))
def __init__(self, context, builder, outer_sig): super(_KernelImpl, self).__init__(context, builder, outer_sig) loop = ufunc_find_matching_loop( ufunc, outer_sig.args + tuple(_unpack_output_types(ufunc, outer_sig))) self.fn = ufunc_db.get_ufunc_info(ufunc).get(loop.ufunc_sig) self.inner_sig = _ufunc_loop_sig(loop.outputs, loop.inputs) if self.fn is None: msg = "Don't know how to lower ufunc '{0}' for loop '{1}'" raise NotImplementedError(msg.format(ufunc.__name__, loop))
def get_ufunc_info(self, ufunc_key): return ufunc_db.get_ufunc_info(ufunc_key)