提交 dce8a601 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Get rid of trailing spaces.

上级 e78c6f90
...@@ -140,7 +140,7 @@ def struct_gen(args, struct_builders, blocks, sub): ...@@ -140,7 +140,7 @@ def struct_gen(args, struct_builders, blocks, sub):
* sub -> dictionary used to template the struct. * sub -> 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.
In a nutshell, this returns code for a struct that represents In a nutshell, this returns code for a struct that represents
a function with state. The state's initialization and destruction a function with state. The state's initialization and destruction
are handled by struct_builders and the actual behavior of the are handled by struct_builders and the actual behavior of the
...@@ -173,7 +173,7 @@ def struct_gen(args, struct_builders, blocks, sub): ...@@ -173,7 +173,7 @@ def struct_gen(args, struct_builders, blocks, sub):
storage_incref = "\n".join(["Py_XINCREF(%s);" % arg for arg in args]) storage_incref = "\n".join(["Py_XINCREF(%s);" % arg for arg in args])
# decrements the storage's refcount in the destructor # decrements the storage's refcount in the destructor
storage_decref = "\n".join(["Py_XDECREF(this->%s);" % arg for arg in args]) storage_decref = "\n".join(["Py_XDECREF(this->%s);" % arg for arg in args])
args_names = ", ".join(args) args_names = ", ".join(args)
args_decl = ", ".join(["PyObject* %s" % arg for arg in args]) args_decl = ", ".join(["PyObject* %s" % arg for arg in args])
...@@ -205,7 +205,7 @@ def struct_gen(args, struct_builders, blocks, sub): ...@@ -205,7 +205,7 @@ def struct_gen(args, struct_builders, blocks, sub):
// The failure code is returned to index what code block failed. // The failure code is returned to index what code block failed.
return %(failure_var)s; return %(failure_var)s;
""" % sub """ % sub
sub = dict(sub) sub = dict(sub)
sub.update(locals()) sub.update(locals())
...@@ -217,7 +217,7 @@ def struct_gen(args, struct_builders, blocks, sub): ...@@ -217,7 +217,7 @@ def struct_gen(args, struct_builders, blocks, sub):
%(storage_decl)s %(storage_decl)s
%(struct_decl)s %(struct_decl)s
%(name)s() {} %(name)s() {}
~%(name)s(void) { ~%(name)s(void) {
cleanup(); cleanup();
...@@ -321,7 +321,7 @@ def struct_result_codeblocks(result, policies, id, symbol_table, sub): ...@@ -321,7 +321,7 @@ def struct_result_codeblocks(result, policies, id, symbol_table, sub):
to the table. to the table.
sub -> dictionary for use by L{CodeBlock}. sub -> dictionary for use by L{CodeBlock}.
""" """
name = "V%i" % id name = "V%i" % id
symbol_table[result] = name symbol_table[result] = name
sub = dict(sub) sub = dict(sub)
...@@ -340,7 +340,7 @@ def struct_result_codeblocks(result, policies, id, symbol_table, sub): ...@@ -340,7 +340,7 @@ def struct_result_codeblocks(result, policies, id, symbol_table, sub):
class CLinker(link.Linker): class CLinker(link.Linker):
""" """
Creates C code for an env, compiles it and returns callables Creates C code for an env, compiles it and returns callables
through make_thunk and make_function that make use of the compiled through make_thunk and make_function that make use of the compiled
code. code.
...@@ -374,7 +374,7 @@ class CLinker(link.Linker): ...@@ -374,7 +374,7 @@ class CLinker(link.Linker):
self.orphans = list(r for r in self.results if isinstance(r, graph.Value) and r not in self.inputs) #list(env.orphans.difference(self.outputs)) self.orphans = list(r for r in self.results if isinstance(r, graph.Value) and r not in self.inputs) #list(env.orphans.difference(self.outputs))
self.temps = list(set(self.results).difference(self.inputs).difference(self.outputs).difference(self.orphans)) self.temps = list(set(self.results).difference(self.inputs).difference(self.outputs).difference(self.orphans))
self.node_order = env.toposort() self.node_order = env.toposort()
def code_gen(self): def code_gen(self):
""" """
Generates code for a struct that does the computation of the env and Generates code for a struct that does the computation of the env and
...@@ -395,7 +395,7 @@ class CLinker(link.Linker): ...@@ -395,7 +395,7 @@ class CLinker(link.Linker):
no_recycling = self.no_recycling no_recycling = self.no_recycling
env = self.env env = self.env
consts = [] consts = []
symbol = {} symbol = {}
...@@ -469,7 +469,7 @@ class CLinker(link.Linker): ...@@ -469,7 +469,7 @@ class CLinker(link.Linker):
# each Result generates two CodeBlocks, one to declare/initialize/destroy struct variables # each Result generates two CodeBlocks, one to declare/initialize/destroy struct variables
# and the other to declare/extract/cleanup each time the function is run. # and the other to declare/extract/cleanup each time the function is run.
# Typically, only one of the two actually does anything (see all the possible combinations above) # Typically, only one of the two actually does anything (see all the possible combinations above)
init_tasks.append((result, 'init', id)) init_tasks.append((result, 'init', id))
init_blocks.append(builder) init_blocks.append(builder)
...@@ -479,7 +479,7 @@ class CLinker(link.Linker): ...@@ -479,7 +479,7 @@ class CLinker(link.Linker):
id += 2 id += 2
for node in self.node_order: for node in self.node_order:
# We populate sub with a mapping from the variable names specified by the op's c_var_names # We populate sub with a mapping from the variable names specified by the op's c_var_names
# method to the actual variable names that we will use. # method to the actual variable names that we will use.
## ivnames, ovnames = op.c_var_names() ## ivnames, ovnames = op.c_var_names()
...@@ -506,7 +506,7 @@ class CLinker(link.Linker): ...@@ -506,7 +506,7 @@ class CLinker(link.Linker):
try: cleanup = op.c_code_cleanup(node, name, isyms, osyms, sub) try: cleanup = op.c_code_cleanup(node, name, isyms, osyms, sub)
except utils.AbstractFunctionError: except utils.AbstractFunctionError:
cleanup = "" cleanup = ""
blocks.append(CodeBlock("", behavior, cleanup, sub)) blocks.append(CodeBlock("", behavior, cleanup, sub))
tasks.append((node, 'code', id)) tasks.append((node, 'code', id))
id += 1 id += 1
...@@ -515,7 +515,7 @@ class CLinker(link.Linker): ...@@ -515,7 +515,7 @@ class CLinker(link.Linker):
# must only be passed once because they are mapped to the same name. # must only be passed once because they are mapped to the same name.
args = [] args = []
args += ["storage_%s" % symbol[result] for result in utils.uniq(self.inputs + self.outputs + self.orphans)] args += ["storage_%s" % symbol[result] for result in utils.uniq(self.inputs + self.outputs + self.orphans)]
struct_code = struct_gen(args, init_blocks, blocks, dict(failure_var = failure_var, name = "<<<<NAME>>>>")) struct_code = struct_gen(args, init_blocks, blocks, dict(failure_var = failure_var, name = "<<<<NAME>>>>"))
# The hash calculated on the code identifies it so weave can cache properly. # The hash calculated on the code identifies it so weave can cache properly.
...@@ -535,12 +535,12 @@ class CLinker(link.Linker): ...@@ -535,12 +535,12 @@ class CLinker(link.Linker):
self.blocks = blocks self.blocks = blocks
self.tasks = tasks self.tasks = tasks
all = self.inputs + self.outputs + self.orphans all = self.inputs + self.outputs + self.orphans
# List of indices that should be ignored when passing the arguments # List of indices that should be ignored when passing the arguments
# (basically, everything that the previous call to uniq eliminated) # (basically, everything that the previous call to uniq eliminated)
self.dupidx = [i for i, x in enumerate(all) if all.count(x) > 1 and all.index(x) != i] self.dupidx = [i for i, x in enumerate(all) if all.count(x) > 1 and all.index(x) != i]
return self.struct_code return self.struct_code
def support_code(self): def support_code(self):
""" """
Returns a list of support code strings that are needed by Returns a list of support code strings that are needed by
...@@ -580,7 +580,7 @@ class CLinker(link.Linker): ...@@ -580,7 +580,7 @@ class CLinker(link.Linker):
try: ret += x.c_headers() try: ret += x.c_headers()
except utils.AbstractFunctionError: pass except utils.AbstractFunctionError: pass
return ret return ret
def libraries(self): def libraries(self):
""" """
Returns a list of libraries that are needed by one Returns a list of libraries that are needed by one
...@@ -597,7 +597,7 @@ class CLinker(link.Linker): ...@@ -597,7 +597,7 @@ class CLinker(link.Linker):
def __compile__(self, input_storage = None, output_storage = None): def __compile__(self, input_storage = None, output_storage = None):
""" """
Compiles this linker's env. Compiles this linker's env.
@type input_storage: list or None @type input_storage: list or None
@param input_storage: list of lists of length 1. In order to use @param input_storage: list of lists of length 1. In order to use
the thunk returned by __compile__, the inputs must be put in the thunk returned by __compile__, the inputs must be put in
...@@ -633,7 +633,7 @@ class CLinker(link.Linker): ...@@ -633,7 +633,7 @@ class CLinker(link.Linker):
Compiles this linker's env and returns a function to perform the Compiles this linker's env and returns a function to perform the
computations, as well as lists of storage cells for both the computations, as well as lists of storage cells for both the
inputs and outputs. inputs and outputs.
@type input_storage: list or None @type input_storage: list or None
@param input_storage: list of lists of length 1. In order to use @param input_storage: list of lists of length 1. In order to use
the thunk returned by __compile__, the inputs must be put in the thunk returned by __compile__, the inputs must be put in
...@@ -653,7 +653,7 @@ class CLinker(link.Linker): ...@@ -653,7 +653,7 @@ class CLinker(link.Linker):
""" """
cthunk, in_storage, out_storage, error_storage = self.__compile__(input_storage, output_storage) cthunk, in_storage, out_storage, error_storage = self.__compile__(input_storage, output_storage)
return _execute(cthunk, self.init_tasks, self.tasks, error_storage), in_storage, out_storage return _execute(cthunk, self.init_tasks, self.tasks, error_storage), in_storage, out_storage
def cthunk_factory(self, error_storage, in_storage, out_storage): def cthunk_factory(self, error_storage, in_storage, out_storage):
""" """
error_storage -> list of length 3 error_storage -> list of length 3
...@@ -669,14 +669,14 @@ class CLinker(link.Linker): ...@@ -669,14 +669,14 @@ class CLinker(link.Linker):
# check if we already compiled this # check if we already compiled this
if not getattr(self, 'instantiate', False): if not getattr(self, 'instantiate', False):
self.code_gen() self.code_gen()
module_name = self.hash module_name = self.hash
# Eliminate duplicate inputs and outputs from the storage that we will pass to instantiate # Eliminate duplicate inputs and outputs from the storage that we will pass to instantiate
out_storage = [x for i, x in enumerate(out_storage) if (i+len(in_storage)) not in self.dupidx] out_storage = [x for i, x in enumerate(out_storage) if (i+len(in_storage)) not in self.dupidx]
in_storage = [x for i, x in enumerate(in_storage) if i not in self.dupidx] in_storage = [x for i, x in enumerate(in_storage) if i not in self.dupidx]
cthunk = object() # dummy so weave can get the type cthunk = object() # dummy so weave can get the type
mod = weave.ext_tools.ext_module(module_name) mod = weave.ext_tools.ext_module(module_name)
...@@ -739,7 +739,7 @@ class CLinker(link.Linker): ...@@ -739,7 +739,7 @@ class CLinker(link.Linker):
module = __import__("%s" % (module_name), {}, {}, [module_name]) module = __import__("%s" % (module_name), {}, {}, [module_name])
self.instantiate = module.instantiate self.instantiate = module.instantiate
else: else:
# Eliminate duplicate inputs and outputs from the storage that we will pass to instantiate # Eliminate duplicate inputs and outputs from the storage that we will pass to instantiate
out_storage = [x for i, x in enumerate(out_storage) if (i+len(in_storage)) not in self.dupidx] out_storage = [x for i, x in enumerate(out_storage) if (i+len(in_storage)) not in self.dupidx]
in_storage = [x for i, x in enumerate(in_storage) if i not in self.dupidx] in_storage = [x for i, x in enumerate(in_storage) if i not in self.dupidx]
...@@ -778,7 +778,7 @@ def _execute(cthunk, init_tasks, tasks, error_storage): ...@@ -778,7 +778,7 @@ def _execute(cthunk, init_tasks, tasks, error_storage):
exc_value.__thunk_trace__ = trace # this can be used to retrieve the location the Op was declared exc_value.__thunk_trace__ = trace # this can be used to retrieve the location the Op was declared
raise exc_type, exc_value, exc_trace raise exc_type, exc_value, exc_trace
return execute return execute
class OpWiseCLinker(link.LocalLinker): class OpWiseCLinker(link.LocalLinker):
...@@ -798,7 +798,7 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -798,7 +798,7 @@ class OpWiseCLinker(link.LocalLinker):
""" """
__cache__ = {} __cache__ = {}
def __init__(self, fallback_on_perform = True): def __init__(self, fallback_on_perform = True):
self.env = None self.env = None
self.fallback_on_perform = fallback_on_perform self.fallback_on_perform = fallback_on_perform
...@@ -847,7 +847,7 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -847,7 +847,7 @@ class OpWiseCLinker(link.LocalLinker):
self.__cache__[desc] = cl self.__cache__[desc] = cl
except: except:
pass pass
thunk, node_input_filters, node_output_filters = cl.make_thunk( thunk, node_input_filters, node_output_filters = cl.make_thunk(
input_storage = node_input_storage, input_storage = node_input_storage,
output_storage = node_output_storage) output_storage = node_output_storage)
...@@ -872,7 +872,7 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -872,7 +872,7 @@ class OpWiseCLinker(link.LocalLinker):
no_recycling = [storage_map[r] for r in no_recycling if r not in env.inputs] no_recycling = [storage_map[r] for r in no_recycling if r not in env.inputs]
f = link.streamline(env, thunks, order, no_recycling = no_recycling, profiler = profiler) f = link.streamline(env, thunks, order, no_recycling = no_recycling, profiler = profiler)
return f, [link.Filter(input, storage) for input, storage in zip(env.inputs, input_storage)], \ return f, [link.Filter(input, storage) for input, storage in zip(env.inputs, input_storage)], \
[link.Filter(output, storage, True) for output, storage in zip(env.outputs, output_storage)], \ [link.Filter(output, storage, True) for output, storage in zip(env.outputs, output_storage)], \
thunks, order thunks, order
...@@ -903,7 +903,7 @@ class DualLinker(link.Linker): ...@@ -903,7 +903,7 @@ class DualLinker(link.Linker):
def __init__(self, checker = _default_checker): def __init__(self, checker = _default_checker):
""" """
Initialize a DualLinker. Initialize a DualLinker.
The checker argument must be a function that takes two lists The checker argument must be a function that takes two lists
of length 1. The first one passed will contain the output of length 1. The first one passed will contain the output
computed by PerformLinker and the second one the output computed by PerformLinker and the second one the output
...@@ -938,7 +938,7 @@ class DualLinker(link.Linker): ...@@ -938,7 +938,7 @@ class DualLinker(link.Linker):
env = self.env env = self.env
no_recycling = self.no_recycling no_recycling = self.no_recycling
_f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs) _f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs)
_f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs) _f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论