提交 8b3d3934 authored 作者: Frederic's avatar Frederic

pep8

上级 6bc3257a
...@@ -20,17 +20,18 @@ floatX = 'float32' ...@@ -20,17 +20,18 @@ floatX = 'float32'
import theano import theano
import theano.tensor as T import theano.tensor as T
def test_pickle_unpickle_with_reoptimization(): def test_pickle_unpickle_with_reoptimization():
x1 = T.fmatrix('x1') x1 = T.fmatrix('x1')
x2 = T.fmatrix('x2') x2 = T.fmatrix('x2')
x3 = theano.shared(numpy.ones((10,10),dtype=floatX)) x3 = theano.shared(numpy.ones((10, 10), dtype=floatX))
x4 = theano.shared(numpy.ones((10,10),dtype=floatX)) x4 = theano.shared(numpy.ones((10, 10), dtype=floatX))
y = T.sum(T.sum(T.sum(x1**2+x2) + x3) + x4) y = T.sum(T.sum(T.sum(x1 ** 2 + x2) + x3) + x4)
updates = OrderedDict() updates = OrderedDict()
updates[x3] = x3 + 1 updates[x3] = x3 + 1
updates[x4] = x4 + 1 updates[x4] = x4 + 1
f = theano.function([x1,x2],y, updates=updates) f = theano.function([x1, x2], y, updates=updates)
# now pickle the compiled theano fn # now pickle the compiled theano fn
string_pkl = cPickle.dumps(f, -1) string_pkl = cPickle.dumps(f, -1)
...@@ -41,23 +42,25 @@ def test_pickle_unpickle_with_reoptimization(): ...@@ -41,23 +42,25 @@ def test_pickle_unpickle_with_reoptimization():
# test unpickle with optimization # test unpickle with optimization
default = theano.config.reoptimize_unpickled_function default = theano.config.reoptimize_unpickled_function
try: try:
theano.config.reoptimize_unpickled_function=True # the default is True # the default is True
theano.config.reoptimize_unpickled_function = True
f_ = cPickle.loads(string_pkl) f_ = cPickle.loads(string_pkl)
assert f(in1, in2) == f_(in1, in2) assert f(in1, in2) == f_(in1, in2)
finally: finally:
theano.config.reoptimize_unpickled_function = default theano.config.reoptimize_unpickled_function = default
def test_pickle_unpickle_without_reoptimization(): def test_pickle_unpickle_without_reoptimization():
x1 = T.fmatrix('x1') x1 = T.fmatrix('x1')
x2 = T.fmatrix('x2') x2 = T.fmatrix('x2')
x3 = theano.shared(numpy.ones((10,10),dtype=floatX)) x3 = theano.shared(numpy.ones((10, 10), dtype=floatX))
x4 = theano.shared(numpy.ones((10,10),dtype=floatX)) x4 = theano.shared(numpy.ones((10, 10), dtype=floatX))
y = T.sum(T.sum(T.sum(x1**2+x2) + x3) + x4) y = T.sum(T.sum(T.sum(x1**2 + x2) + x3) + x4)
updates = OrderedDict() updates = OrderedDict()
updates[x3] = x3 + 1 updates[x3] = x3 + 1
updates[x4] = x4 + 1 updates[x4] = x4 + 1
f = theano.function([x1,x2],y, updates=updates) f = theano.function([x1, x2], y, updates=updates)
# now pickle the compiled theano fn # now pickle the compiled theano fn
string_pkl = cPickle.dumps(f, -1) string_pkl = cPickle.dumps(f, -1)
...@@ -69,12 +72,14 @@ def test_pickle_unpickle_without_reoptimization(): ...@@ -69,12 +72,14 @@ def test_pickle_unpickle_without_reoptimization():
# test unpickle without optimization # test unpickle without optimization
default = theano.config.reoptimize_unpickled_function default = theano.config.reoptimize_unpickled_function
try: try:
theano.config.reoptimize_unpickled_function=False # the default is True # the default is True
theano.config.reoptimize_unpickled_function = False
f_ = cPickle.loads(string_pkl) f_ = cPickle.loads(string_pkl)
assert f(in1, in2) == f_(in1, in2) assert f(in1, in2) == f_(in1, in2)
finally: finally:
theano.config.reoptimize_unpickled_function = default theano.config.reoptimize_unpickled_function = default
if __name__ == '__main__': if __name__ == '__main__':
test_pickle_unpickle_with_reoptimization() test_pickle_unpickle_with_reoptimization()
test_pickle_unpickle_without_reoptimization() test_pickle_unpickle_without_reoptimization()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论