* Fixed bug where making empty module would crash

* Added test case to test this scenario
上级 b914ef2b
...@@ -1092,6 +1092,10 @@ class Module(ComponentDict): ...@@ -1092,6 +1092,10 @@ class Module(ComponentDict):
""" """
InstanceType = ModuleInstance # By default, we use build ModuleInstance InstanceType = ModuleInstance # By default, we use build ModuleInstance
def __init__(self):
super(Module, self).__init__()
self.__dict__["local_attr"]={}
def __wrapper__(self, x): def __wrapper__(self, x):
""" """
This function is called whenever x is set as an attribute of This function is called whenever x is set as an attribute of
...@@ -1140,11 +1144,7 @@ class Module(ComponentDict): ...@@ -1140,11 +1144,7 @@ class Module(ComponentDict):
# print "WARNING: unknow:",v # print "WARNING: unknow:",v
return v return v
value=unpack_member_and_external(value) self.__dict__["local_attr"][attr] = unpack_member_and_external(value)
if not hasattr(self,"local_attr"):
self.__dict__["local_attr"]={}
self.__dict__["local_attr"][attr] = value
def build(self, mode, memo): def build(self, mode, memo):
if self in memo: if self in memo:
......
...@@ -14,6 +14,10 @@ import theano ...@@ -14,6 +14,10 @@ import theano
#TODO: add test for module.make(member=init_value) #TODO: add test for module.make(member=init_value)
class T_module(unittest.TestCase): class T_module(unittest.TestCase):
def test_empty_module(self):
m = Module()
m.make()
def test_whats_up_with_submembers(self): def test_whats_up_with_submembers(self):
class Blah(Module): class Blah(Module):
def __init__(self, stepsize): def __init__(self, stepsize):
...@@ -504,6 +508,7 @@ def test_tuple_members(): ...@@ -504,6 +508,7 @@ def test_tuple_members():
class Temp(Module): class Temp(Module):
def __init__(self): def __init__(self):
super(Temp, self).__init__()
self.a = (1,1) self.a = (1,1)
M = Temp() M = Temp()
assert isinstance(M.a, tuple) assert isinstance(M.a, tuple)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论