def blazefunc_from_numpy_ufunc(uf, modname, name, acquires_gil): """Converts a NumPy ufunc into a Blaze ufunc. Parameters ---------- uf : NumPy ufunc The ufunc to convert. modname : str The module name to report in the ufunc's name name : str The ufunc's name. acquires_gil : bool True if the kernels in the ufunc need the GIL. TODO: should support a dict {type -> bool} to allow per-kernel control. """ # Get the list of type signatures tplist = _lowlevel.numpy_typetuples_from_ufunc(uf) tplist = _filter_tplist(tplist) siglist = [_make_sig(tp) for tp in tplist] kernlist = [_lowlevel.ckernel_deferred_from_ufunc(uf, tp, acquires_gil) for tp in tplist] # Create the empty blaze function to start blaze_func = function.BlazeFunc() blaze_func.add_metadata({'elementwise': True}) # Add default dummy dispatching for 'python' mode pydispatcher = blaze_func.get_dispatcher('python') # Add dispatching to the kernel for each signature ckdispatcher = blaze_func.get_dispatcher('ckernel') for (tp, sig, kern) in zip(tplist, siglist, kernlist): # The blaze function currently requires matching (do-nothing) # python functions pyfunc = _make_pyfunc(len(tp) - 1, modname, name) datashape.overloading.overload(sig, dispatcher=pydispatcher)(pyfunc) datashape.overloading.overload(sig, dispatcher=ckdispatcher)(kern) return blaze_func
def blazefunc_from_numpy_ufunc(uf, modname, name, acquires_gil): """Converts a NumPy ufunc into a Blaze ufunc. Parameters ---------- uf : NumPy ufunc The ufunc to convert. modname : str The module name to report in the ufunc's name name : str The ufunc's name. acquires_gil : bool True if the kernels in the ufunc need the GIL. TODO: should support a dict {type -> bool} to allow per-kernel control. """ # Get the list of type signatures tplist = _lowlevel.numpy_typetuples_from_ufunc(uf) tplist = _filter_tplist(tplist) siglist = [_make_sig(tp) for tp in tplist] kernlist = [_lowlevel.ckernel_deferred_from_ufunc(uf, tp, acquires_gil) for tp in tplist] # Create the empty blaze function to start bf = ElementwiseBlazeFunc('blaze', name) # TODO: specify elementwise #bf.add_metadata({'elementwise': True}) # Add an overload to the function for each signature for (tp, sig, kern) in zip(tplist, siglist, kernlist): bf.add_overload(sig, kern) return bf
def blazefunc_from_numpy_ufunc(uf, modname, name, acquires_gil): """Converts a NumPy ufunc into a Blaze ufunc. Parameters ---------- uf : NumPy ufunc The ufunc to convert. modname : str The module name to report in the ufunc's name name : str The ufunc's name. acquires_gil : bool True if the kernels in the ufunc need the GIL. TODO: should support a dict {type -> bool} to allow per-kernel control. """ # Get the list of type signatures tplist = _lowlevel.numpy_typetuples_from_ufunc(uf) tplist = _filter_tplist(tplist) siglist = [_make_sig(tp) for tp in tplist] kernlist = [ _lowlevel.ckernel_deferred_from_ufunc(uf, tp, acquires_gil) for tp in tplist ] # Create the empty blaze function to start bf = ElementwiseBlazeFunc('blaze', name) # TODO: specify elementwise #bf.add_metadata({'elementwise': True}) # Add an overload to the function for each signature for (tp, sig, kern) in zip(tplist, siglist, kernlist): bf.add_overload(sig, kern) return bf