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

Minor fixes of typos and reverse modiication of test_reallocation()

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