提交 15b8c753 authored 作者: Chinnadhurai Sankar's avatar Chinnadhurai Sankar

fix pep-8 errors in gof

上级 ad6a0499
...@@ -18,8 +18,8 @@ class CallCache(object): ...@@ -18,8 +18,8 @@ class CallCache(object):
def persist(self, filename=None): def persist(self, filename=None):
""" """
Cache "filename" as a pickle file Cache "filename" as a pickle file
""" """
if filename is None: if filename is None:
filename = self.filename filename = self.filename
with open(filename, 'w') as f: with open(filename, 'w') as f:
...@@ -27,16 +27,16 @@ class CallCache(object): ...@@ -27,16 +27,16 @@ class CallCache(object):
def call(self, fn, args=(), key=None): def call(self, fn, args=(), key=None):
""" """
Retrieve item from the cache(if available) Retrieve item from the cache(if available)
based on a key based on a key
Parameters Parameters
------------ ------------
key key
parameter to retrieve cache item parameter to retrieve cache item
fn,args fn,args
key to retrieve if "key" is None key to retrieve if "key" is None
""" """
if key is None: if key is None:
key = (fn, tuple(args)) key = (fn, tuple(args))
if key not in self.cache: if key not in self.cache:
......
...@@ -115,14 +115,12 @@ def failure_code(sub): ...@@ -115,14 +115,12 @@ def failure_code(sub):
def failure_code_init(sub): def failure_code_init(sub):
""" """
Code for failure in the struct init. Code for failure in the struct init.
Parameters: Parameters:
-------------- --------------
sub sub
Dictionary used to template the struct. Dictionary used to template the struct.
* failure_var -> must contain a variable name to use for * failure_var -> must contain a variable name to use for
the failure code. the failure code.
""" """
return '''{ return '''{
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
...@@ -137,8 +135,8 @@ def failure_code_init(sub): ...@@ -137,8 +135,8 @@ def failure_code_init(sub):
def code_gen(blocks): def code_gen(blocks):
""" """
From a list of L{CodeBlock} instances, returns a string From a list of L{CodeBlock} instances, returns a string
that executes them all in sequence. that executes them all in sequence.
Eg for C{(decl1, task1, Eg for C{(decl1, task1,
cleanup1)} and C{(decl2, task2, cleanup2)} the returned string cleanup1)} and C{(decl2, task2, cleanup2)} the returned string
will be of the form: will be of the form:
...@@ -156,7 +154,7 @@ def code_gen(blocks): ...@@ -156,7 +154,7 @@ def code_gen(blocks):
Parameters: Parameters:
---------------- ----------------
blocks blocks
List of CodeBlock instances such that List of CodeBlock instances such that
* declarations, behavior and cleanup are in the run() * declarations, behavior and cleanup are in the run()
method of the struct method of the struct
...@@ -895,7 +893,6 @@ class CLinker(link.Linker): ...@@ -895,7 +893,6 @@ class CLinker(link.Linker):
""" """
Returns a list of support code strings that are needed by Returns a list of support code strings that are needed by
one or more Variables or Ops. one or more Variables or Ops.
The support code from Variables is added before the support code from Ops.This might contain duplicates. The support code from Variables is added before the support code from Ops.This might contain duplicates.
""" """
ret = [] ret = []
...@@ -1172,10 +1169,8 @@ class CLinker(link.Linker): ...@@ -1172,10 +1169,8 @@ class CLinker(link.Linker):
be allocated. be allocated.
storage_map: dict that map variables to storages. storage_map: dict that map variables to storages.
This is used when you need to customize the storage of This is used when you need to customize the storage of
this thunk. this thunk.keep_lock
keep_lock WRITEME
WRITEME
Returns: thunk, input_storage, output_storage Returns: thunk, input_storage, output_storage
The return values can be used as follows: The return values can be used as follows:
...@@ -1845,11 +1840,10 @@ def _default_checker(x, y): ...@@ -1845,11 +1840,10 @@ def _default_checker(x, y):
""" """
Default checker for DualLinker. This checks that the Default checker for DualLinker. This checks that the
variables contain the same data using ==. variables contain the same data using ==.
Parameters Parameters
------------- -------------
x,y x,y
the variables to compare data the variables to compare data
""" """
if x[0] != y[0]: if x[0] != y[0]:
raise Exception("Output mismatch.", raise Exception("Output mismatch.",
......
...@@ -1474,10 +1474,9 @@ class ModuleCache(object): ...@@ -1474,10 +1474,9 @@ class ModuleCache(object):
def _rmtree(parent, ignore_nocleanup=False, msg='', level=logging.DEBUG, def _rmtree(parent, ignore_nocleanup=False, msg='', level=logging.DEBUG,
ignore_if_missing=False): ignore_if_missing=False):
""" """
On NFS filesystems, it is impossible to delete a directory with open On NFS filesystems, it is impossible to delete a directory with open
files in it. files in it.
So instead, some commands in this file will respond to a So instead, some commands in this file will respond to a
failed rmtree() by touching a 'delete.me' file. This file is a message failed rmtree() by touching a 'delete.me' file. This file is a message
...@@ -1485,13 +1484,13 @@ def _rmtree(parent, ignore_nocleanup=False, msg='', level=logging.DEBUG, ...@@ -1485,13 +1484,13 @@ def _rmtree(parent, ignore_nocleanup=False, msg='', level=logging.DEBUG,
Paramters Paramters
---------- ----------
parent parent
Root node to start deleting from Root node to start deleting from
ignore_nocleanup ignore_nocleanup
Delete the tree if flag is TRUE Delete the tree if flag is TRUE
level level
Python Logging level. Set to "DEBUG" by default Python Logging level. Set to "DEBUG" by default
ignore_if_missing ignore_if_missing
If set to True, just return without any issue if parent is NULL If set to True, just return without any issue if parent is NULL
""" """
if ignore_if_missing and not os.path.exists(parent): if ignore_if_missing and not os.path.exists(parent):
return return
......
...@@ -708,7 +708,7 @@ def variables_and_orphans(i, o): ...@@ -708,7 +708,7 @@ def variables_and_orphans(i, o):
i : list i : list
Input L{Variable}s. Input L{Variable}s.
o : list o : list
Output L{Variable}s. Output L{Variable}s.
""" """
def expand(r): def expand(r):
...@@ -775,7 +775,7 @@ def variables(i, o): ...@@ -775,7 +775,7 @@ def variables(i, o):
def orphans(i, o): def orphans(i, o):
""" """
Extracts list of variables within input and output nodes ( via dfs t ravesal) and returns the "orphans" among them Extracts list of variables within input and output nodes ( via dfs t ravesal) and returns the "orphans" among them
Parameters Parameters
---------- ----------
i : list i : list
...@@ -1225,7 +1225,7 @@ def op_as_string(i, op, ...@@ -1225,7 +1225,7 @@ def op_as_string(i, op,
leaf_formatter=default_leaf_formatter, leaf_formatter=default_leaf_formatter,
node_formatter=default_node_formatter): node_formatter=default_node_formatter):
""" """
Op to return a string representation of the subgraph Op to return a string representation of the subgraph
between i and o between i and o
""" """
strs = as_string(i, op.inputs, leaf_formatter, node_formatter) strs = as_string(i, op.inputs, leaf_formatter, node_formatter)
......
...@@ -54,8 +54,7 @@ def thunk_hook(type, value, trace): ...@@ -54,8 +54,7 @@ def thunk_hook(type, value, trace):
""" """
This function is meant to replace excepthook and do some This function is meant to replace excepthook and do some
special work if the exception value has a __thunk_trace__ special work if the exception value has a __thunk_trace__
field. field.
In that case, it retrieves the field, which should In that case, it retrieves the field, which should
contain a trace as returned by L{traceback.extract_stack}, contain a trace as returned by L{traceback.extract_stack},
and prints it out on L{stderr}. and prints it out on L{stderr}.
...@@ -64,7 +63,7 @@ def thunk_hook(type, value, trace): ...@@ -64,7 +63,7 @@ def thunk_hook(type, value, trace):
Parameters Parameters
------------ ------------
type type
Exception class Exception class
value value
Exception instance Exception instance
trace trace
...@@ -617,7 +616,7 @@ def map_storage(fgraph, order, input_storage, output_storage, storage_map=None): ...@@ -617,7 +616,7 @@ def map_storage(fgraph, order, input_storage, output_storage, storage_map=None):
def streamline(fgraph, thunks, order, post_thunk_old_storage=None, def streamline(fgraph, thunks, order, post_thunk_old_storage=None,
no_recycling=None, nice_errors=True): no_recycling=None, nice_errors=True):
""" """
WRITEME WRITEME
Parameters Parameters
---------- ----------
...@@ -714,7 +713,6 @@ class LocalLinker(Linker): ...@@ -714,7 +713,6 @@ class LocalLinker(Linker):
def gc_helper(node_list): def gc_helper(node_list):
""" """
Return the set of Variable instances which are computed by node_list. Return the set of Variable instances which are computed by node_list.
Parameters Parameters
---------- ----------
node_list node_list
...@@ -790,7 +788,7 @@ class PerformLinker(LocalLinker): ...@@ -790,7 +788,7 @@ class PerformLinker(LocalLinker):
def make_all(self, input_storage=None, output_storage=None, storage_map=None): def make_all(self, input_storage=None, output_storage=None, storage_map=None):
""" """
Returns Function to run all nodes, list of input containers, list of outputs Returns Function to run all nodes, list of input containers, list of outputs
Parameters Parameters
---------- ----------
......
...@@ -792,8 +792,8 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -792,8 +792,8 @@ class Op(utils.object2, PureOp, CLinkerOp):
def _props(self): def _props(self):
""" """
Tuple of properties of all attributes Tuple of properties of all attributes
""" """
return tuple(getattr(self, a) for a in self.__props__) return tuple(getattr(self, a) for a in self.__props__)
def _props_dict(self): def _props_dict(self):
...@@ -927,7 +927,7 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -927,7 +927,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
def make_thunk(self, node, storage_map, compute_map, no_recycling): def make_thunk(self, node, storage_map, compute_map, no_recycling):
""" """
This function must return a thunk, that is a zero-arguments This function must return a thunk, that is a zero-arguments
function that encapsulates the computation to be performed function that encapsulates the computation to be performed
by this op on the arguments of the node. by this op on the arguments of the node.
...@@ -981,9 +981,8 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -981,9 +981,8 @@ class Op(utils.object2, PureOp, CLinkerOp):
def make_node(self, *inputs): def make_node(self, *inputs):
""" """
Create a "apply" nodes for the inputs in that order. Create a "apply" nodes for the inputs in that order.
"""
"""
if not hasattr(self, 'itypes'): if not hasattr(self, 'itypes'):
raise NotImplementedError("You can either define itypes and otypes,\ raise NotImplementedError("You can either define itypes and otypes,\
or implement make_node") or implement make_node")
...@@ -1068,7 +1067,7 @@ def debug_error_message(msg): ...@@ -1068,7 +1067,7 @@ def debug_error_message(msg):
def debug_assert(condition, msg=None): def debug_assert(condition, msg=None):
""" """
Customized assert with options to ignore the assert Customized assert with options to ignore the assert
with just a warning with just a warning
""" """
if msg is None: if msg is None:
...@@ -1179,8 +1178,8 @@ class OpenMPOp(Op): ...@@ -1179,8 +1178,8 @@ class OpenMPOp(Op):
def c_compile_args(self): def c_compile_args(self):
""" """
Return the compilation arg "fopenmp" if openMP is supported Return the compilation arg "fopenmp" if openMP is supported
""" """
self.update_self_openmp() self.update_self_openmp()
if self.openmp: if self.openmp:
return ['-fopenmp'] return ['-fopenmp']
...@@ -1188,9 +1187,8 @@ class OpenMPOp(Op): ...@@ -1188,9 +1187,8 @@ class OpenMPOp(Op):
def c_headers(self): def c_headers(self):
""" """
Return the header file name "omp.h" if openMP is supported Return the header file name "omp.h" if openMP is supported
"""
"""
self.update_self_openmp() self.update_self_openmp()
if self.openmp: if self.openmp:
return ["omp.h"] return ["omp.h"]
...@@ -1199,8 +1197,8 @@ class OpenMPOp(Op): ...@@ -1199,8 +1197,8 @@ class OpenMPOp(Op):
@staticmethod @staticmethod
def test_gxx_support(): def test_gxx_support():
""" """
Check if openMP is supported Check if openMP is supported
""" """
code = """ code = """
#include <omp.h> #include <omp.h>
int main( int argc, const char* argv[] ) int main( int argc, const char* argv[] )
...@@ -1418,7 +1416,7 @@ class COp(Op): ...@@ -1418,7 +1416,7 @@ class COp(Op):
def c_init_code(self): def c_init_code(self):
""" """
Get the code section for init_code Get the code section for init_code
""" """
if 'init_code' in self.code_sections: if 'init_code' in self.code_sections:
return [self.code_sections['init_code']] return [self.code_sections['init_code']]
...@@ -1588,8 +1586,8 @@ class COp(Op): ...@@ -1588,8 +1586,8 @@ class COp(Op):
def c_code_cleanup(self, node, name, inputs, outputs, sub): def c_code_cleanup(self, node, name, inputs, outputs, sub):
""" """
Stitches all the macros and "code_cleanup" together Stitches all the macros and "code_cleanup" together
""" """
if 'code_cleanup' in self.code_sections: if 'code_cleanup' in self.code_sections:
op_code = self.code_sections['code_cleanup'] op_code = self.code_sections['code_cleanup']
......
...@@ -115,19 +115,19 @@ class Bookkeeper(Feature): ...@@ -115,19 +115,19 @@ class Bookkeeper(Feature):
def on_attach(self, fgraph): def on_attach(self, fgraph):
""" """
Called by FunctionGraph.attach_feature, the method that attaches Called by FunctionGraph.attach_feature, the method that attaches
the feature to the FunctionGraph. Since this is called after the the feature to the FunctionGraph. Since this is called after the
FunctionGraph is initially populated, this is where you should FunctionGraph is initially populated, this is where you should
run checks on the initial contents of the FunctionGraph. run checks on the initial contents of the FunctionGraph.
""" """
for node in graph.io_toposort(fgraph.inputs, fgraph.outputs): for node in graph.io_toposort(fgraph.inputs, fgraph.outputs):
self.on_import(fgraph, node, "on_attach") self.on_import(fgraph, node, "on_attach")
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
for node in graph.io_toposort(fgraph.inputs, fgraph.outputs): for node in graph.io_toposort(fgraph.inputs, fgraph.outputs):
self.on_prune(fgraph, node, 'Bookkeeper.detach') self.on_prune(fgraph, node, 'Bookkeeper.detach')
...@@ -189,9 +189,9 @@ class History(Feature): ...@@ -189,9 +189,9 @@ class History(Feature):
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
del fgraph.checkpoint del fgraph.checkpoint
del fgraph.revert del fgraph.revert
del self.history[fgraph] del self.history[fgraph]
...@@ -238,18 +238,18 @@ class Validator(Feature): ...@@ -238,18 +238,18 @@ class Validator(Feature):
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
del fgraph.validate del fgraph.validate
del fgraph.consistent del fgraph.consistent
def validate_(self, fgraph): def validate_(self, fgraph):
""" """
If the caller is replace_all_validate, just raise the If the caller is replace_all_validate, just raise the
exception. replace_all_validate will print out the exception. replace_all_validate will print out the
verbose output. Or it has to be done here before raise. verbose output. Or it has to be done here before raise.
""" """
t0 = time.time() t0 = time.time()
try: try:
ret = fgraph.execute_callbacks('validate') ret = fgraph.execute_callbacks('validate')
...@@ -313,9 +313,9 @@ class ReplaceValidate(History, Validator): ...@@ -313,9 +313,9 @@ class ReplaceValidate(History, Validator):
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
History.on_detach(self, fgraph) History.on_detach(self, fgraph)
Validator.on_detach(self, fgraph) Validator.on_detach(self, fgraph)
del self._nodes_removed del self._nodes_removed
...@@ -440,9 +440,9 @@ class NodeFinder(Bookkeeper): ...@@ -440,9 +440,9 @@ class NodeFinder(Bookkeeper):
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
if self.fgraph is not fgraph: if self.fgraph is not fgraph:
raise Exception("This NodeFinder instance was not attached to the" raise Exception("This NodeFinder instance was not attached to the"
" provided fgraph.") " provided fgraph.")
...@@ -493,9 +493,9 @@ class PrintListener(Feature): ...@@ -493,9 +493,9 @@ class PrintListener(Feature):
def on_detach(self, fgraph): def on_detach(self, fgraph):
""" """
Should remove any dynamically added functionality Should remove any dynamically added functionality
that it installed into the function_graph that it installed into the function_graph
""" """
if self.active: if self.active:
print("-- detaching from: ", fgraph) print("-- detaching from: ", fgraph)
......
...@@ -4,7 +4,7 @@ can be "unified" if there exists an assignment to all unification variables ...@@ -4,7 +4,7 @@ can be "unified" if there exists an assignment to all unification variables
such that the two expressions are equal. such that the two expressions are equal.
For instance, [5, A, B] and [A, C, 9] can be unified if A=C=5 and B=9, For instance, [5, A, B] and [A, C, 9] can be unified if A=C=5 and B=9,
yielding [5, 5, 9]. yielding [5, 5, 9].
[5, [A, B]] and [A, [1, 2]] cannot be unified because there is no value for A [5, [A, B]] and [A, [1, 2]] cannot be unified because there is no value for A
that satisfies the constraints. That's useful for pattern matching. that satisfies the constraints. That's useful for pattern matching.
...@@ -135,8 +135,6 @@ class Unification: ...@@ -135,8 +135,6 @@ class Unification:
""" """
This class represents a possible unification of a group of variables This class represents a possible unification of a group of variables
with each other or with tangible values. with each other or with tangible values.
Parameters Parameters
---------- ----------
inplace : bool inplace : bool
......
...@@ -728,8 +728,8 @@ class VM_Linker(link.LocalLinker): ...@@ -728,8 +728,8 @@ class VM_Linker(link.LocalLinker):
def accept(self, fgraph, no_recycling=None): def accept(self, fgraph, no_recycling=None):
""" """
Check if fgraph is the first FunctionGraph that has ever been Check if fgraph is the first FunctionGraph that has ever been
associated to self, else, create a new VM_Linker associated to self, else, create a new VM_Linker
associated to fgraph associated to fgraph
Parameters Parameters
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论