def run(self): dprint_func_ir(self.func_ir, "starting IO") topo_order = find_topo_order(self.func_ir.blocks) for label in topo_order: new_body = [] # copies are collected before running the pass since # variables typed in locals are assigned late self._get_reverse_copies(self.func_ir.blocks[label].body) for inst in self.func_ir.blocks[label].body: if isinstance(inst, ir.Assign): inst_list = self._run_assign(inst) new_body.extend(inst_list) elif isinstance(inst, ir.StaticSetItem): inst_list = self._run_static_setitem(inst) new_body.extend(inst_list) else: new_body.append(inst) self.func_ir.blocks[label].body = new_body # iterative remove dead to make sure all extra code (e.g. df vars) is removed while remove_dead(self.func_ir.blocks, self.func_ir.arg_names, self.func_ir): pass self.func_ir._definitions = get_definitions(self.func_ir.blocks) dprint_func_ir(self.func_ir, "after IO") if debug_prints(): print("h5 files: ", self.h5_files) print("h5 dsets: ", self.h5_dsets)
def visit_vars_sort(sort_node, callback, cbdata): if debug_prints(): # pragma: no cover print("visiting sort vars for:", sort_node) print("cbdata: ", sorted(cbdata.items())) sort_node.key_arr = visit_vars_inner(sort_node.key_arr, callback, cbdata) for col_name in list(sort_node.df_vars.keys()): sort_node.df_vars[col_name] = visit_vars_inner( sort_node.df_vars[col_name], callback, cbdata)
def visit_vars_filter(filter_node, callback, cbdata): if debug_prints(): # pragma: no cover print("visiting filter vars for:", filter_node) print("cbdata: ", sorted(cbdata.items())) filter_node.bool_arr = visit_vars_inner(filter_node.bool_arr, callback, cbdata) for col_name in list(filter_node.df_in_vars.keys()): filter_node.df_in_vars[col_name] = visit_vars_inner( filter_node.df_in_vars[col_name], callback, cbdata) for col_name in list(filter_node.df_out_vars.keys()): filter_node.df_out_vars[col_name] = visit_vars_inner( filter_node.df_out_vars[col_name], callback, cbdata)
def visit_vars_csv(csv_node, callback, cbdata): if debug_prints(): # pragma: no cover print("visiting csv vars for:", csv_node) print("cbdata: ", sorted(cbdata.items())) # update output_vars new_out_vars = [] for col_var in csv_node.out_vars: new_var = visit_vars_inner(col_var, callback, cbdata) new_out_vars.append(new_var) csv_node.out_vars = new_out_vars csv_node.file_name = visit_vars_inner(csv_node.file_name, callback, cbdata) return
def visit_vars_join(join_node, callback, cbdata): if debug_prints(): # pragma: no cover print("visiting join vars for:", join_node) print("cbdata: ", sorted(cbdata.items())) # left for col_name in list(join_node.left_vars.keys()): join_node.left_vars[col_name] = visit_vars_inner( join_node.left_vars[col_name], callback, cbdata) # right for col_name in list(join_node.right_vars.keys()): join_node.right_vars[col_name] = visit_vars_inner( join_node.right_vars[col_name], callback, cbdata) # output for col_name in list(join_node.df_out_vars.keys()): join_node.df_out_vars[col_name] = visit_vars_inner( join_node.df_out_vars[col_name], callback, cbdata)
def dprint(*s): if debug_prints(): print(*s)
from .svc import SVC from .naive_bayes import MultinomialNB from hpat.utils import debug_prints try: from . import d4p except ImportError: if debug_prints(): # pragma: no cover print("daal4py import error")
def run(self): blocks = self.func_ir.blocks topo_order = find_topo_order(blocks) for label in topo_order: new_body = [] for inst in blocks[label].body: if isinstance(inst, ir.Assign): out_nodes = self._run_assign(inst) if isinstance(out_nodes, list): new_body.extend(out_nodes) if isinstance(out_nodes, dict): label = include_new_blocks(blocks, out_nodes, label, new_body) new_body = [] if isinstance(out_nodes, tuple): gen_blocks, post_nodes = out_nodes label = include_new_blocks(blocks, gen_blocks, label, new_body) new_body = post_nodes else: new_body.append(inst) blocks[label].body = new_body if debug_prints(): # pragma: no cover print("--- types before Series replacement:", self.typemap) print("calltypes: ", self.calltypes) replace_series = {} for vname, typ in self.typemap.items(): if isinstance(typ, SeriesType): # print("replacing series type", vname) new_typ = series_to_array_type(typ) replace_series[vname] = new_typ # replace array.call() variable types if isinstance(typ, types.BoundFunction) and isinstance( typ.this, SeriesType): this = series_to_array_type(typ.this) # TODO: handle string arrays, etc. assert typ.typing_key.startswith('array.') attr = typ.typing_key[len('array.'):] resolver = getattr(ArrayAttribute, 'resolve_' + attr) # methods are either installed with install_array_method or # using @bound_function in arraydecl.py if hasattr(resolver, '__wrapped__'): resolver = bound_function(typ.typing_key)( resolver.__wrapped__) new_typ = resolver(ArrayAttribute(self.typingctx), this) replace_series[vname] = new_typ for vname, typ in replace_series.items(): self.typemap.pop(vname) self.typemap[vname] = typ replace_calltype = {} # replace sig of getitem/setitem/... series type with array for call, sig in self.calltypes.items(): if sig is None: continue assert isinstance(sig, Signature) sig.return_type = if_series_to_array_type(sig.return_type) sig.args = tuple(map(if_series_to_array_type, sig.args)) # XXX: side effect: force update of call signatures if isinstance(call, ir.Expr) and call.op == 'call': # StencilFunc requires kws for typing so sig.args can't be used # reusing sig.args since some types become Const in sig argtyps = sig.args[:len(call.args)] kwtyps = {name: self.typemap[v.name] for name, v in call.kws} new_sig = self.typemap[call.func.name].get_call_type( self.typingctx, argtyps, kwtyps) # calltypes of things like BoundFunction (array.call) need to # be update for lowering to work # XXX: new_sig could be None for things like np.int32() if call in self.calltypes and new_sig is not None: old_sig = self.calltypes[call] # fix types with undefined dtypes in empty_inferred, etc. return_type = _fix_typ_undefs(new_sig.return_type, old_sig.return_type) args = tuple( _fix_typ_undefs(a, b) for a, b in zip(new_sig.args, old_sig.args)) replace_calltype[call] = Signature(return_type, args, new_sig.recvr, new_sig.pysig) for call, sig in replace_calltype.items(): self.calltypes.pop(call) self.calltypes[call] = sig if debug_prints(): # pragma: no cover print("--- types after Series replacement:", self.typemap) print("calltypes: ", self.calltypes) self.func_ir._definitions = get_definitions(self.func_ir.blocks) return if_series_to_unbox(self.return_type)