提交 ccb84dc5 authored 作者: Frederic's avatar Frederic

flake8

上级 2956d27e
...@@ -30,7 +30,6 @@ whitelist_flake8 = [ ...@@ -30,7 +30,6 @@ whitelist_flake8 = [
"tests/test_gradient.py", "tests/test_gradient.py",
"tests/test_config.py", "tests/test_config.py",
"tests/diverse_tests.py", "tests/diverse_tests.py",
"tests/test_ifelse.py",
"tests/test_rop.py", "tests/test_rop.py",
"tests/test_2nd_order_grads.py", "tests/test_2nd_order_grads.py",
"tests/run_tests_in_batch.py", "tests/run_tests_in_batch.py",
......
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
""" """
from __future__ import print_function from __future__ import print_function
__docformat__ = 'restructedtext en'
__authors__ = ("Razvan Pascanu ")
__copyright__ = "(c) 2010, Universite de Montreal"
__contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import unittest import unittest
import numpy import numpy
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
...@@ -17,7 +12,13 @@ import theano ...@@ -17,7 +12,13 @@ import theano
from theano import tensor from theano import tensor
import theano.ifelse import theano.ifelse
from theano.ifelse import IfElse, ifelse from theano.ifelse import IfElse, ifelse
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
__docformat__ = 'restructedtext en'
__authors__ = ("Razvan Pascanu ")
__copyright__ = "(c) 2010, Universite de Montreal"
__contact__ = "Razvan Pascanu <r.pascanu@gmail>"
class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...@@ -63,7 +64,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -63,7 +64,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
# the opt. # the opt.
'fusion', 'local_add_canonizer', 'fusion', 'local_add_canonizer',
'inplace', 'constant_folding', 'constant_folding') 'inplace', 'constant_folding', 'constant_folding')
y2 = reduce(lambda x, y: x+y, [y] + range(200)) y2 = reduce(lambda x, y: x + y, [y] + range(200))
f = theano.function([c, x, y], ifelse(c, x, y2), mode=mode) f = theano.function([c, x, y], ifelse(c, x, y2), mode=mode)
# For not inplace ifelse # For not inplace ifelse
self.assertFunctionContains1(f, IfElse(1)) self.assertFunctionContains1(f, IfElse(1))
...@@ -92,9 +93,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -92,9 +93,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
xlen = rng.randint(200) xlen = rng.randint(200)
ylen = rng.randint(200) ylen = rng.randint(200)
vx1 = numpy.asarray(rng.uniform(size=(xlen,))*3, 'int32') vx1 = numpy.asarray(rng.uniform(size=(xlen,)) * 3, 'int32')
vx2 = numpy.asarray(rng.uniform(size=(xlen,)), self.dtype) vx2 = numpy.asarray(rng.uniform(size=(xlen,)), self.dtype)
vy1 = numpy.asarray(rng.uniform(size=(ylen,))*3, 'int32') vy1 = numpy.asarray(rng.uniform(size=(ylen,)) * 3, 'int32')
vy2 = numpy.asarray(rng.uniform(size=(ylen,)), self.dtype) vy2 = numpy.asarray(rng.uniform(size=(ylen,)), self.dtype)
o1, o2 = f(1, vx1, vx2, vy1, vy2) o1, o2 = f(1, vx1, vx2, vy1, vy2)
...@@ -315,8 +316,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -315,8 +316,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
z2 = ifelse(c, x + 2, y + 2) z2 = ifelse(c, x + 2, y + 2)
z = z1 + z2 z = z1 + z2
f = theano.function([c, x, y], z) f = theano.function([c, x, y], z)
assert len([x for x in f.maker.fgraph.toposort() assert len([n for n in f.maker.fgraph.toposort()
if isinstance(x.op, IfElse)]) == 1 if isinstance(n.op, IfElse)]) == 1
def test_remove_useless_inputs1(self): def test_remove_useless_inputs1(self):
raise SkipTest("Optimization temporarily disabled") raise SkipTest("Optimization temporarily disabled")
...@@ -326,8 +327,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -326,8 +327,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
z = ifelse(c, (x, x), (y, y)) z = ifelse(c, (x, x), (y, y))
f = theano.function([c, x, y], z) f = theano.function([c, x, y], z)
ifnode = [x for x in f.maker.fgraph.toposort() ifnode = [n for n in f.maker.fgraph.toposort()
if isinstance(x.op, IfElse)][0] if isinstance(n.op, IfElse)][0]
assert len(ifnode.inputs) == 3 assert len(ifnode.inputs) == 3
def test_remove_useless_inputs2(self): def test_remove_useless_inputs2(self):
...@@ -445,12 +446,12 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -445,12 +446,12 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
c = tensor.iscalar('c') c = tensor.iscalar('c')
out = ifelse(c, out = ifelse(c,
ifelse(c, x1, x2) + ifelse(c, y1, y2) + w1, ifelse(c, x1, x2) + ifelse(c, y1, y2) + w1,
ifelse(c, x1, x2) + ifelse(c, y1, y2) + w2) ifelse(c, x1, x2) + ifelse(c, y1, y2) + w2)
f = theano.function([x1, x2, y1, y2, w1, w2, c], out, f = theano.function([x1, x2, y1, y2, w1, w2, c], out,
allow_input_downcast=True) allow_input_downcast=True)
assert len([x for x in f.maker.fgraph.toposort() assert len([x for x in f.maker.fgraph.toposort()
if isinstance(x.op, IfElse)]) == 1 if isinstance(x.op, IfElse)]) == 1
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
vx1 = rng.uniform() vx1 = rng.uniform()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论