id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
251,600 | serge-sans-paille/pythran | pythran/analyses/cfg.py | CFG.visit_ExceptHandler | 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 | def visit_ExceptHandler(self, node):
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)
raises += nraises
return currs, rai... | [
"def",
"visit_ExceptHandler",
"(",
"self",
",",
"node",
")",
":",
"currs",
"=",
"(",
"node",
",",
")",
"raises",
"=",
"(",
")",
"for",
"n",
"in",
"node",
".",
"body",
":",
"self",
".",
"result",
".",
"add_node",
"(",
"n",
")",
"for",
"curr",
"in"... | OUT = body's, RAISES = body's | [
"OUT",
"=",
"body",
"s",
"RAISES",
"=",
"body",
"s"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/cfg.py#L171-L181 |
251,601 | serge-sans-paille/pythran | pythran/analyses/is_assigned.py | IsAssigned.visit_Name | def visit_Name(self, node):
""" Stored variable have new value. """
if isinstance(node.ctx, ast.Store):
self.result[node.id] = True | python | def visit_Name(self, node):
if isinstance(node.ctx, ast.Store):
self.result[node.id] = True | [
"def",
"visit_Name",
"(",
"self",
",",
"node",
")",
":",
"if",
"isinstance",
"(",
"node",
".",
"ctx",
",",
"ast",
".",
"Store",
")",
":",
"self",
".",
"result",
"[",
"node",
".",
"id",
"]",
"=",
"True"
] | Stored variable have new value. | [
"Stored",
"variable",
"have",
"new",
"value",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/is_assigned.py#L23-L26 |
251,602 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.add | 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 | def add(self, variable, range_):
if variable not in self.result:
self.result[variable] = range_
else:
self.result[variable] = self.result[variable].union(range_)
return self.result[variable] | [
"def",
"add",
"(",
"self",
",",
"variable",
",",
"range_",
")",
":",
"if",
"variable",
"not",
"in",
"self",
".",
"result",
":",
"self",
".",
"result",
"[",
"variable",
"]",
"=",
"range_",
"else",
":",
"self",
".",
"result",
"[",
"variable",
"]",
"=... | 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. | [
"Add",
"a",
"new",
"low",
"and",
"high",
"bound",
"for",
"a",
"variable",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L47-L58 |
251,603 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_Assign | 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 | def visit_Assign(self, node):
assigned_range = self.visit(node.value)
for target in node.targets:
if isinstance(target, ast.Name):
# Make sure all Interval doesn't alias for multiple variables.
self.add(target.id, assigned_range)
else:
... | [
"def",
"visit_Assign",
"(",
"self",
",",
"node",
")",
":",
"assigned_range",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"value",
")",
"for",
"target",
"in",
"node",
".",
"targets",
":",
"if",
"isinstance",
"(",
"target",
",",
"ast",
".",
"Name",
")... | 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")
>>> res = pm.gather(RangeValues, node)
... | [
"Set",
"range",
"value",
"for",
"assigned",
"variable",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L74-L96 |
251,604 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_AugAssign | 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 | def visit_AugAssign(self, node):
self.generic_visit(node)
if isinstance(node.target, ast.Name):
name = node.target.id
res = combine(node.op,
self.result[name],
self.result[node.value])
self.result[name] = self.result... | [
"def",
"visit_AugAssign",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"generic_visit",
"(",
"node",
")",
"if",
"isinstance",
"(",
"node",
".",
"target",
",",
"ast",
".",
"Name",
")",
":",
"name",
"=",
"node",
".",
"target",
".",
"id",
"res",
"... | 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(RangeValues, node)
>>> res['a']
Interva... | [
"Update",
"range",
"value",
"for",
"augassigned",
"variables",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L98-L115 |
251,605 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_For | 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 | def visit_For(self, node):
assert isinstance(node.target, ast.Name), "For apply on variables."
self.visit(node.iter)
if isinstance(node.iter, ast.Call):
for alias in self.aliases[node.iter.func]:
if isinstance(alias, Intrinsic):
self.add(node.targe... | [
"def",
"visit_For",
"(",
"self",
",",
"node",
")",
":",
"assert",
"isinstance",
"(",
"node",
".",
"target",
",",
"ast",
".",
"Name",
")",
",",
"\"For apply on variables.\"",
"self",
".",
"visit",
"(",
"node",
".",
"iter",
")",
"if",
"isinstance",
"(",
... | 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 -= 1
... b += 1''')
... | [
"Handle",
"iterate",
"variable",
"in",
"for",
"loops",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L117-L146 |
251,606 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_loop | 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 | def visit_loop(self, node, cond=None):
# visit once to gather newly declared vars
for stmt in node.body:
self.visit(stmt)
# freeze current state
old_range = self.result.copy()
# extra round
for stmt in node.body:
self.visit(stmt)
# widen... | [
"def",
"visit_loop",
"(",
"self",
",",
"node",
",",
"cond",
"=",
"None",
")",
":",
"# visit once to gather newly declared vars",
"for",
"stmt",
"in",
"node",
".",
"body",
":",
"self",
".",
"visit",
"(",
"stmt",
")",
"# freeze current state",
"old_range",
"=",
... | 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
... b += 1''')
>>> pm = pa... | [
"Handle",
"incremented",
"variables",
"in",
"loop",
"body",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L148-L189 |
251,607 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_BoolOp | 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 | def visit_BoolOp(self, node):
res = list(zip(*[self.visit(elt).bounds() for elt in node.values]))
return self.add(node, Interval(min(res[0]), max(res[1]))) | [
"def",
"visit_BoolOp",
"(",
"self",
",",
"node",
")",
":",
"res",
"=",
"list",
"(",
"zip",
"(",
"*",
"[",
"self",
".",
"visit",
"(",
"elt",
")",
".",
"bounds",
"(",
")",
"for",
"elt",
"in",
"node",
".",
"values",
"]",
")",
")",
"return",
"self"... | 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
... c = 3
... d = ... | [
"Merge",
"right",
"and",
"left",
"operands",
"ranges",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L195-L213 |
251,608 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_BinOp | 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 | def visit_BinOp(self, node):
res = combine(node.op, self.visit(node.left), self.visit(node.right))
return self.add(node, res) | [
"def",
"visit_BinOp",
"(",
"self",
",",
"node",
")",
":",
"res",
"=",
"combine",
"(",
"node",
".",
"op",
",",
"self",
".",
"visit",
"(",
"node",
".",
"left",
")",
",",
"self",
".",
"visit",
"(",
"node",
".",
"right",
")",
")",
"return",
"self",
... | 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 = passmanager.PassManager("test")
>>> ... | [
"Combine",
"operands",
"ranges",
"for",
"given",
"operator",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L215-L231 |
251,609 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_UnaryOp | 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 | def visit_UnaryOp(self, node):
res = self.visit(node.operand)
if isinstance(node.op, ast.Not):
res = Interval(0, 1)
elif(isinstance(node.op, ast.Invert) and
isinstance(res.high, int) and
isinstance(res.low, int)):
res = Interval(~res.high, ~res.l... | [
"def",
"visit_UnaryOp",
"(",
"self",
",",
"node",
")",
":",
"res",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"operand",
")",
"if",
"isinstance",
"(",
"node",
".",
"op",
",",
"ast",
".",
"Not",
")",
":",
"res",
"=",
"Interval",
"(",
"0",
",",
... | 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
... e = not a''')
>>> pm = ... | [
"Update",
"range",
"with",
"given",
"unary",
"operation",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L233-L269 |
251,610 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_If | 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 | def visit_If(self, node):
self.visit(node.test)
old_range = self.result
self.result = old_range.copy()
for stmt in node.body:
self.visit(stmt)
body_range = self.result
self.result = old_range.copy()
for stmt in node.orelse:
self.visit(stm... | [
"def",
"visit_If",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"test",
")",
"old_range",
"=",
"self",
".",
"result",
"self",
".",
"result",
"=",
"old_range",
".",
"copy",
"(",
")",
"for",
"stmt",
"in",
"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.PassManager("test")
>>> res = pm.gat... | [
"Handle",
"iterate",
"variable",
"across",
"branches"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L271-L304 |
251,611 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_IfExp | 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 | def visit_IfExp(self, node):
self.visit(node.test)
body_res = self.visit(node.body)
orelse_res = self.visit(node.orelse)
return self.add(node, orelse_res.union(body_res)) | [
"def",
"visit_IfExp",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"test",
")",
"body_res",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"body",
")",
"orelse_res",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"orelse"... | 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''')
>>> pm = passmanager.PassManager("test... | [
"Use",
"worst",
"case",
"for",
"both",
"possible",
"values",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L306-L324 |
251,612 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_Compare | 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 | def visit_Compare(self, node):
if any(isinstance(op, (ast.In, ast.NotIn, ast.Is, ast.IsNot))
for op in node.ops):
self.generic_visit(node)
return self.add(node, Interval(0, 1))
curr = self.visit(node.left)
res = []
for op, comparator in zip(node.op... | [
"def",
"visit_Compare",
"(",
"self",
",",
"node",
")",
":",
"if",
"any",
"(",
"isinstance",
"(",
"op",
",",
"(",
"ast",
".",
"In",
",",
"ast",
".",
"NotIn",
",",
"ast",
".",
"Is",
",",
"ast",
".",
"IsNot",
")",
")",
"for",
"op",
"in",
"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
... e = b == 4''')
>>> pm... | [
"Boolean",
"are",
"possible",
"index",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L326-L368 |
251,613 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_Call | 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 | def visit_Call(self, node):
for alias in self.aliases[node.func]:
if alias is MODULES['__builtin__']['getattr']:
attr_name = node.args[-1].s
attribute = attributes[attr_name][-1]
self.add(node, attribute.return_range(None))
elif isinstance(... | [
"def",
"visit_Call",
"(",
"self",
",",
"node",
")",
":",
"for",
"alias",
"in",
"self",
".",
"aliases",
"[",
"node",
".",
"func",
"]",
":",
"if",
"alias",
"is",
"MODULES",
"[",
"'__builtin__'",
"]",
"[",
"'getattr'",
"]",
":",
"attr_name",
"=",
"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")
>>> res = pm.gather(RangeValues, nod... | [
"Function",
"calls",
"are",
"not",
"handled",
"for",
"now",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L370-L394 |
251,614 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_Num | 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 | def visit_Num(self, node):
if isinstance(node.n, int):
return self.add(node, Interval(node.n, node.n))
return UNKNOWN_RANGE | [
"def",
"visit_Num",
"(",
"self",
",",
"node",
")",
":",
"if",
"isinstance",
"(",
"node",
".",
"n",
",",
"int",
")",
":",
"return",
"self",
".",
"add",
"(",
"node",
",",
"Interval",
"(",
"node",
".",
"n",
",",
"node",
".",
"n",
")",
")",
"return... | Handle literals integers values. | [
"Handle",
"literals",
"integers",
"values",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L396-L400 |
251,615 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.visit_Name | def visit_Name(self, node):
""" Get range for parameters for examples or false branching. """
return self.add(node, self.result[node.id]) | python | def visit_Name(self, node):
return self.add(node, self.result[node.id]) | [
"def",
"visit_Name",
"(",
"self",
",",
"node",
")",
":",
"return",
"self",
".",
"add",
"(",
"node",
",",
"self",
".",
"result",
"[",
"node",
".",
"id",
"]",
")"
] | Get range for parameters for examples or false branching. | [
"Get",
"range",
"for",
"parameters",
"for",
"examples",
"or",
"false",
"branching",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L402-L404 |
251,616 | serge-sans-paille/pythran | pythran/analyses/range_values.py | RangeValues.generic_visit | 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 | def generic_visit(self, node):
super(RangeValues, self).generic_visit(node)
return self.add(node, UNKNOWN_RANGE) | [
"def",
"generic_visit",
"(",
"self",
",",
"node",
")",
":",
"super",
"(",
"RangeValues",
",",
"self",
")",
".",
"generic_visit",
"(",
"node",
")",
"return",
"self",
".",
"add",
"(",
"node",
",",
"UNKNOWN_RANGE",
")"
] | Other nodes are not known and range value neither. | [
"Other",
"nodes",
"are",
"not",
"known",
"and",
"range",
"value",
"neither",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/range_values.py#L448-L451 |
251,617 | serge-sans-paille/pythran | pythran/run.py | compile_flags | 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 | def compile_flags(args):
compiler_options = {
'define_macros': args.defines,
'undef_macros': args.undefs,
'include_dirs': args.include_dirs,
'extra_compile_args': args.extra_flags,
'library_dirs': args.libraries_dir,
'extra_link_args': args.extra_flags,
}
for ... | [
"def",
"compile_flags",
"(",
"args",
")",
":",
"compiler_options",
"=",
"{",
"'define_macros'",
":",
"args",
".",
"defines",
",",
"'undef_macros'",
":",
"args",
".",
"undefs",
",",
"'include_dirs'",
":",
"args",
".",
"include_dirs",
",",
"'extra_compile_args'",
... | Build a dictionnary with an entry for cppflags, ldflags, and cxxflags.
These options are filled according to the command line defined options | [
"Build",
"a",
"dictionnary",
"with",
"an",
"entry",
"for",
"cppflags",
"ldflags",
"and",
"cxxflags",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/run.py#L25-L46 |
251,618 | serge-sans-paille/pythran | pythran/optimizations/iter_transformation.py | IterTransformation.find_matching_builtin | 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 | def find_matching_builtin(self, node):
for path in EQUIVALENT_ITERATORS.keys():
correct_alias = {path_to_node(path)}
if self.aliases[node.func] == correct_alias:
return path | [
"def",
"find_matching_builtin",
"(",
"self",
",",
"node",
")",
":",
"for",
"path",
"in",
"EQUIVALENT_ITERATORS",
".",
"keys",
"(",
")",
":",
"correct_alias",
"=",
"{",
"path_to_node",
"(",
"path",
")",
"}",
"if",
"self",
".",
"aliases",
"[",
"node",
".",... | Return matched keyword.
If the node alias on a correct keyword (and only it), it matches. | [
"Return",
"matched",
"keyword",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/iter_transformation.py#L58-L67 |
251,619 | serge-sans-paille/pythran | pythran/optimizations/iter_transformation.py | IterTransformation.visit_Module | 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 | def visit_Module(self, node):
self.generic_visit(node)
import_alias = ast.alias(name='itertools', asname=mangle('itertools'))
if self.use_itertools:
importIt = ast.Import(names=[import_alias])
node.body.insert(0, importIt)
return node | [
"def",
"visit_Module",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"generic_visit",
"(",
"node",
")",
"import_alias",
"=",
"ast",
".",
"alias",
"(",
"name",
"=",
"'itertools'",
",",
"asname",
"=",
"mangle",
"(",
"'itertools'",
")",
")",
"if",
"sel... | Add itertools import for imap, izip or ifilter iterator. | [
"Add",
"itertools",
"import",
"for",
"imap",
"izip",
"or",
"ifilter",
"iterator",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/iter_transformation.py#L69-L76 |
251,620 | serge-sans-paille/pythran | pythran/optimizations/iter_transformation.py | IterTransformation.visit_Call | 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 | def visit_Call(self, node):
if node in self.potential_iterator:
matched_path = self.find_matching_builtin(node)
if matched_path is None:
return self.generic_visit(node)
# Special handling for map which can't be turn to imap with None as
# a parame... | [
"def",
"visit_Call",
"(",
"self",
",",
"node",
")",
":",
"if",
"node",
"in",
"self",
".",
"potential_iterator",
":",
"matched_path",
"=",
"self",
".",
"find_matching_builtin",
"(",
"node",
")",
"if",
"matched_path",
"is",
"None",
":",
"return",
"self",
"."... | Replace function call by its correct iterator if it is possible. | [
"Replace",
"function",
"call",
"by",
"its",
"correct",
"iterator",
"if",
"it",
"is",
"possible",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/iter_transformation.py#L78-L105 |
251,621 | serge-sans-paille/pythran | docs/papers/iop2014/xp/numba/hyantes.py | run | 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 | 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... | [
"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 | [
"omp",
"parallel",
"for"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/docs/papers/iop2014/xp/numba/hyantes.py#L4-L14 |
251,622 | serge-sans-paille/pythran | pythran/interval.py | max_values | 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 | def max_values(args):
return Interval(max(x.low for x in args), max(x.high for x in args)) | [
"def",
"max_values",
"(",
"args",
")",
":",
"return",
"Interval",
"(",
"max",
"(",
"x",
".",
"low",
"for",
"x",
"in",
"args",
")",
",",
"max",
"(",
"x",
".",
"high",
"for",
"x",
"in",
"args",
")",
")"
] | Return possible range for max function. | [
"Return",
"possible",
"range",
"for",
"max",
"function",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/interval.py#L405-L407 |
251,623 | serge-sans-paille/pythran | pythran/interval.py | min_values | 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 | def min_values(args):
return Interval(min(x.low for x in args), min(x.high for x in args)) | [
"def",
"min_values",
"(",
"args",
")",
":",
"return",
"Interval",
"(",
"min",
"(",
"x",
".",
"low",
"for",
"x",
"in",
"args",
")",
",",
"min",
"(",
"x",
".",
"high",
"for",
"x",
"in",
"args",
")",
")"
] | Return possible range for min function. | [
"Return",
"possible",
"range",
"for",
"min",
"function",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/interval.py#L410-L412 |
251,624 | serge-sans-paille/pythran | pythran/interval.py | Interval.union | def union(self, other):
""" Intersect current range with other."""
return Interval(min(self.low, other.low), max(self.high, other.high)) | python | def union(self, other):
return Interval(min(self.low, other.low), max(self.high, other.high)) | [
"def",
"union",
"(",
"self",
",",
"other",
")",
":",
"return",
"Interval",
"(",
"min",
"(",
"self",
".",
"low",
",",
"other",
".",
"low",
")",
",",
"max",
"(",
"self",
".",
"high",
",",
"other",
".",
"high",
")",
")"
] | Intersect current range with other. | [
"Intersect",
"current",
"range",
"with",
"other",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/interval.py#L38-L40 |
251,625 | serge-sans-paille/pythran | pythran/interval.py | Interval.widen | 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 | def widen(self, other):
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) | [
"def",
"widen",
"(",
"self",
",",
"other",
")",
":",
"if",
"self",
".",
"low",
"<",
"other",
".",
"low",
":",
"low",
"=",
"-",
"float",
"(",
"\"inf\"",
")",
"else",
":",
"low",
"=",
"self",
".",
"low",
"if",
"self",
".",
"high",
">",
"other",
... | Widen current range. | [
"Widen",
"current",
"range",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/interval.py#L45-L55 |
251,626 | serge-sans-paille/pythran | pythran/transformations/remove_named_arguments.py | RemoveNamedArguments.handle_keywords | 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 | 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... | [
"def",
"handle_keywords",
"(",
"self",
",",
"func",
",",
"node",
",",
"offset",
"=",
"0",
")",
":",
"func_argument_names",
"=",
"{",
"}",
"for",
"i",
",",
"arg",
"in",
"enumerate",
"(",
"func",
".",
"args",
".",
"args",
"[",
"offset",
":",
"]",
")"... | Gather keywords to positional argument information
Assumes the named parameter exist, raises a KeyError otherwise | [
"Gather",
"keywords",
"to",
"positional",
"argument",
"information"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/transformations/remove_named_arguments.py#L38-L62 |
251,627 | serge-sans-paille/pythran | pythran/tables.py | update_effects | 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 | def update_effects(self, node):
return [self.combine(node.args[0], node_args_k, register=True,
aliasing_type=True)
for node_args_k in node.args[1:]] | [
"def",
"update_effects",
"(",
"self",
",",
"node",
")",
":",
"return",
"[",
"self",
".",
"combine",
"(",
"node",
".",
"args",
"[",
"0",
"]",
",",
"node_args_k",
",",
"register",
"=",
"True",
",",
"aliasing_type",
"=",
"True",
")",
"for",
"node_args_k",... | Combiner when we update the first argument of a function.
It turn type of first parameter in combination of all others
parameters types. | [
"Combiner",
"when",
"we",
"update",
"the",
"first",
"argument",
"of",
"a",
"function",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/tables.py#L161-L170 |
251,628 | serge-sans-paille/pythran | pythran/tables.py | save_method | 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 | def save_method(elements, module_path):
for elem, signature in elements.items():
if isinstance(signature, dict): # Submodule case
save_method(signature, module_path + (elem,))
elif isinstance(signature, Class):
save_method(signature.fields, module_path + (elem,))
eli... | [
"def",
"save_method",
"(",
"elements",
",",
"module_path",
")",
":",
"for",
"elem",
",",
"signature",
"in",
"elements",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"signature",
",",
"dict",
")",
":",
"# Submodule case",
"save_method",
"(",
"signa... | Recursively save methods with module name and signature. | [
"Recursively",
"save",
"methods",
"with",
"module",
"name",
"and",
"signature",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/tables.py#L4609-L4624 |
251,629 | serge-sans-paille/pythran | pythran/tables.py | save_function | 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 | def save_function(elements, module_path):
for elem, signature in elements.items():
if isinstance(signature, dict): # Submodule case
save_function(signature, module_path + (elem,))
elif signature.isstaticfunction():
functions.setdefault(elem, []).append((module_path, signatur... | [
"def",
"save_function",
"(",
"elements",
",",
"module_path",
")",
":",
"for",
"elem",
",",
"signature",
"in",
"elements",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"signature",
",",
"dict",
")",
":",
"# Submodule case",
"save_function",
"(",
"s... | Recursively save functions with module name and signature. | [
"Recursively",
"save",
"functions",
"with",
"module",
"name",
"and",
"signature",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/tables.py#L4634-L4642 |
251,630 | serge-sans-paille/pythran | pythran/tables.py | save_attribute | 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 | def save_attribute(elements, module_path):
for elem, signature in elements.items():
if isinstance(signature, dict): # Submodule case
save_attribute(signature, module_path + (elem,))
elif signature.isattribute():
assert elem not in attributes # we need unicity
at... | [
"def",
"save_attribute",
"(",
"elements",
",",
"module_path",
")",
":",
"for",
"elem",
",",
"signature",
"in",
"elements",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"signature",
",",
"dict",
")",
":",
"# Submodule case",
"save_attribute",
"(",
... | Recursively save attributes with module name and signature. | [
"Recursively",
"save",
"attributes",
"with",
"module",
"name",
"and",
"signature",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/tables.py#L4653-L4662 |
251,631 | serge-sans-paille/pythran | pythran/optimizations/list_to_tuple.py | ListToTuple.visit_Assign | 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 | def visit_Assign(self, node):
self.generic_visit(node)
if node.value not in self.fixed_size_list:
return node
node.value = self.convert(node.value)
return node | [
"def",
"visit_Assign",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"generic_visit",
"(",
"node",
")",
"if",
"node",
".",
"value",
"not",
"in",
"self",
".",
"fixed_size_list",
":",
"return",
"node",
"node",
".",
"value",
"=",
"self",
".",
"convert"... | 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 = passmanager.PassManager("test")
>>> _, node = pm.... | [
"Replace",
"list",
"calls",
"by",
"static_list",
"calls",
"when",
"possible"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/list_to_tuple.py#L66-L95 |
251,632 | serge-sans-paille/pythran | setup.py | BuildWithThirdParty.copy_pkg | 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 | 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)
#... | [
"def",
"copy_pkg",
"(",
"self",
",",
"pkg",
",",
"src_only",
"=",
"False",
")",
":",
"if",
"getattr",
"(",
"self",
",",
"'no_'",
"+",
"pkg",
")",
"is",
"None",
":",
"print",
"(",
"'Copying boost dependencies'",
")",
"to_copy",
"=",
"pkg",
",",
"else",
... | Install boost deps from the third_party directory | [
"Install",
"boost",
"deps",
"from",
"the",
"third_party",
"directory"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/setup.py#L75-L95 |
251,633 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.check_list | 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 | def check_list(self, node_list, pattern_list):
if len(node_list) != len(pattern_list):
return False
else:
return all(Check(node_elt,
self.placeholders).visit(pattern_list[i])
for i, node_elt in enumerate(node_list)) | [
"def",
"check_list",
"(",
"self",
",",
"node_list",
",",
"pattern_list",
")",
":",
"if",
"len",
"(",
"node_list",
")",
"!=",
"len",
"(",
"pattern_list",
")",
":",
"return",
"False",
"else",
":",
"return",
"all",
"(",
"Check",
"(",
"node_elt",
",",
"sel... | Check if list of node are equal. | [
"Check",
"if",
"list",
"of",
"node",
"are",
"equal",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L67-L74 |
251,634 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.visit_Placeholder | 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 | def visit_Placeholder(self, pattern):
if (pattern.id in self.placeholders and
not Check(self.node, self.placeholders).visit(
self.placeholders[pattern.id])):
return False
else:
self.placeholders[pattern.id] = self.node
return True | [
"def",
"visit_Placeholder",
"(",
"self",
",",
"pattern",
")",
":",
"if",
"(",
"pattern",
".",
"id",
"in",
"self",
".",
"placeholders",
"and",
"not",
"Check",
"(",
"self",
".",
"node",
",",
"self",
".",
"placeholders",
")",
".",
"visit",
"(",
"self",
... | Save matching node or compare it with the existing one.
FIXME : What if the new placeholder is a better choice? | [
"Save",
"matching",
"node",
"or",
"compare",
"it",
"with",
"the",
"existing",
"one",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L76-L88 |
251,635 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.visit_AST_or | 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 | def visit_AST_or(self, pattern):
return any(self.field_match(self.node, value_or)
for value_or in pattern.args) | [
"def",
"visit_AST_or",
"(",
"self",
",",
"pattern",
")",
":",
"return",
"any",
"(",
"self",
".",
"field_match",
"(",
"self",
".",
"node",
",",
"value_or",
")",
"for",
"value_or",
"in",
"pattern",
".",
"args",
")"
] | Match if any of the or content match with the other node. | [
"Match",
"if",
"any",
"of",
"the",
"or",
"content",
"match",
"with",
"the",
"other",
"node",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L95-L98 |
251,636 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.visit_Set | 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 | def visit_Set(self, pattern):
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)
for pattern_elts in permutations(pat... | [
"def",
"visit_Set",
"(",
"self",
",",
"pattern",
")",
":",
"if",
"len",
"(",
"pattern",
".",
"elts",
")",
">",
"MAX_UNORDERED_LENGTH",
":",
"raise",
"DamnTooLongPattern",
"(",
"\"Pattern for Set is too long\"",
")",
"return",
"(",
"isinstance",
"(",
"self",
".... | Set have unordered values. | [
"Set",
"have",
"unordered",
"values",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L100-L106 |
251,637 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.visit_Dict | 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 | def visit_Dict(self, pattern):
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(range(len(self.node.keys))):
for i, value in e... | [
"def",
"visit_Dict",
"(",
"self",
",",
"pattern",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"node",
",",
"Dict",
")",
":",
"return",
"False",
"if",
"len",
"(",
"pattern",
".",
"keys",
")",
">",
"MAX_UNORDERED_LENGTH",
":",
"raise",
"DamnTo... | Dict can match with unordered values. | [
"Dict",
"can",
"match",
"with",
"unordered",
"values",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L108-L122 |
251,638 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.field_match | 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 | def field_match(self, node_field, pattern_field):
is_good_list = (isinstance(pattern_field, list) and
self.check_list(node_field, pattern_field))
is_good_node = (isinstance(pattern_field, AST) and
Check(node_field,
self.placeh... | [
"def",
"field_match",
"(",
"self",
",",
"node_field",
",",
"pattern_field",
")",
":",
"is_good_list",
"=",
"(",
"isinstance",
"(",
"pattern_field",
",",
"list",
")",
"and",
"self",
".",
"check_list",
"(",
"node_field",
",",
"pattern_field",
")",
")",
"is_goo... | 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. | [
"Check",
"if",
"two",
"fields",
"match",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L124-L146 |
251,639 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | Check.generic_visit | 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 | def generic_visit(self, pattern):
return (isinstance(pattern, type(self.node)) and
all(self.field_match(value, getattr(pattern, field))
for field, value in iter_fields(self.node))) | [
"def",
"generic_visit",
"(",
"self",
",",
"pattern",
")",
":",
"return",
"(",
"isinstance",
"(",
"pattern",
",",
"type",
"(",
"self",
".",
"node",
")",
")",
"and",
"all",
"(",
"self",
".",
"field_match",
"(",
"value",
",",
"getattr",
"(",
"pattern",
... | Check if the pattern match with the checked node.
a node match if:
- type match
- all field match | [
"Check",
"if",
"the",
"pattern",
"match",
"with",
"the",
"checked",
"node",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L148-L158 |
251,640 | serge-sans-paille/pythran | pythran/analyses/ast_matcher.py | ASTMatcher.visit | 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 | def visit(self, node):
if Check(node, dict()).visit(self.pattern):
self.result.add(node)
self.generic_visit(node) | [
"def",
"visit",
"(",
"self",
",",
"node",
")",
":",
"if",
"Check",
"(",
"node",
",",
"dict",
"(",
")",
")",
".",
"visit",
"(",
"self",
".",
"pattern",
")",
":",
"self",
".",
"result",
".",
"add",
"(",
"node",
")",
"self",
".",
"generic_visit",
... | Visitor looking for matching between current node and pattern.
If it match, save it but whatever happen, keep going. | [
"Visitor",
"looking",
"for",
"matching",
"between",
"current",
"node",
"and",
"pattern",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/ast_matcher.py#L199-L207 |
251,641 | serge-sans-paille/pythran | pythran/analyses/lazyness_analysis.py | LazynessAnalysis.visit_Call | 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 | def visit_Call(self, node):
md.visit(self, node)
for arg in node.args:
self.visit(arg)
self.func_args_lazyness(node.func, node.args, node)
self.visit(node.func) | [
"def",
"visit_Call",
"(",
"self",
",",
"node",
")",
":",
"md",
".",
"visit",
"(",
"self",
",",
"node",
")",
"for",
"arg",
"in",
"node",
".",
"args",
":",
"self",
".",
"visit",
"(",
"arg",
")",
"self",
".",
"func_args_lazyness",
"(",
"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. | [
"Compute",
"use",
"of",
"variables",
"in",
"a",
"function",
"call",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/lazyness_analysis.py#L359-L371 |
251,642 | serge-sans-paille/pythran | docs/papers/iop2014/xp/numba/nqueens.py | n_queens | 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 | def n_queens(queen_count):
out =list()
cols = range(queen_count)
#for vec in permutations(cols):
for vec in permutations(cols,None):
if (queen_count == len(set(vec[i]+i for i in cols))
== len(set(vec[i]-i for i in cols))):
#yield vec
out.append(vec... | [
"def",
"n_queens",
"(",
"queen_count",
")",
":",
"out",
"=",
"list",
"(",
")",
"cols",
"=",
"range",
"(",
"queen_count",
")",
"#for vec in permutations(cols):",
"for",
"vec",
"in",
"permutations",
"(",
"cols",
",",
"None",
")",
":",
"if",
"(",
"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
queen, and the index into ... | [
"N",
"-",
"Queens",
"solver",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/docs/papers/iop2014/xp/numba/nqueens.py#L30-L50 |
251,643 | serge-sans-paille/pythran | pythran/optimizations/inlining.py | Inlining.visit_Stmt | 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 | def visit_Stmt(self, node):
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] | [
"def",
"visit_Stmt",
"(",
"self",
",",
"node",
")",
":",
"save_defs",
",",
"self",
".",
"defs",
"=",
"self",
".",
"defs",
"or",
"list",
"(",
")",
",",
"list",
"(",
")",
"self",
".",
"generic_visit",
"(",
"node",
")",
"new_defs",
",",
"self",
".",
... | Add new variable definition before the Statement. | [
"Add",
"new",
"variable",
"definition",
"before",
"the",
"Statement",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/inlining.py#L44-L49 |
251,644 | serge-sans-paille/pythran | pythran/optimizations/inlining.py | Inlining.visit_Call | 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 | def visit_Call(self, node):
func_aliases = self.aliases[node.func]
if len(func_aliases) == 1:
function_def = next(iter(func_aliases))
if (isinstance(function_def, ast.FunctionDef) and
function_def.name in self.inlinable):
self.update = True
... | [
"def",
"visit_Call",
"(",
"self",
",",
"node",
")",
":",
"func_aliases",
"=",
"self",
".",
"aliases",
"[",
"node",
".",
"func",
"]",
"if",
"len",
"(",
"func_aliases",
")",
"==",
"1",
":",
"function_def",
"=",
"next",
"(",
"iter",
"(",
"func_aliases",
... | Replace function call by inlined function's body.
We can inline if it aliases on only one function. | [
"Replace",
"function",
"call",
"by",
"inlined",
"function",
"s",
"body",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/inlining.py#L62-L93 |
251,645 | serge-sans-paille/pythran | pythran/conversion.py | size_container_folding | 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 | def size_container_folding(value):
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):
return ast.Tuple([to_ast(elt) for elt in value], ast.Load())
elif isinstance(value, set):... | [
"def",
"size_container_folding",
"(",
"value",
")",
":",
"if",
"len",
"(",
"value",
")",
"<",
"MAX_LEN",
":",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"return",
"ast",
".",
"List",
"(",
"[",
"to_ast",
"(",
"elt",
")",
"for",
"elt",
... | Convert value to ast expression if size is not too big.
Converter for sized container. | [
"Convert",
"value",
"to",
"ast",
"expression",
"if",
"size",
"is",
"not",
"too",
"big",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/conversion.py#L34-L65 |
251,646 | serge-sans-paille/pythran | pythran/conversion.py | builtin_folding | 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 | def builtin_folding(value):
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('__builtin__', ast.Load(), None),
... | [
"def",
"builtin_folding",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
"type",
"(",
"None",
")",
",",
"bool",
")",
")",
":",
"name",
"=",
"str",
"(",
"value",
")",
"elif",
"value",
".",
"__name__",
"in",
"(",
"\"bool\"",
",",... | Convert builtin function to ast expression. | [
"Convert",
"builtin",
"function",
"to",
"ast",
"expression",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/conversion.py#L68-L77 |
251,647 | serge-sans-paille/pythran | pythran/conversion.py | to_ast | 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 | def to_ast(value):
if isinstance(value, (type(None), bool)):
return builtin_folding(value)
if sys.version_info[0] == 2 and isinstance(value, long):
from pythran.syntax import PythranSyntaxError
raise PythranSyntaxError("constant folding results in big int")
if any(value is t for t in... | [
"def",
"to_ast",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
"type",
"(",
"None",
")",
",",
"bool",
")",
")",
":",
"return",
"builtin_folding",
"(",
"value",
")",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"==",
"2",
... | 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()) | [
"Turn",
"a",
"value",
"into",
"ast",
"expression",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/conversion.py#L80-L118 |
251,648 | serge-sans-paille/pythran | pythran/analyses/global_declarations.py | GlobalDeclarations.visit_Module | 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 | def visit_Module(self, node):
duc = SilentDefUseChains()
duc.visit(node)
for d in duc.locals[node]:
self.result[d.name()] = d.node | [
"def",
"visit_Module",
"(",
"self",
",",
"node",
")",
":",
"duc",
"=",
"SilentDefUseChains",
"(",
")",
"duc",
".",
"visit",
"(",
"node",
")",
"for",
"d",
"in",
"duc",
".",
"locals",
"[",
"node",
"]",
":",
"self",
".",
"result",
"[",
"d",
".",
"na... | Import module define a new variable name. | [
"Import",
"module",
"define",
"a",
"new",
"variable",
"name",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/global_declarations.py#L39-L44 |
251,649 | serge-sans-paille/pythran | pythran/utils.py | attr_to_path | 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 | def attr_to_path(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),)
elif isinstance(attr, ast.Attribute):
module, path = g... | [
"def",
"attr_to_path",
"(",
"node",
")",
":",
"def",
"get_intrinsic_path",
"(",
"modules",
",",
"attr",
")",
":",
"\"\"\" Get function path and intrinsic from an ast.Attribute. \"\"\"",
"if",
"isinstance",
"(",
"attr",
",",
"ast",
".",
"Name",
")",
":",
"return",
... | Compute path and final object for an attribute node | [
"Compute",
"path",
"and",
"final",
"object",
"for",
"an",
"attribute",
"node"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/utils.py#L10-L23 |
251,650 | serge-sans-paille/pythran | pythran/utils.py | path_to_attr | 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 | def path_to_attr(path):
return reduce(lambda hpath, last: ast.Attribute(hpath, last, ast.Load()),
path[1:], ast.Name(mangle(path[0]), ast.Load(), None)) | [
"def",
"path_to_attr",
"(",
"path",
")",
":",
"return",
"reduce",
"(",
"lambda",
"hpath",
",",
"last",
":",
"ast",
".",
"Attribute",
"(",
"hpath",
",",
"last",
",",
"ast",
".",
"Load",
"(",
")",
")",
",",
"path",
"[",
"1",
":",
"]",
",",
"ast",
... | 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__",
... ctx=ast.Load(),
... ... | [
"Transform",
"path",
"to",
"ast",
".",
"Attribute",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/utils.py#L26-L43 |
251,651 | serge-sans-paille/pythran | pythran/utils.py | get_variable | 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 | def get_variable(assignable):
msg = "Only name and subscript can be assigned."
assert isinstance(assignable, (ast.Name, ast.Subscript)), msg
while isinstance(assignable, ast.Subscript) or isattr(assignable):
if isattr(assignable):
assignable = assignable.args[0]
else:
... | [
"def",
"get_variable",
"(",
"assignable",
")",
":",
"msg",
"=",
"\"Only name and subscript can be assigned.\"",
"assert",
"isinstance",
"(",
"assignable",
",",
"(",
"ast",
".",
"Name",
",",
"ast",
".",
"Subscript",
")",
")",
",",
"msg",
"while",
"isinstance",
... | 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)),
... ctx=ast.Load()),
... slice=ast... | [
"Return",
"modified",
"variable",
"name",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/utils.py#L64-L87 |
251,652 | serge-sans-paille/pythran | pythran/types/reorder.py | Reorder.prepare | 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 | def prepare(self, node):
super(Reorder, self).prepare(node)
candidates = self.type_dependencies.successors(
TypeDependencies.NoDeps)
# We first select function which may have a result without calling any
# others functions.
# Then we check if no loops type dependencie... | [
"def",
"prepare",
"(",
"self",
",",
"node",
")",
":",
"super",
"(",
"Reorder",
",",
"self",
")",
".",
"prepare",
"(",
"node",
")",
"candidates",
"=",
"self",
".",
"type_dependencies",
".",
"successors",
"(",
"TypeDependencies",
".",
"NoDeps",
")",
"# We ... | Format type dependencies information to use if for reordering. | [
"Format",
"type",
"dependencies",
"information",
"to",
"use",
"if",
"for",
"reordering",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/types/reorder.py#L57-L91 |
251,653 | serge-sans-paille/pythran | pythran/types/reorder.py | Reorder.visit_Module | 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 | def visit_Module(self, node):
newbody = list()
olddef = list()
for stmt in node.body:
if isinstance(stmt, ast.FunctionDef):
olddef.append(stmt)
else:
newbody.append(stmt)
try:
newdef = topological_sort(
s... | [
"def",
"visit_Module",
"(",
"self",
",",
"node",
")",
":",
"newbody",
"=",
"list",
"(",
")",
"olddef",
"=",
"list",
"(",
")",
"for",
"stmt",
"in",
"node",
".",
"body",
":",
"if",
"isinstance",
"(",
"stmt",
",",
"ast",
".",
"FunctionDef",
")",
":",
... | 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. | [
"Keep",
"everything",
"but",
"function",
"definition",
"then",
"add",
"sorted",
"functions",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/types/reorder.py#L93-L118 |
251,654 | serge-sans-paille/pythran | pythran/optimizations/dead_code_elimination.py | DeadCodeElimination.visit | 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 | def visit(self, node):
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(node, omp_directive)
return node | [
"def",
"visit",
"(",
"self",
",",
"node",
")",
":",
"old_omp",
"=",
"metadata",
".",
"get",
"(",
"node",
",",
"OMPDirective",
")",
"node",
"=",
"super",
"(",
"DeadCodeElimination",
",",
"self",
")",
".",
"visit",
"(",
"node",
")",
"if",
"not",
"metad... | Add OMPDirective from the old node to the new one. | [
"Add",
"OMPDirective",
"from",
"the",
"old",
"node",
"to",
"the",
"new",
"one",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/optimizations/dead_code_elimination.py#L133-L140 |
251,655 | serge-sans-paille/pythran | pythran/analyses/aliases.py | save_intrinsic_alias | 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 | def save_intrinsic_alias(module):
for v in module.values():
if isinstance(v, dict): # Submodules case
save_intrinsic_alias(v)
else:
IntrinsicAliases[v] = frozenset((v,))
if isinstance(v, Class):
save_intrinsic_alias(v.fields) | [
"def",
"save_intrinsic_alias",
"(",
"module",
")",
":",
"for",
"v",
"in",
"module",
".",
"values",
"(",
")",
":",
"if",
"isinstance",
"(",
"v",
",",
"dict",
")",
":",
"# Submodules case",
"save_intrinsic_alias",
"(",
"v",
")",
"else",
":",
"IntrinsicAliase... | Recursively save default aliases for pythonic functions. | [
"Recursively",
"save",
"default",
"aliases",
"for",
"pythonic",
"functions",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L53-L61 |
251,656 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_IfExp | 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 | 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... | [
"def",
"visit_IfExp",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"test",
")",
"rec",
"=",
"[",
"self",
".",
"visit",
"(",
"n",
")",
"for",
"n",
"in",
"(",
"node",
".",
"body",
",",
"node",
".",
"orelse",
")",
... | 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)
>>> Aliases.dump(result, filter=ast.IfExp)
(a if c ... | [
"Resulting",
"node",
"alias",
"to",
"either",
"branch"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L164-L177 |
251,657 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_Dict | 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 | 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)
... | [
"def",
"visit_Dict",
"(",
"self",
",",
"node",
")",
":",
"if",
"node",
".",
"keys",
":",
"elts_aliases",
"=",
"set",
"(",
")",
"for",
"key",
",",
"val",
"in",
"zip",
"(",
"node",
".",
"keys",
",",
"node",
".",
"values",
")",
":",
"self",
".",
"... | 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)
>>> Aliases.dump(result, filter=ast.Dict... | [
"A",
"dict",
"is",
"abstracted",
"as",
"an",
"unordered",
"container",
"of",
"its",
"values"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L179-L200 |
251,658 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_Set | 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 | 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)
... | [
"def",
"visit_Set",
"(",
"self",
",",
"node",
")",
":",
"if",
"node",
".",
"elts",
":",
"elts_aliases",
"=",
"{",
"ContainerOf",
"(",
"alias",
")",
"for",
"elt",
"in",
"node",
".",
"elts",
"for",
"alias",
"in",
"self",
".",
"visit",
"(",
"elt",
")"... | 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)
>>> Aliases.dump(result, filter=ast.Set)
... | [
"A",
"set",
"is",
"abstracted",
"as",
"an",
"unordered",
"container",
"of",
"its",
"elements"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L202-L221 |
251,659 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_Return | 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 | 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... | [
"def",
"visit_Return",
"(",
"self",
",",
"node",
")",
":",
"if",
"not",
"node",
".",
"value",
":",
"return",
"ret_aliases",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"value",
")",
"if",
"Aliases",
".",
"RetId",
"in",
"self",
".",
"aliases",
":",
... | 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')
>>> result = pm.gather(Aliases, module)... | [
"A",
"side",
"effect",
"of",
"computing",
"aliases",
"on",
"a",
"Return",
"is",
"that",
"it",
"updates",
"the",
"return_alias",
"field",
"of",
"current",
"function"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L223-L263 |
251,660 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_Subscript | 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 | 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]'... | [
"def",
"visit_Subscript",
"(",
"self",
",",
"node",
")",
":",
"if",
"isinstance",
"(",
"node",
".",
"slice",
",",
"ast",
".",
"Index",
")",
":",
"aliases",
"=",
"set",
"(",
")",
"self",
".",
"visit",
"(",
"node",
".",
"slice",
")",
"value_aliases",
... | 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]')
>>> result = pm.gather(Aliases, module)
... | [
"Resulting",
"node",
"alias",
"stores",
"the",
"subscript",
"relationship",
"if",
"we",
"don",
"t",
"know",
"anything",
"about",
"the",
"subscripted",
"node",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L388-L445 |
251,661 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_Tuple | 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 | 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)
... | [
"def",
"visit_Tuple",
"(",
"self",
",",
"node",
")",
":",
"if",
"node",
".",
"elts",
":",
"elts_aliases",
"=",
"set",
"(",
")",
"for",
"i",
",",
"elt",
"in",
"enumerate",
"(",
"node",
".",
"elts",
")",
":",
"elt_aliases",
"=",
"self",
".",
"visit",... | 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)
>>> Aliases.dump(result, filter=ast.Tuple)
... | [
"A",
"tuple",
"is",
"abstracted",
"as",
"an",
"ordered",
"container",
"of",
"its",
"values"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L463-L485 |
251,662 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_ListComp | 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 | 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)
>>... | [
"def",
"visit_ListComp",
"(",
"self",
",",
"node",
")",
":",
"for",
"generator",
"in",
"node",
".",
"generators",
":",
"self",
".",
"visit_comprehension",
"(",
"generator",
")",
"self",
".",
"visit",
"(",
"node",
".",
"elt",
")",
"return",
"self",
".",
... | 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)
>>> Aliases.dump(result, filter=ast.ListComp)
... | [
"A",
"comprehension",
"is",
"not",
"abstracted",
"in",
"any",
"way"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L493-L507 |
251,663 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_FunctionDef | 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 | 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... | [
"def",
"visit_FunctionDef",
"(",
"self",
",",
"node",
")",
":",
"self",
".",
"aliases",
"=",
"IntrinsicAliases",
".",
"copy",
"(",
")",
"self",
".",
"aliases",
".",
"update",
"(",
"(",
"f",
".",
"name",
",",
"{",
"f",
"}",
")",
"for",
"f",
"in",
... | Initialise aliasing default value before visiting.
Add aliasing values for :
- Pythonic
- globals declarations
- current function arguments | [
"Initialise",
"aliasing",
"default",
"value",
"before",
"visiting",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L532-L600 |
251,664 | serge-sans-paille/pythran | pythran/analyses/aliases.py | Aliases.visit_For | 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 | 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:
... | [
"def",
"visit_For",
"(",
"self",
",",
"node",
")",
":",
"iter_aliases",
"=",
"self",
".",
"visit",
"(",
"node",
".",
"iter",
")",
"if",
"all",
"(",
"isinstance",
"(",
"x",
",",
"ContainerOf",
")",
"for",
"x",
"in",
"iter_aliases",
")",
":",
"target_a... | 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:
... {i}""")
>>> result = pm.ga... | [
"For",
"loop",
"creates",
"aliasing",
"between",
"the",
"target",
"and",
"the",
"content",
"of",
"the",
"iterator"
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L628-L666 |
251,665 | serge-sans-paille/pythran | pythran/analyses/argument_read_once.py | ArgumentReadOnce.prepare | 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 | def prepare(self, node):
super(ArgumentReadOnce, self).prepare(node)
# global functions init
for n in self.global_declarations.values():
fe = ArgumentReadOnce.FunctionEffects(n)
self.node_to_functioneffect[n] = fe
self.result.add(fe)
# Pythonic functi... | [
"def",
"prepare",
"(",
"self",
",",
"node",
")",
":",
"super",
"(",
"ArgumentReadOnce",
",",
"self",
")",
".",
"prepare",
"(",
"node",
")",
"# global functions init",
"for",
"n",
"in",
"self",
".",
"global_declarations",
".",
"values",
"(",
")",
":",
"fe... | Initialise arguments effects as this analysis in inter-procedural.
Initialisation done for Pythonic functions and default values set for
user defined functions. | [
"Initialise",
"arguments",
"effects",
"as",
"this",
"analysis",
"in",
"inter",
"-",
"procedural",
"."
] | 7e1b5af2dddfabc50bd2a977f0178be269b349b5 | https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/argument_read_once.py#L60-L88 |
251,666 | astropy/regions | regions/io/ds9/write.py | ds9_objects_to_string | 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 | def ds9_objects_to_string(regions, coordsys='fk5', fmt='.6f', radunit='deg'):
shapelist = to_shape_list(regions, coordsys)
return shapelist.to_ds9(coordsys, fmt, radunit) | [
"def",
"ds9_objects_to_string",
"(",
"regions",
",",
"coordsys",
"=",
"'fk5'",
",",
"fmt",
"=",
"'.6f'",
",",
"radunit",
"=",
"'deg'",
")",
":",
"shapelist",
"=",
"to_shape_list",
"(",
"regions",
",",
"coordsys",
")",
"return",
"shapelist",
".",
"to_ds9",
... | 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 frame for all regions.
Default is 'fk5'.
fmt : `str`, optional
A pyth... | [
"Converts",
"a",
"list",
"of",
"~regions",
".",
"Region",
"to",
"DS9",
"region",
"string",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/write.py#L12-L46 |
251,667 | astropy/regions | regions/io/ds9/write.py | write_ds9 | 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 | def write_ds9(regions, filename, coordsys='fk5', fmt='.6f', radunit='deg'):
output = ds9_objects_to_string(regions, coordsys, fmt, radunit)
with open(filename, 'w') as fh:
fh.write(output) | [
"def",
"write_ds9",
"(",
"regions",
",",
"filename",
",",
"coordsys",
"=",
"'fk5'",
",",
"fmt",
"=",
"'.6f'",
",",
"radunit",
"=",
"'deg'",
")",
":",
"output",
"=",
"ds9_objects_to_string",
"(",
"regions",
",",
"coordsys",
",",
"fmt",
",",
"radunit",
")"... | 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 written.
coordsys : `str`, optional #TODO
Coordinate system that overrides t... | [
"Converts",
"a",
"list",
"of",
"~regions",
".",
"Region",
"to",
"DS9",
"string",
"and",
"write",
"to",
"file",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/write.py#L49-L83 |
251,668 | astropy/regions | regions/io/crtf/write.py | crtf_objects_to_string | 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 | def crtf_objects_to_string(regions, coordsys='fk5', fmt='.6f', radunit='deg'):
shapelist = to_shape_list(regions, coordsys)
return shapelist.to_crtf(coordsys, fmt, radunit) | [
"def",
"crtf_objects_to_string",
"(",
"regions",
",",
"coordsys",
"=",
"'fk5'",
",",
"fmt",
"=",
"'.6f'",
",",
"radunit",
"=",
"'deg'",
")",
":",
"shapelist",
"=",
"to_shape_list",
"(",
"regions",
",",
"coordsys",
")",
"return",
"shapelist",
".",
"to_crtf",
... | 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 overrides the coordinate system frame for
all regions. Default is 'fk5'.
fmt : `st... | [
"Converts",
"a",
"list",
"of",
"~regions",
".",
"Region",
"to",
"CRTF",
"region",
"string",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/write.py#L12-L48 |
251,669 | astropy/regions | regions/io/crtf/write.py | write_crtf | 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 | def write_crtf(regions, filename, coordsys='fk5', fmt='.6f', radunit='deg'):
output = crtf_objects_to_string(regions, coordsys, fmt, radunit)
with open(filename, 'w') as fh:
fh.write(output) | [
"def",
"write_crtf",
"(",
"regions",
",",
"filename",
",",
"coordsys",
"=",
"'fk5'",
",",
"fmt",
"=",
"'.6f'",
",",
"radunit",
"=",
"'deg'",
")",
":",
"output",
"=",
"crtf_objects_to_string",
"(",
"regions",
",",
"coordsys",
",",
"fmt",
",",
"radunit",
"... | 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 be written. Default is 'new.crtf'
coordsys : `str`, optional
Astropy Coordina... | [
"Converts",
"a",
"list",
"of",
"~regions",
".",
"Region",
"to",
"CRTF",
"string",
"and",
"write",
"to",
"file",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/write.py#L51-L86 |
251,670 | astropy/regions | regions/shapes/rectangle.py | RectanglePixelRegion.corners | 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 | def corners(self):
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),
]
rotmat = [[np.cos(self.angle), np.sin(self.angle)],
... | [
"def",
"corners",
"(",
"self",
")",
":",
"corners",
"=",
"[",
"(",
"-",
"self",
".",
"width",
"/",
"2",
",",
"-",
"self",
".",
"height",
"/",
"2",
")",
",",
"(",
"self",
".",
"width",
"/",
"2",
",",
"-",
"self",
".",
"height",
"/",
"2",
")"... | Return the x, y coordinate pairs that define the corners | [
"Return",
"the",
"x",
"y",
"coordinate",
"pairs",
"that",
"define",
"the",
"corners"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/shapes/rectangle.py#L202-L216 |
251,671 | astropy/regions | regions/shapes/rectangle.py | RectanglePixelRegion.to_polygon | 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 | def to_polygon(self):
x,y = self.corners.T
vertices = PixCoord(x=x, y=y)
return PolygonPixelRegion(vertices=vertices, meta=self.meta,
visual=self.visual) | [
"def",
"to_polygon",
"(",
"self",
")",
":",
"x",
",",
"y",
"=",
"self",
".",
"corners",
".",
"T",
"vertices",
"=",
"PixCoord",
"(",
"x",
"=",
"x",
",",
"y",
"=",
"y",
")",
"return",
"PolygonPixelRegion",
"(",
"vertices",
"=",
"vertices",
",",
"meta... | Return a 4-cornered polygon equivalent to this rectangle | [
"Return",
"a",
"4",
"-",
"cornered",
"polygon",
"equivalent",
"to",
"this",
"rectangle"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/shapes/rectangle.py#L218-L225 |
251,672 | astropy/regions | regions/shapes/rectangle.py | RectanglePixelRegion._lower_left_xy | 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 | def _lower_left_xy(self):
hw = self.width / 2.
hh = self.height / 2.
sint = np.sin(self.angle)
cost = np.cos(self.angle)
dx = (hh * sint) - (hw * cost)
dy = -(hh * cost) - (hw * sint)
x = self.center.x + dx
y = self.center.y + dy
return x, y | [
"def",
"_lower_left_xy",
"(",
"self",
")",
":",
"hw",
"=",
"self",
".",
"width",
"/",
"2.",
"hh",
"=",
"self",
".",
"height",
"/",
"2.",
"sint",
"=",
"np",
".",
"sin",
"(",
"self",
".",
"angle",
")",
"cost",
"=",
"np",
".",
"cos",
"(",
"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 | [
"Compute",
"lower",
"left",
"xy",
"position",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/shapes/rectangle.py#L228-L244 |
251,673 | astropy/regions | regions/core/compound.py | CompoundPixelRegion._make_annulus_path | 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 | def _make_annulus_path(patch_inner, patch_outer):
import matplotlib.path as mpath
path_inner = patch_inner.get_path()
transform_inner = patch_inner.get_transform()
path_inner = transform_inner.transform_path(path_inner)
path_outer = patch_outer.get_path()
transform_oute... | [
"def",
"_make_annulus_path",
"(",
"patch_inner",
",",
"patch_outer",
")",
":",
"import",
"matplotlib",
".",
"path",
"as",
"mpath",
"path_inner",
"=",
"patch_inner",
".",
"get_path",
"(",
")",
"transform_inner",
"=",
"patch_inner",
".",
"get_transform",
"(",
")",... | 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. | [
"Defines",
"a",
"matplotlib",
"annulus",
"path",
"from",
"two",
"patches",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/core/compound.py#L104-L130 |
251,674 | astropy/regions | regions/io/fits/read.py | read_fits_region | 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 | def read_fits_region(filename, errors='strict'):
regions = []
hdul = fits.open(filename)
for hdu in hdul:
if hdu.name == 'REGION':
table = Table.read(hdu)
wcs = WCS(hdu.header, keysel=['image', 'binary', 'pixel'])
regions_list = FITSRegionParser(table, errors).s... | [
"def",
"read_fits_region",
"(",
"filename",
",",
"errors",
"=",
"'strict'",
")",
":",
"regions",
"=",
"[",
"]",
"hdul",
"=",
"fits",
".",
"open",
"(",
"filename",
")",
"for",
"hdu",
"in",
"hdul",
":",
"if",
"hdu",
".",
"name",
"==",
"'REGION'",
":",
... | 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 use for handling parsing errors.
The default is 'stric... | [
"Reads",
"a",
"FITS",
"region",
"file",
"and",
"scans",
"for",
"any",
"fits",
"regions",
"table",
"and",
"converts",
"them",
"into",
"Region",
"objects",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/fits/read.py#L228-L270 |
251,675 | astropy/regions | regions/io/core.py | to_shape_list | 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 | def to_shape_list(region_list, coordinate_system='fk5'):
shape_list = ShapeList()
for region in region_list:
coord = []
if isinstance(region, SkyRegion):
reg_type = region.__class__.__name__[:-9].lower()
else:
reg_type = region.__class__.__name__[:-11].lower()
... | [
"def",
"to_shape_list",
"(",
"region_list",
",",
"coordinate_system",
"=",
"'fk5'",
")",
":",
"shape_list",
"=",
"ShapeList",
"(",
")",
"for",
"region",
"in",
"region_list",
":",
"coord",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"region",
",",
"SkyRegion",
... | 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. Default is 'DS9'.
coordinate_system: str
The astropy coordin... | [
"Converts",
"a",
"list",
"of",
"regions",
"into",
"a",
"regions",
".",
"ShapeList",
"object",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L670-L738 |
251,676 | astropy/regions | regions/io/core.py | to_ds9_meta | def to_ds9_meta(shape_meta):
"""
Makes the meta data DS9 compatible by filtering and mapping the valid keys
Parameters
----------
shape_meta: dict
meta attribute of a `regions.Shape` object
Returns
-------
meta : dict
DS9 compatible meta dictionary
"""
# meta k... | python | def to_ds9_meta(shape_meta):
# meta keys allowed in DS9.
valid_keys = ['symbol', 'include', 'tag', 'line', 'comment',
'name', 'select', 'highlite', 'fixed', 'label', 'text',
'edit', 'move', 'rotate', 'delete', 'source', 'background']
# visual keys allowed in DS9
vali... | [
"def",
"to_ds9_meta",
"(",
"shape_meta",
")",
":",
"# meta keys allowed in DS9.",
"valid_keys",
"=",
"[",
"'symbol'",
",",
"'include'",
",",
"'tag'",
",",
"'line'",
",",
"'comment'",
",",
"'name'",
",",
"'select'",
",",
"'highlite'",
",",
"'fixed'",
",",
"'lab... | Makes the meta data DS9 compatible by filtering and mapping the valid keys
Parameters
----------
shape_meta: dict
meta attribute of a `regions.Shape` object
Returns
-------
meta : dict
DS9 compatible meta dictionary | [
"Makes",
"the",
"meta",
"data",
"DS9",
"compatible",
"by",
"filtering",
"and",
"mapping",
"the",
"valid",
"keys"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L741-L775 |
251,677 | astropy/regions | regions/io/core.py | _to_io_meta | def _to_io_meta(shape_meta, valid_keys, key_mappings):
"""
This is used to make meta data compatible with a specific io
by filtering and mapping to it's valid keys
Parameters
----------
shape_meta: dict
meta attribute of a `regions.Region` object
valid_keys : python list
Con... | python | def _to_io_meta(shape_meta, valid_keys, key_mappings):
meta = dict()
for key in shape_meta:
if key in valid_keys:
meta[key_mappings.get(key, key)] = shape_meta[key]
return meta | [
"def",
"_to_io_meta",
"(",
"shape_meta",
",",
"valid_keys",
",",
"key_mappings",
")",
":",
"meta",
"=",
"dict",
"(",
")",
"for",
"key",
"in",
"shape_meta",
":",
"if",
"key",
"in",
"valid_keys",
":",
"meta",
"[",
"key_mappings",
".",
"get",
"(",
"key",
... | This is used to make meta data compatible with a specific io
by filtering and mapping to it's valid keys
Parameters
----------
shape_meta: dict
meta attribute of a `regions.Region` object
valid_keys : python list
Contains all the valid keys of a particular file format.
key_mappi... | [
"This",
"is",
"used",
"to",
"make",
"meta",
"data",
"compatible",
"with",
"a",
"specific",
"io",
"by",
"filtering",
"and",
"mapping",
"to",
"it",
"s",
"valid",
"keys"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L809-L835 |
251,678 | astropy/regions | regions/io/core.py | Shape.convert_coords | def convert_coords(self):
"""
Process list of coordinates
This mainly searches for tuple of coordinates in the coordinate list and
creates a SkyCoord or PixCoord object from them if appropriate for a
given region type. This involves again some coordinate transformation,
... | python | def convert_coords(self):
if self.coordsys in ['image', 'physical']:
coords = self._convert_pix_coords()
else:
coords = self._convert_sky_coords()
if self.region_type == 'line':
coords = [coords[0][0], coords[0][1]]
if self.region_type == 'text':
... | [
"def",
"convert_coords",
"(",
"self",
")",
":",
"if",
"self",
".",
"coordsys",
"in",
"[",
"'image'",
",",
"'physical'",
"]",
":",
"coords",
"=",
"self",
".",
"_convert_pix_coords",
"(",
")",
"else",
":",
"coords",
"=",
"self",
".",
"_convert_sky_coords",
... | Process list of coordinates
This mainly searches for tuple of coordinates in the coordinate list and
creates a SkyCoord or PixCoord object from them if appropriate for a
given region type. This involves again some coordinate transformation,
so this step could be moved to the parsing pro... | [
"Process",
"list",
"of",
"coordinates"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L527-L547 |
251,679 | astropy/regions | regions/io/core.py | Shape._convert_sky_coords | def _convert_sky_coords(self):
"""
Convert to sky coordinates
"""
parsed_angles = [(x, y)
for x, y in zip(self.coord[:-1:2], self.coord[1::2])
if (isinstance(x, coordinates.Angle) and isinstance(y, coordinates.Angle))
... | python | def _convert_sky_coords(self):
parsed_angles = [(x, y)
for x, y in zip(self.coord[:-1:2], self.coord[1::2])
if (isinstance(x, coordinates.Angle) and isinstance(y, coordinates.Angle))
]
frame = coordinates.frame_transform_graph.lo... | [
"def",
"_convert_sky_coords",
"(",
"self",
")",
":",
"parsed_angles",
"=",
"[",
"(",
"x",
",",
"y",
")",
"for",
"x",
",",
"y",
"in",
"zip",
"(",
"self",
".",
"coord",
"[",
":",
"-",
"1",
":",
"2",
"]",
",",
"self",
".",
"coord",
"[",
"1",
":"... | Convert to sky coordinates | [
"Convert",
"to",
"sky",
"coordinates"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L549-L572 |
251,680 | astropy/regions | regions/io/core.py | Shape._convert_pix_coords | def _convert_pix_coords(self):
"""
Convert to pixel coordinates, `regions.PixCoord`
"""
if self.region_type in ['polygon', 'line']:
# have to special-case polygon in the phys coord case
# b/c can't typecheck when iterating as in sky coord case
coords =... | python | def _convert_pix_coords(self):
if self.region_type in ['polygon', 'line']:
# have to special-case polygon in the phys coord case
# b/c can't typecheck when iterating as in sky coord case
coords = [PixCoord(self.coord[0::2], self.coord[1::2])]
else:
temp = ... | [
"def",
"_convert_pix_coords",
"(",
"self",
")",
":",
"if",
"self",
".",
"region_type",
"in",
"[",
"'polygon'",
",",
"'line'",
"]",
":",
"# have to special-case polygon in the phys coord case",
"# b/c can't typecheck when iterating as in sky coord case",
"coords",
"=",
"[",
... | Convert to pixel coordinates, `regions.PixCoord` | [
"Convert",
"to",
"pixel",
"coordinates",
"regions",
".",
"PixCoord"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L574-L592 |
251,681 | astropy/regions | regions/io/core.py | Shape.to_region | def to_region(self):
"""
Converts to region, ``regions.Region`` object
"""
coords = self.convert_coords()
log.debug(coords)
viz_keywords = ['color', 'dash', 'dashlist', 'width', 'font', 'symsize',
'symbol', 'symsize', 'fontsize', 'fontstyle', 'use... | python | def to_region(self):
coords = self.convert_coords()
log.debug(coords)
viz_keywords = ['color', 'dash', 'dashlist', 'width', 'font', 'symsize',
'symbol', 'symsize', 'fontsize', 'fontstyle', 'usetex',
'labelpos', 'labeloff', 'linewidth', 'linestyle',... | [
"def",
"to_region",
"(",
"self",
")",
":",
"coords",
"=",
"self",
".",
"convert_coords",
"(",
")",
"log",
".",
"debug",
"(",
"coords",
")",
"viz_keywords",
"=",
"[",
"'color'",
",",
"'dash'",
",",
"'dashlist'",
",",
"'width'",
",",
"'font'",
",",
"'sym... | Converts to region, ``regions.Region`` object | [
"Converts",
"to",
"region",
"regions",
".",
"Region",
"object"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L594-L628 |
251,682 | astropy/regions | regions/io/core.py | Shape.check_crtf | def check_crtf(self):
"""
Checks for CRTF compatibility.
"""
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
"supported by CRTF".format(self.region_type))
if self.coordsys... | python | def check_crtf(self):
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
"supported by CRTF".format(self.region_type))
if self.coordsys not in valid_coordsys['CRTF']:
raise ValueError("'... | [
"def",
"check_crtf",
"(",
"self",
")",
":",
"if",
"self",
".",
"region_type",
"not",
"in",
"regions_attributes",
":",
"raise",
"ValueError",
"(",
"\"'{0}' is not a valid region type in this package\"",
"\"supported by CRTF\"",
".",
"format",
"(",
"self",
".",
"region_... | Checks for CRTF compatibility. | [
"Checks",
"for",
"CRTF",
"compatibility",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L633-L643 |
251,683 | astropy/regions | regions/io/core.py | Shape.check_ds9 | def check_ds9(self):
"""
Checks for DS9 compatibility.
"""
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
"supported by DS9".format(self.region_type))
if self.coordsys no... | python | def check_ds9(self):
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
"supported by DS9".format(self.region_type))
if self.coordsys not in valid_coordsys['DS9']:
raise ValueError("'{0}... | [
"def",
"check_ds9",
"(",
"self",
")",
":",
"if",
"self",
".",
"region_type",
"not",
"in",
"regions_attributes",
":",
"raise",
"ValueError",
"(",
"\"'{0}' is not a valid region type in this package\"",
"\"supported by DS9\"",
".",
"format",
"(",
"self",
".",
"region_ty... | Checks for DS9 compatibility. | [
"Checks",
"for",
"DS9",
"compatibility",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L645-L655 |
251,684 | astropy/regions | regions/io/core.py | Shape._validate | def _validate(self):
"""
Checks whether all the attributes of this object is valid.
"""
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
.format(self.region_type))
if self.... | python | def _validate(self):
if self.region_type not in regions_attributes:
raise ValueError("'{0}' is not a valid region type in this package"
.format(self.region_type))
if self.coordsys not in valid_coordsys['DS9'] + valid_coordsys['CRTF']:
raise ValueErro... | [
"def",
"_validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"region_type",
"not",
"in",
"regions_attributes",
":",
"raise",
"ValueError",
"(",
"\"'{0}' is not a valid region type in this package\"",
".",
"format",
"(",
"self",
".",
"region_type",
")",
")",
"if",... | Checks whether all the attributes of this object is valid. | [
"Checks",
"whether",
"all",
"the",
"attributes",
"of",
"this",
"object",
"is",
"valid",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L657-L667 |
251,685 | astropy/regions | regions/io/crtf/read.py | read_crtf | def read_crtf(filename, errors='strict'):
"""
Reads a CRTF region file and returns a list of region objects.
Parameters
----------
filename : `str`
The file path
errors : ``warn``, ``ignore``, ``strict``, optional
The error handling scheme to use for handling parsing errors.
... | python | def read_crtf(filename, errors='strict'):
with open(filename) as fh:
if regex_begin.search(fh.readline()):
region_string = fh.read()
parser = CRTFParser(region_string, errors)
return parser.shapes.to_regions()
else:
raise CRTFRegionParserError('Every C... | [
"def",
"read_crtf",
"(",
"filename",
",",
"errors",
"=",
"'strict'",
")",
":",
"with",
"open",
"(",
"filename",
")",
"as",
"fh",
":",
"if",
"regex_begin",
".",
"search",
"(",
"fh",
".",
"readline",
"(",
")",
")",
":",
"region_string",
"=",
"fh",
".",... | Reads a CRTF region file and returns a list of region objects.
Parameters
----------
filename : `str`
The file path
errors : ``warn``, ``ignore``, ``strict``, optional
The error handling scheme to use for handling parsing errors.
The default is 'strict', which will raise a `~regions... | [
"Reads",
"a",
"CRTF",
"region",
"file",
"and",
"returns",
"a",
"list",
"of",
"region",
"objects",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L43-L85 |
251,686 | astropy/regions | regions/io/crtf/read.py | CRTFParser.parse_line | def parse_line(self, line):
"""
Parses a single line.
"""
# Skip blanks
if line == '':
return
# Skip comments
if regex_comment.search(line):
return
# Special case / header: parse global parameters into metadata
global_par... | python | def parse_line(self, line):
# Skip blanks
if line == '':
return
# Skip comments
if regex_comment.search(line):
return
# Special case / header: parse global parameters into metadata
global_parameters = regex_global.search(line)
if global_p... | [
"def",
"parse_line",
"(",
"self",
",",
"line",
")",
":",
"# Skip blanks",
"if",
"line",
"==",
"''",
":",
"return",
"# Skip comments",
"if",
"regex_comment",
".",
"search",
"(",
"line",
")",
":",
"return",
"# Special case / header: parse global parameters into metada... | Parses a single line. | [
"Parses",
"a",
"single",
"line",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L161-L199 |
251,687 | astropy/regions | regions/io/crtf/read.py | CRTFRegionParser.parse | def parse(self):
"""
Starting point to parse the CRTF region string.
"""
self.convert_meta()
self.coordsys = self.meta.get('coord', 'image').lower()
self.set_coordsys()
self.convert_coordinates()
self.make_shape() | python | def parse(self):
self.convert_meta()
self.coordsys = self.meta.get('coord', 'image').lower()
self.set_coordsys()
self.convert_coordinates()
self.make_shape() | [
"def",
"parse",
"(",
"self",
")",
":",
"self",
".",
"convert_meta",
"(",
")",
"self",
".",
"coordsys",
"=",
"self",
".",
"meta",
".",
"get",
"(",
"'coord'",
",",
"'image'",
")",
".",
"lower",
"(",
")",
"self",
".",
"set_coordsys",
"(",
")",
"self",... | Starting point to parse the CRTF region string. | [
"Starting",
"point",
"to",
"parse",
"the",
"CRTF",
"region",
"string",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L320-L329 |
251,688 | astropy/regions | regions/io/crtf/read.py | CRTFRegionParser.set_coordsys | def set_coordsys(self):
"""
Mapping to astropy's coordinate system name
# TODO: needs expert attention (Most reference systems are not mapped)
"""
if self.coordsys.lower() in self.coordsys_mapping:
self.coordsys = self.coordsys_mapping[self.coordsys.lower()] | python | def set_coordsys(self):
if self.coordsys.lower() in self.coordsys_mapping:
self.coordsys = self.coordsys_mapping[self.coordsys.lower()] | [
"def",
"set_coordsys",
"(",
"self",
")",
":",
"if",
"self",
".",
"coordsys",
".",
"lower",
"(",
")",
"in",
"self",
".",
"coordsys_mapping",
":",
"self",
".",
"coordsys",
"=",
"self",
".",
"coordsys_mapping",
"[",
"self",
".",
"coordsys",
".",
"lower",
... | Mapping to astropy's coordinate system name
# TODO: needs expert attention (Most reference systems are not mapped) | [
"Mapping",
"to",
"astropy",
"s",
"coordinate",
"system",
"name"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L331-L338 |
251,689 | astropy/regions | regions/io/crtf/read.py | CRTFRegionParser.convert_coordinates | def convert_coordinates(self):
"""
Convert coordinate string to `~astropy.coordinates.Angle` or `~astropy.units.quantity.Quantity` objects
"""
coord_list_str = regex_coordinate.findall(self.reg_str) + regex_length.findall(self.reg_str)
coord_list = []
if self.region_type... | python | def convert_coordinates(self):
coord_list_str = regex_coordinate.findall(self.reg_str) + regex_length.findall(self.reg_str)
coord_list = []
if self.region_type == 'poly':
if len(coord_list_str) < 4:
self._raise_error('Not in proper format: {} polygon should have > 4 ... | [
"def",
"convert_coordinates",
"(",
"self",
")",
":",
"coord_list_str",
"=",
"regex_coordinate",
".",
"findall",
"(",
"self",
".",
"reg_str",
")",
"+",
"regex_length",
".",
"findall",
"(",
"self",
".",
"reg_str",
")",
"coord_list",
"=",
"[",
"]",
"if",
"sel... | Convert coordinate string to `~astropy.coordinates.Angle` or `~astropy.units.quantity.Quantity` objects | [
"Convert",
"coordinate",
"string",
"to",
"~astropy",
".",
"coordinates",
".",
"Angle",
"or",
"~astropy",
".",
"units",
".",
"quantity",
".",
"Quantity",
"objects"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L340-L387 |
251,690 | astropy/regions | regions/io/crtf/read.py | CRTFRegionParser.convert_meta | def convert_meta(self):
"""
Parses the meta_str to python dictionary and stores in ``meta`` attribute.
"""
if self.meta_str:
self.meta_str = regex_meta.findall(self.meta_str + ',')
if self.meta_str:
for par in self.meta_str:
if par[0] is no... | python | def convert_meta(self):
if self.meta_str:
self.meta_str = regex_meta.findall(self.meta_str + ',')
if self.meta_str:
for par in self.meta_str:
if par[0] is not '':
val1 = par[0]
val2 = par[1]
else:
... | [
"def",
"convert_meta",
"(",
"self",
")",
":",
"if",
"self",
".",
"meta_str",
":",
"self",
".",
"meta_str",
"=",
"regex_meta",
".",
"findall",
"(",
"self",
".",
"meta_str",
"+",
"','",
")",
"if",
"self",
".",
"meta_str",
":",
"for",
"par",
"in",
"self... | Parses the meta_str to python dictionary and stores in ``meta`` attribute. | [
"Parses",
"the",
"meta_str",
"to",
"python",
"dictionary",
"and",
"stores",
"in",
"meta",
"attribute",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/crtf/read.py#L389-L419 |
251,691 | astropy/regions | regions/io/fits/write.py | fits_region_objects_to_table | def fits_region_objects_to_table(regions):
"""
Converts list of regions to FITS region table.
Parameters
----------
regions : list
List of `regions.Region` objects
Returns
-------
region_string : `~astropy.table.Table`
FITS region table
Examples
--------
>... | python | def fits_region_objects_to_table(regions):
for reg in regions:
if isinstance(reg, SkyRegion):
raise TypeError('Every region must be a pixel region'.format(reg))
shape_list = to_shape_list(regions, coordinate_system='image')
return shape_list.to_fits() | [
"def",
"fits_region_objects_to_table",
"(",
"regions",
")",
":",
"for",
"reg",
"in",
"regions",
":",
"if",
"isinstance",
"(",
"reg",
",",
"SkyRegion",
")",
":",
"raise",
"TypeError",
"(",
"'Every region must be a pixel region'",
".",
"format",
"(",
"reg",
")",
... | Converts list of regions to FITS region table.
Parameters
----------
regions : list
List of `regions.Region` objects
Returns
-------
region_string : `~astropy.table.Table`
FITS region table
Examples
--------
>>> from regions import CirclePixelRegion, PixCoord
... | [
"Converts",
"list",
"of",
"regions",
"to",
"FITS",
"region",
"table",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/fits/write.py#L15-L47 |
251,692 | astropy/regions | regions/io/fits/write.py | write_fits_region | def write_fits_region(filename, regions, header=None):
"""
Converts list of regions to FITS region table and write to a file.
Parameters
----------
filename: str
Filename in which the table is to be written. Default is 'new.fits'
regions: list
List of `regions.Region` objects
... | python | def write_fits_region(filename, regions, header=None):
output = fits_region_objects_to_table(regions)
bin_table = fits.BinTableHDU(data=output, header=header)
bin_table.writeto(filename) | [
"def",
"write_fits_region",
"(",
"filename",
",",
"regions",
",",
"header",
"=",
"None",
")",
":",
"output",
"=",
"fits_region_objects_to_table",
"(",
"regions",
")",
"bin_table",
"=",
"fits",
".",
"BinTableHDU",
"(",
"data",
"=",
"output",
",",
"header",
"=... | Converts list of regions to FITS region table and write to a file.
Parameters
----------
filename: str
Filename in which the table is to be written. Default is 'new.fits'
regions: list
List of `regions.Region` objects
header: `~astropy.io.fits.header.Header` object
The FITS ... | [
"Converts",
"list",
"of",
"regions",
"to",
"FITS",
"region",
"table",
"and",
"write",
"to",
"a",
"file",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/fits/write.py#L50-L78 |
251,693 | astropy/regions | regions/_utils/examples.py | make_example_dataset | def make_example_dataset(data='simulated', config=None):
"""Make example dataset.
This is a factory function for ``ExampleDataset`` objects.
The following config options are available (default values shown):
* ``crval = 0, 0``
* ``crpix = 180, 90``
* ``cdelt = -1, 1``
* ``shape = 180, 360... | python | def make_example_dataset(data='simulated', config=None):
if data == 'simulated':
return ExampleDatasetSimulated(config=config)
elif data == 'fermi':
return ExampleDatasetFermi(config=config)
else:
raise ValueError('Invalid selection data: {}'.format(data)) | [
"def",
"make_example_dataset",
"(",
"data",
"=",
"'simulated'",
",",
"config",
"=",
"None",
")",
":",
"if",
"data",
"==",
"'simulated'",
":",
"return",
"ExampleDatasetSimulated",
"(",
"config",
"=",
"config",
")",
"elif",
"data",
"==",
"'fermi'",
":",
"retur... | Make example dataset.
This is a factory function for ``ExampleDataset`` objects.
The following config options are available (default values shown):
* ``crval = 0, 0``
* ``crpix = 180, 90``
* ``cdelt = -1, 1``
* ``shape = 180, 360``
* ``ctype = 'GLON-AIT', 'GLAT-AIT'``
Parameters
... | [
"Make",
"example",
"dataset",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/_utils/examples.py#L17-L64 |
251,694 | astropy/regions | regions/_utils/examples.py | _table_to_bintable | def _table_to_bintable(table):
"""Convert `~astropy.table.Table` to `astropy.io.fits.BinTable`."""
data = table.as_array()
header = fits.Header()
header.update(table.meta)
name = table.meta.pop('name', None)
return fits.BinTableHDU(data, header, name=name) | python | def _table_to_bintable(table):
data = table.as_array()
header = fits.Header()
header.update(table.meta)
name = table.meta.pop('name', None)
return fits.BinTableHDU(data, header, name=name) | [
"def",
"_table_to_bintable",
"(",
"table",
")",
":",
"data",
"=",
"table",
".",
"as_array",
"(",
")",
"header",
"=",
"fits",
".",
"Header",
"(",
")",
"header",
".",
"update",
"(",
"table",
".",
"meta",
")",
"name",
"=",
"table",
".",
"meta",
".",
"... | Convert `~astropy.table.Table` to `astropy.io.fits.BinTable`. | [
"Convert",
"~astropy",
".",
"table",
".",
"Table",
"to",
"astropy",
".",
"io",
".",
"fits",
".",
"BinTable",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/_utils/examples.py#L223-L229 |
251,695 | astropy/regions | regions/io/ds9/read.py | read_ds9 | def read_ds9(filename, errors='strict'):
"""
Read a DS9 region file in as a `list` of `~regions.Region` objects.
Parameters
----------
filename : `str`
The file path
errors : ``warn``, ``ignore``, ``strict``, optional
The error handling scheme to use for handling parsing errors.
... | python | def read_ds9(filename, errors='strict'):
with open(filename) as fh:
region_string = fh.read()
parser = DS9Parser(region_string, errors=errors)
return parser.shapes.to_regions() | [
"def",
"read_ds9",
"(",
"filename",
",",
"errors",
"=",
"'strict'",
")",
":",
"with",
"open",
"(",
"filename",
")",
"as",
"fh",
":",
"region_string",
"=",
"fh",
".",
"read",
"(",
")",
"parser",
"=",
"DS9Parser",
"(",
"region_string",
",",
"errors",
"="... | Read a DS9 region file in as a `list` of `~regions.Region` objects.
Parameters
----------
filename : `str`
The file path
errors : ``warn``, ``ignore``, ``strict``, optional
The error handling scheme to use for handling parsing errors.
The default is 'strict', which will raise a `~re... | [
"Read",
"a",
"DS9",
"region",
"file",
"in",
"as",
"a",
"list",
"of",
"~regions",
".",
"Region",
"objects",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/read.py#L38-L77 |
251,696 | astropy/regions | regions/io/ds9/read.py | DS9Parser.set_coordsys | def set_coordsys(self, coordsys):
"""
Transform coordinate system
# TODO: needs expert attention
"""
if coordsys in self.coordsys_mapping:
self.coordsys = self.coordsys_mapping[coordsys]
else:
self.coordsys = coordsys | python | def set_coordsys(self, coordsys):
if coordsys in self.coordsys_mapping:
self.coordsys = self.coordsys_mapping[coordsys]
else:
self.coordsys = coordsys | [
"def",
"set_coordsys",
"(",
"self",
",",
"coordsys",
")",
":",
"if",
"coordsys",
"in",
"self",
".",
"coordsys_mapping",
":",
"self",
".",
"coordsys",
"=",
"self",
".",
"coordsys_mapping",
"[",
"coordsys",
"]",
"else",
":",
"self",
".",
"coordsys",
"=",
"... | Transform coordinate system
# TODO: needs expert attention | [
"Transform",
"coordinate",
"system"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/read.py#L215-L224 |
251,697 | astropy/regions | regions/io/ds9/read.py | DS9Parser.run | def run(self):
"""
Run all steps
"""
for line_ in self.region_string.split('\n'):
for line in line_.split(";"):
self.parse_line(line)
log.debug('Global state: {}'.format(self)) | python | def run(self):
for line_ in self.region_string.split('\n'):
for line in line_.split(";"):
self.parse_line(line)
log.debug('Global state: {}'.format(self)) | [
"def",
"run",
"(",
"self",
")",
":",
"for",
"line_",
"in",
"self",
".",
"region_string",
".",
"split",
"(",
"'\\n'",
")",
":",
"for",
"line",
"in",
"line_",
".",
"split",
"(",
"\";\"",
")",
":",
"self",
".",
"parse_line",
"(",
"line",
")",
"log",
... | Run all steps | [
"Run",
"all",
"steps"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/read.py#L226-L233 |
251,698 | astropy/regions | regions/io/ds9/read.py | DS9Parser.parse_meta | def parse_meta(meta_str):
"""
Parse the metadata for a single ds9 region string.
Parameters
----------
meta_str : `str`
Meta string, the metadata is everything after the close-paren of the
region coordinate specification. All metadata is specified as
... | python | def parse_meta(meta_str):
keys_vals = [(x, y) for x, _, y in regex_meta.findall(meta_str.strip())]
extra_text = regex_meta.split(meta_str.strip())[-1]
result = OrderedDict()
for key, val in keys_vals:
# regex can include trailing whitespace or inverted commas
# re... | [
"def",
"parse_meta",
"(",
"meta_str",
")",
":",
"keys_vals",
"=",
"[",
"(",
"x",
",",
"y",
")",
"for",
"x",
",",
"_",
",",
"y",
"in",
"regex_meta",
".",
"findall",
"(",
"meta_str",
".",
"strip",
"(",
")",
")",
"]",
"extra_text",
"=",
"regex_meta",
... | Parse the metadata for a single ds9 region string.
Parameters
----------
meta_str : `str`
Meta string, the metadata is everything after the close-paren of the
region coordinate specification. All metadata is specified as
key=value pairs separated by whitespac... | [
"Parse",
"the",
"metadata",
"for",
"a",
"single",
"ds9",
"region",
"string",
"."
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/read.py#L288-L327 |
251,699 | astropy/regions | regions/io/ds9/read.py | DS9Parser.parse_region | def parse_region(self, include, region_type, region_end, line):
"""
Extract a Shape from a region string
"""
if self.coordsys is None:
raise DS9RegionParserError("No coordinate system specified and a"
" region has been found.")
e... | python | def parse_region(self, include, region_type, region_end, line):
if self.coordsys is None:
raise DS9RegionParserError("No coordinate system specified and a"
" region has been found.")
else:
helper = DS9RegionParser(coordsys=self.coordsys,
... | [
"def",
"parse_region",
"(",
"self",
",",
"include",
",",
"region_type",
",",
"region_end",
",",
"line",
")",
":",
"if",
"self",
".",
"coordsys",
"is",
"None",
":",
"raise",
"DS9RegionParserError",
"(",
"\"No coordinate system specified and a\"",
"\" region has been ... | Extract a Shape from a region string | [
"Extract",
"a",
"Shape",
"from",
"a",
"region",
"string"
] | 452d962c417e4ff20d1268f99535c6ff89c83437 | https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/ds9/read.py#L329-L344 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.