提交 1ce27e83 authored 作者: James Bergstra's avatar James Bergstra

added pickling test for Module with _instance_methods

上级 1c8c114c
...@@ -8,7 +8,7 @@ from theano.compile.mode import default_mode ...@@ -8,7 +8,7 @@ from theano.compile.mode import default_mode
from theano.compile.module import * from theano.compile.module import *
from theano.compile.function_module import AliasedMemoryError from theano.compile.function_module import AliasedMemoryError
import theano.tensor as T import theano.tensor as T
import sys import sys, copy
import theano import theano
#TODO: add test for module.make(member=init_value) #TODO: add test for module.make(member=init_value)
...@@ -792,6 +792,24 @@ def test_default_instance_initialize(): ...@@ -792,6 +792,24 @@ def test_default_instance_initialize():
assert m.z.b == 6 assert m.z.b == 6
assert all(m.z.c == [7, 8]) assert all(m.z.c == [7, 8])
class MyModule(Module):
def __init__(self):
Module.__init__(self)
self.a = T.dscalar()
self.b = T.dscalar()
def _instance_initialize(self, obj):
obj.a = 4.5
obj.b = 3.5
def _instance_something(self, obj, a):
return obj.a + a
def test_pickle_module():
M = MyModule()
m = M.make()
mm = copy.deepcopy(m)
assert m.a == mm.a
assert m.b == mm.b
if __name__ == '__main__': if __name__ == '__main__':
from theano.tests import main from theano.tests import main
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论