cleanup

上级 a7442159
......@@ -10,52 +10,35 @@ import opt
import core
def to_func(inputs, outputs):
# print gof.Env(inputs, outputs).io_toposort()
p = prog(inputs, outputs)
# print p.env
def f(*args):
for input, value in zip(inputs, args):
p[input] = value
outputs = p()
if len(outputs) == 1:
return outputs[0]
else:
return outputs
return f
# def prog(inputs, outputs):
# outputs = gof.ext.mark_outputs_as_destroyed(outputs)
# program = gof.Prog(inputs, outputs, opt.optimizer, gof.link.ThunkLinker(), [gof.features.PrintListener])
# for orphan in program.env.orphans():
# if orphan.storage is core.UNCOMPUTED:
# raise Exception("Your program depends on a few uncomputed values.")
# return program
class prog(gof.Prog):
def __init__(self, inputs, outputs, optimizer = opt.optimizer([])):
"""Compile a subgraph.
N.B. This triggers computation of the subgraph leading to the outputs
that is not fed by the inputs (the orphans).
def __init__(self, inputs, outputs):
# core.build_mode()
outputs = gof.ext.mark_outputs_as_destroyed(outputs)
TODO: think about whether orphan computation should be in this function,
or in self.__call__()
"""
outputs = gof.mark_outputs_as_destroyed(outputs)
gof.Prog.__init__(self,
inputs,
outputs,
opt.optimizer,
optimizer,
gof.link.perform_linker,
[])
# core.pop_mode()
self.compute_orphans()
def __call__(self, check_uncomputed = True):
"""Recompute the graph.
If the inputs are uncomputed (and check_uncomputed is True) then an
Exception is raised.
"""
if check_uncomputed:
for input in self.env.inputs:
if input.data is core.UNCOMPUTED:
raise Exception("You must provide a value for input %s!" % input)
self.compute_orphans()
# for orphan in self.env.orphans():
# if orphan.data is core.UNCOMPUTED:
# raise Exception("Orphan %s is uncomputed but needed to calculate the function. " % orphan + \
# "Try calling prog.compute_orphans() or set it manually.")
return gof.Prog.__call__(self)
def compute_orphans(self):
......@@ -67,6 +50,19 @@ class prog(gof.Prog):
raise Exception("Orphan %s is uncomputed but needed to calculate the function." % orphan)
def to_func(inputs, outputs):
# print gof.Env(inputs, outputs).io_toposort()
p = prog(inputs, outputs)
print p.env
def f(*args):
for input, value in zip(inputs, args):
p[input] = value
outputs = p()
if len(outputs) == 1:
return outputs[0]
else:
return outputs
return f
def single(*outputs):
return prog(gof.graph.inputs(outputs), outputs)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论