* Fixed bug where making empty module would crash

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