small PEP-8 changes

This commit is contained in:
Thomas McColgan 2015-06-30 11:23:21 +02:00 committed by Tennessee Leeuwenburg
parent b48e39aafd
commit 4956ed9e97

@ -2,11 +2,12 @@ import unittest
import numpy as np import numpy as np
from theano import tensor as T from theano import tensor as T
class TestConstraints(unittest.TestCase): class TestConstraints(unittest.TestCase):
def setUp(self): def setUp(self):
self.some_values = [0.1,0.5,3,8,1e-7] self.some_values = [0.1, 0.5, 3, 8, 1e-7]
self.example_array = np.random.random((100,100))*100. - 50. self.example_array = np.random.random((100, 100)) * 100. - 50.
self.example_array[0,0] = 0. # 0 could possibly cause trouble self.example_array[0, 0] = 0. # 0 could possibly cause trouble
def test_maxnorm(self): def test_maxnorm(self):
from keras.constraints import maxnorm from keras.constraints import maxnorm
@ -14,27 +15,28 @@ class TestConstraints(unittest.TestCase):
for m in self.some_values: for m in self.some_values:
norm_instance = maxnorm(m) norm_instance = maxnorm(m)
normed = norm_instance(self.example_array) normed = norm_instance(self.example_array)
assert(np.all(normed.eval() < m)) assert (np.all(normed.eval() < m))
def test_nonneg(self): def test_nonneg(self):
from keras.constraints import nonneg from keras.constraints import nonneg
normed = nonneg(self.example_array) normed = nonneg(self.example_array)
assert(np.all(np.min(normed.eval(),axis=1) == 0.)) assert (np.all(np.min(normed.eval(), axis=1) == 0.))
def test_identity(self): def test_identity(self):
from keras.constraints import identity from keras.constraints import identity
normed = identity(self.example_array) normed = identity(self.example_array)
assert(np.all(normed == self.example_array)) assert (np.all(normed == self.example_array))
def test_unitnorm(self): def test_unitnorm(self):
from keras.constraints import unitnorm from keras.constraints import unitnorm
normed = unitnorm(self.example_array) normed = unitnorm(self.example_array)
self.assertAlmostEqual( self.assertAlmostEqual(
np.max(np.abs(np.sqrt(np.sum(normed.eval()**2,axis=1))-1.)) np.max(np.abs(np.sqrt(np.sum(normed.eval() ** 2, axis=1)) - 1.))
,0.) , 0.)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()