_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q233100
TypeDependencies.visit_ExceptHandler
train
def visit_ExceptHandler(self, node): """ Exception may declare a new variable. """ if node.name: self.naming[node.name.id] = [frozenset()] for stmt in node.body: self.visit(stmt)
python
{ "resource": "" }
q233101
arc_distance
train
def arc_distance(theta_1, phi_1, theta_2, phi_2): """ Calculates the pairwise arc distance between all points in vector a and b. """ temp = np.sin((theta_2-theta_1)/2)**2+np.cos(theta_1)*np.cos(theta_2)*np.sin((phi_2-phi_1)/2)**2 distance_matrix = 2 * (np.arctan2(np.sqrt(temp)...
python
{ "resource": "" }
q233102
ExpandGlobals.visit_Module
train
def visit_Module(self, node): """Turn globals assignment to functionDef and visit function defs. """ module_body = list() symbols = set() # Gather top level assigned variables. for stmt in node.body: if isinstance(stmt, (ast.Import, ast.ImportFrom)): f...
python
{ "resource": "" }
q233103
ExpandGlobals.visit_Name
train
def visit_Name(self, node): """ Turn global variable used not shadows to function call. We check it is a name from an assignment as import or functions use should not be turn into call. """ if (isinstance(node.ctx, ast.Load) and node.id not in self.local_...
python
{ "resource": "" }
q233104
NormalizeMethodCalls.visit_Module
train
def visit_Module(self, node): """ When we normalize call, we need to add correct import for method to function transformation. a.max() for numpy array will become: numpy.max(a) so we have to import numpy. """ self.skip_f...
python
{ "resource": "" }
q233105
NormalizeMethodCalls.renamer
train
def renamer(v, cur_module): """ Rename function path to fit Pythonic naming. """ mname = demangle(v) name = v + '_' if name in cur_module: return name, mname else: return v, mname
python
{ "resource": "" }
q233106
NormalizeMethodCalls.visit_Call
train
def visit_Call(self, node): """ Transform call site to have normal function call. Examples -------- For methods: >> a = [1, 2, 3] >> a.append(1) Becomes >> __list__.append(a, 1) For functions: >> __builtin__.dict.fromkeys([1, ...
python
{ "resource": "" }
q233107
_extract_specs_dependencies
train
def _extract_specs_dependencies(specs): """ Extract types dependencies from specs for each exported signature. """ deps = set() # for each function for signatures in specs.functions.values(): # for each signature for signature in signatures: # for each argument fo...
python
{ "resource": "" }
q233108
_parse_optimization
train
def _parse_optimization(optimization): '''Turns an optimization of the form my_optim my_package.my_optim into the associated symbol''' splitted = optimization.split('.') if len(splitted) == 1: splitted = ['pythran', 'optimizations'] + splitted return reduce(getattr, split...
python
{ "resource": "" }
q233109
_write_temp
train
def _write_temp(content, suffix): '''write `content` to a temporary XXX`suffix` file and return the filename. It is user's responsibility to delete when done.''' with NamedTemporaryFile(mode='w', suffix=suffix, delete=False) as out: out.write(content) return out.name
python
{ "resource": "" }
q233110
front_middle_end
train
def front_middle_end(module_name, code, optimizations=None, module_dir=None): """Front-end and middle-end compilation steps""" pm = PassManager(module_name, module_dir) # front end ir, renamings, docstrings = frontend.parse(pm, code) # middle-end if optimizations is None: optimizations...
python
{ "resource": "" }
q233111
generate_py
train
def generate_py(module_name, code, optimizations=None, module_dir=None): '''python + pythran spec -> py code Prints and returns the optimized python code. ''' pm, ir, _, _ = front_middle_end(module_name, code, optimizations, module_dir) return pm.dump(Python, ...
python
{ "resource": "" }
q233112
compile_cxxfile
train
def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs): '''c++ file -> native module Return the filename of the produced shared library Raises CompileError on failure ''' builddir = mkdtemp() buildtmp = mkdtemp() extension_args = make_extension(python=True, **kwargs) ...
python
{ "resource": "" }
q233113
compile_pythranfile
train
def compile_pythranfile(file_path, output_file=None, module_name=None, cpponly=False, pyonly=False, **kwargs): """ Pythran file -> c++ file -> native module. Returns the generated .so (or .cpp if `cpponly` is set to true). Usage without an existing spec file >>> with open(...
python
{ "resource": "" }
q233114
RemoveComprehension.nest_reducer
train
def nest_reducer(x, g): """ Create a ast.For node from a comprehension and another node. g is an ast.comprehension. x is the code that have to be executed. Examples -------- >> [i for i in xrange(2)] Becomes >> for i in xrange(2): >> ...
python
{ "resource": "" }
q233115
Declarator.inline
train
def inline(self): """Return the declarator as a single line.""" tp_lines, tp_decl = self.get_decl_pair() tp_lines = " ".join(tp_lines) if tp_decl is None: return tp_lines else: return "%s %s" % (tp_lines, tp_decl)
python
{ "resource": "" }
q233116
Struct.get_decl_pair
train
def get_decl_pair(self): """ See Declarator.get_decl_pair.""" def get_tp(): """ Iterator generating lines for struct definition. """ decl = "struct " if self.tpname is not None: decl += self.tpname if self.inherit is not None: ...
python
{ "resource": "" }
q233117
NormalizeStaticIf.make_control_flow_handlers
train
def make_control_flow_handlers(self, cont_n, status_n, expected_return, has_cont, has_break): ''' Create the statements in charge of gathering control flow information for the static_if result, and executes the expected control flow instruction ...
python
{ "resource": "" }
q233118
PlaceholderReplace.visit
train
def visit(self, node): """ Replace the placeholder if it is one or continue. """ if isinstance(node, Placeholder): return self.placeholders[node.id] else: return super(PlaceholderReplace, self).visit(node)
python
{ "resource": "" }
q233119
PatternTransform.visit
train
def visit(self, node): """ Try to replace if node match the given pattern or keep going. """ for pattern, replace in know_pattern: check = Check(node, dict()) if check.visit(pattern): node = PlaceholderReplace(check.placeholders).visit(replace()) s...
python
{ "resource": "" }
q233120
LocalNameDeclarations.visit_Name
train
def visit_Name(self, node): """ Any node with Store or Param context is a new identifier. """ if isinstance(node.ctx, (ast.Store, ast.Param)): self.result.add(node.id)
python
{ "resource": "" }
q233121
LocalNameDeclarations.visit_FunctionDef
train
def visit_FunctionDef(self, node): """ Function name is a possible identifier. """ self.result.add(node.name) self.generic_visit(node)
python
{ "resource": "" }
q233122
CFG.visit_If
train
def visit_If(self, node): """ OUT = true branch U false branch RAISES = true branch U false branch """ currs = (node,) raises = () # true branch for n in node.body: self.result.add_node(n) for curr in currs: self.re...
python
{ "resource": "" }
q233123
CFG.visit_Try
train
def visit_Try(self, node): """ OUT = body's U handler's RAISES = handler's this equation is not has good has it could be... but we need type information to be more accurate """ currs = (node,) raises = () for handler in node.handlers: s...
python
{ "resource": "" }
q233124
CFG.visit_ExceptHandler
train
def visit_ExceptHandler(self, node): """OUT = body's, RAISES = body's""" currs = (node,) raises = () for n in node.body: self.result.add_node(n) for curr in currs: self.result.add_edge(curr, n) currs, nraises = self.visit(n) ...
python
{ "resource": "" }
q233125
IsAssigned.visit_Name
train
def visit_Name(self, node): """ Stored variable have new value. """ if isinstance(node.ctx, ast.Store): self.result[node.id] = True
python
{ "resource": "" }
q233126
RangeValues.add
train
def add(self, variable, range_): """ Add a new low and high bound for a variable. As it is flow insensitive, it compares it with old values and update it if needed. """ if variable not in self.result: self.result[variable] = range_ else: s...
python
{ "resource": "" }
q233127
RangeValues.visit_Assign
train
def visit_Assign(self, node): """ Set range value for assigned variable. We do not handle container values. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse("def foo(): a = b = 2") >>> pm = passmanager.PassManager("test") ...
python
{ "resource": "" }
q233128
RangeValues.visit_AugAssign
train
def visit_AugAssign(self, node): """ Update range value for augassigned variables. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse("def foo(): a = 2; a -= 1") >>> pm = passmanager.PassManager("test") >>> res = pm.gather(RangeValue...
python
{ "resource": "" }
q233129
RangeValues.visit_For
train
def visit_For(self, node): """ Handle iterate variable in for loops. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = b = c = 2 ... for i in __builtin__.range(1): ... a -= ...
python
{ "resource": "" }
q233130
RangeValues.visit_loop
train
def visit_loop(self, node, cond=None): """ Handle incremented variables in loop body. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = b = c = 2 ... while a > 0: ... a -= 1...
python
{ "resource": "" }
q233131
RangeValues.visit_BoolOp
train
def visit_BoolOp(self, node): """ Merge right and left operands ranges. TODO : We could exclude some operand with this range information... >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = 2 ...
python
{ "resource": "" }
q233132
RangeValues.visit_BinOp
train
def visit_BinOp(self, node): """ Combine operands ranges for given operator. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = 2 ... c = 3 ... d = a - c''') >>> pm = pas...
python
{ "resource": "" }
q233133
RangeValues.visit_UnaryOp
train
def visit_UnaryOp(self, node): """ Update range with given unary operation. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = 2 ... c = -a ... d = ~a ... f = +a ...
python
{ "resource": "" }
q233134
RangeValues.visit_If
train
def visit_If(self, node): """ Handle iterate variable across branches >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(a): ... if a > 1: b = 1 ... else: b = 3''') >>> pm = passmanager.PassMa...
python
{ "resource": "" }
q233135
RangeValues.visit_IfExp
train
def visit_IfExp(self, node): """ Use worst case for both possible values. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = 2 or 3 ... b = 4 or 5 ... c = a if a else b''') ...
python
{ "resource": "" }
q233136
RangeValues.visit_Compare
train
def visit_Compare(self, node): """ Boolean are possible index. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = 2 or 3 ... b = 4 or 5 ... c = a < b ... d = b < 3 ...
python
{ "resource": "" }
q233137
RangeValues.visit_Call
train
def visit_Call(self, node): """ Function calls are not handled for now. >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse(''' ... def foo(): ... a = __builtin__.range(10)''') >>> pm = passmanager.PassManager("test") ...
python
{ "resource": "" }
q233138
RangeValues.visit_Num
train
def visit_Num(self, node): """ Handle literals integers values. """ if isinstance(node.n, int): return self.add(node, Interval(node.n, node.n)) return UNKNOWN_RANGE
python
{ "resource": "" }
q233139
RangeValues.visit_Name
train
def visit_Name(self, node): """ Get range for parameters for examples or false branching. """ return self.add(node, self.result[node.id])
python
{ "resource": "" }
q233140
RangeValues.generic_visit
train
def generic_visit(self, node): """ Other nodes are not known and range value neither. """ super(RangeValues, self).generic_visit(node) return self.add(node, UNKNOWN_RANGE)
python
{ "resource": "" }
q233141
compile_flags
train
def compile_flags(args): """ Build a dictionnary with an entry for cppflags, ldflags, and cxxflags. These options are filled according to the command line defined options """ compiler_options = { 'define_macros': args.defines, 'undef_macros': args.undefs, 'include_dirs': a...
python
{ "resource": "" }
q233142
IterTransformation.find_matching_builtin
train
def find_matching_builtin(self, node): """ Return matched keyword. If the node alias on a correct keyword (and only it), it matches. """ for path in EQUIVALENT_ITERATORS.keys(): correct_alias = {path_to_node(path)} if self.aliases[node.func] == correct_al...
python
{ "resource": "" }
q233143
IterTransformation.visit_Module
train
def visit_Module(self, node): """Add itertools import for imap, izip or ifilter iterator.""" self.generic_visit(node) import_alias = ast.alias(name='itertools', asname=mangle('itertools')) if self.use_itertools: importIt = ast.Import(names=[import_alias]) node.bod...
python
{ "resource": "" }
q233144
IterTransformation.visit_Call
train
def visit_Call(self, node): """Replace function call by its correct iterator if it is possible.""" if node in self.potential_iterator: matched_path = self.find_matching_builtin(node) if matched_path is None: return self.generic_visit(node) # Special h...
python
{ "resource": "" }
q233145
run
train
def run(xmin, ymin, xmax, ymax, step, range_, range_x, range_y, t): X,Y = t.shape pt = np.zeros((X,Y)) "omp parallel for" for i in range(X): for j in range(Y): for k in t: tmp = 6368.* np.arccos( np.cos(xmin+step*i)*np.cos( k[0] ) * np.cos((ymin+step*j)-k[1])+ np.sin...
python
{ "resource": "" }
q233146
max_values
train
def max_values(args): """ Return possible range for max function. """ return Interval(max(x.low for x in args), max(x.high for x in args))
python
{ "resource": "" }
q233147
min_values
train
def min_values(args): """ Return possible range for min function. """ return Interval(min(x.low for x in args), min(x.high for x in args))
python
{ "resource": "" }
q233148
Interval.union
train
def union(self, other): """ Intersect current range with other.""" return Interval(min(self.low, other.low), max(self.high, other.high))
python
{ "resource": "" }
q233149
Interval.widen
train
def widen(self, other): """ Widen current range. """ if self.low < other.low: low = -float("inf") else: low = self.low if self.high > other.high: high = float("inf") else: high = self.high return Interval(low, high)
python
{ "resource": "" }
q233150
RemoveNamedArguments.handle_keywords
train
def handle_keywords(self, func, node, offset=0): ''' Gather keywords to positional argument information Assumes the named parameter exist, raises a KeyError otherwise ''' func_argument_names = {} for i, arg in enumerate(func.args.args[offset:]): assert isinst...
python
{ "resource": "" }
q233151
update_effects
train
def update_effects(self, node): """ Combiner when we update the first argument of a function. It turn type of first parameter in combination of all others parameters types. """ return [self.combine(node.args[0], node_args_k, register=True, aliasing_type=True) ...
python
{ "resource": "" }
q233152
save_method
train
def save_method(elements, module_path): """ Recursively save methods with module name and signature. """ for elem, signature in elements.items(): if isinstance(signature, dict): # Submodule case save_method(signature, module_path + (elem,)) elif isinstance(signature, Class): ...
python
{ "resource": "" }
q233153
save_function
train
def save_function(elements, module_path): """ Recursively save functions with module name and signature. """ for elem, signature in elements.items(): if isinstance(signature, dict): # Submodule case save_function(signature, module_path + (elem,)) elif signature.isstaticfunction(): ...
python
{ "resource": "" }
q233154
save_attribute
train
def save_attribute(elements, module_path): """ Recursively save attributes with module name and signature. """ for elem, signature in elements.items(): if isinstance(signature, dict): # Submodule case save_attribute(signature, module_path + (elem,)) elif signature.isattribute(): ...
python
{ "resource": "" }
q233155
ListToTuple.visit_Assign
train
def visit_Assign(self, node): """ Replace list calls by static_list calls when possible >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse("def foo(n): x = __builtin__.list(n); x[0] = 0; return __builtin__.tuple(x)") >>> pm = passman...
python
{ "resource": "" }
q233156
BuildWithThirdParty.copy_pkg
train
def copy_pkg(self, pkg, src_only=False): "Install boost deps from the third_party directory" if getattr(self, 'no_' + pkg) is None: print('Copying boost dependencies') to_copy = pkg, else: return src = os.path.join('third_party', *to_copy) #...
python
{ "resource": "" }
q233157
Check.check_list
train
def check_list(self, node_list, pattern_list): """ Check if list of node are equal. """ if len(node_list) != len(pattern_list): return False else: return all(Check(node_elt, self.placeholders).visit(pattern_list[i]) for ...
python
{ "resource": "" }
q233158
Check.visit_Placeholder
train
def visit_Placeholder(self, pattern): """ Save matching node or compare it with the existing one. FIXME : What if the new placeholder is a better choice? """ if (pattern.id in self.placeholders and not Check(self.node, self.placeholders).visit( ...
python
{ "resource": "" }
q233159
Check.visit_AST_or
train
def visit_AST_or(self, pattern): """ Match if any of the or content match with the other node. """ return any(self.field_match(self.node, value_or) for value_or in pattern.args)
python
{ "resource": "" }
q233160
Check.visit_Set
train
def visit_Set(self, pattern): """ Set have unordered values. """ if len(pattern.elts) > MAX_UNORDERED_LENGTH: raise DamnTooLongPattern("Pattern for Set is too long") return (isinstance(self.node, Set) and any(self.check_list(self.node.elts, pattern_elts) ...
python
{ "resource": "" }
q233161
Check.visit_Dict
train
def visit_Dict(self, pattern): """ Dict can match with unordered values. """ if not isinstance(self.node, Dict): return False if len(pattern.keys) > MAX_UNORDERED_LENGTH: raise DamnTooLongPattern("Pattern for Dict is too long") for permutation in permutations(rang...
python
{ "resource": "" }
q233162
Check.field_match
train
def field_match(self, node_field, pattern_field): """ Check if two fields match. Field match if: - If it is a list, all values have to match. - If if is a node, recursively check it. - Otherwise, check values are equal. """ is_good_list = (isi...
python
{ "resource": "" }
q233163
Check.generic_visit
train
def generic_visit(self, pattern): """ Check if the pattern match with the checked node. a node match if: - type match - all field match """ return (isinstance(pattern, type(self.node)) and all(self.field_match(value, getattr(pattern, field...
python
{ "resource": "" }
q233164
ASTMatcher.visit
train
def visit(self, node): """ Visitor looking for matching between current node and pattern. If it match, save it but whatever happen, keep going. """ if Check(node, dict()).visit(self.pattern): self.result.add(node) self.generic_visit(node)
python
{ "resource": "" }
q233165
LazynessAnalysis.visit_Call
train
def visit_Call(self, node): """ Compute use of variables in a function call. Each arg is use once and function name too. Information about modified arguments is forwarded to func_args_lazyness. """ md.visit(self, node) for arg in node.args: se...
python
{ "resource": "" }
q233166
n_queens
train
def n_queens(queen_count): """N-Queens solver. Args: queen_count: the number of queens to solve for. This is also the board size. Yields: Solutions to the problem. Each yielded value is looks like (3, 8, 2, 1, 4, ..., 6) where each number is the column position for the ...
python
{ "resource": "" }
q233167
Inlining.visit_Stmt
train
def visit_Stmt(self, node): """ Add new variable definition before the Statement. """ save_defs, self.defs = self.defs or list(), list() self.generic_visit(node) new_defs, self.defs = self.defs, save_defs return new_defs + [node]
python
{ "resource": "" }
q233168
Inlining.visit_Call
train
def visit_Call(self, node): """ Replace function call by inlined function's body. We can inline if it aliases on only one function. """ func_aliases = self.aliases[node.func] if len(func_aliases) == 1: function_def = next(iter(func_aliases)) if (i...
python
{ "resource": "" }
q233169
size_container_folding
train
def size_container_folding(value): """ Convert value to ast expression if size is not too big. Converter for sized container. """ if len(value) < MAX_LEN: if isinstance(value, list): return ast.List([to_ast(elt) for elt in value], ast.Load()) elif isinstance(value, tuple...
python
{ "resource": "" }
q233170
builtin_folding
train
def builtin_folding(value): """ Convert builtin function to ast expression. """ if isinstance(value, (type(None), bool)): name = str(value) elif value.__name__ in ("bool", "float", "int"): name = value.__name__ + "_" else: name = value.__name__ return ast.Attribute(ast.Name('...
python
{ "resource": "" }
q233171
to_ast
train
def to_ast(value): """ Turn a value into ast expression. >>> a = 1 >>> print(ast.dump(to_ast(a))) Num(n=1) >>> a = [1, 2, 3] >>> print(ast.dump(to_ast(a))) List(elts=[Num(n=1), Num(n=2), Num(n=3)], ctx=Load()) """ if isinstance(value, (type(None), bool)): return builtin...
python
{ "resource": "" }
q233172
GlobalDeclarations.visit_Module
train
def visit_Module(self, node): """ Import module define a new variable name. """ duc = SilentDefUseChains() duc.visit(node) for d in duc.locals[node]: self.result[d.name()] = d.node
python
{ "resource": "" }
q233173
attr_to_path
train
def attr_to_path(node): """ Compute path and final object for an attribute node """ def get_intrinsic_path(modules, attr): """ Get function path and intrinsic from an ast.Attribute. """ if isinstance(attr, ast.Name): return modules[demangle(attr.id)], (demangle(attr.id),) e...
python
{ "resource": "" }
q233174
path_to_attr
train
def path_to_attr(path): """ Transform path to ast.Attribute. >>> import gast as ast >>> path = ('__builtin__', 'my', 'constant') >>> value = path_to_attr(path) >>> ref = ast.Attribute( ... value=ast.Attribute(value=ast.Name(id="__builtin__", ... ...
python
{ "resource": "" }
q233175
get_variable
train
def get_variable(assignable): """ Return modified variable name. >>> import gast as ast >>> ref = ast.Subscript( ... value=ast.Subscript( ... value=ast.Name(id='a', ctx=ast.Load(), annotation=None), ... slice=ast.Index(value=ast.Name('i', ast.Load(), None)), ... ...
python
{ "resource": "" }
q233176
Reorder.prepare
train
def prepare(self, node): """ Format type dependencies information to use if for reordering. """ super(Reorder, self).prepare(node) candidates = self.type_dependencies.successors( TypeDependencies.NoDeps) # We first select function which may have a result without calling any ...
python
{ "resource": "" }
q233177
Reorder.visit_Module
train
def visit_Module(self, node): """ Keep everything but function definition then add sorted functions. Most of the time, many function sort work so we use function calldepth as a "sort hint" to simplify typing. """ newbody = list() olddef = list() for stmt ...
python
{ "resource": "" }
q233178
DeadCodeElimination.visit
train
def visit(self, node): """ Add OMPDirective from the old node to the new one. """ old_omp = metadata.get(node, OMPDirective) node = super(DeadCodeElimination, self).visit(node) if not metadata.get(node, OMPDirective): for omp_directive in old_omp: metadata.add...
python
{ "resource": "" }
q233179
save_intrinsic_alias
train
def save_intrinsic_alias(module): """ Recursively save default aliases for pythonic functions. """ for v in module.values(): if isinstance(v, dict): # Submodules case save_intrinsic_alias(v) else: IntrinsicAliases[v] = frozenset((v,)) if isinstance(v, Class):...
python
{ "resource": "" }
q233180
Aliases.visit_IfExp
train
def visit_IfExp(self, node): ''' Resulting node alias to either branch >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b, c): return a if c else b') >>> result = pm.gather(Aliases, module) >>> Aliase...
python
{ "resource": "" }
q233181
Aliases.visit_Dict
train
def visit_Dict(self, node): ''' A dict is abstracted as an unordered container of its values >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return {0: a, 1: b}') >>> result = pm.gather(Aliases, module) ...
python
{ "resource": "" }
q233182
Aliases.visit_Set
train
def visit_Set(self, node): ''' A set is abstracted as an unordered container of its elements >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return {a, b}') >>> result = pm.gather(Aliases, module) ...
python
{ "resource": "" }
q233183
Aliases.visit_Return
train
def visit_Return(self, node): ''' A side effect of computing aliases on a Return is that it updates the ``return_alias`` field of current function >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return a...
python
{ "resource": "" }
q233184
Aliases.visit_Subscript
train
def visit_Subscript(self, node): ''' Resulting node alias stores the subscript relationship if we don't know anything about the subscripted node. >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a): return a[0]'...
python
{ "resource": "" }
q233185
Aliases.visit_Tuple
train
def visit_Tuple(self, node): ''' A tuple is abstracted as an ordered container of its values >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return a, b') >>> result = pm.gather(Aliases, module) ...
python
{ "resource": "" }
q233186
Aliases.visit_ListComp
train
def visit_ListComp(self, node): ''' A comprehension is not abstracted in any way >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return [a for i in b]') >>> result = pm.gather(Aliases, module) >>...
python
{ "resource": "" }
q233187
Aliases.visit_FunctionDef
train
def visit_FunctionDef(self, node): ''' Initialise aliasing default value before visiting. Add aliasing values for : - Pythonic - globals declarations - current function arguments ''' self.aliases = IntrinsicAliases.copy() self.aliases...
python
{ "resource": "" }
q233188
Aliases.visit_For
train
def visit_For(self, node): ''' For loop creates aliasing between the target and the content of the iterator >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse(""" ... def foo(a): ... for i in a: ...
python
{ "resource": "" }
q233189
ArgumentReadOnce.prepare
train
def prepare(self, node): """ Initialise arguments effects as this analysis in inter-procedural. Initialisation done for Pythonic functions and default values set for user defined functions. """ super(ArgumentReadOnce, self).prepare(node) # global functions init ...
python
{ "resource": "" }
q233190
ds9_objects_to_string
train
def ds9_objects_to_string(regions, coordsys='fk5', fmt='.6f', radunit='deg'): """ Converts a `list` of `~regions.Region` to DS9 region string. Parameters ---------- regions : `list` List of `~regions.Region` objects coordsys : `str`, optional This overrides the coordinate system...
python
{ "resource": "" }
q233191
write_ds9
train
def write_ds9(regions, filename, coordsys='fk5', fmt='.6f', radunit='deg'): """ Converts a `list` of `~regions.Region` to DS9 string and write to file. Parameters ---------- regions : `list` List of `regions.Region` objects filename : `str` Filename in which the string is to be ...
python
{ "resource": "" }
q233192
crtf_objects_to_string
train
def crtf_objects_to_string(regions, coordsys='fk5', fmt='.6f', radunit='deg'): """ Converts a `list` of `~regions.Region` to CRTF region string. Parameters ---------- regions : `list` List of `~regions.Region` objects coordsys : `str`, optional Astropy Coordinate system that ove...
python
{ "resource": "" }
q233193
write_crtf
train
def write_crtf(regions, filename, coordsys='fk5', fmt='.6f', radunit='deg'): """ Converts a `list` of `~regions.Region` to CRTF string and write to file. Parameters ---------- regions : `list` List of `~regions.Region` objects filename : `str` Filename in which the string is to ...
python
{ "resource": "" }
q233194
RectanglePixelRegion.corners
train
def corners(self): """ Return the x, y coordinate pairs that define the corners """ corners = [(-self.width/2, -self.height/2), ( self.width/2, -self.height/2), ( self.width/2, self.height/2), (-self.width/2, self.height/2), ...
python
{ "resource": "" }
q233195
RectanglePixelRegion.to_polygon
train
def to_polygon(self): """ Return a 4-cornered polygon equivalent to this rectangle """ x,y = self.corners.T vertices = PixCoord(x=x, y=y) return PolygonPixelRegion(vertices=vertices, meta=self.meta, visual=self.visual)
python
{ "resource": "" }
q233196
RectanglePixelRegion._lower_left_xy
train
def _lower_left_xy(self): """ Compute lower left `xy` position. This is used for the conversion to matplotlib in ``as_artist`` Taken from http://photutils.readthedocs.io/en/latest/_modules/photutils/aperture/rectangle.html#RectangularAperture.plot """ hw = self.width / ...
python
{ "resource": "" }
q233197
CompoundPixelRegion._make_annulus_path
train
def _make_annulus_path(patch_inner, patch_outer): """ Defines a matplotlib annulus path from two patches. This preserves the cubic Bezier curves (CURVE4) of the aperture paths. # This is borrowed from photutils aperture. """ import matplotlib.path as mpath ...
python
{ "resource": "" }
q233198
read_fits_region
train
def read_fits_region(filename, errors='strict'): """ Reads a FITS region file and scans for any fits regions table and converts them into `Region` objects. Parameters ---------- filename : str The file path errors : ``warn``, ``ignore``, ``strict`` The error handling scheme to...
python
{ "resource": "" }
q233199
to_shape_list
train
def to_shape_list(region_list, coordinate_system='fk5'): """ Converts a list of regions into a `regions.ShapeList` object. Parameters ---------- region_list: python list Lists of `regions.Region` objects format_type: str ('DS9' or 'CRTF') The format type of the Shape object. Def...
python
{ "resource": "" }