提交 c63fe0ea authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Use assertTrue (and assert*) instead of failUnless (and fail*) in tests.

fail* functions are deprecated in Python 2.7. Also remove reference to these deprecated functions from the doc.
上级 b53baf0a
...@@ -47,7 +47,7 @@ example: ...@@ -47,7 +47,7 @@ example:
# test passes cleanly # test passes cleanly
def test1(self): def test1(self):
self.failUnless(2+2 == 5) self.assertTrue(2+2 == 5)
# raises an exception, causes test to fail # raises an exception, causes test to fail
def test2(self): def test2(self):
...@@ -221,13 +221,13 @@ Example: ...@@ -221,13 +221,13 @@ Example:
c = T.dot(a,b) c = T.dot(a,b)
f = theano.function([a,b],[c]) f = theano.function([a,b],[c])
cmp = f(self.avals,self.bvals) == numpy.dot(self.avals,self.bvals) cmp = f(self.avals,self.bvals) == numpy.dot(self.avals,self.bvals)
self.failUnless(numpy.all(cmp)) self.assertTrue(numpy.all(cmp))
Avoid hard-coding variables, as in the following case: Avoid hard-coding variables, as in the following case:
.. code-block:: python .. code-block:: python
self.failUnless(numpy.all(f(self.avals,self.bvals)==numpy.array([[25,25,30,28],[21,18,14,25]]))) self.assertTrue(numpy.all(f(self.avals,self.bvals)==numpy.array([[25,25,30,28],[21,18,14,25]])))
This makes the test case less manageable and forces the user to update This makes the test case less manageable and forces the user to update
the variables each time the input is changed or possibly when the the variables each time the input is changed or possibly when the
...@@ -238,15 +238,15 @@ idea. ...@@ -238,15 +238,15 @@ idea.
Here is a list of useful functions, as defined by TestCase: Here is a list of useful functions, as defined by TestCase:
* checking the state of boolean variables: assert, failUnless, * checking the state of boolean variables: assert,
assertTrue, failIf, assertFalse assertTrue, assertFalse
* checking for (in)equality constraints: assertEqual, failUnlessEqual, * checking for (in)equality constraints: assertEqual,
assertNotEqual, failIfEqual assertNotEqual
* checking for (in)equality constraints up to a given precision (very * checking for (in)equality constraints up to a given precision (very
useful in theano): assertAlmostEqual, failUnlessAlmostEqual, useful in theano): assertAlmostEqual,
assertNotAlmostEqual, failIfAlmostEqual assertNotAlmostEqual
Checking for errors Checking for errors
...@@ -270,11 +270,11 @@ Example: ...@@ -270,11 +270,11 @@ Example:
b = T.dmatrix() b = T.dmatrix()
c = T.dot(a,b) # we expect this to fail c = T.dot(a,b) # we expect this to fail
# above should fail as dot operates on 2D tensors only # above should fail as dot operates on 2D tensors only
self.failUnlessRaises(TypeError, func) self.assertRaises(TypeError, func)
Useful functions, as defined by TestCase: Useful function, as defined by TestCase:
* assertRaises, failUnlessRaises * assertRaises
Test Cases and Theano Modes Test Cases and Theano Modes
......
...@@ -126,11 +126,11 @@ Guillaume can you make sure to hit these points: ...@@ -126,11 +126,11 @@ Guillaume can you make sure to hit these points:
* What is the right eq function to use? * What is the right eq function to use?
* There are a lot of tests that define their own epsilon, but this should be standardized. e.g. in test_elemwise.py ``self.failUnless((numpy.abs(f(xv) - zv) < 1e-10).all())`` * There are a lot of tests that define their own epsilon, but this should be standardized. e.g. in test_elemwise.py ``self.assertTrue((numpy.abs(f(xv) - zv) < 1e-10).all())``
* If the expected variable of a test is that an Exception is thrown, how do we correctly detect and handle that? * If the expected variable of a test is that an Exception is thrown, how do we correctly detect and handle that?
nosetests has ``failUnlessRaises`` nosetests has ``assertRaises``
* Convention is that all test files must start with ``test_``, not * Convention is that all test files must start with ``test_``, not
``_test_``, so rename all that use the old convention? ``_test_``, so rename all that use the old convention?
......
...@@ -475,15 +475,15 @@ class Test_check_isfinite(unittest.TestCase): ...@@ -475,15 +475,15 @@ class Test_check_isfinite(unittest.TestCase):
# if TensorType.filter_checks_isfinite were true, these would raise ValueError # if TensorType.filter_checks_isfinite were true, these would raise ValueError
# if not, DebugMode will check internally, and raise InvalidValueError # if not, DebugMode will check internally, and raise InvalidValueError
# passing an invalid value as an input should trigger ValueError # passing an invalid value as an input should trigger ValueError
self.failUnlessRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
numpy.log([3, -4, 5]).astype(config.floatX)) numpy.log([3, -4, 5]).astype(config.floatX))
self.failUnlessRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
(numpy.asarray([0, 1.0, 0])/0).astype(config.floatX)) (numpy.asarray([0, 1.0, 0])/0).astype(config.floatX))
self.failUnlessRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
(numpy.asarray([1.0, 1.0, 1.0])/0).astype(config.floatX)) (numpy.asarray([1.0, 1.0, 1.0])/0).astype(config.floatX))
# generating an invalid value internally should trigger InvalidValueError # generating an invalid value internally should trigger InvalidValueError
self.failUnlessRaises(debugmode.InvalidValueError, g, self.assertRaises(debugmode.InvalidValueError, g,
numpy.asarray([3,-4,5], dtype=config.floatX)) numpy.asarray([3,-4,5], dtype=config.floatX))
# this should disable the exception # this should disable the exception
......
...@@ -43,12 +43,12 @@ class T_function(unittest.TestCase): ...@@ -43,12 +43,12 @@ class T_function(unittest.TestCase):
def test_empty(self): def test_empty(self):
fn = function([], []) #ok fn = function([], []) #ok
self.failUnless(fn() == []) self.assertTrue(fn() == [])
def test_extra_inputs(self): def test_extra_inputs(self):
x,s = T.scalars('xs') x,s = T.scalars('xs')
fn = function([x], [x]) fn = function([x], [x])
self.failUnlessRaises(TypeError,fn,1,2) self.assertRaises(TypeError,fn,1,2)
def test_missing_inputs(self): def test_missing_inputs(self):
...@@ -87,23 +87,23 @@ class T_function(unittest.TestCase): ...@@ -87,23 +87,23 @@ class T_function(unittest.TestCase):
def test_input_anon_singleton(self): def test_input_anon_singleton(self):
x,s = T.scalars('xs') x,s = T.scalars('xs')
fn = function([s,x], [x+s]) fn = function([s,x], [x+s])
self.failUnless(fn(2,3) == [5]) self.assertTrue(fn(2,3) == [5])
# no state # no state
self.failUnless(fn(2,3) == [5]) self.assertTrue(fn(2,3) == [5])
def test_input_anon_unpack(self): def test_input_anon_unpack(self):
x,s = T.scalars('xs') x,s = T.scalars('xs')
fn = function([s,x], x+s) fn = function([s,x], x+s)
self.failUnless(fn(2,3) == 5) self.assertTrue(fn(2,3) == 5)
def test_naming_rule0(self): def test_naming_rule0(self):
x,s = T.scalars('xs') x,s = T.scalars('xs')
f = function([x,s], x/s) f = function([x,s], x/s)
self.failUnless(f(1,2) == 0.5) self.assertTrue(f(1,2) == 0.5)
self.failUnless(f(2,1) == 2.0) self.assertTrue(f(2,1) == 2.0)
self.failUnless(f(s=2,x=1) == 0.5) self.assertTrue(f(s=2,x=1) == 0.5)
self.failUnless(f(x=2,s=1) == 2.0) self.assertTrue(f(x=2,s=1) == 2.0)
self.failUnless(f(2, s=1) == 2.0) self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda :f(2, x=2.0), TypeError) #got multiple values for keyword argument 'x' checkfor(self, lambda :f(2, x=2.0), TypeError) #got multiple values for keyword argument 'x'
checkfor(self, lambda :f(x=1), TypeError) #takes exactly 2 non-keyword arguments (1 given) checkfor(self, lambda :f(x=1), TypeError) #takes exactly 2 non-keyword arguments (1 given)
checkfor(self, lambda :f(s=1), TypeError) #takes exactly 2 non-keyword arguments (0 given) checkfor(self, lambda :f(s=1), TypeError) #takes exactly 2 non-keyword arguments (0 given)
...@@ -112,9 +112,9 @@ class T_function(unittest.TestCase): ...@@ -112,9 +112,9 @@ class T_function(unittest.TestCase):
a = T.scalar() # the a is for 'anonymous' (un-named). a = T.scalar() # the a is for 'anonymous' (un-named).
x,s = T.scalars('xs') x,s = T.scalars('xs')
f = function([a, s], a/s) f = function([a, s], a/s)
self.failUnless(f(1,2) == 0.5) self.assertTrue(f(1,2) == 0.5)
self.failUnless(f(2,1) == 2.0) self.assertTrue(f(2,1) == 2.0)
self.failUnless(f(2, s=1) == 2.0) self.assertTrue(f(2, s=1) == 2.0)
checkfor(self, lambda:f(q=2,s=1), TypeError) #got unexpected keyword argument 'q' checkfor(self, lambda:f(q=2,s=1), TypeError) #got unexpected keyword argument 'q'
checkfor(self, lambda:f(a=2,s=1), TypeError) #got unexpected keyword argument 'a' checkfor(self, lambda:f(a=2,s=1), TypeError) #got unexpected keyword argument 'a'
...@@ -124,9 +124,9 @@ class T_function(unittest.TestCase): ...@@ -124,9 +124,9 @@ class T_function(unittest.TestCase):
#x's name is ignored because it is followed by anonymous parameter a. #x's name is ignored because it is followed by anonymous parameter a.
f = function([x, a, s], a/s) f = function([x, a, s], a/s)
self.failUnless(f(9,1,2) == 0.5) self.assertTrue(f(9,1,2) == 0.5)
self.failUnless(f(9,2,1) == 2.0) self.assertTrue(f(9,2,1) == 2.0)
self.failUnless(f(9,2, s=1) == 2.0) self.assertTrue(f(9,2, s=1) == 2.0)
checkfor(self, lambda:f(x=9,a=2,s=1), TypeError) #got unexpected keyword argument 'x' checkfor(self, lambda:f(x=9,a=2,s=1), TypeError) #got unexpected keyword argument 'x'
checkfor(self, lambda:f(5.0,x=9), TypeError) #got unexpected keyword argument 'x' checkfor(self, lambda:f(5.0,x=9), TypeError) #got unexpected keyword argument 'x'
...@@ -136,10 +136,10 @@ class T_function(unittest.TestCase): ...@@ -136,10 +136,10 @@ class T_function(unittest.TestCase):
#x's name is not ignored (as in test_naming_rule2) because a has a default value. #x's name is not ignored (as in test_naming_rule2) because a has a default value.
f = function([x, In(a, value=1.0), s], a/s+x) f = function([x, In(a, value=1.0), s], a/s+x)
self.failUnless(f(9,2,4) == 9.5) #can specify all args in order self.assertTrue(f(9,2,4) == 9.5) #can specify all args in order
self.failUnless(f(9,2,s=4) == 9.5) # can give s as kwarg self.assertTrue(f(9,2,s=4) == 9.5) # can give s as kwarg
self.failUnless(f(9,s=4) == 9.25) # can give s as kwarg, get default a self.assertTrue(f(9,s=4) == 9.25) # can give s as kwarg, get default a
self.failUnless(f(x=9,s=4) == 9.25) # can give s as kwarg, omit a, x as kw self.assertTrue(f(x=9,s=4) == 9.25) # can give s as kwarg, omit a, x as kw
checkfor(self, lambda:f(x=9,a=2,s=4), TypeError) #got unexpected keyword argument 'a' checkfor(self, lambda:f(x=9,a=2,s=4), TypeError) #got unexpected keyword argument 'a'
checkfor(self, lambda:f(), TypeError) #takes exactly 3 non-keyword arguments (0 given) checkfor(self, lambda:f(), TypeError) #takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda:f(x=9), TypeError) #takes exactly 3 non-keyword arguments (1 given) checkfor(self, lambda:f(x=9), TypeError) #takes exactly 3 non-keyword arguments (1 given)
...@@ -150,12 +150,12 @@ class T_function(unittest.TestCase): ...@@ -150,12 +150,12 @@ class T_function(unittest.TestCase):
f = function([x, In(a, value=1.0,name='a'), s], a/s+x) f = function([x, In(a, value=1.0,name='a'), s], a/s+x)
self.failUnless(f(9,2,4) == 9.5) #can specify all args in order self.assertTrue(f(9,2,4) == 9.5) #can specify all args in order
self.failUnless(f(9,2,s=4) == 9.5) # can give s as kwarg self.assertTrue(f(9,2,s=4) == 9.5) # can give s as kwarg
self.failUnless(f(9,s=4) == 9.25) # can give s as kwarg, get default a self.assertTrue(f(9,s=4) == 9.25) # can give s as kwarg, get default a
self.failUnless(f(9,a=2,s=4) == 9.5) # can give s as kwarg, a as kwarg self.assertTrue(f(9,a=2,s=4) == 9.5) # can give s as kwarg, a as kwarg
self.failUnless(f(x=9,a=2, s=4) == 9.5) # can give all kwargs self.assertTrue(f(x=9,a=2, s=4) == 9.5) # can give all kwargs
self.failUnless(f(x=9,s=4) == 9.25) # can give all kwargs self.assertTrue(f(x=9,s=4) == 9.25) # can give all kwargs
checkfor(self, lambda:f(), TypeError) #takes exactly 3 non-keyword arguments (0 given) checkfor(self, lambda:f(), TypeError) #takes exactly 3 non-keyword arguments (0 given)
checkfor(self, lambda:f(5.0,x=9), TypeError) #got multiple values for keyword argument 'x' checkfor(self, lambda:f(5.0,x=9), TypeError) #got multiple values for keyword argument 'x'
...@@ -165,25 +165,25 @@ class T_function(unittest.TestCase): ...@@ -165,25 +165,25 @@ class T_function(unittest.TestCase):
f = function([x, In(a, value=1.0,name='a'), In(s, value=0.0, update=s+a*x)], s+a*x) f = function([x, In(a, value=1.0,name='a'), In(s, value=0.0, update=s+a*x)], s+a*x)
self.failUnless(f[a] == 1.0) self.assertTrue(f[a] == 1.0)
self.failUnless(f[s] == 0.0) self.assertTrue(f[s] == 0.0)
self.failUnless(f(3.0) == 3.0) self.assertTrue(f(3.0) == 3.0)
self.failUnless(f(3.0,a=2.0) == 9.0) #3.0 + 2*3.0 self.assertTrue(f(3.0,a=2.0) == 9.0) #3.0 + 2*3.0
self.failUnless(f[a] == 1.0) #state hasn't changed permanently, we just overrode it last line self.assertTrue(f[a] == 1.0) #state hasn't changed permanently, we just overrode it last line
self.failUnless(f[s] == 9.0) self.assertTrue(f[s] == 9.0)
f[a] = 5.0 f[a] = 5.0
self.failUnless(f[a] == 5.0) self.assertTrue(f[a] == 5.0)
self.failUnless(f(3.0) == 24.0) #9 + 3*5 self.assertTrue(f(3.0) == 24.0) #9 + 3*5
self.failUnless(f[s] == 24.0) self.assertTrue(f[s] == 24.0)
def test_same_names(self): def test_same_names(self):
a,x,s = T.scalars('xxx') a,x,s = T.scalars('xxx')
#implicit names would cause error. What do we do? #implicit names would cause error. What do we do?
f = function([a, x, s], a+x+s) f = function([a, x, s], a+x+s)
self.failUnless(f(1,2,3) == 6) self.assertTrue(f(1,2,3) == 6)
checkfor(self, lambda:f(1,2,x=3), TypeError) checkfor(self, lambda:f(1,2,x=3), TypeError)
def test_weird_names(self): def test_weird_names(self):
...@@ -206,18 +206,18 @@ class T_function(unittest.TestCase): ...@@ -206,18 +206,18 @@ class T_function(unittest.TestCase):
g = copy.copy(f) g = copy.copy(f)
#if they both return, assume that they return equivalent things. #if they both return, assume that they return equivalent things.
self.failIf(g.container[x].storage is f.container[x].storage) self.assertFalse(g.container[x].storage is f.container[x].storage)
self.failIf(g.container[a].storage is f.container[a].storage) self.assertFalse(g.container[a].storage is f.container[a].storage)
self.failIf(g.container[s].storage is f.container[s].storage) self.assertFalse(g.container[s].storage is f.container[s].storage)
self.failIf(g.value[a] is not f.value[a]) # should not have been copied self.assertFalse(g.value[a] is not f.value[a]) # should not have been copied
self.failIf(g.value[s] is f.value[s]) # should have been copied because it is mutable. self.assertFalse(g.value[s] is f.value[s]) # should have been copied because it is mutable.
self.failIf((g.value[s] != f.value[s]).any()) # its contents should be identical self.assertFalse((g.value[s] != f.value[s]).any()) # its contents should be identical
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
f(1,2) # put them out of sync f(1,2) # put them out of sync
self.failIf(f(1, 2) == g(1, 2)) #they should not be equal anymore. self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
def test_shared_state0(self): def test_shared_state0(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = T.scalar() # the a is for 'anonymous' (un-named).
...@@ -227,11 +227,11 @@ class T_function(unittest.TestCase): ...@@ -227,11 +227,11 @@ class T_function(unittest.TestCase):
g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s], update=s-a*x, mutable=True)], s+a*x) g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s], update=s-a*x, mutable=True)], s+a*x)
f(1, 2) f(1, 2)
self.failUnless(f[s] == 2) self.assertTrue(f[s] == 2)
self.failUnless(g[s] == 2) self.assertTrue(g[s] == 2)
g(1, 2) g(1, 2)
self.failUnless(f[s] == 0) self.assertTrue(f[s] == 0)
self.failUnless(g[s] == 0) self.assertTrue(g[s] == 0)
def test_shared_state1(self): def test_shared_state1(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = T.scalar() # the a is for 'anonymous' (un-named).
...@@ -241,12 +241,12 @@ class T_function(unittest.TestCase): ...@@ -241,12 +241,12 @@ class T_function(unittest.TestCase):
g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s])], s+a*x) g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s])], s+a*x)
f(1, 2) f(1, 2)
self.failUnless(f[s] == 2) self.assertTrue(f[s] == 2)
self.failUnless(g[s] == 2) self.assertTrue(g[s] == 2)
f(1, 2) f(1, 2)
g(1, 2) g(1, 2)
self.failUnless(f[s] == 4) self.assertTrue(f[s] == 4)
self.failUnless(g[s] == 4) self.assertTrue(g[s] == 4)
def test_shared_state2(self): def test_shared_state2(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = T.scalar() # the a is for 'anonymous' (un-named).
...@@ -257,14 +257,14 @@ class T_function(unittest.TestCase): ...@@ -257,14 +257,14 @@ class T_function(unittest.TestCase):
g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s])], s+a*x) g = function([x, In(a, value=1.0,name='a'), In(s, value=f.container[s])], s+a*x)
f(1, 2) f(1, 2)
self.failUnless(f[s] == 2) self.assertTrue(f[s] == 2)
self.failUnless(g[s] == 2) self.assertTrue(g[s] == 2)
f(1, 2) f(1, 2)
self.failUnless(f[s] == 4) self.assertTrue(f[s] == 4)
self.failUnless(g[s] == 4) self.assertTrue(g[s] == 4)
g(1, 2) # has no effect on state g(1, 2) # has no effect on state
self.failUnless(f[s] == 4) self.assertTrue(f[s] == 4)
self.failUnless(g[s] == 4) self.assertTrue(g[s] == 4)
def test_shared_state_not_implicit(self): def test_shared_state_not_implicit(self):
# This test is taken from the documentation in # This test is taken from the documentation in
...@@ -275,14 +275,14 @@ class T_function(unittest.TestCase): ...@@ -275,14 +275,14 @@ class T_function(unittest.TestCase):
inc = function([x, In(s, update=(s+x), value=10.0)], []) inc = function([x, In(s, update=(s+x), value=10.0)], [])
dec = function([x, In(s, update=(s-x), value=inc.container[s], dec = function([x, In(s, update=(s-x), value=inc.container[s],
implicit = False)], []) implicit = False)], [])
self.failUnless(dec[s] is inc[s]) self.assertTrue(dec[s] is inc[s])
inc[s] = 2 inc[s] = 2
self.failUnless(dec[s] == 2) self.assertTrue(dec[s] == 2)
dec(1) dec(1)
self.failUnless(inc[s] == 1) self.assertTrue(inc[s] == 1)
dec(1, 0) dec(1, 0)
self.failUnless(inc[s] == -1) self.assertTrue(inc[s] == -1)
self.failUnless(dec[s] == -1) self.assertTrue(dec[s] == -1)
def test_constant_output(self): def test_constant_output(self):
...@@ -370,29 +370,29 @@ class T_picklefunction(unittest.TestCase): ...@@ -370,29 +370,29 @@ class T_picklefunction(unittest.TestCase):
#print [(k,id(k)) for k in f.finder.keys()] #print [(k,id(k)) for k in f.finder.keys()]
#print [(k,id(k)) for k in g.finder.keys()] #print [(k,id(k)) for k in g.finder.keys()]
self.failIf(g.container[0].storage is f.container[0].storage) self.assertFalse(g.container[0].storage is f.container[0].storage)
self.failIf(g.container[1].storage is f.container[1].storage) self.assertFalse(g.container[1].storage is f.container[1].storage)
self.failIf(g.container[2].storage is f.container[2].storage) self.assertFalse(g.container[2].storage is f.container[2].storage)
self.failIf(x in g.container) self.assertFalse(x in g.container)
self.failIf(x in g.value) self.assertFalse(x in g.value)
self.failUnless(len(f.defaults) == len(g.defaults)) self.assertTrue(len(f.defaults) == len(g.defaults))
print 'f.defaults = %s' % (f.defaults, ) print 'f.defaults = %s' % (f.defaults, )
print 'g.defaults = %s' % (g.defaults, ) print 'g.defaults = %s' % (g.defaults, )
self.failUnless(all([f_req == g_req and f_feed == g_feed and self.assertTrue(all([f_req == g_req and f_feed == g_feed and
f_val == g_val f_val == g_val
for ((f_req, f_feed, f_val), (g_req, g_feed, g_val)) in zip( for ((f_req, f_feed, f_val), (g_req, g_feed, g_val)) in zip(
f.defaults, g.defaults)])) f.defaults, g.defaults)]))
self.failIf(g.value[1] is f.value[1]) # should not have been copied self.assertFalse(g.value[1] is f.value[1]) # should not have been copied
self.failIf(g.value[2] is f.value[2]) # should have been copied because it is mutable. self.assertFalse(g.value[2] is f.value[2]) # should have been copied because it is mutable.
self.failIf((g.value[2] != f.value[2]).any()) # its contents should be identical self.assertFalse((g.value[2] != f.value[2]).any()) # its contents should be identical
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
f(1,2) # put them out of sync f(1,2) # put them out of sync
self.failIf(f(1, 2) == g(1, 2)) #they should not be equal anymore. self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
g(1, 2) # put them back in sync g(1, 2) # put them back in sync
self.failUnless(f(3) == g(3)) # They should be in sync again. self.assertTrue(f(3) == g(3)) # They should be in sync again.
def test_deepcopy_shared_container(self): def test_deepcopy_shared_container(self):
# Ensure that shared containers remain shared after a deep copy. # Ensure that shared containers remain shared after a deep copy.
...@@ -415,8 +415,8 @@ class T_picklefunction(unittest.TestCase): ...@@ -415,8 +415,8 @@ class T_picklefunction(unittest.TestCase):
raise raise
h[a] = 1 h[a] = 1
hc[ac] = 2 hc[ac] = 2
self.failUnless(f[a] == 1) self.assertTrue(f[a] == 1)
self.failUnless(fc[ac] == 2) self.assertTrue(fc[ac] == 2)
def test_pickle(self): def test_pickle(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = T.scalar() # the a is for 'anonymous' (un-named).
...@@ -435,20 +435,20 @@ class T_picklefunction(unittest.TestCase): ...@@ -435,20 +435,20 @@ class T_picklefunction(unittest.TestCase):
#print [(k,id(k)) for k in f.finder.keys()] #print [(k,id(k)) for k in f.finder.keys()]
#print [(k,id(k)) for k in g.finder.keys()] #print [(k,id(k)) for k in g.finder.keys()]
self.failIf(g.container[0].storage is f.container[0].storage) self.assertFalse(g.container[0].storage is f.container[0].storage)
self.failIf(g.container[1].storage is f.container[1].storage) self.assertFalse(g.container[1].storage is f.container[1].storage)
self.failIf(g.container[2].storage is f.container[2].storage) self.assertFalse(g.container[2].storage is f.container[2].storage)
self.failIf(x in g.container) self.assertFalse(x in g.container)
self.failIf(x in g.value) self.assertFalse(x in g.value)
self.failIf(g.value[1] is f.value[1]) # should not have been copied self.assertFalse(g.value[1] is f.value[1]) # should not have been copied
self.failIf(g.value[2] is f.value[2]) # should have been copied because it is mutable. self.assertFalse(g.value[2] is f.value[2]) # should have been copied because it is mutable.
self.failIf((g.value[2] != f.value[2]).any()) # its contents should be identical self.assertFalse((g.value[2] != f.value[2]).any()) # its contents should be identical
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
self.failUnless(f(2, 1) == g(2)) #they should be in sync, default value should be copied. self.assertTrue(f(2, 1) == g(2)) #they should be in sync, default value should be copied.
f(1,2) # put them out of sync f(1,2) # put them out of sync
self.failIf(f(1, 2) == g(1, 2)) #they should not be equal anymore. self.assertFalse(f(1, 2) == g(1, 2)) #they should not be equal anymore.
def test_optimizations_preserved(self): def test_optimizations_preserved(self):
a = T.dvector() # the a is for 'anonymous' (un-named). a = T.dvector() # the a is for 'anonymous' (un-named).
......
...@@ -52,7 +52,7 @@ class TestNnet(unittest.TestCase): ...@@ -52,7 +52,7 @@ class TestNnet(unittest.TestCase):
mean_cost += cost mean_cost += cost
mean_cost /= float(len(data)) mean_cost /= float(len(data))
print 'Mean cost at epoch %s: %s' % (epoch, mean_cost) print 'Mean cost at epoch %s: %s' % (epoch, mean_cost)
self.failUnless(abs(mean_cost - 0.20588975452) < 1e-6) self.assertTrue(abs(mean_cost - 0.20588975452) < 1e-6)
# Just call functions to make sure they do not crash. # Just call functions to make sure they do not crash.
out = nnet.compute_output(input) out = nnet.compute_output(input)
out = nnet.output_from_hidden(numpy.ones(10)) out = nnet.output_from_hidden(numpy.ones(10))
......
...@@ -27,23 +27,23 @@ class Test_pfunc(unittest.TestCase): ...@@ -27,23 +27,23 @@ class Test_pfunc(unittest.TestCase):
b = shared(1) b = shared(1)
f1 = pfunc([a], a+b) f1 = pfunc([a], a+b)
f2 = pfunc([Param(a, default=44)], a + b, updates={b: b + 1}) f2 = pfunc([Param(a, default=44)], a + b, updates={b: b + 1})
self.failUnless(b.get_value() == 1) self.assertTrue(b.get_value() == 1)
self.failUnless(f1(3) == 4) self.assertTrue(f1(3) == 4)
self.failUnless(f2(3) == 4) self.assertTrue(f2(3) == 4)
self.failUnless(b.get_value() == 2) self.assertTrue(b.get_value() == 2)
self.failUnless(f1(3) == 5) self.assertTrue(f1(3) == 5)
b.set_value(0) b.set_value(0)
self.failUnless(f1(3) == 3) self.assertTrue(f1(3) == 3)
# Example #2. # Example #2.
a = tensor.lscalar() a = tensor.lscalar()
b = shared(7) b = shared(7)
f1 = pfunc([a], a + b) f1 = pfunc([a], a + b)
f2 = pfunc([a], a * b) f2 = pfunc([a], a * b)
self.failUnless(f1(5) == 12) self.assertTrue(f1(5) == 12)
b.set_value(8) b.set_value(8)
self.failUnless(f1(5) == 13) self.assertTrue(f1(5) == 13)
self.failUnless(f2(4) == 32) self.assertTrue(f2(4) == 32)
def test_shared(self): def test_shared(self):
...@@ -317,25 +317,25 @@ class Test_pfunc(unittest.TestCase): ...@@ -317,25 +317,25 @@ class Test_pfunc(unittest.TestCase):
x = shared(0) x = shared(0)
assign = pfunc([], [], updates = {x: 3}) assign = pfunc([], [], updates = {x: 3})
assign() assign()
self.failUnless(x.get_value() == 3) self.assertTrue(x.get_value() == 3)
# Basic increment function. # Basic increment function.
x.set_value(0) x.set_value(0)
inc = pfunc([], [], updates = {x: x + 1}) inc = pfunc([], [], updates = {x: x + 1})
inc() inc()
self.failUnless(x.get_value() == 1) self.assertTrue(x.get_value() == 1)
# Increment by a constant value. # Increment by a constant value.
x.set_value(-1) x.set_value(-1)
y = shared(2) y = shared(2)
inc_by_y = pfunc([], [], updates = {x: x + y}) inc_by_y = pfunc([], [], updates = {x: x + y})
inc_by_y() inc_by_y()
self.failUnless(x.get_value() == 1) self.assertTrue(x.get_value() == 1)
def test_duplicate_updates(self): def test_duplicate_updates(self):
x, y = dmatrices('x', 'y') x, y = dmatrices('x', 'y')
z = shared(numpy.ones((2,3))) z = shared(numpy.ones((2,3)))
self.failUnlessRaises(ValueError, theano.function, [x,y], [z], updates=[(z, z+x+y), (z, z-x)]) self.assertRaises(ValueError, theano.function, [x,y], [z], updates=[(z, z+x+y), (z, z-x)])
def test_givens(self): def test_givens(self):
x = shared(0) x = shared(0)
...@@ -419,9 +419,9 @@ class Test_pfunc(unittest.TestCase): ...@@ -419,9 +419,9 @@ class Test_pfunc(unittest.TestCase):
print x.get_value() print x.get_value()
assert x.get_value() == 6 assert x.get_value() == 6
self.failUnlessRaises(TypeError, pfunc, [], [x], no_default_updates=(x)) self.assertRaises(TypeError, pfunc, [], [x], no_default_updates=(x))
self.failUnlessRaises(TypeError, pfunc, [], [x], no_default_updates=x) self.assertRaises(TypeError, pfunc, [], [x], no_default_updates=x)
self.failUnlessRaises(TypeError, pfunc, [], [x], no_default_updates='canard') self.assertRaises(TypeError, pfunc, [], [x], no_default_updates='canard')
# Mix explicit updates and no_default_updates # Mix explicit updates and no_default_updates
g1 = pfunc([], [x], updates=[(x,x-1)], no_default_updates=True) g1 = pfunc([], [x], updates=[(x,x-1)], no_default_updates=True)
...@@ -582,7 +582,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -582,7 +582,7 @@ class Test_pfunc(unittest.TestCase):
assert y.get_value() == 2 assert y.get_value() == 2
# a is needed as input if y.default_update is used # a is needed as input if y.default_update is used
self.failUnlessRaises(TypeError, pfunc, [], x) self.assertRaises(TypeError, pfunc, [], x)
def test_default_updates_partial_graph(self): def test_default_updates_partial_graph(self):
a = shared(0) a = shared(0)
......
...@@ -34,7 +34,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -34,7 +34,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared([]).type == generic assert shared([]).type == generic
def badfunc(): def badfunc():
shared(7, bad_kw=False) shared(7, bad_kw=False)
self.failUnlessRaises(TypeError, badfunc) self.assertRaises(TypeError, badfunc)
def test_strict_generic(self): def test_strict_generic(self):
...@@ -119,38 +119,38 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -119,38 +119,38 @@ class Test_SharedVariable(unittest.TestCase):
b = shared(numpy.int64(7), strict=True) b = shared(numpy.int64(7), strict=True)
assert b.type == theano.tensor.lscalar assert b.type == theano.tensor.lscalar
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int32(7), strict=True) b = shared(numpy.int32(7), strict=True)
assert b.type == theano.tensor.iscalar assert b.type == theano.tensor.iscalar
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int16(7), strict=True) b = shared(numpy.int16(7), strict=True)
assert b.type == theano.tensor.wscalar assert b.type == theano.tensor.wscalar
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int8(7), strict=True) b = shared(numpy.int8(7), strict=True)
assert b.type == theano.tensor.bscalar assert b.type == theano.tensor.bscalar
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.float64(7.234), strict=True) b = shared(numpy.float64(7.234), strict=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
b = shared(numpy.float32(7.234), strict=True) b = shared(numpy.float32(7.234), strict=True)
assert b.type == theano.tensor.fscalar assert b.type == theano.tensor.fscalar
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
b = shared(numpy.float(7.234), strict=True) b = shared(numpy.float(7.234), strict=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
b = shared(7.234, strict=True) b = shared(7.234, strict=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
c = shared(numpy.zeros((5,5), dtype='float32')) c = shared(numpy.zeros((5,5), dtype='float32'))
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.assertRaises(TypeError, f, b, numpy.random.rand(5,5))
...@@ -160,40 +160,40 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -160,40 +160,40 @@ class Test_SharedVariable(unittest.TestCase):
b = shared(numpy.int64([7]), strict=True) b = shared(numpy.int64([7]), strict=True)
assert b.type == theano.tensor.lvector assert b.type == theano.tensor.lvector
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int32([7]), strict=True) b = shared(numpy.int32([7]), strict=True)
assert b.type == theano.tensor.ivector assert b.type == theano.tensor.ivector
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int16([7]), strict=True) b = shared(numpy.int16([7]), strict=True)
assert b.type == theano.tensor.wvector assert b.type == theano.tensor.wvector
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.int8([7]), strict=True) b = shared(numpy.int8([7]), strict=True)
assert b.type == theano.tensor.bvector assert b.type == theano.tensor.bvector
self.failUnlessRaises(TypeError, f, b, 8.23) self.assertRaises(TypeError, f, b, 8.23)
b = shared(numpy.float64([7.234]), strict=True) b = shared(numpy.float64([7.234]), strict=True)
assert b.type == theano.tensor.dvector assert b.type == theano.tensor.dvector
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
b = shared(numpy.float32([7.234]), strict=True) b = shared(numpy.float32([7.234]), strict=True)
assert b.type == theano.tensor.fvector assert b.type == theano.tensor.fvector
self.failUnlessRaises(TypeError, f, b, 8) self.assertRaises(TypeError, f, b, 8)
#numpy.float([7.234]) don't work #numpy.float([7.234]) don't work
# b = shared(numpy.float([7.234]), strict=True) # b = shared(numpy.float([7.234]), strict=True)
# assert b.type == theano.tensor.dvector # assert b.type == theano.tensor.dvector
# self.failUnlessRaises(TypeError, f, b, 8) # self.assertRaises(TypeError, f, b, 8)
#This generate a generic type. Should we cast? I don't think. #This generate a generic type. Should we cast? I don't think.
# b = shared([7.234], strict=True) # b = shared([7.234], strict=True)
# assert b.type == theano.tensor.dvector # assert b.type == theano.tensor.dvector
# self.failUnlessRaises(TypeError, f, b, 8) # self.assertRaises(TypeError, f, b, 8)
c = shared(numpy.zeros((5,5), dtype='float32')) c = shared(numpy.zeros((5,5), dtype='float32'))
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.assertRaises(TypeError, f, b, numpy.random.rand(5,5))
...@@ -252,7 +252,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -252,7 +252,7 @@ class Test_SharedVariable(unittest.TestCase):
assert b.get_value()==8 assert b.get_value()==8
c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True) c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True)
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.assertRaises(TypeError, f, b, numpy.random.rand(5,5))
...@@ -306,4 +306,4 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -306,4 +306,4 @@ class Test_SharedVariable(unittest.TestCase):
assert b.get_value() == 8 assert b.get_value() == 8
c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True) c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True)
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.assertRaises(TypeError, f, b, numpy.random.rand(5,5))
...@@ -59,7 +59,7 @@ class T_solve(unittest.TestCase): ...@@ -59,7 +59,7 @@ class T_solve(unittest.TestCase):
x=scipy.linalg.solve(A,b) x=scipy.linalg.solve(A,b)
Ax = numpy.dot(A,x) Ax = numpy.dot(A,x)
are = tensor.numeric_grad.abs_rel_err(Ax, b) are = tensor.numeric_grad.abs_rel_err(Ax, b)
self.failUnless(numpy.all(are < 1.0e-5), (are, Ax, b)) self.assertTrue(numpy.all(are < 1.0e-5), (are, Ax, b))
#print A,b #print A,b
#print numpy.dot(A,x) #print numpy.dot(A,x)
...@@ -49,7 +49,7 @@ class test_ScalarOps(unittest.TestCase): ...@@ -49,7 +49,7 @@ class test_ScalarOps(unittest.TestCase):
(1,2), (-1,2), (1,-2), (-1,-2), (1,2), (-1,2), (1,-2), (-1,-2),
(5,3), (-5,3), (5,-3), (-5,-3) (5,3), (-5,3), (5,-3), (-5,-3)
): ):
self.failUnless(fn(a,b) == a%b, (a,)) self.assertTrue(fn(a,b) == a%b, (a,))
class test_composite(unittest.TestCase): class test_composite(unittest.TestCase):
...@@ -106,72 +106,72 @@ class test_logical(unittest.TestCase): ...@@ -106,72 +106,72 @@ class test_logical(unittest.TestCase):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [x > y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x > y])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a>b)) self.assertTrue(fn(a,b) == (a>b))
def test_lt(self): def test_lt(self):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [x < y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x < y])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a<b)) self.assertTrue(fn(a,b) == (a<b))
def test_le(self): def test_le(self):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [x <= y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x <= y])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a<=b)) self.assertTrue(fn(a,b) == (a<=b))
def test_ge(self): def test_ge(self):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [x >= y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x >= y])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a>=b)) self.assertTrue(fn(a,b) == (a>=b))
def test_eq(self): def test_eq(self):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [eq(x,y)])).make_function() fn = gof.DualLinker().accept(Env([x,y], [eq(x,y)])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a==b)) self.assertTrue(fn(a,b) == (a==b))
def test_neq(self): def test_neq(self):
x, y, z = inputs() x, y, z = inputs()
fn = gof.DualLinker().accept(Env([x,y], [neq(x,y)])).make_function() fn = gof.DualLinker().accept(Env([x,y], [neq(x,y)])).make_function()
for a,b in ((3.,9), (3,0.9), (3,3)): for a,b in ((3.,9), (3,0.9), (3,3)):
self.failUnless(fn(a,b) == (a!=b)) self.assertTrue(fn(a,b) == (a!=b))
def test_or(self): def test_or(self):
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [x|y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x|y])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == (a|b), (a,b)) self.assertTrue(fn(a,b) == (a|b), (a,b))
def test_xor(self): def test_xor(self):
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [x^y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x^y])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == (a ^ b), (a,b)) self.assertTrue(fn(a,b) == (a ^ b), (a,b))
def test_and(self): def test_and(self):
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [and_(x, y)])).make_function() fn = gof.DualLinker().accept(Env([x,y], [and_(x, y)])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == (a & b), (a,b)) self.assertTrue(fn(a,b) == (a & b), (a,b))
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [x & y])).make_function() fn = gof.DualLinker().accept(Env([x,y], [x & y])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == (a & b), (a,b)) self.assertTrue(fn(a,b) == (a & b), (a,b))
def test_not(self): def test_not(self):
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [invert(x)])).make_function() fn = gof.DualLinker().accept(Env([x,y], [invert(x)])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == ~a, (a,)) self.assertTrue(fn(a,b) == ~a, (a,))
x, y, z = ints('xyz') x, y, z = ints('xyz')
fn = gof.DualLinker().accept(Env([x,y], [~x])).make_function() fn = gof.DualLinker().accept(Env([x,y], [~x])).make_function()
for a,b in ((0,1), (0,0), (1,0), (1,1)): for a,b in ((0,1), (0,0), (1,0), (1,1)):
self.failUnless(fn(a,b) == ~a, (a,)) self.assertTrue(fn(a,b) == ~a, (a,))
class test_div(unittest.TestCase): class test_div(unittest.TestCase):
......
...@@ -93,103 +93,103 @@ class test_true_dot(unittest.TestCase): ...@@ -93,103 +93,103 @@ class test_true_dot(unittest.TestCase):
x = as_sparse_variable(mtype((500,3))) x = as_sparse_variable(mtype((500,3)))
x.data[(10, 1)] = 1 x.data[(10, 1)] = 1
x.data[(20, 2)] = 2 x.data[(20, 2)] = 2
self.failUnless(_is_sparse_variable(x)) self.assertTrue(_is_sparse_variable(x))
xT = x.T xT = x.T
self.failUnless(_is_sparse_variable(xT)) self.assertTrue(_is_sparse_variable(xT))
zop = true_dot(x,xT) zop = true_dot(x,xT)
self.failUnless(_is_sparse_variable(zop)) self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop]) z = eval_outputs([zop])
self.failUnless(_is_sparse(z)) self.assertTrue(_is_sparse(z))
self.failUnless(z.shape == (500,500)) self.assertTrue(z.shape == (500,500))
self.failUnless(type(z) is mtype) self.assertTrue(type(z) is mtype)
w = mtype((500,500)) w = mtype((500,500))
w[(10, 10)] = 1 w[(10, 10)] = 1
w[(20, 20)] = 4 w[(20, 20)] = 4
self.failUnless(z.shape == w.shape) self.assertTrue(z.shape == w.shape)
self.failUnless(type(z) == type(w)) self.assertTrue(type(z) == type(w))
self.failUnless(z.dtype == w.dtype) self.assertTrue(z.dtype == w.dtype)
#self.failUnless(z == w) #self.assertTrue(z == w)
self.failUnless(abs(z-w).nnz == 0) self.assertTrue(abs(z-w).nnz == 0)
z = z.todense() z = z.todense()
w = w.todense() w = w.todense()
self.failUnless((z == w).all() == True) self.assertTrue((z == w).all() == True)
def test_basicSD(self): def test_basicSD(self):
for mtype in _mtypes: for mtype in _mtypes:
x = as_sparse_variable(mtype((500,3))) x = as_sparse_variable(mtype((500,3)))
x.data[(10, 1)] = 1 x.data[(10, 1)] = 1
x.data[(20, 2)] = 2 x.data[(20, 2)] = 2
self.failUnless(_is_sparse_variable(x)) self.assertTrue(_is_sparse_variable(x))
y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]])
self.failUnless(_is_dense_variable(y)) self.assertTrue(_is_dense_variable(y))
zop = true_dot(x,y) zop = true_dot(x,y)
self.failUnless(_is_sparse_variable(zop)) self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop]) z = eval_outputs([zop])
self.failUnless(_is_sparse(z)) self.assertTrue(_is_sparse(z))
self.failUnless(z.shape == (500,2)) self.assertTrue(z.shape == (500,2))
self.failUnless(type(z) is mtype) self.assertTrue(type(z) is mtype)
w = mtype((500,2)) w = mtype((500,2))
w[(10, 0)] = 3. w[(10, 0)] = 3.
w[(20, 0)] = 4 w[(20, 0)] = 4
w[(10, 1)] = 4 w[(10, 1)] = 4
w[(20, 1)] = 2 w[(20, 1)] = 2
self.failUnless(z.shape == w.shape) self.assertTrue(z.shape == w.shape)
self.failUnless(type(z) == type(w)) self.assertTrue(type(z) == type(w))
self.failUnless(z.dtype == w.dtype) self.assertTrue(z.dtype == w.dtype)
#self.failUnless(z == w) #self.assertTrue(z == w)
self.failUnless(abs(z-w).nnz == 0) self.assertTrue(abs(z-w).nnz == 0)
z = z.todense() z = z.todense()
w = w.todense() w = w.todense()
self.failUnless((z == w).all() == True) self.assertTrue((z == w).all() == True)
def test_basicDS(self): def test_basicDS(self):
for mtype in _mtypes: for mtype in _mtypes:
x = as_sparse_variable(mtype((500,3))) x = as_sparse_variable(mtype((500,3)))
x.data[(10, 1)] = 1 x.data[(10, 1)] = 1
x.data[(20, 2)] = 2 x.data[(20, 2)] = 2
self.failUnless(_is_sparse_variable(x)) self.assertTrue(_is_sparse_variable(x))
y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]])
self.failUnless(_is_dense_variable(y)) self.assertTrue(_is_dense_variable(y))
x.data = x.data.T x.data = x.data.T
y.data = y.data.T y.data = y.data.T
zop = true_dot(y, x) zop = true_dot(y, x)
zop = transpose(true_dot(y, x)) zop = transpose(true_dot(y, x))
self.failUnless(_is_sparse_variable(zop)) self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop]) z = eval_outputs([zop])
self.failUnless(_is_sparse(z)) self.assertTrue(_is_sparse(z))
self.failUnless(z.shape == (500,2)) self.assertTrue(z.shape == (500,2))
# self.failUnless(type(z) is mtype) # self.assertTrue(type(z) is mtype)
w = mtype((500,2)) w = mtype((500,2))
w[(10, 0)] = 3. w[(10, 0)] = 3.
w[(20, 0)] = 4 w[(20, 0)] = 4
w[(10, 1)] = 4 w[(10, 1)] = 4
w[(20, 1)] = 2 w[(20, 1)] = 2
self.failUnless(z.shape == w.shape) self.assertTrue(z.shape == w.shape)
# Type should switch from csr to csc and vice-versa, so don't perform this test # Type should switch from csr to csc and vice-versa, so don't perform this test
#self.failUnless(type(z) == type(w)) #self.assertTrue(type(z) == type(w))
self.failUnless(z.dtype == w.dtype) self.assertTrue(z.dtype == w.dtype)
# Type should switch from csr to csc and vice-versa, so don't perform this test # Type should switch from csr to csc and vice-versa, so don't perform this test
#self.failUnless(z == w) #self.assertTrue(z == w)
self.failUnless(abs(z-w).nnz == 0) self.assertTrue(abs(z-w).nnz == 0)
z = z.todense() z = z.todense()
w = w.todense() w = w.todense()
self.failUnless((z == w).all() == True) self.assertTrue((z == w).all() == True)
def test_graph_bprop0(self): def test_graph_bprop0(self):
for mtype in _mtypes: for mtype in _mtypes:
...@@ -213,8 +213,8 @@ class test_true_dot(unittest.TestCase): ...@@ -213,8 +213,8 @@ class test_true_dot(unittest.TestCase):
w = w - (lr * gw) w = w - (lr * gw)
print loss print loss
self.failUnless(origloss > loss) self.assertTrue(origloss > loss)
self.failUnless('1.05191241115' == str(loss)) self.assertTrue('1.05191241115' == str(loss))
def test_graph_bprop_rand(self): def test_graph_bprop_rand(self):
for i in range(10): for i in range(10):
...@@ -239,5 +239,5 @@ class test_true_dot(unittest.TestCase): ...@@ -239,5 +239,5 @@ class test_true_dot(unittest.TestCase):
y, loss, gw = trainfn(x, w) y, loss, gw = trainfn(x, w)
w = w - (lr * gw) w = w - (lr * gw)
self.failUnless(origloss > loss) self.assertTrue(origloss > loss)
...@@ -51,27 +51,27 @@ class T_transpose(unittest.TestCase): ...@@ -51,27 +51,27 @@ class T_transpose(unittest.TestCase):
def test_transpose_csc(self): def test_transpose_csc(self):
sp = scipy.sparse.csc_matrix(scipy.sparse.eye(5,3)) sp = scipy.sparse.csc_matrix(scipy.sparse.eye(5,3))
a = as_sparse_variable(sp) a = as_sparse_variable(sp)
self.failIf(a.data is sp) self.assertFalse(a.data is sp)
self.failUnless(a.data.shape == (5,3)) self.assertTrue(a.data.shape == (5,3))
self.failUnless(a.type.dtype == 'float64', a.type.dtype) self.assertTrue(a.type.dtype == 'float64', a.type.dtype)
self.failUnless(a.type.format == 'csc', a.type.format) self.assertTrue(a.type.format == 'csc', a.type.format)
ta = transpose(a) ta = transpose(a)
self.failUnless(ta.type.dtype == 'float64', ta.type.dtype) self.assertTrue(ta.type.dtype == 'float64', ta.type.dtype)
self.failUnless(ta.type.format == 'csr', ta.type.format) self.assertTrue(ta.type.format == 'csr', ta.type.format)
vta = eval_outputs([ta]) vta = eval_outputs([ta])
self.failUnless(vta.shape == (3,5)) self.assertTrue(vta.shape == (3,5))
def test_transpose_csr(self): def test_transpose_csr(self):
a = as_sparse_variable(scipy.sparse.csr_matrix(scipy.sparse.eye(5,3))) a = as_sparse_variable(scipy.sparse.csr_matrix(scipy.sparse.eye(5,3)))
self.failUnless(a.data.shape == (5,3)) self.assertTrue(a.data.shape == (5,3))
self.failUnless(a.type.dtype == 'float64') self.assertTrue(a.type.dtype == 'float64')
self.failUnless(a.type.format == 'csr') self.assertTrue(a.type.format == 'csr')
ta = transpose(a) ta = transpose(a)
self.failUnless(ta.type.dtype == 'float64', ta.type.dtype) self.assertTrue(ta.type.dtype == 'float64', ta.type.dtype)
self.failUnless(ta.type.format == 'csc', ta.type.format) self.assertTrue(ta.type.format == 'csc', ta.type.format)
vta = eval_outputs([ta]) vta = eval_outputs([ta])
self.failUnless(vta.shape == (3,5)) self.assertTrue(vta.shape == (3,5))
class T_AddMul(unittest.TestCase): class T_AddMul(unittest.TestCase):
def testAddSS(self): def testAddSS(self):
...@@ -99,63 +99,63 @@ class T_AddMul(unittest.TestCase): ...@@ -99,63 +99,63 @@ class T_AddMul(unittest.TestCase):
for mtype in _mtypes: for mtype in _mtypes:
a = mtype(array1) a = mtype(array1)
aR = as_sparse_variable(a) aR = as_sparse_variable(a)
self.failIf(aR.data is a) self.assertFalse(aR.data is a)
self.failUnless(_is_sparse(a)) self.assertTrue(_is_sparse(a))
self.failUnless(_is_sparse_variable(aR)) self.assertTrue(_is_sparse_variable(aR))
b = mtype(array2) b = mtype(array2)
bR = as_sparse_variable(b) bR = as_sparse_variable(b)
self.failIf(bR.data is b) self.assertFalse(bR.data is b)
self.failUnless(_is_sparse(b)) self.assertTrue(_is_sparse(b))
self.failUnless(_is_sparse_variable(bR)) self.assertTrue(_is_sparse_variable(bR))
apb = op(aR, bR) apb = op(aR, bR)
self.failUnless(_is_sparse_variable(apb)) self.assertTrue(_is_sparse_variable(apb))
self.failUnless(apb.type.dtype == aR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == aR.type.dtype, apb.type.dtype)
self.failUnless(apb.type.dtype == bR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == bR.type.dtype, apb.type.dtype)
self.failUnless(apb.type.format == aR.type.format, apb.type.format) self.assertTrue(apb.type.format == aR.type.format, apb.type.format)
self.failUnless(apb.type.format == bR.type.format, apb.type.format) self.assertTrue(apb.type.format == bR.type.format, apb.type.format)
val = eval_outputs([apb]) val = eval_outputs([apb])
self.failUnless(val.shape == (3,2)) self.assertTrue(val.shape == (3,2))
if op is add: if op is add:
self.failUnless(numpy.all(val.todense() == (a + b).todense())) self.assertTrue(numpy.all(val.todense() == (a + b).todense()))
self.failUnless(numpy.all(val.todense() == numpy.array([[1., 2], [3, 4], [5, 6]]))) self.assertTrue(numpy.all(val.todense() == numpy.array([[1., 2], [3, 4], [5, 6]])))
elif op is mul: elif op is mul:
self.failUnless(numpy.all(val.todense() == (a.multiply(b)).todense())) self.assertTrue(numpy.all(val.todense() == (a.multiply(b)).todense()))
self.failUnless(numpy.all(val.todense() == numpy.array([[1, 0], [9, 0], [0, 36]]))) self.assertTrue(numpy.all(val.todense() == numpy.array([[1, 0], [9, 0], [0, 36]])))
def _testSD(self, op, array1 = numpy.array([[1., 0], [3, 0], [0, 6]]), def _testSD(self, op, array1 = numpy.array([[1., 0], [3, 0], [0, 6]]),
array2 = numpy.asarray([[0, 2.], [0, 4], [5, 0]])): array2 = numpy.asarray([[0, 2.], [0, 4], [5, 0]])):
for mtype in _mtypes: for mtype in _mtypes:
a = numpy.array(array1) a = numpy.array(array1)
aR = tensor.as_tensor_variable(a) aR = tensor.as_tensor_variable(a)
self.failIf(aR.data is a) #constants are copied self.assertFalse(aR.data is a) #constants are copied
self.failUnless(_is_dense(a)) self.assertTrue(_is_dense(a))
self.failUnless(_is_dense_variable(aR)) self.assertTrue(_is_dense_variable(aR))
b = mtype(array2) b = mtype(array2)
bR = as_sparse_variable(b) bR = as_sparse_variable(b)
self.failIf(bR.data is b) #constants are copied self.assertFalse(bR.data is b) #constants are copied
self.failUnless(_is_sparse(b)) self.assertTrue(_is_sparse(b))
self.failUnless(_is_sparse_variable(bR)) self.assertTrue(_is_sparse_variable(bR))
apb = op(aR, bR) apb = op(aR, bR)
self.failUnless(apb.type.dtype == aR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == aR.type.dtype, apb.type.dtype)
self.failUnless(apb.type.dtype == bR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == bR.type.dtype, apb.type.dtype)
val = eval_outputs([apb]) val = eval_outputs([apb])
self.failUnless(val.shape == (3, 2)) self.assertTrue(val.shape == (3, 2))
if op is add: if op is add:
self.failUnless(_is_dense_variable(apb)) self.assertTrue(_is_dense_variable(apb))
self.failUnless(numpy.all(val == (a + b))) self.assertTrue(numpy.all(val == (a + b)))
self.failUnless(numpy.all(val == numpy.array([[1., 2], [3, 4], [5, 6]]))) self.assertTrue(numpy.all(val == numpy.array([[1., 2], [3, 4], [5, 6]])))
elif op is mul: elif op is mul:
self.failUnless(_is_sparse_variable(apb)) self.assertTrue(_is_sparse_variable(apb))
self.failUnless(numpy.all(val.todense() == (b.multiply(a)))) self.assertTrue(numpy.all(val.todense() == (b.multiply(a))))
self.failUnless(numpy.all(val.todense() == numpy.array([[1, 0], self.assertTrue(numpy.all(val.todense() == numpy.array([[1, 0],
[9, 0], [0, 36]]))) [9, 0], [0, 36]])))
def _testDS(self, op, array1 = numpy.array([[1., 0], [3, 0], [0, 6]]), def _testDS(self, op, array1 = numpy.array([[1., 0], [3, 0], [0, 6]]),
...@@ -163,31 +163,31 @@ class T_AddMul(unittest.TestCase): ...@@ -163,31 +163,31 @@ class T_AddMul(unittest.TestCase):
for mtype in _mtypes: for mtype in _mtypes:
a = mtype(array1) a = mtype(array1)
aR = as_sparse_variable(a) aR = as_sparse_variable(a)
self.failIf(aR.data is a) self.assertFalse(aR.data is a)
self.failUnless(_is_sparse(a)) self.assertTrue(_is_sparse(a))
self.failUnless(_is_sparse_variable(aR)) self.assertTrue(_is_sparse_variable(aR))
b = numpy.asarray(array2) b = numpy.asarray(array2)
bR = tensor.as_tensor_variable(b) bR = tensor.as_tensor_variable(b)
self.failIf(bR.data is b) self.assertFalse(bR.data is b)
self.failUnless(_is_dense(b)) self.assertTrue(_is_dense(b))
self.failUnless(_is_dense_variable(bR)) self.assertTrue(_is_dense_variable(bR))
apb = op(aR, bR) apb = op(aR, bR)
self.failUnless(apb.type.dtype == aR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == aR.type.dtype, apb.type.dtype)
self.failUnless(apb.type.dtype == bR.type.dtype, apb.type.dtype) self.assertTrue(apb.type.dtype == bR.type.dtype, apb.type.dtype)
val = eval_outputs([apb]) val = eval_outputs([apb])
self.failUnless(val.shape == (3, 2)) self.assertTrue(val.shape == (3, 2))
if op is add: if op is add:
self.failUnless(_is_dense_variable(apb)) self.assertTrue(_is_dense_variable(apb))
self.failUnless(numpy.all(val == (a + b))) self.assertTrue(numpy.all(val == (a + b)))
self.failUnless(numpy.all(val == numpy.array([[1., 2], [3, 4], [5, 6]]))) self.assertTrue(numpy.all(val == numpy.array([[1., 2], [3, 4], [5, 6]])))
elif op is mul: elif op is mul:
self.failUnless(_is_sparse_variable(apb)) self.assertTrue(_is_sparse_variable(apb))
self.failUnless(numpy.all(val.todense() == (a.multiply(b)))) self.assertTrue(numpy.all(val.todense() == (a.multiply(b))))
self.failUnless(numpy.all(val.todense() == numpy.array([[1, 0], self.assertTrue(numpy.all(val.todense() == numpy.array([[1, 0],
[9, 0], [0, 36]]))) [9, 0], [0, 36]])))
...@@ -200,16 +200,16 @@ class T_conversion(unittest.TestCase): ...@@ -200,16 +200,16 @@ class T_conversion(unittest.TestCase):
a = tensor.as_tensor_variable(numpy.random.rand(5)) a = tensor.as_tensor_variable(numpy.random.rand(5))
s = csc_from_dense(a) s = csc_from_dense(a)
val = eval_outputs([s]) val = eval_outputs([s])
self.failUnless(str(val.dtype)=='float64') self.assertTrue(str(val.dtype)=='float64')
self.failUnless(val.format == 'csc') self.assertTrue(val.format == 'csc')
if 0: if 0:
def test1(self): def test1(self):
a = tensor.as_tensor_variable(numpy.random.rand(5)) a = tensor.as_tensor_variable(numpy.random.rand(5))
s = csr_from_dense(a) s = csr_from_dense(a)
val = eval_outputs([s]) val = eval_outputs([s])
self.failUnless(str(val.dtype)=='float64') self.assertTrue(str(val.dtype)=='float64')
self.failUnless(val.format == 'csr') self.assertTrue(val.format == 'csr')
if 1: if 1:
def test2(self): def test2(self):
...@@ -221,8 +221,8 @@ class T_conversion(unittest.TestCase): ...@@ -221,8 +221,8 @@ class T_conversion(unittest.TestCase):
s[0,0] = 3.0 # changes s, but not the copy s[0,0] = 3.0 # changes s, but not the copy
val = eval_outputs([d]) val = eval_outputs([d])
return return
self.failUnless(str(val.dtype)==s.dtype) self.assertTrue(str(val.dtype)==s.dtype)
self.failUnless(numpy.all(val[0] == [1,0,0,0,0])) self.assertTrue(numpy.all(val[0] == [1,0,0,0,0]))
class test_structureddot(unittest.TestCase): class test_structureddot(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -405,9 +405,9 @@ class test_structureddot(unittest.TestCase): ...@@ -405,9 +405,9 @@ class test_structureddot(unittest.TestCase):
# fail if Theano is slower than scipy by more than a certain amount # fail if Theano is slower than scipy by more than a certain amount
overhead_tol = 0.003 # seconds overall overhead_tol = 0.003 # seconds overall
overhead_rtol = 1.2 # times as long overhead_rtol = 1.2 # times as long
self.failUnless(numpy.allclose(theano_result, scipy_result)) self.assertTrue(numpy.allclose(theano_result, scipy_result))
if not theano.config.mode in ["DebugMode", "DEBUG_MODE"]: if not theano.config.mode in ["DebugMode", "DEBUG_MODE"]:
self.failIf(theano_time > overhead_rtol*scipy_time + overhead_tol) self.assertFalse(theano_time > overhead_rtol*scipy_time + overhead_tol)
def test_csr_correct_output_faster_than_scipy(self): def test_csr_correct_output_faster_than_scipy(self):
...@@ -442,9 +442,9 @@ class test_structureddot(unittest.TestCase): ...@@ -442,9 +442,9 @@ class test_structureddot(unittest.TestCase):
print 'scipy took', scipy_time print 'scipy took', scipy_time
overhead_tol = 0.002 # seconds overhead_tol = 0.002 # seconds
overhead_rtol = 1.1 # times as long overhead_rtol = 1.1 # times as long
self.failUnless(numpy.allclose(theano_result, scipy_result)) self.assertTrue(numpy.allclose(theano_result, scipy_result))
if not theano.config.mode in ["DebugMode", "DEBUG_MODE"]: if not theano.config.mode in ["DebugMode", "DEBUG_MODE"]:
self.failIf(theano_time > overhead_rtol*scipy_time + overhead_tol) self.assertFalse(theano_time > overhead_rtol*scipy_time + overhead_tol)
def test_shape_i(): def test_shape_i():
sparse_dtype = 'float32' sparse_dtype = 'float32'
......
...@@ -90,7 +90,7 @@ class TestConv2D(unittest.TestCase): ...@@ -90,7 +90,7 @@ class TestConv2D(unittest.TestCase):
icol:icol+N_filter_shape[3]]*filter2d[::-1,::-1] icol:icol+N_filter_shape[3]]*filter2d[::-1,::-1]
).sum() ).sum()
self.failUnless(_allclose(theano_output, ref_output)) self.assertTrue(_allclose(theano_output, ref_output))
############# TEST GRADIENT ############ ############# TEST GRADIENT ############
if verify_grad: if verify_grad:
...@@ -222,7 +222,7 @@ class TestConv2D(unittest.TestCase): ...@@ -222,7 +222,7 @@ class TestConv2D(unittest.TestCase):
""" """
def f(): def f():
self.validate((3,2,8,8), (4,3,5,5), 'valid') self.validate((3,2,8,8), (4,3,5,5), 'valid')
self.failUnlessRaises(AssertionError, f) self.assertRaises(AssertionError, f)
def test_missing_info(self): def test_missing_info(self):
""" """
...@@ -246,7 +246,7 @@ class TestConv2D(unittest.TestCase): ...@@ -246,7 +246,7 @@ class TestConv2D(unittest.TestCase):
self.validate((3,2,5,5), (4,2,8,8), 'full') self.validate((3,2,5,5), (4,2,8,8), 'full')
def f(): def f():
self.validate((3,2,5,5), (4,2,8,8), 'valid') self.validate((3,2,5,5), (4,2,8,8), 'valid')
self.failUnlessRaises(Exception, f) self.assertRaises(Exception, f)
def test_wrong_input(self): def test_wrong_input(self):
""" """
......
...@@ -213,8 +213,8 @@ class T_prepend(unittest.TestCase): ...@@ -213,8 +213,8 @@ class T_prepend(unittest.TestCase):
f=theano.function([x],[y]) f=theano.function([x],[y])
m=numpy.random.rand(3,5) m=numpy.random.rand(3,5)
my = f(m) my = f(m)
self.failUnless(my.shape == (3, 6), my.shape) self.assertTrue(my.shape == (3, 6), my.shape)
self.failUnless(numpy.all( my[:,0] == 4.0)) self.assertTrue(numpy.all( my[:,0] == 4.0))
class T_prepend(unittest.TestCase): class T_prepend(unittest.TestCase):
...@@ -225,8 +225,8 @@ class T_prepend(unittest.TestCase): ...@@ -225,8 +225,8 @@ class T_prepend(unittest.TestCase):
f=theano.function([x],y) f=theano.function([x],y)
m=numpy.ones((3,5),dtype="float32") m=numpy.ones((3,5),dtype="float32")
my = f(m) my = f(m)
self.failUnless(my.shape == (3, 6)) self.assertTrue(my.shape == (3, 6))
self.failUnless(numpy.all(my[:,0] == 5.0)) self.assertTrue(numpy.all(my[:,0] == 5.0))
class T_CrossentropyCategorical1Hot(unittest.TestCase): class T_CrossentropyCategorical1Hot(unittest.TestCase):
def setUp(self): def setUp(self):
......
...@@ -66,7 +66,7 @@ class TestSignalConv2D(unittest.TestCase): ...@@ -66,7 +66,7 @@ class TestSignalConv2D(unittest.TestCase):
).sum() ).sum()
self.failUnless(_allclose(theano_output4d[b,k,:,:], output2d)) self.assertTrue(_allclose(theano_output4d[b,k,:,:], output2d))
############# TEST GRADIENT ############ ############# TEST GRADIENT ############
if verify_grad: if verify_grad:
......
...@@ -998,22 +998,22 @@ _approx_eq.debug = 0 ...@@ -998,22 +998,22 @@ _approx_eq.debug = 0
# def check_eq(self, node_in, node_out, arg_in, arg_out): # def check_eq(self, node_in, node_out, arg_in, arg_out):
# fn = Function([node_in], node_out) # fn = Function([node_in], node_out)
# self.failUnless( numpy.all(fn(arg_in) == arg_out), (arg_in, arg_out)) # self.assertTrue( numpy.all(fn(arg_in) == arg_out), (arg_in, arg_out))
# def check_eq2(self, inputs, output, args_in, arg_out): # def check_eq2(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, output) # fn = Function(inputs, output)
# val = fn(*args_in) # val = fn(*args_in)
# self.failUnless( numpy.all(val == arg_out), (val, arg_out)) # self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
# def check_eq2_c(self, inputs, output, args_in, arg_out): # def check_eq2_c(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, [output], linker_cls = gof.CLinker) # fn = Function(inputs, [output], linker_cls = gof.CLinker)
# val = fn(*args_in) # val = fn(*args_in)
# self.failUnless( numpy.all(val == arg_out), (val, arg_out)) # self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
# def check_eq2_both(self, inputs, output, args_in, arg_out): # def check_eq2_both(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, [output], linker_cls = lambda env: gof.DualLinker(env, _numpy_checker)) # fn = Function(inputs, [output], linker_cls = lambda env: gof.DualLinker(env, _numpy_checker))
# val = fn(*args_in) # val = fn(*args_in)
# self.failUnless( numpy.all(val == arg_out), (val, arg_out)) # self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
def test_tensor_values_eq_approx(): def test_tensor_values_eq_approx():
#test, inf, -inf and nan equal themself #test, inf, -inf and nan equal themself
...@@ -1041,13 +1041,13 @@ def test_tensor_values_eq_approx(): ...@@ -1041,13 +1041,13 @@ def test_tensor_values_eq_approx():
class T_Shape(unittest.TestCase): class T_Shape(unittest.TestCase):
def test_basic0(self): def test_basic0(self):
s = shape(numpy.ones((5, 3))) s = shape(numpy.ones((5, 3)))
self.failUnless((eval_outputs([s]) == [5, 3]).all()) self.assertTrue((eval_outputs([s]) == [5, 3]).all())
def test_basic1(self): def test_basic1(self):
s = shape(numpy.ones((2))) s = shape(numpy.ones((2)))
self.failUnless((eval_outputs([s]) == [2]).all()) self.assertTrue((eval_outputs([s]) == [2]).all())
def test_basic2(self): def test_basic2(self):
s = shape(numpy.ones((5, 3, 10))) s = shape(numpy.ones((5, 3, 10)))
self.failUnless((eval_outputs([s]) == [5, 3, 10]).all()) self.assertTrue((eval_outputs([s]) == [5, 3, 10]).all())
class T_max_and_argmax(unittest.TestCase): class T_max_and_argmax(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -1057,8 +1057,8 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1057,8 +1057,8 @@ class T_max_and_argmax(unittest.TestCase):
def test0(self): def test0(self):
n = as_tensor_variable(5.0) n = as_tensor_variable(5.0)
v,i = eval_outputs(max_and_argmax(n)) v,i = eval_outputs(max_and_argmax(n))
self.failUnless(v == 5.0) self.assertTrue(v == 5.0)
self.failUnless(i == 0) self.assertTrue(i == 0)
v = eval_outputs(max_and_argmax(n)[0].shape) v = eval_outputs(max_and_argmax(n)[0].shape)
assert len(v)==0 assert len(v)==0
v = eval_outputs(max_and_argmax(n)[1].shape) v = eval_outputs(max_and_argmax(n)[1].shape)
...@@ -1067,8 +1067,8 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1067,8 +1067,8 @@ class T_max_and_argmax(unittest.TestCase):
def test1(self): def test1(self):
n = as_tensor_variable([1,2,3,2,-6]) n = as_tensor_variable([1,2,3,2,-6])
v,i = eval_outputs(max_and_argmax(n)) v,i = eval_outputs(max_and_argmax(n))
self.failUnless(v == 3) self.assertTrue(v == 3)
self.failUnless(i == 2) self.assertTrue(i == 2)
v = eval_outputs(max_and_argmax(n)[0].shape) v = eval_outputs(max_and_argmax(n)[0].shape)
assert len(v)==0 assert len(v)==0
...@@ -1076,8 +1076,8 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1076,8 +1076,8 @@ class T_max_and_argmax(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
v,i = eval_outputs(max_and_argmax(n,-1)) v,i = eval_outputs(max_and_argmax(n,-1))
self.failUnless(numpy.all(v == numpy.max(data,-1))) self.assertTrue(numpy.all(v == numpy.max(data,-1)))
self.failUnless(numpy.all(i == numpy.argmax(data,-1))) self.assertTrue(numpy.all(i == numpy.argmax(data,-1)))
v = eval_outputs(max_and_argmax(n,-1)[0].shape) v = eval_outputs(max_and_argmax(n,-1)[0].shape)
assert v==(2) assert v==(2)
...@@ -1085,8 +1085,8 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1085,8 +1085,8 @@ class T_max_and_argmax(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
v,i = eval_outputs(max_and_argmax(n,0)) v,i = eval_outputs(max_and_argmax(n,0))
self.failUnless(numpy.all(v == numpy.max(data,0))) self.assertTrue(numpy.all(v == numpy.max(data,0)))
self.failUnless(numpy.all(i == numpy.argmax(data,0))) self.assertTrue(numpy.all(i == numpy.argmax(data,0)))
v = eval_outputs(max_and_argmax(n,0)[0].shape) v = eval_outputs(max_and_argmax(n,0)[0].shape)
assert v==(3) assert v==(3)
v = eval_outputs(max_and_argmax(n,1)[0].shape) v = eval_outputs(max_and_argmax(n,1)[0].shape)
...@@ -1124,15 +1124,15 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1124,15 +1124,15 @@ class T_max_and_argmax(unittest.TestCase):
def test2_valid_neg(self): def test2_valid_neg(self):
n = as_tensor_variable(numpy.random.rand(2,3)) n = as_tensor_variable(numpy.random.rand(2,3))
v,i = eval_outputs(max_and_argmax(n,-1)) v,i = eval_outputs(max_and_argmax(n,-1))
self.failUnless(v.shape == (2,)) self.assertTrue(v.shape == (2,))
self.failUnless(i.shape == (2,)) self.assertTrue(i.shape == (2,))
self.failUnless(numpy.all(v == numpy.max(n.value,-1))) self.assertTrue(numpy.all(v == numpy.max(n.value,-1)))
self.failUnless(numpy.all(i == numpy.argmax(n.value,-1))) self.assertTrue(numpy.all(i == numpy.argmax(n.value,-1)))
v,i = eval_outputs(max_and_argmax(n,-2)) v,i = eval_outputs(max_and_argmax(n,-2))
self.failUnless(v.shape == (3,)) self.assertTrue(v.shape == (3,))
self.failUnless(i.shape == (3,)) self.assertTrue(i.shape == (3,))
self.failUnless(numpy.all(v == numpy.max(n.value,-2))) self.assertTrue(numpy.all(v == numpy.max(n.value,-2)))
self.failUnless(numpy.all(i == numpy.argmax(n.value,-2))) self.assertTrue(numpy.all(i == numpy.argmax(n.value,-2)))
v = eval_outputs(max_and_argmax(n,-1)[0].shape) v = eval_outputs(max_and_argmax(n,-1)[0].shape)
assert v==(2) assert v==(2)
v = eval_outputs(max_and_argmax(n,-2)[0].shape) v = eval_outputs(max_and_argmax(n,-2)[0].shape)
...@@ -1141,14 +1141,14 @@ class T_max_and_argmax(unittest.TestCase): ...@@ -1141,14 +1141,14 @@ class T_max_and_argmax(unittest.TestCase):
def test3(self): def test3(self):
n = as_tensor_variable(numpy.random.rand(2,3,4)) n = as_tensor_variable(numpy.random.rand(2,3,4))
v,i = eval_outputs(max_and_argmax(n,0)) v,i = eval_outputs(max_and_argmax(n,0))
self.failUnless(v.shape == (3,4)) self.assertTrue(v.shape == (3,4))
self.failUnless(i.shape == (3,4)) self.assertTrue(i.shape == (3,4))
v,i = eval_outputs(max_and_argmax(n,1)) v,i = eval_outputs(max_and_argmax(n,1))
self.failUnless(v.shape == (2,4)) self.assertTrue(v.shape == (2,4))
self.failUnless(i.shape == (2,4)) self.assertTrue(i.shape == (2,4))
v,i = eval_outputs(max_and_argmax(n,2)) v,i = eval_outputs(max_and_argmax(n,2))
self.failUnless(v.shape == (2,3)) self.assertTrue(v.shape == (2,3))
self.failUnless(i.shape == (2,3)) self.assertTrue(i.shape == (2,3))
v = eval_outputs(max_and_argmax(n,0)[0].shape) v = eval_outputs(max_and_argmax(n,0)[0].shape)
assert tuple(v)==(3,4) assert tuple(v)==(3,4)
v = eval_outputs(max_and_argmax(n,1)[0].shape) v = eval_outputs(max_and_argmax(n,1)[0].shape)
...@@ -1201,20 +1201,20 @@ class T_argmin_argmax(unittest.TestCase): ...@@ -1201,20 +1201,20 @@ class T_argmin_argmax(unittest.TestCase):
for fct in [argmin,argmax]: for fct in [argmin,argmax]:
n = as_tensor_variable(5.0) n = as_tensor_variable(5.0)
i = eval_outputs(fct(n)) i = eval_outputs(fct(n))
self.failUnless(i == 0) self.assertTrue(i == 0)
v = eval_outputs(fct(n).shape) v = eval_outputs(fct(n).shape)
assert len(v)==0 assert len(v)==0
def test1(self): def test1(self):
n = as_tensor_variable([1,2,3,2,-6]) n = as_tensor_variable([1,2,3,2,-6])
i = eval_outputs(argmin(n)) i = eval_outputs(argmin(n))
self.failUnless(i == 4) self.assertTrue(i == 4)
v = eval_outputs(argmin(n).shape) v = eval_outputs(argmin(n).shape)
assert len(v)==0 assert len(v)==0
n = as_tensor_variable([1,2,3,2,-6]) n = as_tensor_variable([1,2,3,2,-6])
i = eval_outputs(argmax(n)) i = eval_outputs(argmax(n))
self.failUnless(i == 2) self.assertTrue(i == 2)
v = eval_outputs(argmax(n).shape) v = eval_outputs(argmax(n).shape)
assert len(v)==0 assert len(v)==0
...@@ -1223,7 +1223,7 @@ class T_argmin_argmax(unittest.TestCase): ...@@ -1223,7 +1223,7 @@ class T_argmin_argmax(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
i = eval_outputs(fct(n,-1)) i = eval_outputs(fct(n,-1))
self.failUnless(numpy.all(i == nfct(data,-1))) self.assertTrue(numpy.all(i == nfct(data,-1)))
v = eval_outputs(fct(n,-1).shape) v = eval_outputs(fct(n,-1).shape)
assert v==(2) assert v==(2)
...@@ -1232,7 +1232,7 @@ class T_argmin_argmax(unittest.TestCase): ...@@ -1232,7 +1232,7 @@ class T_argmin_argmax(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
i = eval_outputs(fct(n,0)) i = eval_outputs(fct(n,0))
self.failUnless(numpy.all(i == nfct(data,0))) self.assertTrue(numpy.all(i == nfct(data,0)))
v = eval_outputs(fct(n,0).shape) v = eval_outputs(fct(n,0).shape)
assert v==(3) assert v==(3)
v = eval_outputs(fct(n,1).shape) v = eval_outputs(fct(n,1).shape)
...@@ -1275,11 +1275,11 @@ class T_argmin_argmax(unittest.TestCase): ...@@ -1275,11 +1275,11 @@ class T_argmin_argmax(unittest.TestCase):
for fct,nfct in [(argmax,numpy.argmax),(argmin,numpy.argmin)]: for fct,nfct in [(argmax,numpy.argmax),(argmin,numpy.argmin)]:
n = as_tensor_variable(numpy.random.rand(2,3)) n = as_tensor_variable(numpy.random.rand(2,3))
i = eval_outputs(fct(n,-1)) i = eval_outputs(fct(n,-1))
self.failUnless(i.shape == (2,)) self.assertTrue(i.shape == (2,))
self.failUnless(numpy.all(i == nfct(n.value,-1))) self.assertTrue(numpy.all(i == nfct(n.value,-1)))
i = eval_outputs(fct(n,-2)) i = eval_outputs(fct(n,-2))
self.failUnless(i.shape == (3,)) self.assertTrue(i.shape == (3,))
self.failUnless(numpy.all(i == nfct(n.value,-2))) self.assertTrue(numpy.all(i == nfct(n.value,-2)))
v = eval_outputs(fct(n,-1).shape) v = eval_outputs(fct(n,-1).shape)
assert v==(2) assert v==(2)
...@@ -1290,14 +1290,14 @@ class T_argmin_argmax(unittest.TestCase): ...@@ -1290,14 +1290,14 @@ class T_argmin_argmax(unittest.TestCase):
for fct,nfct in [(argmax,numpy.argmax),(argmin,numpy.argmin)]: for fct,nfct in [(argmax,numpy.argmax),(argmin,numpy.argmin)]:
n = as_tensor_variable(numpy.random.rand(2,3,4)) n = as_tensor_variable(numpy.random.rand(2,3,4))
i = eval_outputs(fct(n,0)) i = eval_outputs(fct(n,0))
self.failUnless(i.shape == (3,4)) self.assertTrue(i.shape == (3,4))
self.failUnless(numpy.all(i == nfct(n.value,0))) self.assertTrue(numpy.all(i == nfct(n.value,0)))
i = eval_outputs(fct(n,1)) i = eval_outputs(fct(n,1))
self.failUnless(i.shape == (2,4)) self.assertTrue(i.shape == (2,4))
self.failUnless(numpy.all(i == nfct(n.value,1))) self.assertTrue(numpy.all(i == nfct(n.value,1)))
i = eval_outputs(fct(n,2)) i = eval_outputs(fct(n,2))
self.failUnless(i.shape == (2,3)) self.assertTrue(i.shape == (2,3))
self.failUnless(numpy.all(i == nfct(n.value,2))) self.assertTrue(numpy.all(i == nfct(n.value,2)))
v = eval_outputs(fct(n,0).shape) v = eval_outputs(fct(n,0).shape)
assert tuple(v)==(3,4) assert tuple(v)==(3,4)
...@@ -1353,7 +1353,7 @@ class T_min_max(unittest.TestCase): ...@@ -1353,7 +1353,7 @@ class T_min_max(unittest.TestCase):
for fct in [max,min]: for fct in [max,min]:
n = as_tensor_variable(5.0) n = as_tensor_variable(5.0)
v = eval_outputs(fct(n)) v = eval_outputs(fct(n))
self.failUnless(v == 5.0) self.assertTrue(v == 5.0)
v = eval_outputs(fct(n).shape) v = eval_outputs(fct(n).shape)
assert len(v)==0 assert len(v)==0
...@@ -1362,7 +1362,7 @@ class T_min_max(unittest.TestCase): ...@@ -1362,7 +1362,7 @@ class T_min_max(unittest.TestCase):
for fct,nfct in [(max,numpy.max),(min,numpy.min)]: for fct,nfct in [(max,numpy.max),(min,numpy.min)]:
n = as_tensor_variable([1,2,3,2,-6]) n = as_tensor_variable([1,2,3,2,-6])
v = eval_outputs([fct(n)]) v = eval_outputs([fct(n)])
self.failUnless(v == nfct(n.value)) self.assertTrue(v == nfct(n.value))
v = eval_outputs(fct(n).shape) v = eval_outputs(fct(n).shape)
assert len(v)==0 assert len(v)==0
...@@ -1372,7 +1372,7 @@ class T_min_max(unittest.TestCase): ...@@ -1372,7 +1372,7 @@ class T_min_max(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
v = eval_outputs(fct(n,-1)) v = eval_outputs(fct(n,-1))
self.failUnless(numpy.all(v == nfct(data,-1))) self.assertTrue(numpy.all(v == nfct(data,-1)))
v = eval_outputs(fct(n,-1).shape) v = eval_outputs(fct(n,-1).shape)
assert v==(2) assert v==(2)
...@@ -1382,7 +1382,7 @@ class T_min_max(unittest.TestCase): ...@@ -1382,7 +1382,7 @@ class T_min_max(unittest.TestCase):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
n = as_tensor_variable(data) n = as_tensor_variable(data)
v = eval_outputs(fct(n,0)) v = eval_outputs(fct(n,0))
self.failUnless(numpy.all(v == nfct(data,0))) self.assertTrue(numpy.all(v == nfct(data,0)))
v = eval_outputs(fct(n,0).shape) v = eval_outputs(fct(n,0).shape)
assert v==(3) assert v==(3)
...@@ -1423,11 +1423,11 @@ class T_min_max(unittest.TestCase): ...@@ -1423,11 +1423,11 @@ class T_min_max(unittest.TestCase):
for fct,nfct in [(max,numpy.max),(min,numpy.min)]: for fct,nfct in [(max,numpy.max),(min,numpy.min)]:
n = as_tensor_variable(numpy.random.rand(2,3)) n = as_tensor_variable(numpy.random.rand(2,3))
v = eval_outputs(fct(n,-1)) v = eval_outputs(fct(n,-1))
self.failUnless(v.shape == (2,)) self.assertTrue(v.shape == (2,))
self.failUnless(numpy.all(v == nfct(n.value,-1))) self.assertTrue(numpy.all(v == nfct(n.value,-1)))
v = eval_outputs(fct(n,-2)) v = eval_outputs(fct(n,-2))
self.failUnless(v.shape == (3,)) self.assertTrue(v.shape == (3,))
self.failUnless(numpy.all(v == nfct(n.value,-2))) self.assertTrue(numpy.all(v == nfct(n.value,-2)))
v = eval_outputs(fct(n,-1).shape) v = eval_outputs(fct(n,-1).shape)
assert v==(2) assert v==(2)
...@@ -1438,25 +1438,25 @@ class T_min_max(unittest.TestCase): ...@@ -1438,25 +1438,25 @@ class T_min_max(unittest.TestCase):
for fct,nfct in [(max,numpy.max),(min,numpy.min)]: for fct,nfct in [(max,numpy.max),(min,numpy.min)]:
n = as_tensor_variable(numpy.random.rand(2,3,4)) n = as_tensor_variable(numpy.random.rand(2,3,4))
v = eval_outputs(fct(n,0)) v = eval_outputs(fct(n,0))
self.failUnless(v.shape == (3,4)) self.assertTrue(v.shape == (3,4))
self.failUnless(numpy.all(v == nfct(n.value,0))) self.assertTrue(numpy.all(v == nfct(n.value,0)))
v = eval_outputs(fct(n,1)) v = eval_outputs(fct(n,1))
self.failUnless(v.shape == (2,4)) self.assertTrue(v.shape == (2,4))
self.failUnless(numpy.all(v == nfct(n.value,1))) self.assertTrue(numpy.all(v == nfct(n.value,1)))
v = eval_outputs(fct(n,2)) v = eval_outputs(fct(n,2))
self.failUnless(v.shape == (2,3)) self.assertTrue(v.shape == (2,3))
self.failUnless(numpy.all(v == nfct(n.value,2))) self.assertTrue(numpy.all(v == nfct(n.value,2)))
v = eval_outputs(fct(n,[0,1])) v = eval_outputs(fct(n,[0,1]))
self.failUnless(v.shape == (4,)) self.assertTrue(v.shape == (4,))
self.failUnless(numpy.all(v == nfct(nfct(n.value,1),0))) self.assertTrue(numpy.all(v == nfct(nfct(n.value,1),0)))
v = eval_outputs(fct(n,[0,2])) v = eval_outputs(fct(n,[0,2]))
self.failUnless(v.shape == (3,)) self.assertTrue(v.shape == (3,))
self.failUnless(numpy.all(v == nfct(nfct(n.value,2),0))) self.assertTrue(numpy.all(v == nfct(nfct(n.value,2),0)))
v = eval_outputs(fct(n,[1,2])) v = eval_outputs(fct(n,[1,2]))
self.failUnless(v.shape == (2,)) self.assertTrue(v.shape == (2,))
self.failUnless(numpy.all(v == nfct(nfct(n.value,2),1))) self.assertTrue(numpy.all(v == nfct(nfct(n.value,2),1)))
v = eval_outputs(fct(n,[0,1,2])) v = eval_outputs(fct(n,[0,1,2]))
self.failUnless(v.shape == ()) self.assertTrue(v.shape == ())
v = eval_outputs(fct(n,0).shape) v = eval_outputs(fct(n,0).shape)
assert tuple(v)==(3,4) assert tuple(v)==(3,4)
...@@ -1465,13 +1465,13 @@ class T_min_max(unittest.TestCase): ...@@ -1465,13 +1465,13 @@ class T_min_max(unittest.TestCase):
v = eval_outputs(fct(n,2).shape) v = eval_outputs(fct(n,2).shape)
assert tuple(v)==(2,3) assert tuple(v)==(2,3)
v = eval_outputs(fct(n,[0,1]).shape) v = eval_outputs(fct(n,[0,1]).shape)
self.failUnless(v == (4,)) self.assertTrue(v == (4,))
v = eval_outputs(fct(n,[0,2]).shape) v = eval_outputs(fct(n,[0,2]).shape)
self.failUnless(v == (3,)) self.assertTrue(v == (3,))
v = eval_outputs(fct(n,[1,2]).shape) v = eval_outputs(fct(n,[1,2]).shape)
self.failUnless(v == (2,)) self.assertTrue(v == (2,))
v = eval_outputs(fct(n,[0,1,2]).shape) v = eval_outputs(fct(n,[0,1,2]).shape)
self.failUnless(v.size == 0) self.assertTrue(v.size == 0)
def test_grad_max(self): def test_grad_max(self):
data = numpy.random.rand(2,3) data = numpy.random.rand(2,3)
...@@ -1594,14 +1594,14 @@ class T_subtensor(unittest.TestCase): ...@@ -1594,14 +1594,14 @@ class T_subtensor(unittest.TestCase):
try: try:
t = n[0] t = n[0]
except ValueError, e: except ValueError, e:
self.failUnless(hasattr(e,'subtensor_invalid')) self.assertTrue(hasattr(e,'subtensor_invalid'))
return return
self.fail() self.fail()
def test1_err_bounds(self): def test1_err_bounds(self):
n = self.shared(numpy.ones(3, dtype=self.dtype)) n = self.shared(numpy.ones(3, dtype=self.dtype))
t = n[7] t = n[7]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
# Silence expected error messages # Silence expected error messages
_logger = logging.getLogger('theano.gof.opt') _logger = logging.getLogger('theano.gof.opt')
oldlevel = _logger.getEffectiveLevel() oldlevel = _logger.getEffectiveLevel()
...@@ -1630,81 +1630,81 @@ class T_subtensor(unittest.TestCase): ...@@ -1630,81 +1630,81 @@ class T_subtensor(unittest.TestCase):
def test1_ok_range_finite(self): def test1_ok_range_finite(self):
n = self.shared(numpy.ones(3, dtype=self.dtype)*5) n = self.shared(numpy.ones(3, dtype=self.dtype)*5)
t = n[0:2] t = n[0:2]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
f = inplace_func([], t, mode=self.mode) f = inplace_func([], t, mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)] topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)]
assert len(topo_)==1 assert len(topo_)==1
assert isinstance(topo_[0].op, self.sub) assert isinstance(topo_[0].op, self.sub)
tval = f() tval = f()
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(tval[1] == 5.0) self.assertTrue(tval[1] == 5.0)
def test2_ok_range_finite(self): def test2_ok_range_finite(self):
n = self.shared(numpy.ones((3,4), dtype=self.dtype)*5) n = self.shared(numpy.ones((3,4), dtype=self.dtype)*5)
t = n[0:2,3] t = n[0:2,3]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
f = inplace_func([], t, mode=self.mode) f = inplace_func([], t, mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)] topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)]
assert len(topo_)==1 assert len(topo_)==1
assert isinstance(topo_[0].op, self.sub) assert isinstance(topo_[0].op, self.sub)
tval = f() tval = f()
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(tval[1] == 5.0) self.assertTrue(tval[1] == 5.0)
def test1_err_invalid(self): def test1_err_invalid(self):
n = self.shared(numpy.ones(1, dtype=self.dtype)) n = self.shared(numpy.ones(1, dtype=self.dtype))
try: try:
t = n[0,0] t = n[0,0]
except ValueError, e: except ValueError, e:
self.failUnless(hasattr(e,'subtensor_invalid')) self.assertTrue(hasattr(e,'subtensor_invalid'))
return return
self.fail() self.fail()
def test1_ok_elem(self): def test1_ok_elem(self):
n = self.shared(numpy.ones(1, dtype=self.dtype)*5) n = self.shared(numpy.ones(1, dtype=self.dtype)*5)
t = n[0] t = n[0]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
f = inplace_func([], t, mode=self.mode) f = inplace_func([], t, mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)] topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)]
assert len(topo_)==1 assert len(topo_)==1
assert isinstance(topo_[0].op, self.sub) assert isinstance(topo_[0].op, self.sub)
tval = f() tval = f()
self.failUnless(tval.shape == ()) self.assertTrue(tval.shape == ())
self.failUnless(tval == 5.0) self.assertTrue(tval == 5.0)
def test1_ok_range_infinite(self): def test1_ok_range_infinite(self):
#Subtensor.debug = True #Subtensor.debug = True
n = self.shared(numpy.ones(3, dtype=self.dtype)*5) n = self.shared(numpy.ones(3, dtype=self.dtype)*5)
t = n[1:] t = n[1:]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
f = inplace_func([], t, mode=self.mode) f = inplace_func([], t, mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)] topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)]
assert len(topo_)==1 assert len(topo_)==1
assert isinstance(topo_[0].op, self.sub) assert isinstance(topo_[0].op, self.sub)
tval = f() tval = f()
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(tval[1] == 5.0) self.assertTrue(tval[1] == 5.0)
def test1_ok_strided(self): def test1_ok_strided(self):
n = self.shared(numpy.ones(5, dtype=self.dtype)*5) n = self.shared(numpy.ones(5, dtype=self.dtype)*5)
t = n[1::2] t = n[1::2]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(tval[1] == 5.0) self.assertTrue(tval[1] == 5.0)
t = n[0:-1:2] #0 to 1 from the end stepping by 2 t = n[0:-1:2] #0 to 1 from the end stepping by 2
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(tval[1] == 5.0) self.assertTrue(tval[1] == 5.0)
def test2_err_bounds0(self): def test2_err_bounds0(self):
n = self.shared(numpy.ones((2,3), dtype=self.dtype)*5) n = self.shared(numpy.ones((2,3), dtype=self.dtype)*5)
t = n[0,4] t = n[0,4]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
# Silence expected warnings # Silence expected warnings
_logger = logging.getLogger('theano.gof.opt') _logger = logging.getLogger('theano.gof.opt')
oldlevel = _logger.getEffectiveLevel() oldlevel = _logger.getEffectiveLevel()
...@@ -1720,7 +1720,7 @@ class T_subtensor(unittest.TestCase): ...@@ -1720,7 +1720,7 @@ class T_subtensor(unittest.TestCase):
def test2_err_bounds1(self): def test2_err_bounds1(self):
n = self.shared((numpy.ones((2,3), dtype=self.dtype)*5)) n = self.shared((numpy.ones((2,3), dtype=self.dtype)*5))
t = n[4:5,2] t = n[4:5,2]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
old_stderr = sys.stderr old_stderr = sys.stderr
sys.stderr = StringIO.StringIO() sys.stderr = StringIO.StringIO()
try: try:
...@@ -1734,59 +1734,59 @@ class T_subtensor(unittest.TestCase): ...@@ -1734,59 +1734,59 @@ class T_subtensor(unittest.TestCase):
def test2_ok_elem(self): def test2_ok_elem(self):
n = self.shared(numpy.asarray(range(6), dtype=self.dtype).reshape((2,3))) n = self.shared(numpy.asarray(range(6), dtype=self.dtype).reshape((2,3)))
t = n[0,2] t = n[0,2]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == ()) self.assertTrue(tval.shape == ())
self.failUnless(numpy.all(tval == 2)) self.assertTrue(numpy.all(tval == 2))
def test2_ok_row(self): def test2_ok_row(self):
n = self.shared(numpy.asarray(range(6), dtype=self.dtype).reshape((2,3))) n = self.shared(numpy.asarray(range(6), dtype=self.dtype).reshape((2,3)))
t = n[1] t = n[1]
self.failIf(any(n.type.broadcastable)) self.assertFalse(any(n.type.broadcastable))
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (3,)) self.assertTrue(tval.shape == (3,))
self.failUnless(numpy.all(tval == [3,4,5])) self.assertTrue(numpy.all(tval == [3,4,5]))
def test2_ok_col(self): def test2_ok_col(self):
n = self.shared(numpy.ones((2,3), dtype=self.dtype)*5) n = self.shared(numpy.ones((2,3), dtype=self.dtype)*5)
t = n[:,0] t = n[:,0]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
self.failIf(any(n.type.broadcastable)) self.assertFalse(any(n.type.broadcastable))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(numpy.all(tval == 5.0)) self.assertTrue(numpy.all(tval == 5.0))
def test2_ok_rows_finite(self): def test2_ok_rows_finite(self):
n = self.shared(numpy.ones((4,3), dtype=self.dtype)*5) n = self.shared(numpy.ones((4,3), dtype=self.dtype)*5)
t = n[1:3,0] t = n[1:3,0]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.failUnless(numpy.all(tval == 5.0)) self.assertTrue(numpy.all(tval == 5.0))
def test2_ok_cols_infinite(self): def test2_ok_cols_infinite(self):
n = self.shared(numpy.asarray(range(12), dtype=self.dtype).reshape((4,3))) n = self.shared(numpy.asarray(range(12), dtype=self.dtype).reshape((4,3)))
t = n[1,2:] t = n[1,2:]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (1,)) self.assertTrue(tval.shape == (1,))
self.failUnless(numpy.all(tval == 5)) self.assertTrue(numpy.all(tval == 5))
def test2_ok_strided(self): def test2_ok_strided(self):
n = self.shared(numpy.asarray(range(20), dtype=self.dtype).reshape((4,5))) n = self.shared(numpy.asarray(range(20), dtype=self.dtype).reshape((4,5)))
t = n[1:4:2,1:5:2] t = n[1:4:2,1:5:2]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == (2,2)) self.assertTrue(tval.shape == (2,2))
self.failUnless(numpy.all(tval == [[6, 8],[16, 18]])) self.assertTrue(numpy.all(tval == [[6, 8],[16, 18]]))
def test3_ok_mat(self): def test3_ok_mat(self):
n = self.shared(numpy.asarray(range(24), dtype=self.dtype).reshape((2,3,4))) n = self.shared(numpy.asarray(range(24), dtype=self.dtype).reshape((2,3,4)))
t = n[0,0,0] t = n[0,0,0]
self.failUnless(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
tval = self.eval_output_and_check(t) tval = self.eval_output_and_check(t)
self.failUnless(tval.shape == ()) self.assertTrue(tval.shape == ())
self.failUnless(numpy.all(tval == 0)) self.assertTrue(numpy.all(tval == 0))
def test_grad_1d(self): def test_grad_1d(self):
subi = 0 subi = 0
...@@ -1807,7 +1807,7 @@ class T_subtensor(unittest.TestCase): ...@@ -1807,7 +1807,7 @@ class T_subtensor(unittest.TestCase):
good = numpy.zeros_like(data) good = numpy.zeros_like(data)
good[subi:,subi] = numpy.exp(data[subi:,subi]) good[subi:,subi] = numpy.exp(data[subi:,subi])
self.failUnless(numpy.allclose(gval, good), (gval, good)) self.assertTrue(numpy.allclose(gval, good), (gval, good))
def test_grad_0d(self): def test_grad_0d(self):
data = numpy.asarray(numpy.random.rand(2,3), dtype=self.dtype) data = numpy.asarray(numpy.random.rand(2,3), dtype=self.dtype)
...@@ -1825,7 +1825,7 @@ class T_subtensor(unittest.TestCase): ...@@ -1825,7 +1825,7 @@ class T_subtensor(unittest.TestCase):
gval = f() gval = f()
good = numpy.zeros_like(data) good = numpy.zeros_like(data)
good[1,0] = numpy.exp(data[1,0]) good[1,0] = numpy.exp(data[1,0])
self.failUnless(numpy.allclose(gval, good), (gval, good)) self.assertTrue(numpy.allclose(gval, good), (gval, good))
def test_ok_list(self): def test_ok_list(self):
for data, idx in [(numpy.random.rand(4), [1,0]), for data, idx in [(numpy.random.rand(4), [1,0]),
...@@ -1838,12 +1838,12 @@ class T_subtensor(unittest.TestCase): ...@@ -1838,12 +1838,12 @@ class T_subtensor(unittest.TestCase):
t = n[idx] t = n[idx]
# We test again AdvancedSubtensor1 as we transfer data to the cpu. # We test again AdvancedSubtensor1 as we transfer data to the cpu.
self.failUnless(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1)) self.assertTrue(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1))
val = self.eval_output_and_check(t, list=True) val = self.eval_output_and_check(t, list=True)
good = data[idx] good = data[idx]
self.failUnless(val.ndim == data.ndim) self.assertTrue(val.ndim == data.ndim)
self.failUnless(numpy.allclose(val, good), (val, good)) self.assertTrue(numpy.allclose(val, good), (val, good))
def test_err_invalid_list(self): def test_err_invalid_list(self):
n = self.shared(numpy.asarray(5, dtype=self.dtype)) n = self.shared(numpy.asarray(5, dtype=self.dtype))
...@@ -1858,13 +1858,13 @@ class T_subtensor(unittest.TestCase): ...@@ -1858,13 +1858,13 @@ class T_subtensor(unittest.TestCase):
n = self.shared(numpy.ones((2,3),dtype=self.dtype)*5) n = self.shared(numpy.ones((2,3),dtype=self.dtype)*5)
t = n[[0,4]] t = n[[0,4]]
# We test again AdvancedSubtensor1 as we transfer data to the cpu. # We test again AdvancedSubtensor1 as we transfer data to the cpu.
self.failUnless(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1)) self.assertTrue(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1))
f = function([], t, mode=self.mode) f = function([], t, mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)] topo_ = [node for node in topo if not isinstance(node.op, self.ignore_topo)]
assert len(topo_)==1 assert len(topo_)==1
self.failUnless(isinstance(topo_[0].op, self.adv_sub1)) self.assertTrue(isinstance(topo_[0].op, self.adv_sub1))
self.assertRaises(IndexError, f) self.assertRaises(IndexError, f)
def test_shape_i_const(self): def test_shape_i_const(self):
...@@ -2089,9 +2089,9 @@ class T_subtensor(unittest.TestCase): ...@@ -2089,9 +2089,9 @@ class T_subtensor(unittest.TestCase):
# good[idx] += numpy.exp(data[idx]) don't work when the same index is used many time # good[idx] += numpy.exp(data[idx]) don't work when the same index is used many time
for i in idx: for i in idx:
good[i] += numpy.exp(data[i]) good[i] += numpy.exp(data[i])
self.failUnless(gval.ndim == data.ndim) self.assertTrue(gval.ndim == data.ndim)
self.failUnless(numpy.allclose(gval, good), (gval, good)) self.assertTrue(numpy.allclose(gval, good), (gval, good))
self.failUnless(numpy.allclose(gshape, data.shape)) self.assertTrue(numpy.allclose(gshape, data.shape))
def fct(t): def fct(t):
return sum(t[idx_]) return sum(t[idx_])
...@@ -2107,8 +2107,8 @@ class T_subtensor(unittest.TestCase): ...@@ -2107,8 +2107,8 @@ class T_subtensor(unittest.TestCase):
f = function([], [gn.shape, n[idx_].shape], mode=self.mode) f = function([], [gn.shape, n[idx_].shape], mode=self.mode)
topo = f.maker.env.toposort() topo = f.maker.env.toposort()
if not self.fast_compile: if not self.fast_compile:
self.failUnless(not any([isinstance(node.op, self.adv_incsub1) for node in topo])) self.assertTrue(not any([isinstance(node.op, self.adv_incsub1) for node in topo]))
self.failUnless(not any([isinstance(node.op, self.adv_sub1) for node in topo])) self.assertTrue(not any([isinstance(node.op, self.adv_sub1) for node in topo]))
f() f()
...@@ -2141,7 +2141,7 @@ class T_subtensor(unittest.TestCase): ...@@ -2141,7 +2141,7 @@ class T_subtensor(unittest.TestCase):
t = n[idx] t = n[idx]
f = function([], t.shape, mode=None) f = function([], t.shape, mode=None)
val = f() val = f()
self.failUnless(numpy.allclose(val, data[idx].shape)) self.assertTrue(numpy.allclose(val, data[idx].shape))
class T_Join_and_Split(unittest.TestCase): class T_Join_and_Split(unittest.TestCase):
""" """
...@@ -2167,7 +2167,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2167,7 +2167,7 @@ class T_Join_and_Split(unittest.TestCase):
s = stack(a, b, c) s = stack(a, b, c)
want = numpy.array([1, 2, 3]) want = numpy.array([1, 2, 3])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_stack_scalar(self): def test_stack_scalar(self):
a = as_tensor_variable(1) a = as_tensor_variable(1)
...@@ -2176,7 +2176,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2176,7 +2176,7 @@ class T_Join_and_Split(unittest.TestCase):
s = stack(a, b, c) s = stack(a, b, c)
want = numpy.array([1, 2, 3]) want = numpy.array([1, 2, 3])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_stack_scalar_make_vector(self): def test_stack_scalar_make_vector(self):
'''Test that calling stack() on scalars instantiates MakeVector, '''Test that calling stack() on scalars instantiates MakeVector,
...@@ -2187,7 +2187,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2187,7 +2187,7 @@ class T_Join_and_Split(unittest.TestCase):
f = function([a,b], s) f = function([a,b], s)
val = f(1,2) val = f(1,2)
print val print val
self.failUnless(numpy.all(val == [1,2,1,2])) self.assertTrue(numpy.all(val == [1,2,1,2]))
e = f.maker.env.toposort() e = f.maker.env.toposort()
assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0 assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0
assert len([n for n in e if isinstance(n, Join)]) == 0 assert len([n for n in e if isinstance(n, Join)]) == 0
...@@ -2201,7 +2201,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2201,7 +2201,7 @@ class T_Join_and_Split(unittest.TestCase):
s = stack(a, b, a, b) s = stack(a, b, a, b)
f = function([a,b], s) f = function([a,b], s)
val = f(1,2) val = f(1,2)
self.failUnless(numpy.all(val == [1,2,1,2])) self.assertTrue(numpy.all(val == [1,2,1,2]))
e = f.maker.env.toposort() e = f.maker.env.toposort()
assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0 assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0
assert len([n for n in e if isinstance(n, Join)]) == 0 assert len([n for n in e if isinstance(n, Join)]) == 0
...@@ -2217,7 +2217,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2217,7 +2217,7 @@ class T_Join_and_Split(unittest.TestCase):
s = stack(10,a,b, numpy.int8(3)) s = stack(10,a,b, numpy.int8(3))
f = function([a,b], s) f = function([a,b], s)
val = f(1,2) val = f(1,2)
self.failUnless(numpy.all(val == [10,1,2,3])) self.assertTrue(numpy.all(val == [10,1,2,3]))
e = f.maker.env.toposort() e = f.maker.env.toposort()
assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0 assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0
assert len([n for n in e if isinstance(n, Join)]) == 0 assert len([n for n in e if isinstance(n, Join)]) == 0
...@@ -2229,7 +2229,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2229,7 +2229,7 @@ class T_Join_and_Split(unittest.TestCase):
s = join(0, a, b) s = join(0, a, b)
want = numpy.array([1, 2, 3, 7, 8, 9]) want = numpy.array([1, 2, 3, 7, 8, 9])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_stack_vector(self): def test_stack_vector(self):
a = as_tensor_variable(numpy.array([1, 2, 3])) a = as_tensor_variable(numpy.array([1, 2, 3]))
...@@ -2237,7 +2237,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2237,7 +2237,7 @@ class T_Join_and_Split(unittest.TestCase):
s = stack(a, b) s = stack(a, b)
want = numpy.array([[1, 2, 3],[ 7, 8, 9]]) want = numpy.array([[1, 2, 3],[ 7, 8, 9]])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_join_matrix0(self): def test_join_matrix0(self):
a = as_tensor_variable(numpy.array([[1, 2, 3], [4, 5, 6]])) a = as_tensor_variable(numpy.array([[1, 2, 3], [4, 5, 6]]))
...@@ -2245,7 +2245,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2245,7 +2245,7 @@ class T_Join_and_Split(unittest.TestCase):
s = join(0, a, b) s = join(0, a, b)
want = numpy.array([[1, 2, 3],[4,5,6],[7, 8, 9]]) want = numpy.array([[1, 2, 3],[4,5,6],[7, 8, 9]])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_join_matrix1(self): def test_join_matrix1(self):
av=numpy.array([[1, 2, 3], [4, 5, 6]], dtype='float32') av=numpy.array([[1, 2, 3], [4, 5, 6]], dtype='float32')
...@@ -2254,7 +2254,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2254,7 +2254,7 @@ class T_Join_and_Split(unittest.TestCase):
b = as_tensor_variable(bv) b = as_tensor_variable(bv)
s = join(1, a, b) s = join(1, a, b)
want = numpy.array([[1, 2, 3, 7], [4, 5, 6, 8]], dtype='float32') want = numpy.array([[1, 2, 3, 7], [4, 5, 6, 8]], dtype='float32')
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
utt.verify_grad(lambda a, b: join(1,a,b), [av, bv], eps=1.0e-4, rel_tol=1.0e-3) utt.verify_grad(lambda a, b: join(1,a,b), [av, bv], eps=1.0e-4, rel_tol=1.0e-3)
...@@ -2265,7 +2265,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2265,7 +2265,7 @@ class T_Join_and_Split(unittest.TestCase):
s = vertical_stack(a, b, c) s = vertical_stack(a, b, c)
want = numpy.array([[1, 2, 3],[4,5,6],[7, 8, 9], [9, 8, 7]]) want = numpy.array([[1, 2, 3],[4,5,6],[7, 8, 9], [9, 8, 7]])
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
def test_join_matrix1_using_horizontal_stack(self): def test_join_matrix1_using_horizontal_stack(self):
av=numpy.array([[1, 2, 3], [4, 5, 6]], dtype='float32') av=numpy.array([[1, 2, 3], [4, 5, 6]], dtype='float32')
...@@ -2276,7 +2276,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2276,7 +2276,7 @@ class T_Join_and_Split(unittest.TestCase):
c = as_tensor_variable(cv) c = as_tensor_variable(cv)
s = horizontal_stack(a, b, c) s = horizontal_stack(a, b, c)
want = numpy.array([[1, 2, 3, 7, 3, 2, 1], [4, 5, 6, 8, 6, 5, 4]], dtype='float32') want = numpy.array([[1, 2, 3, 7, 3, 2, 1], [4, 5, 6, 8, 6, 5, 4]], dtype='float32')
self.failUnless((eval_outputs([s]) == want).all()) self.assertTrue((eval_outputs([s]) == want).all())
utt.verify_grad(lambda a, b: join(1,a,b), [av, bv], eps=1.0e-4, rel_tol=1.0e-3) utt.verify_grad(lambda a, b: join(1,a,b), [av, bv], eps=1.0e-4, rel_tol=1.0e-3)
...@@ -2292,11 +2292,11 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2292,11 +2292,11 @@ class T_Join_and_Split(unittest.TestCase):
want = numpy.array([[1, 2, 3], [4, 5, 6] ,[1, 2, 3], [4, 5, 6]]) want = numpy.array([[1, 2, 3], [4, 5, 6] ,[1, 2, 3], [4, 5, 6]])
got = f(0) got = f(0)
self.failUnless((got == want).all(), (got, want)) self.assertTrue((got == want).all(), (got, want))
want = numpy.array([[ 1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6]]) want = numpy.array([[ 1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6]])
got = f(1) got = f(1)
self.failUnless((got == want).all(), (got, want)) self.assertTrue((got == want).all(), (got, want))
utt.verify_grad(lambda a, b: join(0,a,b), [v, 2*v]) utt.verify_grad(lambda a, b: join(0,a,b), [v, 2*v])
utt.verify_grad(lambda a, b: join(1,a,b), [v, 2*v]) utt.verify_grad(lambda a, b: join(1,a,b), [v, 2*v])
...@@ -2456,7 +2456,7 @@ class test_comparison(unittest.TestCase): ...@@ -2456,7 +2456,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l > r)), (v, (l>r))) self.assertTrue(numpy.all(v == (l > r)), (v, (l>r)))
def test_lt(self): def test_lt(self):
for dtype in ['float64', 'float32', 'complex64', 'complex128']: for dtype in ['float64', 'float32', 'complex64', 'complex128']:
...@@ -2465,7 +2465,7 @@ class test_comparison(unittest.TestCase): ...@@ -2465,7 +2465,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l < r)), (v, (l<r))) self.assertTrue(numpy.all(v == (l < r)), (v, (l<r)))
def test_le(self): def test_le(self):
for dtype in ['float64', 'float32', 'complex64', 'complex128']: for dtype in ['float64', 'float32', 'complex64', 'complex128']:
...@@ -2474,7 +2474,7 @@ class test_comparison(unittest.TestCase): ...@@ -2474,7 +2474,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l <= r)), (v, (l<=r))) self.assertTrue(numpy.all(v == (l <= r)), (v, (l<=r)))
def test_ge(self): def test_ge(self):
for dtype in ['float64', 'float32', 'complex64', 'complex128']: for dtype in ['float64', 'float32', 'complex64', 'complex128']:
...@@ -2483,7 +2483,7 @@ class test_comparison(unittest.TestCase): ...@@ -2483,7 +2483,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l >= r)), (v, (l>=r))) self.assertTrue(numpy.all(v == (l >= r)), (v, (l>=r)))
def test_eq(self): def test_eq(self):
for dtype in ['float64', 'float32', 'complex64', 'complex128']: for dtype in ['float64', 'float32', 'complex64', 'complex128']:
...@@ -2492,7 +2492,7 @@ class test_comparison(unittest.TestCase): ...@@ -2492,7 +2492,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l == r)), (v, (l==r))) self.assertTrue(numpy.all(v == (l == r)), (v, (l==r)))
def test_neq(self): def test_neq(self):
for dtype in ['float64', 'float32', 'complex64', 'complex128']: for dtype in ['float64', 'float32', 'complex64', 'complex128']:
...@@ -2501,7 +2501,7 @@ class test_comparison(unittest.TestCase): ...@@ -2501,7 +2501,7 @@ class test_comparison(unittest.TestCase):
l = numpy.asarray([0.,-1.,1.], dtype=dtype) l = numpy.asarray([0.,-1.,1.], dtype=dtype)
r = numpy.asarray([0.,1.,-1.], dtype=dtype) r = numpy.asarray([0.,1.,-1.], dtype=dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l != r)), (v, (l!=r))) self.assertTrue(numpy.all(v == (l != r)), (v, (l!=r)))
class test_bitwise(unittest.TestCase): class test_bitwise(unittest.TestCase):
dtype = ['int8', 'int16', 'int32', 'int64',] dtype = ['int8', 'int16', 'int32', 'int64',]
...@@ -2513,7 +2513,7 @@ class test_bitwise(unittest.TestCase): ...@@ -2513,7 +2513,7 @@ class test_bitwise(unittest.TestCase):
l = theano._asarray([0,0,1,1], dtype = dtype) l = theano._asarray([0,0,1,1], dtype = dtype)
r = theano._asarray([0,1,0,1], dtype = dtype) r = theano._asarray([0,1,0,1], dtype = dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (operator.or_(l, r))), (l, r, v)) self.assertTrue(numpy.all(v == (operator.or_(l, r))), (l, r, v))
def test_xor(self): def test_xor(self):
for dtype in self.dtype: for dtype in self.dtype:
...@@ -2525,10 +2525,10 @@ class test_bitwise(unittest.TestCase): ...@@ -2525,10 +2525,10 @@ class test_bitwise(unittest.TestCase):
l = theano._asarray([0,0,1,1], dtype = dtype) l = theano._asarray([0,0,1,1], dtype = dtype)
r = theano._asarray([0,1,0,1], dtype = dtype) r = theano._asarray([0,1,0,1], dtype = dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (operator.xor(l, r))), (l, r, v)) self.assertTrue(numpy.all(v == (operator.xor(l, r))), (l, r, v))
v = gn(l, r) v = gn(l, r)
#test the in-place stuff #test the in-place stuff
self.failUnless(numpy.all(l == numpy.asarray([0,1,1,0])), l) self.assertTrue(numpy.all(l == numpy.asarray([0,1,1,0])), l)
def test_and(self): def test_and(self):
for dtype in self.dtype: for dtype in self.dtype:
...@@ -2537,7 +2537,7 @@ class test_bitwise(unittest.TestCase): ...@@ -2537,7 +2537,7 @@ class test_bitwise(unittest.TestCase):
l = theano._asarray([0,0,1,1], dtype = dtype) l = theano._asarray([0,0,1,1], dtype = dtype)
r = theano._asarray([0,1,0,1], dtype = dtype) r = theano._asarray([0,1,0,1], dtype = dtype)
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (operator.and_(l, r))), (l, r, v)) self.assertTrue(numpy.all(v == (operator.and_(l, r))), (l, r, v))
def test_inv(self): def test_inv(self):
for dtype in self.dtype: for dtype in self.dtype:
...@@ -2549,14 +2549,14 @@ class test_bitwise(unittest.TestCase): ...@@ -2549,14 +2549,14 @@ class test_bitwise(unittest.TestCase):
]: ]:
l = theano._asarray([0,0,1,1], dtype = dtype) l = theano._asarray([0,0,1,1], dtype = dtype)
v = fn(l) v = fn(l)
self.failUnless(numpy.all(v == (~l)), (l, v)) self.assertTrue(numpy.all(v == (~l)), (l, v))
def test_eye(self): def test_eye(self):
n = iscalar() n = iscalar()
m = iscalar() m = iscalar()
k = iscalar() k = iscalar()
fn = theano.function([m,n,k],eye(m,n,k) ) fn = theano.function([m,n,k],eye(m,n,k) )
self.failUnless(numpy.all(fn(5,6,1) == numpy.eye(5,6,1))) self.assertTrue(numpy.all(fn(5,6,1) == numpy.eye(5,6,1)))
class T_add(unittest.TestCase): class T_add(unittest.TestCase):
...@@ -2575,7 +2575,7 @@ class T_add(unittest.TestCase): ...@@ -2575,7 +2575,7 @@ class T_add(unittest.TestCase):
f = inplace_func([a,b], fn(a, b)) f = inplace_func([a,b], fn(a, b))
print 'valid output:', fn(a.data, b.data) print 'valid output:', fn(a.data, b.data)
print 'theano output:', f(a.data, b.data) print 'theano output:', f(a.data, b.data)
self.failUnless(a.type.values_eq_approx(fn(a.data, b.data), f(a.data, b.data))) self.assertTrue(a.type.values_eq_approx(fn(a.data, b.data), f(a.data, b.data)))
def test_grad_scalar_l(self): def test_grad_scalar_l(self):
utt.verify_grad(add, [numpy.asarray([3.0]), numpy.random.rand(3)]) utt.verify_grad(add, [numpy.asarray([3.0]), numpy.random.rand(3)])
...@@ -2662,29 +2662,29 @@ class T_divimpl(unittest.TestCase): ...@@ -2662,29 +2662,29 @@ class T_divimpl(unittest.TestCase):
# try: # try:
# utt.verify_grad(T_abs.AbsBadGrad, [numpy.ones(())]) # utt.verify_grad(T_abs.AbsBadGrad, [numpy.ones(())])
# except Exception, e: # except Exception, e:
# self.failUnless(str(e) == utt.verify_grad.E_grad, str(e)) # self.assertTrue(str(e) == utt.verify_grad.E_grad, str(e))
# return # return
# self.fail() # self.fail()
# class T_fill(unittest.TestCase): # class T_fill(unittest.TestCase):
# def test0(self): # def test0(self):
# t = fill(numpy.asarray([1,2,3]), 9) # t = fill(numpy.asarray([1,2,3]), 9)
# self.failUnless(t.owner.__class__ == Fill) # self.assertTrue(t.owner.__class__ == Fill)
# o = t.owner # o = t.owner
# self.failUnless(o.inputs[0].broadcastable == (0,)) # self.assertTrue(o.inputs[0].broadcastable == (0,))
# # self.failUnless(o.inputs[0].dtype[0:3] == 'int') # # self.assertTrue(o.inputs[0].dtype[0:3] == 'int')
# self.failUnless(o.inputs[1].broadcastable == (1,)) # self.assertTrue(o.inputs[1].broadcastable == (1,))
# # self.failUnless(o.inputs[1].dtype[0:3] == 'flo') # # self.assertTrue(o.inputs[1].dtype[0:3] == 'flo')
# self.failUnless(o.outputs[0].broadcastable == (0,)) # self.assertTrue(o.outputs[0].broadcastable == (0,))
# # self.failUnless(o.outputs[0].dtype[0:3] == 'flo') # # self.assertTrue(o.outputs[0].dtype[0:3] == 'flo')
# self.failUnless(numpy.all(eval_outputs([t]) == [9,9,9])) # self.assertTrue(numpy.all(eval_outputs([t]) == [9,9,9]))
# def test1(self): # def test1(self):
# x = as_tensor_variable(numpy.ones((4,5))) # x = as_tensor_variable(numpy.ones((4,5)))
# l = ones_like(x[:,0:1]) # l = ones_like(x[:,0:1])
# r = ones_like(x[0:1,:]) # r = ones_like(x[0:1,:])
# xx = x + dot(l,r) # xx = x + dot(l,r)
# self.failUnless(numpy.mean(eval_outputs([xx]) == 2.0)) # self.assertTrue(numpy.mean(eval_outputs([xx]) == 2.0))
# class T_sum(unittest.TestCase): # class T_sum(unittest.TestCase):
# def test_impl(self): # def test_impl(self):
...@@ -2720,7 +2720,7 @@ class T_divimpl(unittest.TestCase): ...@@ -2720,7 +2720,7 @@ class T_divimpl(unittest.TestCase):
# b = as_tensor_variable(2.0) # b = as_tensor_variable(2.0)
# check_eq2_both(self, [a,b], mul(a,b), [r, 2.0], r*2.0) # check_eq2_both(self, [a,b], mul(a,b), [r, 2.0], r*2.0)
# check_eq2_both(self, [a,b], mul(a,b), [r, 4.0], r*4.0) # check_eq2_both(self, [a,b], mul(a,b), [r, 4.0], r*4.0)
# self.failUnless(b.data == 2.0) # self.assertTrue(b.data == 2.0)
# def test_rowcol(self): # def test_rowcol(self):
# r1 = numpy.random.rand(3,5) # r1 = numpy.random.rand(3,5)
...@@ -2752,7 +2752,7 @@ class T_divimpl(unittest.TestCase): ...@@ -2752,7 +2752,7 @@ class T_divimpl(unittest.TestCase):
# [numpy.ones(3), numpy.ones(4)], 1.0) # [numpy.ones(3), numpy.ones(4)], 1.0)
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless('shape mismatch' in str(e)) # self.assertTrue('shape mismatch' in str(e))
# try: # try:
# check_eq2_c(self, [a,b], Mul(a,b).out, # check_eq2_c(self, [a,b], Mul(a,b).out,
# [numpy.ones(3), numpy.ones(4)], 1.0) # [numpy.ones(3), numpy.ones(4)], 1.0)
...@@ -2883,9 +2883,9 @@ class t_dot(unittest.TestCase): ...@@ -2883,9 +2883,9 @@ class t_dot(unittest.TestCase):
return type(x), x.dtype, x.shape return type(x), x.dtype, x.shape
nz = numpy.dot(x,y) nz = numpy.dot(x,y)
tz = eval_outputs([dot(as_tensor_variable(x), as_tensor_variable(y))]) tz = eval_outputs([dot(as_tensor_variable(x), as_tensor_variable(y))])
self.failUnless(tz.dtype == nz.dtype) self.assertTrue(tz.dtype == nz.dtype)
self.failUnless(tz.shape == nz.shape) self.assertTrue(tz.shape == nz.shape)
self.failUnless(_approx_eq(nz, tz)) self.assertTrue(_approx_eq(nz, tz))
#def test_dot_0d_0d(self): self.cmp_dot(1.1, 2.2) #def test_dot_0d_0d(self): self.cmp_dot(1.1, 2.2)
#def test_dot_0d_1d(self): self.cmp_dot(1.1, self.rand(5)) #def test_dot_0d_1d(self): self.cmp_dot(1.1, self.rand(5))
...@@ -2916,7 +2916,7 @@ class t_dot(unittest.TestCase): ...@@ -2916,7 +2916,7 @@ class t_dot(unittest.TestCase):
tz = eval_outputs([z]) tz = eval_outputs([z])
assert False # should have raised exception assert False # should have raised exception
except ValueError, e: except ValueError, e:
self.failUnless( self.assertTrue(
e[0].split()[1:4] == ['are', 'not', 'aligned'] or # reported by numpy e[0].split()[1:4] == ['are', 'not', 'aligned'] or # reported by numpy
e[0].split()[0:2] == ['Shape', 'mismatch:'], e) # reported by blas return self.fail() e[0].split()[0:2] == ['Shape', 'mismatch:'], e) # reported by blas return self.fail()
finally: finally:
...@@ -2982,16 +2982,16 @@ class T_tensorfromscalar(unittest.TestCase): ...@@ -2982,16 +2982,16 @@ class T_tensorfromscalar(unittest.TestCase):
def test0(self): def test0(self):
s = scal.constant(56) s = scal.constant(56)
t = tensor_from_scalar(s) t = tensor_from_scalar(s)
self.failUnless(t.owner.op is tensor_from_scalar) self.assertTrue(t.owner.op is tensor_from_scalar)
self.failUnless(t.type.broadcastable == (), t.type.broadcastable) self.assertTrue(t.type.broadcastable == (), t.type.broadcastable)
self.failUnless(t.type.ndim == 0, t.type.ndim) self.assertTrue(t.type.ndim == 0, t.type.ndim)
self.failUnless(t.type.dtype == s.type.dtype) self.assertTrue(t.type.dtype == s.type.dtype)
v = eval_outputs([t]) v = eval_outputs([t])
self.failUnless(v == 56, v) self.assertTrue(v == 56, v)
self.failUnless(isinstance(v, numpy.ndarray)) self.assertTrue(isinstance(v, numpy.ndarray))
self.failUnless(v.shape == (), v.shape) self.assertTrue(v.shape == (), v.shape)
@dec.knownfailureif( @dec.knownfailureif(
isinstance(get_default_mode(),theano.compile.debugmode.DebugMode), isinstance(get_default_mode(),theano.compile.debugmode.DebugMode),
...@@ -3000,19 +3000,19 @@ class T_tensorfromscalar(unittest.TestCase): ...@@ -3000,19 +3000,19 @@ class T_tensorfromscalar(unittest.TestCase):
def test1(self): def test1(self):
s = scal.constant(56) s = scal.constant(56)
t = as_tensor_variable(s) t = as_tensor_variable(s)
self.failUnless(t.owner.op is tensor_from_scalar) self.assertTrue(t.owner.op is tensor_from_scalar)
self.failUnless(t.type.broadcastable == (), t.type.broadcastable) self.assertTrue(t.type.broadcastable == (), t.type.broadcastable)
self.failUnless(t.type.ndim == 0, t.type.ndim) self.assertTrue(t.type.ndim == 0, t.type.ndim)
self.failUnless(t.type.dtype == s.type.dtype) self.assertTrue(t.type.dtype == s.type.dtype)
v = eval_outputs([t]) v = eval_outputs([t])
self.failUnless(v == 56, v) self.assertTrue(v == 56, v)
self.failUnless(isinstance(v, numpy.ndarray)) self.assertTrue(isinstance(v, numpy.ndarray))
self.failUnless(v.shape == (), v.shape) self.assertTrue(v.shape == (), v.shape)
g = grad(t, s) g = grad(t, s)
self.failUnless(eval_outputs([g])==1) self.assertTrue(eval_outputs([g])==1)
class T_scalarfromtensor(unittest.TestCase): class T_scalarfromtensor(unittest.TestCase):
@dec.knownfailureif( @dec.knownfailureif(
...@@ -3022,22 +3022,22 @@ class T_scalarfromtensor(unittest.TestCase): ...@@ -3022,22 +3022,22 @@ class T_scalarfromtensor(unittest.TestCase):
def test0(self): def test0(self):
tt = constant(56)#scal.constant(56) tt = constant(56)#scal.constant(56)
ss = scalar_from_tensor(tt) ss = scalar_from_tensor(tt)
self.failUnless(ss.owner.op is scalar_from_tensor) self.assertTrue(ss.owner.op is scalar_from_tensor)
self.failUnless(ss.type.dtype == tt.type.dtype) self.assertTrue(ss.type.dtype == tt.type.dtype)
v = eval_outputs([ss]) v = eval_outputs([ss])
self.failUnless(v == 56, v) self.assertTrue(v == 56, v)
self.failUnless(isinstance(v, numpy.int8)) self.assertTrue(isinstance(v, numpy.int8))
self.failUnless(v.shape == (), v.shape) self.assertTrue(v.shape == (), v.shape)
tt = lscalar() tt = lscalar()
ss = scalar_from_tensor(tt) ss = scalar_from_tensor(tt)
g = ss.owner.op.grad([tt],[ss]) g = ss.owner.op.grad([tt],[ss])
fff=function([tt],ss) fff=function([tt],ss)
v = fff(numpy.asarray(5)) v = fff(numpy.asarray(5))
self.failUnless(v == 5, v) self.assertTrue(v == 5, v)
self.failUnless(isinstance(v, numpy.int64)) self.assertTrue(isinstance(v, numpy.int64))
self.failUnless(v.shape == (),v.shape) self.assertTrue(v.shape == (),v.shape)
# def _tensor(data, broadcastable=None, name=None): # def _tensor(data, broadcastable=None, name=None):
# """Return a TensorType containing given data""" # """Return a TensorType containing given data"""
...@@ -3057,121 +3057,121 @@ class T_scalarfromtensor(unittest.TestCase): ...@@ -3057,121 +3057,121 @@ class T_scalarfromtensor(unittest.TestCase):
# utt.seed_rng() # utt.seed_rng()
# def test0(self): # allocate from a scalar float # def test0(self): # allocate from a scalar float
# t = _tensor(1.0) # t = _tensor(1.0)
# self.failUnless(isinstance(t, TensorType)) # self.assertTrue(isinstance(t, TensorType))
# self.failUnless(t.dtype == 'float64') # self.assertTrue(t.dtype == 'float64')
# self.failUnless(t.broadcastable == ()) # self.assertTrue(t.broadcastable == ())
# self.failUnless(t.role == None) # self.assertTrue(t.role == None)
# self.failUnless(isinstance(t.data, numpy.ndarray)) # self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.failUnless(str(t.data.dtype) == 'float64') # self.assertTrue(str(t.data.dtype) == 'float64')
# self.failUnless(t.data == 1.0) # self.assertTrue(t.data == 1.0)
# def test0_int(self): # allocate from a scalar float # def test0_int(self): # allocate from a scalar float
# t = _tensor(1) # t = _tensor(1)
# self.failUnless(isinstance(t, TensorType)) # self.assertTrue(isinstance(t, TensorType))
# self.failUnless(t.dtype == 'int64' or t.dtype == 'int32') # self.assertTrue(t.dtype == 'int64' or t.dtype == 'int32')
# def test1(self): # allocate from a vector of ints, not broadcastable # def test1(self): # allocate from a vector of ints, not broadcastable
# t = _tensor(numpy.ones(5,dtype='int32')) # t = _tensor(numpy.ones(5,dtype='int32'))
# self.failUnless(isinstance(t, TensorType)) # self.assertTrue(isinstance(t, TensorType))
# self.failUnless(t.dtype == 'int32') # self.assertTrue(t.dtype == 'int32')
# self.failUnless(t.broadcastable == (0,)) # self.assertTrue(t.broadcastable == (0,))
# self.failUnless(isinstance(t.data, numpy.ndarray)) # self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.failUnless(str(t.data.dtype) == 'int32') # self.assertTrue(str(t.data.dtype) == 'int32')
# def test2(self): # allocate from a column matrix of complex with name # def test2(self): # allocate from a column matrix of complex with name
# t = _tensor(numpy.ones((5,1),dtype='complex64'),name='bart') # t = _tensor(numpy.ones((5,1),dtype='complex64'),name='bart')
# self.failUnless(isinstance(t, TensorType)) # self.assertTrue(isinstance(t, TensorType))
# self.failUnless(t.dtype == 'complex64') # self.assertTrue(t.dtype == 'complex64')
# self.failUnless(t.broadcastable == (0,1)) # self.assertTrue(t.broadcastable == (0,1))
# self.failUnless(isinstance(t.data, numpy.ndarray)) # self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.failUnless(t.name == 'bart') # self.assertTrue(t.name == 'bart')
# def test2b(self): # allocate from a column matrix, not broadcastable # def test2b(self): # allocate from a column matrix, not broadcastable
# t = _tensor(numpy.ones((5,1),dtype='complex64'),broadcastable=0) # t = _tensor(numpy.ones((5,1),dtype='complex64'),broadcastable=0)
# self.failUnless(isinstance(t, TensorType)) # self.assertTrue(isinstance(t, TensorType))
# self.failUnless(t.dtype == 'complex64') # self.assertTrue(t.dtype == 'complex64')
# self.failUnless(t.broadcastable == (0,0)) # self.assertTrue(t.broadcastable == (0,0))
# self.failUnless(isinstance(t.data, numpy.ndarray)) # self.assertTrue(isinstance(t.data, numpy.ndarray))
# f = Function([t], [t], linker_cls=gof.CLinker) # f = Function([t], [t], linker_cls=gof.CLinker)
# self.failUnless(numpy.all(t.data == f(t.data))) # self.assertTrue(numpy.all(t.data == f(t.data)))
# def test_data_normal(self): #test that assigning to .data works when it should # def test_data_normal(self): #test that assigning to .data works when it should
# t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0) # t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0)
# o27 = numpy.ones((2,7), dtype='complex64') # o27 = numpy.ones((2,7), dtype='complex64')
# t.data = o27 # t.data = o27
# lst = t._data # lst = t._data
# self.failUnless(t.data.shape == (2,7)) # self.assertTrue(t.data.shape == (2,7))
# self.failUnless(t.data is o27) # self.assertTrue(t.data is o27)
# self.failUnless(t._data is lst) # self.assertTrue(t._data is lst)
# def test_data_badrank0(self): # def test_data_badrank0(self):
# t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0) # t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0)
# try: # try:
# t.data = numpy.ones((2,7,1)) # t.data = numpy.ones((2,7,1))
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_rank) # self.assertTrue(e[0] is TensorType.filter.E_rank)
# try: # try:
# t.data = numpy.ones(1) # t.data = numpy.ones(1)
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_rank) # self.assertTrue(e[0] is TensorType.filter.E_rank)
# def test_data_badrank1(self): # def test_data_badrank1(self):
# t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1) # t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1)
# try: # try:
# t.data = numpy.ones((1,1,1)) # t.data = numpy.ones((1,1,1))
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_rank) # self.assertTrue(e[0] is TensorType.filter.E_rank)
# try: # try:
# t.data = numpy.ones(1) # t.data = numpy.ones(1)
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_rank) # self.assertTrue(e[0] is TensorType.filter.E_rank)
# def test_data_badshape0(self): # def test_data_badshape0(self):
# t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1) # t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1)
# try: # try:
# t.data = numpy.ones((1,2)) # t.data = numpy.ones((1,2))
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_shape) # self.assertTrue(e[0] is TensorType.filter.E_shape)
# try: # try:
# t.data = numpy.ones((0,1)) # t.data = numpy.ones((0,1))
# self.fail() # self.fail()
# except ValueError, e: # except ValueError, e:
# self.failUnless(e[0] is TensorType.filter.E_shape) # self.assertTrue(e[0] is TensorType.filter.E_shape)
# def test_cast0(self): # def test_cast0(self):
# t = TensorType('float32', [0]) # t = TensorType('float32', [0])
# t.data = numpy.random.rand(4) > 0.5 # t.data = numpy.random.rand(4) > 0.5
# self.failUnless(str(t.data.dtype) == t.dtype) # self.assertTrue(str(t.data.dtype) == t.dtype)
# class T_stdlib(unittest.TestCase): # class T_stdlib(unittest.TestCase):
# def test0(self): # def test0(self):
# t = _tensor(1.0) # t = _tensor(1.0)
# tt = t.clone(False) # tt = t.clone(False)
# self.failUnless(t.dtype == tt.dtype) # self.assertTrue(t.dtype == tt.dtype)
# self.failUnless(t.broadcastable is tt.broadcastable) # self.assertTrue(t.broadcastable is tt.broadcastable)
# self.failUnless(tt.data is None) # self.assertTrue(tt.data is None)
# self.failUnless(t.data == 1.0) # self.assertTrue(t.data == 1.0)
# def test0b(self): # def test0b(self):
# t = _tensor(1.0) # t = _tensor(1.0)
# tt = t.clone() # tt = t.clone()
# self.failUnless(t.dtype == tt.dtype) # self.assertTrue(t.dtype == tt.dtype)
# self.failUnless(t.broadcastable is tt.broadcastable) # self.assertTrue(t.broadcastable is tt.broadcastable)
# self.failUnless(tt.data is None) # self.assertTrue(tt.data is None)
# self.failUnless(t.data == 1.0) # self.assertTrue(t.data == 1.0)
# def test1(self): # def test1(self):
# t = _tensor(1.0) # t = _tensor(1.0)
# tt = t.clone(True) # tt = t.clone(True)
# self.failUnless(t.dtype == tt.dtype) # self.assertTrue(t.dtype == tt.dtype)
# self.failUnless(t.broadcastable is tt.broadcastable) # self.assertTrue(t.broadcastable is tt.broadcastable)
# self.failUnless(tt.data == 1.0) # self.assertTrue(tt.data == 1.0)
# self.failUnless(t.data == 1.0) # self.assertTrue(t.data == 1.0)
# self.failUnless(t.data is not tt.data) # self.assertTrue(t.data is not tt.data)
# def test1b(self): # def test1b(self):
# t = _tensor(1.0) # t = _tensor(1.0)
# tt = copy(t) # tt = copy(t)
# self.failUnless(t.dtype == tt.dtype) # self.assertTrue(t.dtype == tt.dtype)
# self.failUnless(t.broadcastable is tt.broadcastable) # self.assertTrue(t.broadcastable is tt.broadcastable)
# self.failUnless(tt.data == 1.0) # self.assertTrue(tt.data == 1.0)
# self.failUnless(t.data == 1.0) # self.assertTrue(t.data == 1.0)
# self.failUnless(t.data is not tt.data) # self.assertTrue(t.data is not tt.data)
class test_grad(unittest.TestCase): class test_grad(unittest.TestCase):
...@@ -3192,23 +3192,23 @@ class test_grad(unittest.TestCase): ...@@ -3192,23 +3192,23 @@ class test_grad(unittest.TestCase):
"""grad: Test passing a single variable param""" """grad: Test passing a single variable param"""
o = test_grad.O() o = test_grad.O()
a1 = o.make_node() a1 = o.make_node()
self.failUnless(o.gval0 is grad(a1.outputs[0], a1.inputs[0])) self.assertTrue(o.gval0 is grad(a1.outputs[0], a1.inputs[0]))
def test_Nparam(self): def test_Nparam(self):
"""grad: Test passing multiple variable params""" """grad: Test passing multiple variable params"""
o = test_grad.O() o = test_grad.O()
a1 = o.make_node() a1 = o.make_node()
g0,g1 = grad(a1.outputs[0], a1.inputs) g0,g1 = grad(a1.outputs[0], a1.inputs)
self.failUnless(o.gval0 is g0) self.assertTrue(o.gval0 is g0)
self.failUnless(o.gval1 is g1) self.assertTrue(o.gval1 is g1)
def test_1None_rval(self): def test_1None_rval(self):
"""grad: Test returning a single zero value from grad""" """grad: Test returning a single zero value from grad"""
o = test_grad.O() o = test_grad.O()
a1 = o.make_node() a1 = o.make_node()
g = grad(a1.outputs[0], a1.outputs[1]) g = grad(a1.outputs[0], a1.outputs[1])
self.failUnless(g.owner.op == fill) self.assertTrue(g.owner.op == fill)
self.failUnless(g.owner.inputs[1].data == 0) self.assertTrue(g.owner.inputs[1].data == 0)
try: try:
grad(a1.outputs[0], 'wtf') grad(a1.outputs[0], 'wtf')
except AttributeError, e: except AttributeError, e:
...@@ -3220,18 +3220,18 @@ class test_grad(unittest.TestCase): ...@@ -3220,18 +3220,18 @@ class test_grad(unittest.TestCase):
o = test_grad.O() o = test_grad.O()
a1 = o.make_node() a1 = o.make_node()
g0,g1,g2 = grad(a1.outputs[0], a1.inputs + [scalar('z')]) g0,g1,g2 = grad(a1.outputs[0], a1.inputs + [scalar('z')])
self.failUnless(o.gval0 is g0) self.assertTrue(o.gval0 is g0)
self.failUnless(o.gval1 is g1) self.assertTrue(o.gval1 is g1)
self.failUnless(g2.owner.op == fill) self.assertTrue(g2.owner.op == fill)
self.failUnless(g2.owner.inputs[1].data == 0) self.assertTrue(g2.owner.inputs[1].data == 0)
def test_zero_gradient_shape(self): def test_zero_gradient_shape(self):
"""Ensure that a zero gradient has the proper shape.""" """Ensure that a zero gradient has the proper shape."""
x = dmatrix() x = dmatrix()
f = theano.function([x], grad(dscalar(), x)) f = theano.function([x], grad(dscalar(), x))
a = numpy.ones((3, 7)) a = numpy.ones((3, 7))
self.failUnless((f(a) == 0).all()) # Zero gradient. self.assertTrue((f(a) == 0).all()) # Zero gradient.
self.failUnless(a.shape == f(a).shape) # With proper shape. self.assertTrue(a.shape == f(a).shape) # With proper shape.
def test_cost_is_scalar(self): def test_cost_is_scalar(self):
'''grad: Test that a non-scalar cost raises a TypeError''' '''grad: Test that a non-scalar cost raises a TypeError'''
...@@ -3257,7 +3257,7 @@ class T_op_cache(unittest.TestCase): ...@@ -3257,7 +3257,7 @@ class T_op_cache(unittest.TestCase):
fn_c_or_py = inplace_func([v], gv) fn_c_or_py = inplace_func([v], gv)
a = numpy.random.rand(5,2).astype(config.floatX) a = numpy.random.rand(5,2).astype(config.floatX)
self.failUnless(numpy.all(fn_py(a) == fn_c_or_py(a))) self.assertTrue(numpy.all(fn_py(a) == fn_c_or_py(a)))
def test_reshape(): def test_reshape():
...@@ -3779,7 +3779,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3779,7 +3779,7 @@ class test_tensordot(unittest.TestCase):
f1 = inplace_func([avec,bvec],c) f1 = inplace_func([avec,bvec],c)
aval = self.rand(5); aval = self.rand(5);
bval = self.rand(5); bval = self.rand(5);
self.failUnless(numpy.tensordot(aval,bval,axes) == \ self.assertTrue(numpy.tensordot(aval,bval,axes) == \
f1(aval,bval)) f1(aval,bval))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3790,7 +3790,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3790,7 +3790,7 @@ class test_tensordot(unittest.TestCase):
f2 = inplace_func([avec,bmat],c) f2 = inplace_func([avec,bmat],c)
aval = self.rand(5); aval = self.rand(5);
bval = self.rand(8,5); bval = self.rand(8,5);
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f2(aval,bval))) f2(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3801,7 +3801,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3801,7 +3801,7 @@ class test_tensordot(unittest.TestCase):
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
aval = self.rand(4,7); aval = self.rand(4,7);
bval = self.rand(7,9); bval = self.rand(7,9);
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f3(aval,bval))) f3(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3812,7 +3812,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3812,7 +3812,7 @@ class test_tensordot(unittest.TestCase):
f4 = inplace_func([atens,bmat],c) f4 = inplace_func([atens,bmat],c)
aval = self.rand(1,2,3,4); aval = self.rand(1,2,3,4);
bval = self.rand(2,3); bval = self.rand(2,3);
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f4(aval,bval))) f4(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3824,14 +3824,14 @@ class test_tensordot(unittest.TestCase): ...@@ -3824,14 +3824,14 @@ class test_tensordot(unittest.TestCase):
f5 = inplace_func([atens,btens],c) f5 = inplace_func([atens,btens],c)
aval = self.rand(4,3,5,2); aval = self.rand(4,3,5,2);
bval = self.rand(3,4,2); bval = self.rand(3,4,2);
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f5(aval,bval))) f5(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
axes = (axes[1],axes[0]) axes = (axes[1],axes[0])
c = tensordot(btens, atens, axes) c = tensordot(btens, atens, axes)
f6 = inplace_func([btens,atens],c) f6 = inplace_func([btens,atens],c)
self.failUnless(numpy.allclose(numpy.tensordot(bval,aval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(bval,aval,axes),
f6(bval,aval))) f6(bval,aval)))
utt.verify_grad(TensorDot(axes), [bval,aval]) utt.verify_grad(TensorDot(axes), [bval,aval])
...@@ -3885,7 +3885,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3885,7 +3885,7 @@ class test_tensordot(unittest.TestCase):
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
aval = self.rand(4,7); aval = self.rand(4,7);
bval = self.rand(7,9); bval = self.rand(7,9);
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f3(aval,bval))) f3(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3898,7 +3898,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3898,7 +3898,7 @@ class test_tensordot(unittest.TestCase):
bval = numpy.random.rand(5,3) bval = numpy.random.rand(5,3)
c = tensordot(amat, bmat, axes) c = tensordot(amat, bmat, axes)
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f3(aval,bval))) f3(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3910,7 +3910,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3910,7 +3910,7 @@ class test_tensordot(unittest.TestCase):
bval = self.rand(4,5,3) bval = self.rand(4,5,3)
c = tensordot(amat, bmat, axes) c = tensordot(amat, bmat, axes)
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f3(aval,bval))) f3(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3923,7 +3923,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3923,7 +3923,7 @@ class test_tensordot(unittest.TestCase):
bval = self.rand(5,4) bval = self.rand(5,4)
c = tensordot(amat, bmat, axes) c = tensordot(amat, bmat, axes)
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
self.failUnless(numpy.allclose(numpy.tensordot(aval,bval,axes), self.assertTrue(numpy.allclose(numpy.tensordot(aval,bval,axes),
f3(aval,bval))) f3(aval,bval)))
utt.verify_grad(TensorDot(axes), [aval,bval]) utt.verify_grad(TensorDot(axes), [aval,bval])
...@@ -3941,8 +3941,8 @@ class test_tensordot(unittest.TestCase): ...@@ -3941,8 +3941,8 @@ class test_tensordot(unittest.TestCase):
f2 = inplace_func([amat,bmat,gzmat],tensordot_grad(((1,),(0,)))(amat, bmat, gzmat)) f2 = inplace_func([amat,bmat,gzmat],tensordot_grad(((1,),(0,)))(amat, bmat, gzmat))
o1=f1(aval,bval,gzval) o1=f1(aval,bval,gzval)
o2=f2(aval,bval,gzval) o2=f2(aval,bval,gzval)
self.failUnless(numpy.allclose(o1[0],o2[0])) self.assertTrue(numpy.allclose(o1[0],o2[0]))
self.failUnless(numpy.allclose(o1[1],o2[1])) self.assertTrue(numpy.allclose(o1[1],o2[1]))
def test_smallest_stack(): def test_smallest_stack():
sx, sy = dscalar(), dscalar() sx, sy = dscalar(), dscalar()
...@@ -4120,7 +4120,7 @@ class test_broadcast(unittest.TestCase): ...@@ -4120,7 +4120,7 @@ class test_broadcast(unittest.TestCase):
def f(): def f():
x = matrix() x = matrix()
addbroadcast(x,2) addbroadcast(x,2)
self.failUnlessRaises(ValueError, f) self.assertRaises(ValueError, f)
def test_unbroadcast_addbroadcast(self): def test_unbroadcast_addbroadcast(self):
""" """
......
...@@ -67,11 +67,11 @@ class t_gemm(TestCase): ...@@ -67,11 +67,11 @@ class t_gemm(TestCase):
#print z_orig, z_after, z, type(z_orig), type(z_after), type(z) #print z_orig, z_after, z, type(z_orig), type(z_after), type(z)
#_approx_eq.debug = 1 #_approx_eq.debug = 1
self.failUnless(_approx_eq(z_after, z)) self.assertTrue(_approx_eq(z_after, z))
if a == 0.0 and b == 1.0: if a == 0.0 and b == 1.0:
return return
else: else:
self.failIf(numpy.all(z_orig == z)) self.assertFalse(numpy.all(z_orig == z))
cmp_linker(copy(z), a, x, y, b, 'c|py') cmp_linker(copy(z), a, x, y, b, 'c|py')
cmp_linker(copy(z), a, x, y, b, 'py') cmp_linker(copy(z), a, x, y, b, 'py')
...@@ -100,7 +100,7 @@ class t_gemm(TestCase): ...@@ -100,7 +100,7 @@ class t_gemm(TestCase):
try: try:
self.cmp(2., 1.0, [3,2,1.], [[1],[2],[3.]], 1.0) self.cmp(2., 1.0, [3,2,1.], [[1],[2],[3.]], 1.0)
except ValueError, e: except ValueError, e:
self.failUnless(e[0] == Gemm.E_rank) self.assertTrue(e[0] == Gemm.E_rank)
return return
self.fail() self.fail()
def test4(self): def test4(self):
...@@ -217,11 +217,11 @@ class t_gemm(TestCase): ...@@ -217,11 +217,11 @@ class t_gemm(TestCase):
#f(z, a, x, y, b) #f(z, a, x, y, b)
f = inplace_func([], gemm_inplace(tz,ta,tx,ty,tb), mode = compile.Mode(optimizer = None, linker=l)) f = inplace_func([], gemm_inplace(tz,ta,tx,ty,tb), mode = compile.Mode(optimizer = None, linker=l))
f() f()
self.failUnless(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z)) self.assertTrue(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z))
f() f()
self.failUnless(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z)) self.assertTrue(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z))
f() f()
self.failUnless(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z)) self.assertTrue(_approx_eq(z_after, tz.get_value(borrow=True)), (z_orig, z_after, z, z_after - z))
#tz.value *= 0 # clear z's value #tz.value *= 0 # clear z's value
y_T = ty.get_value(borrow=True).T y_T = ty.get_value(borrow=True).T
...@@ -230,7 +230,7 @@ class t_gemm(TestCase): ...@@ -230,7 +230,7 @@ class t_gemm(TestCase):
f() f()
# test that the transposed version of multiplication gives same answer # test that the transposed version of multiplication gives same answer
self.failUnless(_approx_eq(z_after, tz.get_value(borrow=True).T)) self.assertTrue(_approx_eq(z_after, tz.get_value(borrow=True).T))
t(C,A,B) t(C,A,B)
t(C.T, A, B) t(C.T, A, B)
...@@ -275,17 +275,17 @@ class t_as_scalar(TestCase): ...@@ -275,17 +275,17 @@ class t_as_scalar(TestCase):
d_b = T.DimShuffle([True, True, True], [0,2,1])(b) d_b = T.DimShuffle([True, True, True], [0,2,1])(b)
d_a2 = T.DimShuffle([], ['x', 'x', 'x'])(a) d_a2 = T.DimShuffle([], ['x', 'x', 'x'])(a)
self.failUnless(_as_scalar(a) == a) self.assertTrue(_as_scalar(a) == a)
self.failUnless(_as_scalar(b) != b) self.assertTrue(_as_scalar(b) != b)
self.failUnless(_as_scalar(d_a) != d_a) self.assertTrue(_as_scalar(d_a) != d_a)
self.failUnless(_as_scalar(d_b) != d_b) self.assertTrue(_as_scalar(d_b) != d_b)
self.failUnless(_as_scalar(d_a2) != d_a2) self.assertTrue(_as_scalar(d_a2) != d_a2)
def test1(self): def test1(self):
"""Test that it fails on nonscalar constants""" """Test that it fails on nonscalar constants"""
a = T.constant(numpy.ones(5)) a = T.constant(numpy.ones(5))
self.failUnless(None == _as_scalar(a)) self.assertTrue(None == _as_scalar(a))
self.failUnless(None == _as_scalar(T.DimShuffle([False], [0,'x'])(a))) self.assertTrue(None == _as_scalar(T.DimShuffle([False], [0,'x'])(a)))
def test2(self): def test2(self):
"""Test that it works on scalar variables""" """Test that it works on scalar variables"""
...@@ -293,20 +293,20 @@ class t_as_scalar(TestCase): ...@@ -293,20 +293,20 @@ class t_as_scalar(TestCase):
d_a = T.DimShuffle([], [])(a) d_a = T.DimShuffle([], [])(a)
d_a2 = T.DimShuffle([], ['x', 'x'])(a) d_a2 = T.DimShuffle([], ['x', 'x'])(a)
self.failUnless(_as_scalar(a) is a) self.assertTrue(_as_scalar(a) is a)
self.failUnless(_as_scalar(d_a) is a) self.assertTrue(_as_scalar(d_a) is a)
self.failUnless(_as_scalar(d_a2) is a) self.assertTrue(_as_scalar(d_a2) is a)
def test3(self): def test3(self):
"""Test that it fails on nonscalar variables""" """Test that it fails on nonscalar variables"""
a = T.dmatrix() a = T.dmatrix()
self.failUnless(None == _as_scalar(a)) self.assertTrue(None == _as_scalar(a))
self.failUnless(None == _as_scalar(T.DimShuffle([False, False], [0,'x', 1])(a))) self.assertTrue(None == _as_scalar(T.DimShuffle([False, False], [0,'x', 1])(a)))
class T_real_matrix(TestCase): class T_real_matrix(TestCase):
def test0(self): def test0(self):
self.failUnless(_is_real_matrix(T.DimShuffle([False,False], [1, 0])(T.dmatrix()))) self.assertTrue(_is_real_matrix(T.DimShuffle([False,False], [1, 0])(T.dmatrix())))
self.failUnless(not _is_real_matrix(T.DimShuffle([False], ['x', 0])(T.dvector()))) self.assertTrue(not _is_real_matrix(T.DimShuffle([False], ['x', 0])(T.dvector())))
def fail(msg): def fail(msg):
print 'FAIL', msg print 'FAIL', msg
......
...@@ -36,7 +36,7 @@ class test_casting(unittest.TestCase): ...@@ -36,7 +36,7 @@ class test_casting(unittest.TestCase):
f = function([compile.In(x, strict = True)], y) f = function([compile.In(x, strict = True)], y)
a = numpy.arange(10, dtype = type1) a = numpy.arange(10, dtype = type1)
b = f(a) b = f(a)
self.failUnless(numpy.all(b == numpy.arange(10, dtype = type2))) self.assertTrue(numpy.all(b == numpy.arange(10, dtype = type2)))
def test_convert_to_complex(self): def test_convert_to_complex(self):
a = value(numpy.ones(3, dtype='complex64')+0.5j) a = value(numpy.ones(3, dtype='complex64')+0.5j)
......
...@@ -29,7 +29,7 @@ class TestRealImag(unittest.TestCase): ...@@ -29,7 +29,7 @@ class TestRealImag(unittest.TestCase):
def test_cast(self): def test_cast(self):
x= zvector() x= zvector()
self.failUnlessRaises(TypeError, cast, x, 'int32') self.assertRaises(TypeError, cast, x, 'int32')
def test_complex(self): def test_complex(self):
rng = numpy.random.RandomState(2333) rng = numpy.random.RandomState(2333)
......
...@@ -81,7 +81,7 @@ class test_Broadcast(unittest.TestCase): ...@@ -81,7 +81,7 @@ class test_Broadcast(unittest.TestCase):
yv = numpy.asarray(numpy.random.rand(*ysh)) yv = numpy.asarray(numpy.random.rand(*ysh))
zv = xv + yv zv = xv + yv
self.failUnless((f(xv, yv) == zv).all()) self.assertTrue((f(xv, yv) == zv).all())
#test CAReduce.infer_shape #test CAReduce.infer_shape
#the Shape op don't implement c_code! #the Shape op don't implement c_code!
...@@ -111,7 +111,7 @@ class test_Broadcast(unittest.TestCase): ...@@ -111,7 +111,7 @@ class test_Broadcast(unittest.TestCase):
f(xv, yv) f(xv, yv)
self.failUnless((xv == zv).all()) self.assertTrue((xv == zv).all())
#test CAReduce.infer_shape #test CAReduce.infer_shape
#the Shape op don't implement c_code! #the Shape op don't implement c_code!
if isinstance(linker,gof.PerformLinker): if isinstance(linker,gof.PerformLinker):
...@@ -238,7 +238,7 @@ class test_CAReduce(unittest.TestCase): ...@@ -238,7 +238,7 @@ class test_CAReduce(unittest.TestCase):
else: else:
self.fail() self.fail()
else: else:
self.failUnless((numpy.abs(f(xv) - zv) < 1e-10).all()) self.assertTrue((numpy.abs(f(xv) - zv) < 1e-10).all())
#test CAReduce.infer_shape #test CAReduce.infer_shape
......
...@@ -51,7 +51,7 @@ class Test_inc_subtensor(unittest.TestCase): ...@@ -51,7 +51,7 @@ class Test_inc_subtensor(unittest.TestCase):
else: else:
expected_result[:,:val_sl2_end] += val_inc expected_result[:,:val_sl2_end] += val_inc
self.failUnless(numpy.array_equal(result, expected_result)) self.assertTrue(numpy.array_equal(result, expected_result))
return return
def test_grad(self): def test_grad(self):
......
...@@ -48,7 +48,7 @@ class Test_incsubtensor(unittest.TestCase): ...@@ -48,7 +48,7 @@ class Test_incsubtensor(unittest.TestCase):
else: else:
expected_result[:,:val_sl2_end] += val_inc expected_result[:,:val_sl2_end] += val_inc
self.failUnless(numpy.array_equal(result, expected_result)) self.assertTrue(numpy.array_equal(result, expected_result))
return return
def test_grad(self): def test_grad(self):
......
...@@ -49,35 +49,35 @@ class test_dimshuffle_lift(unittest.TestCase): ...@@ -49,35 +49,35 @@ class test_dimshuffle_lift(unittest.TestCase):
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(x, (1, 0)), (1, 0)) e = ds(ds(x, (1, 0)), (1, 0))
g = Env([x], [e]) g = Env([x], [e])
self.failUnless(str(g) == "[DimShuffle{1,0}(DimShuffle{1,0}(x))]") self.assertTrue(str(g) == "[DimShuffle{1,0}(DimShuffle{1,0}(x))]")
dimshuffle_lift.optimize(g) dimshuffle_lift.optimize(g)
self.failUnless(str(g) == "[x]") self.assertTrue(str(g) == "[x]")
def test_merge2(self): def test_merge2(self):
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(x, (1, 'x', 0)), (2, 0, 'x', 1)) e = ds(ds(x, (1, 'x', 0)), (2, 0, 'x', 1))
g = Env([x], [e]) g = Env([x], [e])
self.failUnless(str(g) == "[DimShuffle{2,0,x,1}(DimShuffle{1,x,0}(x))]", str(g)) self.assertTrue(str(g) == "[DimShuffle{2,0,x,1}(DimShuffle{1,x,0}(x))]", str(g))
dimshuffle_lift.optimize(g) dimshuffle_lift.optimize(g)
self.failUnless(str(g) == "[DimShuffle{0,1,x,x}(x)]", str(g)) self.assertTrue(str(g) == "[DimShuffle{0,1,x,x}(x)]", str(g))
def test_elim3(self): def test_elim3(self):
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(ds(x, (0, 'x', 1)), (2, 0, 'x', 1)), (1, 0)) e = ds(ds(ds(x, (0, 'x', 1)), (2, 0, 'x', 1)), (1, 0))
g = Env([x], [e]) g = Env([x], [e])
self.failUnless(str(g) == "[DimShuffle{1,0}(DimShuffle{2,0,x,1}(DimShuffle{0,x,1}(x)))]", str(g)) self.assertTrue(str(g) == "[DimShuffle{1,0}(DimShuffle{2,0,x,1}(DimShuffle{0,x,1}(x)))]", str(g))
dimshuffle_lift.optimize(g) dimshuffle_lift.optimize(g)
self.failUnless(str(g) == "[x]", str(g)) self.assertTrue(str(g) == "[x]", str(g))
def test_lift(self): def test_lift(self):
x, y, z = inputs([False]*1, [False]*2, [False]*3) x, y, z = inputs([False]*1, [False]*2, [False]*3)
e = x + y + z e = x + y + z
g = Env([x, y, z], [e]) g = Env([x, y, z], [e])
self.failUnless(str(g) == ("[Elemwise{add,no_inplace}(" self.assertTrue(str(g) == ("[Elemwise{add,no_inplace}("
"InplaceDimShuffle{x,0,1}(Elemwise{add,no_inplace}" "InplaceDimShuffle{x,0,1}(Elemwise{add,no_inplace}"
"(InplaceDimShuffle{x,0}(x), y)), z)]"), str(g)) "(InplaceDimShuffle{x,0}(x), y)), z)]"), str(g))
dimshuffle_lift.optimize(g) dimshuffle_lift.optimize(g)
self.failUnless(str(g) == ("[Elemwise{add,no_inplace}(Elemwise" self.assertTrue(str(g) == ("[Elemwise{add,no_inplace}(Elemwise"
"{add,no_inplace}(InplaceDimShuffle{x,x,0}(x), InplaceDimShuffle" "{add,no_inplace}(InplaceDimShuffle{x,x,0}(x), InplaceDimShuffle"
"{x,0,1}(y)), z)]"), str(g)) "{x,0,1}(y)), z)]"), str(g))
...@@ -1699,7 +1699,7 @@ class test_assert(unittest.TestCase): ...@@ -1699,7 +1699,7 @@ class test_assert(unittest.TestCase):
y=T.scalar() y=T.scalar()
f = theano.function([x,y],theano.tensor.opt.assert_(x,T.eq(x,y))) f = theano.function([x,y],theano.tensor.opt.assert_(x,T.eq(x,y)))
f(1,1) f(1,1)
self.failUnlessRaises(AssertionError, f, 1,0) self.assertRaises(AssertionError, f, 1,0)
def test1(self): def test1(self):
#remove assert that are always true #remove assert that are always true
...@@ -1743,7 +1743,7 @@ class test_assert(unittest.TestCase): ...@@ -1743,7 +1743,7 @@ class test_assert(unittest.TestCase):
x=T.scalar() x=T.scalar()
y=T.scalar() y=T.scalar()
f = theano.function([x,y],theano.tensor.opt.assert_(x,y,0),mode=mode) f = theano.function([x,y],theano.tensor.opt.assert_(x,y,0),mode=mode)
self.failUnlessRaises(AssertionError, f, 1,0) self.assertRaises(AssertionError, f, 1,0)
topo=f.maker.env.toposort() topo=f.maker.env.toposort()
assert len(topo)==2 assert len(topo)==2
assert len(topo[0].inputs)==3 assert len(topo[0].inputs)==3
......
...@@ -18,7 +18,7 @@ class T_XlogX(unittest.TestCase): ...@@ -18,7 +18,7 @@ class T_XlogX(unittest.TestCase):
x = as_tensor_variable([1, 0]) x = as_tensor_variable([1, 0])
y = xlogx(x) y = xlogx(x)
f = theano.function([], [y]) f = theano.function([], [y])
self.failUnless(numpy.all(f() == numpy.asarray([0, 0.]))) self.assertTrue(numpy.all(f() == numpy.asarray([0, 0.])))
def test1(self): def test1(self):
# class Dummy(object): # class Dummy(object):
# def make_node(self, a): # def make_node(self, a):
...@@ -36,7 +36,7 @@ class T_XlogY0(unittest.TestCase): ...@@ -36,7 +36,7 @@ class T_XlogY0(unittest.TestCase):
y = as_tensor_variable([1, 0]) y = as_tensor_variable([1, 0])
z = xlogy0(x, y) z = xlogy0(x, y)
f = theano.function([], z) f = theano.function([], z)
self.failUnless(numpy.all(f() == numpy.asarray([0, 0.]))) self.assertTrue(numpy.all(f() == numpy.asarray([0, 0.])))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -30,7 +30,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -30,7 +30,7 @@ class test_grad_sources_inputs(unittest.TestCase):
try: try:
_grad_sources_inputs([(a.out, 1)], None) _grad_sources_inputs([(a.out, 1)], None)
except ValueError, e: except ValueError, e:
self.failUnless(e[0] is gradient._msg_retType) self.assertTrue(e[0] is gradient._msg_retType)
return return
self.fail() self.fail()
def test_retNone1_b(self): def test_retNone1_b(self):
...@@ -44,7 +44,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -44,7 +44,7 @@ class test_grad_sources_inputs(unittest.TestCase):
i = gof.generic() i = gof.generic()
a = retNone().make_node(i) a = retNone().make_node(i)
g = _grad_sources_inputs([(a.out, 1)], None) g = _grad_sources_inputs([(a.out, 1)], None)
self.failUnless(not i in g) self.assertTrue(not i in g)
def test_wrong_rval_len1(self): def test_wrong_rval_len1(self):
"""Test that it is not ok to return the wrong number of gradients""" """Test that it is not ok to return the wrong number of gradients"""
...@@ -63,7 +63,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -63,7 +63,7 @@ class test_grad_sources_inputs(unittest.TestCase):
try: try:
g = _grad_sources_inputs([(a2.out, 1)], None) g = _grad_sources_inputs([(a2.out, 1)], None)
except ValueError, e: except ValueError, e:
self.failUnless(e[0] is gradient._msg_badlen) self.assertTrue(e[0] is gradient._msg_badlen)
return return
self.fail() self.fail()
...@@ -95,7 +95,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -95,7 +95,7 @@ class test_grad_sources_inputs(unittest.TestCase):
return gval, return gval,
a1 = O().make_node() a1 = O().make_node()
g = _grad_sources_inputs([(a1.outputs[0], 1)], None) g = _grad_sources_inputs([(a1.outputs[0], 1)], None)
self.failUnless(g[a1.inputs[0]] is gval) self.assertTrue(g[a1.inputs[0]] is gval)
def test_1in_Nout(self): def test_1in_Nout(self):
"""Test grad is called correctly for a 1-to-many op""" """Test grad is called correctly for a 1-to-many op"""
...@@ -111,7 +111,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -111,7 +111,7 @@ class test_grad_sources_inputs(unittest.TestCase):
return gval, return gval,
a1 = O().make_node() a1 = O().make_node()
g = _grad_sources_inputs([(a1.outputs[0], 1)], None) g = _grad_sources_inputs([(a1.outputs[0], 1)], None)
self.failUnless(g[a1.inputs[0]] is gval) self.assertTrue(g[a1.inputs[0]] is gval)
def test_Nin_1out(self): def test_Nin_1out(self):
"""Test grad is called correctly for a many-to-1 op""" """Test grad is called correctly for a many-to-1 op"""
gval0 = gof.generic() gval0 = gof.generic()
...@@ -127,8 +127,8 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -127,8 +127,8 @@ class test_grad_sources_inputs(unittest.TestCase):
return (gval0, gval1) return (gval0, gval1)
a1 = O().make_node() a1 = O().make_node()
g = _grad_sources_inputs([(a1.outputs[0], 1)], None) g = _grad_sources_inputs([(a1.outputs[0], 1)], None)
self.failUnless(g[a1.inputs[0]] is gval0) self.assertTrue(g[a1.inputs[0]] is gval0)
self.failUnless(g[a1.inputs[1]] is gval1) self.assertTrue(g[a1.inputs[1]] is gval1)
def test_Nin_Nout(self): def test_Nin_Nout(self):
"""Test grad is called correctly for a many-to-many op""" """Test grad is called correctly for a many-to-many op"""
gval0 = gof.generic() gval0 = gof.generic()
...@@ -142,8 +142,8 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -142,8 +142,8 @@ class test_grad_sources_inputs(unittest.TestCase):
return gval0, gval1 return gval0, gval1
a1 = O().make_node() a1 = O().make_node()
g = _grad_sources_inputs([(a1.outputs[0], 1)], None) g = _grad_sources_inputs([(a1.outputs[0], 1)], None)
self.failUnless(g[a1.inputs[0]] is gval0) self.assertTrue(g[a1.inputs[0]] is gval0)
self.failUnless(g[a1.inputs[1]] is gval1) self.assertTrue(g[a1.inputs[1]] is gval1)
def test_some_None_ograds(self): def test_some_None_ograds(self):
"""Test grad is called when some output gradients are None""" """Test grad is called when some output gradients are None"""
class O(gof.op.Op): class O(gof.op.Op):
...@@ -157,7 +157,7 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -157,7 +157,7 @@ class test_grad_sources_inputs(unittest.TestCase):
i = gof.generic() i = gof.generic()
a1 = O(self).make_node(i) a1 = O(self).make_node(i)
g = grad_sources_inputs([(a1.outputs[0], 1)], None, warn_type=False) g = grad_sources_inputs([(a1.outputs[0], 1)], None, warn_type=False)
self.failUnless(g[i] is 1) self.assertTrue(g[i] is 1)
def test_some_None_igrads(self): def test_some_None_igrads(self):
"""Test that traversal works properly when an op return some None""" """Test that traversal works properly when an op return some None"""
...@@ -179,12 +179,12 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -179,12 +179,12 @@ class test_grad_sources_inputs(unittest.TestCase):
a1 = O(self, True).make_node(i,j) a1 = O(self, True).make_node(i,j)
a2 = O(self, True).make_node(a1.outputs[1], k) a2 = O(self, True).make_node(a1.outputs[1], k)
g = grad_sources_inputs([(a2.outputs[0], 1)], None, warn_type=False) g = grad_sources_inputs([(a2.outputs[0], 1)], None, warn_type=False)
self.failUnless(g[i] is 1 and j not in g and k not in g) self.assertTrue(g[i] is 1 and j not in g and k not in g)
a1 = O(self, True).make_node(i,j) a1 = O(self, True).make_node(i,j)
a2 = O(self, True).make_node(k, a1.outputs[1]) a2 = O(self, True).make_node(k, a1.outputs[1])
g = _grad_sources_inputs([(a2.outputs[0], 1)], None) g = _grad_sources_inputs([(a2.outputs[0], 1)], None)
self.failUnless(g[k] is 1 and i not in g and j not in g) self.assertTrue(g[k] is 1 and i not in g and j not in g)
def test_inputs(self): def test_inputs(self):
"""Test that passing inputs shortens the traversal""" """Test that passing inputs shortens the traversal"""
...@@ -211,12 +211,12 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -211,12 +211,12 @@ class test_grad_sources_inputs(unittest.TestCase):
a2 = O(self, True).make_node(k,a1.outputs[1]) a2 = O(self, True).make_node(k,a1.outputs[1])
g = _grad_sources_inputs([(a2.outputs[0], 1), (a1.outputs[1],4), g = _grad_sources_inputs([(a2.outputs[0], 1), (a1.outputs[1],4),
(a1.outputs[0], 3), (a1.outputs[0], 3)], a1.outputs) (a1.outputs[0], 3), (a1.outputs[0], 3)], a1.outputs)
self.failUnless(g[a2.inputs[0]] == 1) self.assertTrue(g[a2.inputs[0]] == 1)
self.failUnless(g[a2.inputs[1]] == 5) self.assertTrue(g[a2.inputs[1]] == 5)
self.failUnless(g[a1.outputs[0]] == 6) self.assertTrue(g[a1.outputs[0]] == 6)
self.failUnless(g[a1.outputs[1]] == 5) self.assertTrue(g[a1.outputs[1]] == 5)
self.failUnless(a1.inputs[0] not in g) self.assertTrue(a1.inputs[0] not in g)
self.failUnless(a1.inputs[1] not in g) self.assertTrue(a1.inputs[1] not in g)
def test_multiple_sources(self): def test_multiple_sources(self):
"""Test that passing multiple sources works""" """Test that passing multiple sources works"""
...@@ -243,12 +243,12 @@ class test_grad_sources_inputs(unittest.TestCase): ...@@ -243,12 +243,12 @@ class test_grad_sources_inputs(unittest.TestCase):
a2 = O(self,True).make_node(k,a1.outputs[1]) a2 = O(self,True).make_node(k,a1.outputs[1])
g = _grad_sources_inputs([(a2.outputs[0], 1), (a1.outputs[1],4), g = _grad_sources_inputs([(a2.outputs[0], 1), (a1.outputs[1],4),
(a1.outputs[0], 3), (a1.outputs[0], 3)], None) (a1.outputs[0], 3), (a1.outputs[0], 3)], None)
self.failUnless(g[a2.inputs[0]] == 1) self.assertTrue(g[a2.inputs[0]] == 1)
self.failUnless(g[a2.inputs[1]] == 5) self.assertTrue(g[a2.inputs[1]] == 5)
self.failUnless(g[a1.outputs[0]] == 6) self.assertTrue(g[a1.outputs[0]] == 6)
self.failUnless(g[a1.outputs[1]] == 5) self.assertTrue(g[a1.outputs[1]] == 5)
self.failUnless(g[a1.inputs[0]] == 6) self.assertTrue(g[a1.inputs[0]] == 6)
self.failUnless(g[a1.inputs[1]] == 11) self.assertTrue(g[a1.inputs[1]] == 11)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -106,7 +106,7 @@ class T_extending(unittest.TestCase): ...@@ -106,7 +106,7 @@ class T_extending(unittest.TestCase):
assert f(5.6, 6.7) == 37.519999999999996 assert f(5.6, 6.7) == 37.519999999999996
x = double('x') x = double('x')
self.failUnlessRaises(AttributeError, mul, x, 2) self.assertRaises(AttributeError, mul, x, 2)
def make_node(x, y): def make_node(x, y):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论