Mentions légales du service

Skip to content
Snippets Groups Projects
Commit f21bc746 authored by hhakim's avatar hhakim
Browse files

Factor test_basis and test_basis_py into verif_basis.

parent ee4c05a1
No related branches found
No related tags found
No related merge requests found
...@@ -24,13 +24,7 @@ class TestPoly(unittest.TestCase): ...@@ -24,13 +24,7 @@ class TestPoly(unittest.TestCase):
self.L @= self.L.H self.L @= self.L.H
self.K = 5 self.K = 5
def test_basis_py(self): def verif_basis(self, d, F, K, L):
print("Test basis(impl='py')")
d = self.d
L = self.L
K = self.K
density = self.density
F = basis(L, K, 'chebyshev', dev=self.dev, impl='py')
# assert the dimensions are consistent to L # assert the dimensions are consistent to L
self.assertEqual(F.shape[0], (K+1)*L.shape[0]) self.assertEqual(F.shape[0], (K+1)*L.shape[0])
self.assertEqual(F.shape[1], L.shape[0]) self.assertEqual(F.shape[1], L.shape[0])
...@@ -63,6 +57,14 @@ class TestPoly(unittest.TestCase): ...@@ -63,6 +57,14 @@ class TestPoly(unittest.TestCase):
zero_part = degn_fac[n*d:, :-2*d] zero_part = degn_fac[n*d:, :-2*d]
self.assertTrue(np.linalg.norm(zero_part) == 0) self.assertTrue(np.linalg.norm(zero_part) == 0)
def test_basis_py(self):
print("Test basis(impl='py')")
d = self.d
L = self.L
K = self.K
density = self.density
F = basis(L, K, 'chebyshev', dev=self.dev, impl='py')
self.verif_basis(d, F, K, L)
def test_basis(self): def test_basis(self):
print("Test basis(impl='native')") print("Test basis(impl='native')")
...@@ -71,38 +73,7 @@ class TestPoly(unittest.TestCase): ...@@ -71,38 +73,7 @@ class TestPoly(unittest.TestCase):
K = self.K K = self.K
density = self.density density = self.density
F = basis(L, K, 'chebyshev', dev=self.dev, impl='native') F = basis(L, K, 'chebyshev', dev=self.dev, impl='native')
# assert the dimensions are consistent to L self.verif_basis(d, F, K, L)
self.assertEqual(F.shape[0], (K+1)*L.shape[0])
self.assertEqual(F.shape[1], L.shape[0])
# assert the 0-degree polynomial matrix is the identity
last_fac = F.factors(F.numfactors()-1).toarray()
Id = np.eye(d)
self.assertTrue(np.allclose(Id, last_fac))
if K >= 1:
# assert the 1-degree polynomial matrix is in the form [Id ; L]
deg1_fac = F.factors(F.numfactors()-2).toarray()
self.assertTrue(np.allclose(deg1_fac[:d, :], Id))
self.assertTrue(np.allclose(deg1_fac[d:2*d, :], L.toarray()))
if K >= 2:
# assert the 2-degree polynomial matrix is in the form [Id ; [-Id, L]]
I2d = np.eye(2*d)
deg2_fac = F.factors(F.numfactors()-3).toarray()
self.assertTrue(np.allclose(deg2_fac[:2*d, :], I2d))
self.assertTrue(np.allclose(deg2_fac[2*d:, :d], -Id))
self.assertTrue(np.allclose(deg2_fac[2*d:, d:], 2*L.toarray()))
if K >= 3:
# assert the n-degree polynomial matrix is in the form
# [I_nd ; [0 , -Id, 2L]]
for n in range(3, K):
Ind = np.eye(n*d)
degn_fac = F.factors(F.numfactors()-n-1).toarray()
self.assertTrue(np.allclose(degn_fac[:n*d, :], Ind))
self.assertTrue(np.allclose(degn_fac[n*d:, -2*d:-d], -Id))
self.assertTrue(np.allclose(degn_fac[n*d:, -d:],
2*L.toarray()))
zero_part = degn_fac[n*d:, :-2*d]
self.assertTrue(np.linalg.norm(zero_part) == 0)
def test_basisT0(self): def test_basisT0(self):
print("Test basis(T0)") print("Test basis(T0)")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment