Skip to content

Commit

Permalink
Don't use test_values when checking for errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
abergeron committed Nov 6, 2017
1 parent 7286408 commit b3523b8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
83 changes: 42 additions & 41 deletions theano/tensor/tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,47 +421,48 @@ def numpy_inc_subtensor(x, idx, a):
assert_array_equal(numpy_inc_subtensor(numpy_n4, [numpy_n > 2, Ellipsis, 0, 1], 1),
inc_subtensor(n4[n > 2, ..., 0, 1], 1).eval())

# the boolean mask should have the correct shape
# - too large, padded with True
mask = np.array([True, False, True])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True, False, False, True], [False, True, False, True]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - too large, padded with False (this works in NumPy < 0.13.0)
mask = np.array([True, False, False])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True, False, False, False], [False, True, False, False]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - mask too small (this works in NumPy < 0.13.0)
mask = np.array([True])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True], [True]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - too many dimensions
mask = np.array([[[True, False, False],
[False, True, False]]])
self.assertRaises(IndexError, n.__getitem__, mask)
self.assertRaises(IndexError, n.__getitem__, mask)

# special cases: Python bools and bools nested in Python arrays are not supported
self.assertRaises(TypeError, n.__getitem__, (True,))
self.assertRaises(TypeError, n.__getitem__, (False,))
self.assertRaises(TypeError, n.__getitem__, (True, False))
self.assertRaises(TypeError, n.__getitem__, ([True, False]))
self.assertRaises(TypeError, n.__getitem__, ([0, 1], [0, False]))
self.assertRaises(TypeError, n.__getitem__, ([0, 1], [0, theano.shared(True)]))
with change_flags(compute_test_value='off'):
# the boolean mask should have the correct shape
# - too large, padded with True
mask = np.array([True, False, True])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True, False, False, True], [False, True, False, True]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - too large, padded with False (this works in NumPy < 0.13.0)
mask = np.array([True, False, False])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True, False, False, False], [False, True, False, False]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - mask too small (this works in NumPy < 0.13.0)
mask = np.array([True])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, n[mask, ...].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
self.assertRaises(IndexError, inc_subtensor(n[mask, ...], 1).eval)
mask = np.array([[True], [True]])
self.assertRaises(IndexError, n[mask].eval)
self.assertRaises(IndexError, inc_subtensor(n[mask], 1).eval)
# - too many dimensions
mask = np.array([[[True, False, False],
[False, True, False]]])
self.assertRaises(IndexError, n.__getitem__, mask)
self.assertRaises(IndexError, n.__getitem__, mask)

# special cases: Python bools and bools nested in Python arrays are not supported
self.assertRaises(TypeError, n.__getitem__, (True,))
self.assertRaises(TypeError, n.__getitem__, (False,))
self.assertRaises(TypeError, n.__getitem__, (True, False))
self.assertRaises(TypeError, n.__getitem__, ([True, False]))
self.assertRaises(TypeError, n.__getitem__, ([0, 1], [0, False]))
self.assertRaises(TypeError, n.__getitem__, ([0, 1], [0, theano.shared(True)]))

def test_newaxis(self):
# newaxis support comes from logic in the __getitem__ of TensorType
Expand Down
3 changes: 2 additions & 1 deletion theano/tests/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from six.moves import xrange

import theano
from theano import gof
from theano import gof, change_flags
from theano.compat import izip
from theano.tests import unittest_tools as utt

Expand Down Expand Up @@ -803,6 +803,7 @@ def test_grad_scale():
assert np.allclose(out, (8, 4))


@change_flags(compute_test_value='off')
def test_undefined_grad_opt():
# Make sure that undefined grad get removed in optimized graph.
random = RandomStreams(np.random.randint(1, 2147462579))
Expand Down

0 comments on commit b3523b8

Please sign in to comment.