提交 724ba41d authored 作者: ChienliMa's avatar ChienliMa

Minor fixes of typos and reverse modiication of test_reallocation()

上级 25721632
...@@ -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
...@@ -572,8 +572,8 @@ class Function(object): ...@@ -572,8 +572,8 @@ class Function(object):
ins, outs = copy.deepcopy([self.maker.inputs, self.maker.outputs]) ins, outs = copy.deepcopy([self.maker.inputs, self.maker.outputs])
# get copied input, output variables # get copied input, output variables
in_vars = [ i.variabls for i in ins ] in_vars = [ i.variable for i in ins ]
out_vars = [ o.variabls for o in outs ] out_vars = [ o.variable for o in outs ]
# contruct memo that map old variables to new variables # contruct memo that map old variables to new variables
memo = {} memo = {}
...@@ -590,19 +590,18 @@ class Function(object): ...@@ -590,19 +590,18 @@ class Function(object):
# re-initialize new FunctionMaker # re-initialize new FunctionMaker
maker = self.maker maker = self.maker
kwargs = dict(inputs=ins, outputs=outs, fgraph=new_fgraph, new_maker = FunctionMaker( inputs=ins, outputs=outs, fgraph=new_fgraph,
mode=maker.mode, profile=maker.profile, mode=maker.mode, 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 ) on_unused_input=maker.on_unused_input )
new_maker = FunctionMaker( kwargs )
# 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
for key in storage_map.keys(): for key in storage_map.keys():
if not isinstance(key, theano.tensor.constant) and \ if not isinstance(key, theano.tensor.Constant) and \
equiv.has_key(key): equiv.has_key(key):
new_storage_map[memo[key]] = storage_map[key] new_storage_map[memo[key]] = storage_map[key]
......
...@@ -368,9 +368,6 @@ def test_vm_gc(): ...@@ -368,9 +368,6 @@ def test_vm_gc():
def test_reallocation(): def test_reallocation():
"""
test share memory.
"""
x = tensor.scalar('x') x = tensor.scalar('x')
y = tensor.scalar('y') y = tensor.scalar('y')
z = tensor.tanh(3 * x + y) + tensor.cosh(x + 5 * y) z = tensor.tanh(3 * x + y) + tensor.cosh(x + 5 * y)
...@@ -387,10 +384,6 @@ def test_reallocation(): ...@@ -387,10 +384,6 @@ def test_reallocation():
storage_map = f.fn.storage_map storage_map = f.fn.storage_map
def check_storage(storage_map): def check_storage(storage_map):
"""
Return [True, same_value] if two storages have same value,
otherwise return [False, None]
"""
from theano.tensor.var import TensorConstant from theano.tensor.var import TensorConstant
for i in storage_map: for i in storage_map:
if not isinstance(i, TensorConstant): if not isinstance(i, TensorConstant):
...@@ -402,7 +395,6 @@ def test_reallocation(): ...@@ -402,7 +395,6 @@ def test_reallocation():
return [True, storage_map[o][0]] return [True, storage_map[o][0]]
return [False, None] return [False, None]
# assert there's same value in strage_map
assert check_storage(storage_map)[0] assert check_storage(storage_map)[0]
assert len(set(id(v) for v in assert len(set(id(v) for v in
itervalues(storage_map))) < len(storage_map) itervalues(storage_map))) < len(storage_map)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论