def init(self): self.native_funcs = utils.UniqueDict() self.is32bit = (utils.MACHINE_BITS == 32) # Map external C functions. externals.c_math_functions.install() externals.c_numpy_functions.install() # Add target specific implementations self.insert_func_defn(cmathimpl.registry.functions) self.insert_func_defn(mathimpl.registry.functions) self.insert_func_defn(npyimpl.registry.functions) self.insert_func_defn(operatorimpl.registry.functions) self.insert_func_defn(printimpl.registry.functions) self.insert_func_defn(randomimpl.registry.functions) self._internal_codegen = codegen.JITCPUCodegen("numba.exec")
def unify(self): typdict = utils.UniqueDict() for var, tv in self.typevars.items(): if len(tv) == 1: unified = tv.getone() elif len(tv) == 0: raise TypeError("Variable %s has no type" % var) else: unified = self.context.unify_types(*tv.get()) if unified == types.pyobject: raise TypingError("Var '%s' unified to object: %s" % (var, tv)) typdict[var] = unified retty = self.get_return_type(typdict) fntys = self.get_function_types(typdict) if self.generator_info: retty = self.get_generator_type(typdict, retty) return typdict, retty, fntys
def get_function_types(self, typemap): """ Fill and return a calltypes map using the inferred `typemap`. """ # XXX why can't this be done on the fly? calltypes = utils.UniqueDict() for call, constraint in self.intrcalls: calltypes[call] = constraint.get_call_signature() for call, args, kws, vararg in self.usercalls: if isinstance(call.func, ir.Intrinsic): signature = call.func.type else: fnty = typemap[call.func.name] args = tuple(typemap[a.name] for a in args) kws = dict((kw, typemap[var.name]) for (kw, var) in kws) if vararg is not None: tp = typemap[vararg.name] assert isinstance(tp, types.BaseTuple) args = args + tp.types signature = self.context.resolve_function_type(fnty, args, kws) assert signature is not None, (fnty, args, kws, vararg) calltypes[call] = signature for inst in self.delitemcalls: target = typemap[inst.target.name] index = typemap[inst.index.name] signature = self.context.resolve_delitem(target, index) calltypes[inst] = signature for inst in self.setitemcalls: target = typemap[inst.target.name] index = typemap[inst.index.name] value = typemap[inst.value.name] signature = self.context.resolve_setitem(target, index, value) calltypes[inst] = signature for inst in self.setattrcalls: target = typemap[inst.target.name] attr = inst.attr value = typemap[inst.value.name] signature = self.context.resolve_setattr(target, attr, value) calltypes[inst] = signature return calltypes
def init(self): self.execmodule = lc.Module.new("numba.exec") eb = le.EngineBuilder.new(self.execmodule).opt(3) if not avx_support.detect_avx_support(): eb.mattrs("-avx") self.tm = tm = eb.select_target() self.engine = eb.create(tm) self.pm = self.build_pass_manager() self.native_funcs = utils.UniqueDict() self.cmath_provider = {} self.is32bit = (tuple.__itemsize__ == 4) # map math functions self.map_math_functions() # Add target specific implementations self.insert_func_defn(mathimpl.functions) self.insert_func_defn(npyimpl.functions)
def get_function_types(self, typemap): calltypes = utils.UniqueDict() for call, args, kws in self.intrcalls: if call.op in ('inplace_binop', 'binop', 'unary'): fnty = call.fn else: fnty = call.op args = tuple(typemap[a.name] for a in args) assert not kws signature = self.context.resolve_function_type(fnty, args, ()) assert signature is not None, (fnty, args) calltypes[call] = signature for call, args, kws, vararg in self.usercalls: if isinstance(call.func, ir.Intrinsic): signature = call.func.type else: fnty = typemap[call.func.name] args = tuple(typemap[a.name] for a in args) kws = dict((kw, typemap[var.name]) for (kw, var) in kws) if vararg is not None: tp = typemap[vararg.name] assert isinstance(tp, types.BaseTuple) args = args + tp.types signature = self.context.resolve_function_type(fnty, args, kws) assert signature is not None, (fnty, args, kws, vararg) calltypes[call] = signature for inst in self.setitemcalls: target = typemap[inst.target.name] index = typemap[inst.index.name] value = typemap[inst.value.name] signature = self.context.resolve_setitem(target, index, value) calltypes[inst] = signature for inst in self.setattrcalls: target = typemap[inst.target.name] attr = inst.attr value = typemap[inst.value.name] signature = self.context.resolve_setattr(target, attr, value) calltypes[inst] = signature return calltypes
def unify(self): """ Run the final unification pass over all inferred types, and catch imprecise types. """ typdict = utils.UniqueDict() def check_var(name): tv = self.typevars[name] if not tv.defined: offender = None for block in self.func_ir.blocks.values(): offender = block.find_variable_assignment(name) if offender is not None: break val = getattr(offender, 'value', 'unknown operation') loc = getattr(offender, 'loc', 'unknown location') msg = "Undefined variable '%s', operation: %s, location: %s" raise TypingError(msg % (var, val, loc), loc) tp = tv.getone() if not tp.is_precise(): raise TypingError("Can't infer type of variable '%s': %s" % (var, tp)) typdict[var] = tp # For better error display, check first user-visible vars, then # temporaries temps = set(k for k in self.typevars if not k[0].isalpha()) others = set(self.typevars) - temps for var in sorted(others): check_var(var) for var in sorted(temps): check_var(var) retty = self.get_return_type(typdict) fntys = self.get_function_types(typdict) if self.generator_info: retty = self.get_generator_type(typdict, retty) self.debug.unify_finished(typdict, retty, fntys) return typdict, retty, fntys
def __init__(self): self._unresolved = utils.UniqueDict() self._defined = set() self._resolved = []
def __init__(self, py_func, locals={}, targetoptions={}): self.py_func = py_func self.overloads = utils.UniqueDict() self.targetoptions = targetoptions self.locals = locals self.cache = NullCache()
def __init__(self, *args, **kws): super(TargetRegistry, self).__init__(*args, **kws) self.ondemand = utils.UniqueDict()
def __init__(self, base): self.__base = base self.metdata = utils.UniqueDict()
def __init__(self): self.functions = defaultdict(list) self.attributes = {} self.globals = utils.UniqueDict() self.tm = rules.default_type_manager self._load_builtins()
def __init__(self, base): self.__base = base self.metadata = utils.UniqueDict() self.linking = set()
def __init__(self): self.devices = utils.UniqueDict()