def build_ufunc(self): dtypelist = [] ptrlist = [] if not self.nb_func: raise TypeError("No definition") # Get signature in the order they are added keepalive = [] for sig in self._sigs: cres = self._cres[sig] dtypenums, ptr, env = self.build(cres) dtypelist.append(dtypenums) ptrlist.append(utils.longint(ptr)) keepalive.append((cres.library, env)) datlist = [None] * len(ptrlist) inct = len(self.sin) outct = len(self.sout) # Pass envs to fromfuncsig to bind to the lifetime of the ufunc object ufunc = _internal.fromfunc( self.py_func.__name__, self.py_func.__doc__, ptrlist, dtypelist, inct, outct, datlist, keepalive, self.identity, self.signature, ) return ufunc
def _compile_for_argtys(self, argtys, return_type=None): """ Given a tuple of argument types (these should be the array dtypes, and not the array types themselves), compile the element-wise function for those inputs, generate a UFunc loop wrapper, and register the loop with the Numpy ufunc object for this DUFunc. """ if self._frozen: raise RuntimeError("compilation disabled for %s" % (self, )) assert isinstance(argtys, tuple) if return_type is None: sig = argtys else: sig = return_type(*argtys) cres, argtys, return_type = ufuncbuilder._compile_element_wise_function( self._dispatcher, self.targetoptions, sig) actual_sig = ufuncbuilder._finalize_ufunc_signature( cres, argtys, return_type) dtypenums, ptr, env = ufuncbuilder._build_element_wise_ufunc_wrapper( cres, actual_sig) self._add_loop(utils.longint(ptr), dtypenums) self._keepalive.append((ptr, cres.library, env)) self._lower_me.libs.append(cres.library) return cres
def build_ufunc(self): with global_compiler_lock: dtypelist = [] ptrlist = [] if not self.nb_func: raise TypeError("No definition") # Get signature in the order they are added keepalive = [] cres = None for sig in self._sigs: cres = self._cres[sig] dtypenums, ptr, env = self.build(cres, sig) dtypelist.append(dtypenums) ptrlist.append(utils.longint(ptr)) keepalive.append((cres.library, env)) datlist = [None] * len(ptrlist) if cres is None: argspec = inspect.getfullargspec(self.py_func) inct = len(argspec.args) else: inct = len(cres.signature.args) outct = 1 # Becareful that fromfunc does not provide full error checking yet. # If typenum is out-of-bound, we have nasty memory corruptions. # For instance, -1 for typenum will cause segfault. # If elements of type-list (2nd arg) is tuple instead, # there will also memory corruption. (Seems like code rewrite.) ufunc = _internal.fromfunc( self.py_func.__name__, self.py_func.__doc__, ptrlist, dtypelist, inct, outct, datlist, keepalive, self.identity, ) return ufunc