提交 12997087 authored 作者: ChienliMa's avatar ChienliMa

Finish draft of Function.copy()

上级 5ffc4cee
...@@ -551,7 +551,7 @@ class Function(object): ...@@ -551,7 +551,7 @@ class Function(object):
there.data = here.data there.data = here.data
return cpy return cpy
def copy(self, share_memory=False): def copy(self, share_memory = False):
""" """
Copy this function. Copied function will have separated maker and fgraph Copy this function. Copied function will have separated maker and fgraph
with original function. User can choose whether to separate storage by with original function. User can choose whether to separate storage by
...@@ -580,15 +580,20 @@ class Function(object): ...@@ -580,15 +580,20 @@ class Function(object):
fgraph=fg_cpy, profile=maker.profile, fgraph=fg_cpy, profile=maker.profile,
accept_inplace=maker.accept_inplace, accept_inplace=maker.accept_inplace,
function_builder=maker.function_builder, function_builder=maker.function_builder,
on_unused_input=maker.on_unused_input)
# construct new storage_map that map new variable to old storage # construct new storage_map that map new variable to old storage
# so that the ensuing function shares storage with the original one # so that the ensuing function shares storage with the original one
new_storage_map = {} new_storage_map = {}
storage_map = self.fn.storage_map storage_map = self.fn.storage_map
# TODO: We could share the output storage, but we must make sure
# 2 different function call won't override each other values. This
# is already done elsewhere, so to reuse it the user would need to
# use Out(var, borrow=True) and maybe the mutable=True flag too.
# But to be safe for now as it isn't documented and we aren't sure
# it is well tested, we don't share the part of the storage_map.
for key in storage_map.keys(): for key in storage_map.keys():
# output_storages should not be shared if key not in self.maker.fgraph.outputs:
if key not in self.maker.fgraph.outputs and memo.has_key(key):
new_storage_map[memo[key]] = storage_map[key] new_storage_map[memo[key]] = storage_map[key]
# copy input storages if it's mutable # copy input storages if it's mutable
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论