提交 078a645d authored 作者: Frederic's avatar Frederic

pep8

上级 918c51cb
...@@ -20,6 +20,7 @@ from theano import tensor ...@@ -20,6 +20,7 @@ from theano import tensor
from theano.ifelse import ifelse from theano.ifelse import ifelse
import theano import theano
class TestCallbacks(unittest.TestCase): class TestCallbacks(unittest.TestCase):
""" """
Test the VM_Linker's callback argument, which can be useful for debugging. Test the VM_Linker's callback argument, which can be useful for debugging.
...@@ -34,7 +35,7 @@ class TestCallbacks(unittest.TestCase): ...@@ -34,7 +35,7 @@ class TestCallbacks(unittest.TestCase):
def test_callback(self): def test_callback(self):
a, b, c = tensor.scalars('abc') a, b, c = tensor.scalars('abc')
f = function([a,b,c], (a + b) + c, f = function([a, b, c], (a + b) + c,
mode=Mode( mode=Mode(
optimizer=None, optimizer=None,
linker=vm.VM_Linker(callback=self.callback))) linker=vm.VM_Linker(callback=self.callback)))
...@@ -44,10 +45,9 @@ class TestCallbacks(unittest.TestCase): ...@@ -44,10 +45,9 @@ class TestCallbacks(unittest.TestCase):
f(1, 2, 3) f(1, 2, 3)
assert sum(self.n_callbacks.values()) == len(f.maker.fgraph.toposort()) * 2 assert sum(self.n_callbacks.values()) == len(f.maker.fgraph.toposort()) * 2
def test_callback_with_ifelse(self): def test_callback_with_ifelse(self):
a, b, c = tensor.scalars('abc') a, b, c = tensor.scalars('abc')
f = function([a,b,c], ifelse(a, 2*b, 2*c), f = function([a, b, c], ifelse(a, 2*b, 2*c),
mode=Mode( mode=Mode(
optimizer=None, optimizer=None,
linker=vm.VM_Linker(callback=self.callback))) linker=vm.VM_Linker(callback=self.callback)))
...@@ -71,6 +71,7 @@ def test_speed(): ...@@ -71,6 +71,7 @@ def test_speed():
for d in xrange(depth): for d in xrange(depth):
z = (z+z) z = (z+z)
return z return z
def time_numpy(): def time_numpy():
steps_a = 5 steps_a = 5
steps_b = 100 steps_b = 100
...@@ -78,10 +79,10 @@ def test_speed(): ...@@ -78,10 +79,10 @@ def test_speed():
numpy_version(x, steps_a) numpy_version(x, steps_a)
t0 = time.time() t0 = time.time()
#print numpy_version(x, steps_a) # print numpy_version(x, steps_a)
t1 = time.time() t1 = time.time()
t2 = time.time() t2 = time.time()
#print numpy_version(x, steps_b) # print numpy_version(x, steps_b)
t3 = time.time() t3 = time.time()
t_a = t1 - t0 t_a = t1 - t0
t_b = t3 - t2 t_b = t3 - t2
...@@ -94,9 +95,8 @@ def test_speed(): ...@@ -94,9 +95,8 @@ def test_speed():
steps_a = 5 steps_a = 5
steps_b = 100 steps_b = 100
x = tensor.vector() x = tensor.vector()
a = build_graph(x,steps_a) a = build_graph(x, steps_a)
b = build_graph(x,steps_b) b = build_graph(x, steps_b)
f_a = function([x], a, f_a = function([x], a,
mode=Mode(optimizer=None, linker=linker()), mode=Mode(optimizer=None, linker=linker()),
...@@ -127,12 +127,13 @@ def test_speed(): ...@@ -127,12 +127,13 @@ def test_speed():
time_linker('c|py', OpWiseCLinker) time_linker('c|py', OpWiseCLinker)
time_linker('vmLinker', vm.VM_Linker) time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False)) time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
if theano.config.cxx: if theano.config.cxx:
time_linker('vmLinker_CLOOP', lambda : vm.VM_Linker(allow_gc=False, time_linker('vmLinker_CLOOP', lambda: vm.VM_Linker(allow_gc=False,
use_cloop=True)) use_cloop=True))
time_numpy() time_numpy()
def test_speed_lazy(): def test_speed_lazy():
def build_graph(x, depth=5): def build_graph(x, depth=5):
...@@ -148,7 +149,6 @@ def test_speed_lazy(): ...@@ -148,7 +149,6 @@ def test_speed_lazy():
a = build_graph(x, steps_a) a = build_graph(x, steps_a)
b = build_graph(x, steps_b) b = build_graph(x, steps_b)
f_a = function([x], a, f_a = function([x], a,
mode=Mode(optimizer=None, mode=Mode(optimizer=None,
linker=linker()), linker=linker()),
...@@ -179,9 +179,9 @@ def test_speed_lazy(): ...@@ -179,9 +179,9 @@ def test_speed_lazy():
(1000*(t_b-t_a) / (steps_b - steps_a))) (1000*(t_b-t_a) / (steps_b - steps_a)))
time_linker('vmLinker', vm.VM_Linker) time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False)) time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
if theano.config.cxx: if theano.config.cxx:
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False, time_linker('vmLinker_C', lambda: vm.VM_Linker(allow_gc=False,
use_cloop=True)) use_cloop=True))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论