def visit_FunctionDef(self, node): self.curr_locals_declaration = self.passmanager.gather( LocalNodeDeclarations, node) self.current = node self.typedefs = list() self.name_to_nodes = {arg.id: {arg} for arg in node.args.args} self.yield_points = self.passmanager.gather(YieldPoints, node) # two stages, one for inter procedural propagation self.stage = 0 self.generic_visit(node) # and one for backward propagation # but this step is generally costly if cfg.getboolean('typing', 'enable_two_steps_typing'): self.stage = 1 self.generic_visit(node) # propagate type information through all aliases for name, nodes in self.name_to_nodes.iteritems(): final_node = ast.Name("__fake__" + name, ast.Load()) for n in nodes: self.combine(final_node, n) for n in nodes: self.result[n] = self.result[final_node] self.current_global_declarations[node.name] = node # return type may be unset if the function always raises return_type = self.result.get(node, NamedType("pythonic::types::none_type")) self.result[node] = (Returnable(return_type), self.typedefs) for k in self.passmanager.gather(LocalNodeDeclarations, node): self.result[k] = self.get_qualifier(k)(self.result[k])
def visit_FunctionDef(self, node): self.curr_locals_declaration = self.passmanager.gather( LocalDeclarations, node) self.current = node self.typedefs = list() self.name_to_nodes = {arg.id: {arg} for arg in node.args.args} self.yield_points = self.passmanager.gather(YieldPoints, node) # two stages, one for inter procedural propagation self.stage = 0 self.generic_visit(node) # and one for backward propagation # but this step is generally costly if cfg.getboolean('typing', 'enable_two_steps_typing'): self.stage = 1 self.generic_visit(node) # propagate type information through all aliases for name, nodes in self.name_to_nodes.iteritems(): final_node = ast.Name("__fake__" + name, ast.Load()) for n in nodes: self.combine(final_node, n) for n in nodes: self.result[n] = self.result[final_node] self.current_global_declarations[node.name] = node # return type may be unset if the function always raises return_type = self.result.get(node, NamedType("pythonic::types::none_type")) self.result[node] = (Returnable(return_type), self.typedefs) for k in self.passmanager.gather(LocalDeclarations, node): self.result[k] = self.get_qualifier(k)(self.result[k])
def visit_FunctionDef(self, node): self.curr_locals_declaration = self.gather(LocalNodeDeclarations, node) self.current = node self.typedefs = list() self.name_to_nodes = defaultdict(ordered_set) for arg in node.args.args: self.name_to_nodes[arg.id].append(arg) self.yield_points = self.gather(YieldPoints, node) # two stages, one for inter procedural propagation self.stage = 0 self.generic_visit(node) # and one for backward propagation # but this step is generally costly if cfg.getboolean('typing', 'enable_two_steps_typing'): self.stage = 1 self.generic_visit(node) # propagate type information through all aliases for name, nodes in self.name_to_nodes.items(): unique_types = ordered_set(self.result[n] for n in nodes) final_node = reduce(self.builder.Type.__add__, unique_types) for n in nodes: self.result[n] = final_node self.current_global_declarations[node.name] = node # return type may be unset if the function always raises return_type = self.result.get( node, self.builder.NamedType("pythonic::types::none_type")) self.result[node] = self.builder.Returnable(return_type), self.typedefs for k in self.gather(LocalNodeDeclarations, node): self.result[k] = self.get_qualifier(k)(self.result[k])
def test_complex_limited_range(self): """ Check complex computation is the same as numpy for corner case. """ # see -fcx-limited-range if cfg.getboolean('pythran', 'complex_hook'): self.run_test(""" def test_complex_limited_range(a, b): return a * b""", complex(-4, np.nan), complex(4, -np.inf), test_complex_limited_range=[complex, complex])
def _pythran_cppflags(): curr_dir = os.path.dirname(os.path.dirname(__file__)) def get(*x): return '-I' + os.path.join(curr_dir, *x) flags = [get('.'), get('pythran')] if cfg.getboolean('pythran', 'complex_hook'): # the patch is *not* portable flags.append(get('pythran', 'pythonic', 'patch')) return flags
def visit_FunctionDef(self, node): self.curr_locals_declaration = self.gather( LocalNodeDeclarations, node) self.current = node self.typedefs = list() self.name_to_nodes = defaultdict(ordered_set) for arg in node.args.args: self.name_to_nodes[arg.id].append(arg) self.yield_points = self.gather(YieldPoints, node) # two stages, one for inter procedural propagation self.stage = 0 self.generic_visit(node) # and one for backward propagation # but this step is generally costly if cfg.getboolean('typing', 'enable_two_steps_typing'): self.stage = 1 self.generic_visit(node) # propagate type information through all aliases for name, nodes in self.name_to_nodes.items(): unique_types = ordered_set(self.result[n] for n in nodes) final_node = reduce(self.builder.Type.__add__, unique_types) for n in nodes: self.result[n] = final_node self.current_global_declarations[node.name] = node # return type may be unset if the function always raises return_type = self.result.get( node, self.builder.NamedType("pythonic::types::none_type")) self.result[node] = self.builder.Returnable(return_type), self.typedefs for k in self.gather(LocalNodeDeclarations, node): self.result[k] = self.get_qualifier(k)(self.result[k])