Repository: Theano/Theano

Issue:
Remove equality checks between arrays and None
There is a warning in NumPy 1.9 that the result of such comparisons will be an array instead of a Boolean in the future:

```
/Library/Python/2.7/site-packages/theano/tensor/opt.py:2165: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
```



Discussion:
This did not fix all instances of the problem. For instance, these ones had been reported [on theano-dev](https://groups.google.com/d/msg/theano-users/R7vQyhZkycw/mCVyhWKKsCgJ):
- https://github.com/Theano/Theano/blob/master/theano/tensor/opt.py#L2503 : `replace_x` or `replace_y` could be `None`, and the other one an `ndarray`.
- https://github.com/Theano/Theano/blob/master/theano/tensor/subtensor.py#L142, checking for appartenance to a list with `in` uses `==`.

The correct way of detecting and fixing that is to actually install NumPy 1.9, and make sure no such warning is raised when executing the whole nightly build (including debugmode).


Resolving patch:
diff --git a/theano/tensor/opt.py b/theano/tensor/opt.py
--- a/theano/tensor/opt.py
+++ b/theano/tensor/opt.py
@@ -1935,11 +1935,11 @@ def local_useless_subtensor(node):
                 # If idx is not a slice, this means we remove this dimension
                 # from the output, so the subtensor is not useless
                 return False
-            if idx.start not in [0, None]:
+            if idx.start is not None and idx.start != 0:
                 # If the start of the slice is different from 0, or is a
                 # variable, then we assume the subtensor is not useless
                 return False
-            if idx.step not in [1, None]:
+            if idx.step is not None and idx.step != 1:
                 # If we are going backwards, or skipping elements, then this
                 # is not a useless subtensor
                 return False
@@ -2543,9 +2543,9 @@ def local_setsubtensor_of_constants(node):
         except NotScalarConstantError:
             pass
 
-        if (replace_x == replace_y and
-            replace_x is not None and
-            replace_y is not None):
+        if (replace_x is not None and
+            replace_y is not None and
+            replace_x == replace_y):
             return [x]
         else:
             return False
diff --git a/theano/tensor/subtensor.py b/theano/tensor/subtensor.py
--- a/theano/tensor/subtensor.py
+++ b/theano/tensor/subtensor.py
@@ -137,11 +137,11 @@ def analyze(x):
         # in the generic case below.
         if step == 1:
             is_start_0 = (
-                start in [None, 0] or
+                start is None or start == 0 or
                 (is_start_constant and is_length_constant and
                  start < 0 and start + length <= 0))
             is_stop_length = (
-                stop in [None, length, maxsize] or
+                stop is None or stop in [length, maxsize] or
                 (is_stop_constant and is_length_constant and
                  stop >= length))
             if is_start_0:
@@ -217,7 +217,7 @@ def switch_neg_step(a, b):
             start = switch(ge(start, length),
                            switch_neg_step(length - 1, length),
                            start)
-        if stop in [None, maxsize]:
+        if stop is None or stop == maxsize:
             # The special "maxsize" case is probably not needed here,
             # as slices containing maxsize are not generated by
             # __getslice__ anymore.
@@ -478,7 +478,7 @@ def make_node(self, x, *inputs):
                         start = get_scalar_constant_value(start)
                     except NotScalarConstantError:
                         pass
-                    if start in [None, 0]:
+                    if start is None or start == 0:
                         start = p.start
                         if start is None:
                             start = 0
diff --git a/theano/tensor/var.py b/theano/tensor/var.py
--- a/theano/tensor/var.py
+++ b/theano/tensor/var.py
@@ -369,7 +369,7 @@ def __getitem__(self, args):
         axis = None
         for i, arg in enumerate(args):
             try:
-                if arg != numpy.newaxis:
+                if arg is not numpy.newaxis:
                     theano.tensor.subtensor.Subtensor.convert(arg)
             except theano.tensor.subtensor.AdvancedIndexingError:
                 if advanced:


Test patch: