提交 df258db8 authored 作者: Olivier Breuleux's avatar Olivier Breuleux

merge

...@@ -115,8 +115,9 @@ class PerformLinker(Linker): ...@@ -115,8 +115,9 @@ class PerformLinker(Linker):
the L{Env} in the order given by L{Env.toposort}. the L{Env} in the order given by L{Env.toposort}.
""" """
def __init__(self, env): def __init__(self, env, no_recycling = []):
self.env = env self.env = env
self.no_recycling = no_recycling
def make_thunk(self, inplace = False, profiler = None): def make_thunk(self, inplace = False, profiler = None):
if inplace: if inplace:
...@@ -125,8 +126,14 @@ class PerformLinker(Linker): ...@@ -125,8 +126,14 @@ class PerformLinker(Linker):
env = self.env.clone(True) env = self.env.clone(True)
order = env.toposort() order = env.toposort()
thunks = [op.perform for op in order] thunks = [op.perform for op in order]
no_recycling = self.no_recycling
if no_recycling is True:
no_recycling = list(env.results())
no_recycling = utils.difference(no_recycling, env.inputs)
if profiler is None: if profiler is None:
def f(): def f():
for r in no_recycling:
r.data = None
try: try:
for thunk, op in zip(thunks, order): for thunk, op in zip(thunks, order):
thunk() thunk()
...@@ -134,6 +141,8 @@ class PerformLinker(Linker): ...@@ -134,6 +141,8 @@ class PerformLinker(Linker):
raise_with_op(op) raise_with_op(op)
else: else:
def f(): def f():
for r in no_recycling:
r.data = None
def g(): def g():
for thunk, op in zip(thunks, order): for thunk, op in zip(thunks, order):
profiler.profile_op(thunk, op) profiler.profile_op(thunk, op)
......
...@@ -317,7 +317,7 @@ def astensor(data, broadcastable=None, name=None): ...@@ -317,7 +317,7 @@ def astensor(data, broadcastable=None, name=None):
raise ValueError("Cannot rename an existing Tensor.") raise ValueError("Cannot rename an existing Tensor.")
return data return data
elif isinstance(data, Result): elif isinstance(data, Result):
raise TypeError("Cannot make a Tensor out of a non-Tensor result:", data) raise TypeError("Cannot make a Tensor out of a result that is not an instance of Tensor: %s (%s)" % (data, data.__class__.__name__), data)
if data is None and broadcastable is None: if data is None and broadcastable is None:
raise TypeError("Cannot make a Tensor out of None.") raise TypeError("Cannot make a Tensor out of None.")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论