def _handle_empty_like(self, lhs, rhs, assign, call_table):
# B = empty_like(A) -> B = empty(len(A), dtype)
if (rhs.op == 'call'
and rhs.func.name in call_table
and call_table[rhs.func.name] == ['empty_like', np]):
in_arr= rhs.args[0]
def f(A):
c = len(A)
f_block = compile_to_numba_ir(f, {}, self.typingctx, (self.typemap[in_arr.name],),
self.typemap, self.calltypes).blocks.popitem()[1]
replace_arg_nodes(f_block, [in_arr])
nodes = f_block.body[:-3] # remove none return
size_var = nodes[-1].target
alloc_nodes = mk_alloc(self.typemap, self.calltypes, assign.target,
size_var,
self.typemap[in_arr.name].dtype, in_arr.scope, in_arr.loc)
return nodes + alloc_nodes
return None
评论列表
文章目录