Repository: Theano/Theano

Issue:
pep8 typed_list dir



Discussion:

Resolving patch:
diff --git a/theano/typed_list/basic.py b/theano/typed_list/basic.py
--- a/theano/typed_list/basic.py
+++ b/theano/typed_list/basic.py
@@ -1,4 +1,3 @@
-import copy
 
 import numpy
 
@@ -109,7 +108,7 @@ def c_code_cache_version(self):
 ----------
 x
     Typed list.
-index 
+index
     The index of the value to return from `x`.
 
 """
@@ -596,7 +595,7 @@ def make_node(self, a):
         a2 = []
         for elem in a:
             if not isinstance(elem, theano.gof.Variable):
-                elem = as_tensor_variable(elem)
+                elem = theano.tensor.as_tensor_variable(elem)
             a2.append(elem)
         if not all(a2[0].type == elem.type for elem in a2):
             raise TypeError(
diff --git a/theano/typed_list/opt.py b/theano/typed_list/opt.py
--- a/theano/typed_list/opt.py
+++ b/theano/typed_list/opt.py
@@ -1,21 +1,19 @@
 from theano import gof
 from theano import compile
 from theano.gof import TopoOptimizer
-from theano.typed_list.basic import (Reverse,
-                    Append, Extend, Insert, Remove)
+from theano.typed_list.basic import Reverse, Append, Extend, Insert, Remove
 
 
 @gof.local_optimizer([Append, Extend, Insert, Reverse, Remove], inplace=True)
 def typed_list_inplace_opt(node):
-    if isinstance(node.op, (Append, Extend, Insert, Reverse, Remove)) \
-                                        and not node.op.inplace:
+    if (isinstance(node.op, (Append, Extend, Insert, Reverse, Remove)) and not
+       node.op.inplace):
 
-        new_op = node.op.__class__(
-                    inplace=True)
+        new_op = node.op.__class__(inplace=True)
         new_node = new_op(*node.inputs)
         return [new_node]
     return False
 compile.optdb.register('typed_list_inplace_opt',
                        TopoOptimizer(typed_list_inplace_opt,
-    failure_callback=TopoOptimizer.warn_inplace), 60,
-                       'fast_run', 'inplace')
+                                     failure_callback=TopoOptimizer.warn_inplace),
+                       60, 'fast_run', 'inplace')
diff --git a/theano/typed_list/type.py b/theano/typed_list/type.py
--- a/theano/typed_list/type.py
+++ b/theano/typed_list/type.py
@@ -3,7 +3,7 @@
 
 class TypedListType(gof.Type):
     """
-   
+
     Parameters
     ----------
     ttype
@@ -15,10 +15,10 @@ class TypedListType(gof.Type):
     """
 
     def __init__(self, ttype, depth=0):
-       
+
         if depth < 0:
             raise ValueError('Please specify a depth superior or'
-                            'equal to 0')
+                             'equal to 0')
         if not isinstance(ttype, gof.Type):
             raise TypeError('Expected a Theano Type')
 
@@ -58,7 +58,7 @@ def __eq__(self, other):
         Two lists are equal if they contain the same type.
 
         """
-        return  type(self) == type(other) and self.ttype == other.ttype
+        return type(self) == type(other) and self.ttype == other.ttype
 
     def __hash__(self):
         return gof.hashtype(self) ^ hash(self.ttype)


Test patch:
diff --git a/theano/tests/test_flake8.py b/theano/tests/test_flake8.py
--- a/theano/tests/test_flake8.py
+++ b/theano/tests/test_flake8.py
@@ -51,13 +51,7 @@
     "compile/tests/test_pfunc.py",
     "compile/tests/test_debugmode.py",
     "compile/tests/test_profiling.py",
-    "typed_list/type.py",
     "typed_list/__init__.py",
-    "typed_list/opt.py",
-    "typed_list/basic.py",
-    "typed_list/tests/test_type.py",
-    "typed_list/tests/test_opt.py",
-    "typed_list/tests/test_basic.py",
     "tensor/__init__.py",
     "tensor/tests/test_subtensor.py",
     "tensor/tests/test_utils.py",
diff --git a/theano/typed_list/tests/test_basic.py b/theano/typed_list/tests/test_basic.py
--- a/theano/typed_list/tests/test_basic.py
+++ b/theano/typed_list/tests/test_basic.py
@@ -10,7 +10,7 @@
 from theano.typed_list.type import TypedListType
 from theano.typed_list.basic import (GetItem, Insert,
                                      Append, Extend, Remove, Reverse,
-                                     Index, Count, Length, make_list, MakeList)
+                                     Index, Count, Length, make_list)
 from theano import sparse
 from theano.tests import unittest_tools as utt
 # TODO, handle the case where scipy isn't installed.
@@ -23,8 +23,8 @@
 
 # took from tensors/tests/test_basic.py
 def rand_ranged_matrix(minimum, maximum, shape):
-    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum)
-                         + minimum, dtype=theano.config.floatX)
+    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum) +
+                         minimum, dtype=theano.config.floatX)
 
 
 # took from sparse/tests/test_basic.py
@@ -82,7 +82,6 @@ def test_sanity_check_single(self):
                             z)
 
         x = rand_ranged_matrix(-1000, 1000, [100, 101])
-        y = rand_ranged_matrix(-1000, 1000, [100, 101])
 
         self.assertTrue(numpy.array_equal(f([x],
                                             numpy.asarray(0, dtype='int64')),
@@ -555,7 +554,7 @@ def test_interface(self):
         self.assertTrue(f([x, x]) == 2)
 
 
-class T_MakeList(unittest.TestCase):
+class TestMakeList(unittest.TestCase):
 
     def test_wrong_shape(self):
         a = T.vector()
@@ -563,22 +562,22 @@ def test_wrong_shape(self):
 
         self.assertRaises(TypeError, make_list, (a, b))
 
-    def correct_answer(self):
+    def test_correct_answer(self):
         a = T.matrix()
         b = T.matrix()
 
         x = T.tensor3()
         y = T.tensor3()
 
-        A = numpy.random.rand(5)
-        B = numpy.random.rand(7)
-        X = numpy.random.rand(5, 6)
-        Y = numpy.random.rand(1, 9)
+        A = numpy.cast[theano.config.floatX](numpy.random.rand(5, 3))
+        B = numpy.cast[theano.config.floatX](numpy.random.rand(7, 2))
+        X = numpy.cast[theano.config.floatX](numpy.random.rand(5, 6, 1))
+        Y = numpy.cast[theano.config.floatX](numpy.random.rand(1, 9, 3))
 
+        make_list((3., 4.))
         c = make_list((a, b))
         z = make_list((x, y))
-        fc = function([a, b], c)
-        fz = function([x, y], z)
-
-        self.assertTrue(f([A, B]) == [A, B])
-        self.assertTrue(f([X, Y]) == [X, Y])
+        fc = theano.function([a, b], c)
+        fz = theano.function([x, y], z)
+        self.assertTrue(fc(A, B) == [A, B])
+        self.assertTrue(fz(X, Y) == [X, Y])
diff --git a/theano/typed_list/tests/test_opt.py b/theano/typed_list/tests/test_opt.py
--- a/theano/typed_list/tests/test_opt.py
+++ b/theano/typed_list/tests/test_opt.py
@@ -5,30 +5,28 @@
 import theano
 import theano.typed_list
 from theano import tensor as T
-from theano.tensor.type_other import SliceType
 from theano.typed_list.type import TypedListType
-from theano.typed_list.basic import (GetItem, Insert,
-                                      Append, Extend, Remove, Reverse,
-                                      Index, Count)
+from theano.typed_list.basic import (Insert,
+                                     Append, Extend, Remove, Reverse)
 from theano import In
 
 
 # took from tensors/tests/test_basic.py
 def rand_ranged_matrix(minimum, maximum, shape):
-    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum)
-                         + minimum, dtype=theano.config.floatX)
+    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum) +
+                         minimum, dtype=theano.config.floatX)
 
 
 class test_inplace(unittest.TestCase):
 
     def test_reverse_inplace(self):
         mySymbolicMatricesList = TypedListType(T.TensorType(
-                                theano.config.floatX, (False, False)))()
+                                               theano.config.floatX, (False, False)))()
 
         z = Reverse()(mySymbolicMatricesList)
         m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
         f = theano.function([In(mySymbolicMatricesList, borrow=True,
-                        mutable=True)], z, accept_inplace=True, mode=m)
+                                mutable=True)], z, accept_inplace=True, mode=m)
         self.assertTrue(f.maker.fgraph.toposort()[0].op.inplace)
 
         x = rand_ranged_matrix(-1000, 1000, [100, 101])
@@ -39,13 +37,14 @@ def test_reverse_inplace(self):
 
     def test_append_inplace(self):
         mySymbolicMatricesList = TypedListType(T.TensorType(
-                                theano.config.floatX, (False, False)))()
+                                               theano.config.floatX, (False, False)))()
         mySymbolicMatrix = T.matrix()
         z = Append()(mySymbolicMatricesList, mySymbolicMatrix)
         m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
         f = theano.function([In(mySymbolicMatricesList, borrow=True,
-                        mutable=True), In(mySymbolicMatrix, borrow=True,
-                        mutable=True)], z, accept_inplace=True, mode=m)
+                                mutable=True),
+                            In(mySymbolicMatrix, borrow=True,
+                               mutable=True)], z, accept_inplace=True, mode=m)
         self.assertTrue(f.maker.fgraph.toposort()[0].op.inplace)
 
         x = rand_ranged_matrix(-1000, 1000, [100, 101])
@@ -56,15 +55,15 @@ def test_append_inplace(self):
 
     def test_extend_inplace(self):
         mySymbolicMatricesList1 = TypedListType(T.TensorType(
-                                theano.config.floatX, (False, False)))()
+                                                theano.config.floatX, (False, False)))()
 
         mySymbolicMatricesList2 = TypedListType(T.TensorType(
-                                theano.config.floatX, (False, False)))()
+                                                theano.config.floatX, (False, False)))()
 
         z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2)
         m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
         f = theano.function([In(mySymbolicMatricesList1, borrow=True,
-                    mutable=True), mySymbolicMatricesList2],
+                             mutable=True), mySymbolicMatricesList2],
                             z, mode=m)
         self.assertTrue(f.maker.fgraph.toposort()[0].op.inplace)
 
@@ -76,7 +75,7 @@ def test_extend_inplace(self):
 
     def test_insert_inplace(self):
         mySymbolicMatricesList = TypedListType(T.TensorType(
-                                theano.config.floatX, (False, False)))()
+                                               theano.config.floatX, (False, False)))()
         mySymbolicIndex = T.scalar(dtype='int64')
         mySymbolicMatrix = T.matrix()
 
@@ -84,8 +83,8 @@ def test_insert_inplace(self):
         m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
 
         f = theano.function([In(mySymbolicMatricesList, borrow=True,
-                        mutable=True), mySymbolicIndex, mySymbolicMatrix],
-                        z, accept_inplace=True, mode=m)
+                             mutable=True), mySymbolicIndex, mySymbolicMatrix],
+                            z, accept_inplace=True, mode=m)
         self.assertTrue(f.maker.fgraph.toposort()[0].op.inplace)
 
         x = rand_ranged_matrix(-1000, 1000, [100, 101])
@@ -93,11 +92,11 @@ def test_insert_inplace(self):
         y = rand_ranged_matrix(-1000, 1000, [100, 101])
 
         self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
-                                dtype='int64'), y), [x, y]))
+                        dtype='int64'), y), [x, y]))
 
     def test_remove_inplace(self):
         mySymbolicMatricesList = TypedListType(T.TensorType(
-                                    theano.config.floatX, (False, False)))()
+                                               theano.config.floatX, (False, False)))()
         mySymbolicMatrix = T.matrix()
         z = Remove()(mySymbolicMatricesList, mySymbolicMatrix)
         m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
diff --git a/theano/typed_list/tests/test_type.py b/theano/typed_list/tests/test_type.py
--- a/theano/typed_list/tests/test_type.py
+++ b/theano/typed_list/tests/test_type.py
@@ -11,8 +11,8 @@
 
 # took from tensors/tests/test_basic.py
 def rand_ranged_matrix(minimum, maximum, shape):
-    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum)
-                         + minimum, dtype=theano.config.floatX)
+    return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum) +
+                         minimum, dtype=theano.config.floatX)
 
 
 class test_typed_list_type(unittest.TestCase):
@@ -63,13 +63,13 @@ def test_type_equality(self):
         """
         # list of matrices
         myType1 = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)))
+                                             (False, False)))
         # list of matrices
         myType2 = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)))
+                                             (False, False)))
         # list of scalars
         myType3 = TypedListType(T.TensorType(theano.config.floatX,
-                                            ()))
+                                             ()))
 
         self.assertTrue(myType2 == myType1)
         self.assertFalse(myType3 == myType1)
@@ -118,7 +118,7 @@ def test_basic_nested_list(self):
         Testing nested list with one level of depth
         """
         myNestedType = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)))
+                                                  (False, False)))
 
         myType = TypedListType(myNestedType)
 
@@ -131,7 +131,7 @@ def test_comparison_different_depth(self):
         Nested list with different depth aren't the same
         """
         myNestedType = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)))
+                                                  (False, False)))
 
         myNestedType2 = TypedListType(myNestedType)
 
@@ -144,13 +144,13 @@ def test_nested_list_arg(self):
         test for the 'depth' optionnal argument
         """
         myNestedType = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)), 3)
+                                                  (False, False)), 3)
 
         myType = TypedListType(T.TensorType(theano.config.floatX,
                                             (False, False)))
 
         myManualNestedType = TypedListType(TypedListType(
-                             TypedListType(myType)))
+                                           TypedListType(myType)))
 
         self.assertTrue(myNestedType == myManualNestedType)
 
@@ -162,7 +162,7 @@ def test_get_depth(self):
                                             (False, False)))
 
         myManualNestedType = TypedListType(TypedListType(
-                             TypedListType(myType)))
+                                           TypedListType(myType)))
 
         self.assertTrue(myManualNestedType.get_depth() == 3)
 
@@ -175,17 +175,16 @@ def test_comparison_uneven_nested(self):
                                             (False, False)))
 
         myManualNestedType1 = TypedListType(TypedListType(
-                             TypedListType(myType)))
+                                            TypedListType(myType)))
 
-        myManualNestedType2 = TypedListType(TypedListType(
-                             myType))
+        myManualNestedType2 = TypedListType(TypedListType(myType))
 
         self.assertFalse(myManualNestedType1 == myManualNestedType2)
         self.assertFalse(myManualNestedType2 == myManualNestedType1)
 
     def test_variable_is_Typed_List_variable(self):
         mySymbolicVariable = TypedListType(T.TensorType(theano.config.floatX,
-                                            (False, False)))()
+                                           (False, False)))()
 
         self.assertTrue(isinstance(mySymbolicVariable,
                                    theano.typed_list.TypedListVariable))