# Path: megaman/relaxation/tests/utils.py
# def generate_toy_laplacian(n=1000):
#     neighbor_counts = 10
#     adjacency_mat = np.zeros((n,n))
#     for i in range(n):
#         x = np.ones(neighbor_counts,dtype=np.int32)*i
#         y = np.random.choice(n, neighbor_counts, replace=False)
#         adjacency_mat[(x,y)] = 1
# 
#     np.fill_diagonal(adjacency_mat,0)
#     adjacency_mat = (adjacency_mat.T + adjacency_mat) / 2
#     degree = np.sum(adjacency_mat,axis=1)
#     degree_mat = np.diag(degree)
# 
#     return sp.sparse.csc_matrix(degree_mat - adjacency_mat)


from megaman.relaxation.precomputed import *
from .utils import generate_toy_laplacian

    def test_pairs(self):
        np.testing.assert_array_equal(
            self.pairs, self.correct_pairs,
            err_msg='Sorted pairs should be the same.'
        )

    def test_A(self):
        testing_S = self.A.dot(self.Y)
        np.testing.assert_allclose(
            testing_S, self.correct_S,
            err_msg='A*y should be the same as yj-yi for all j>i'
        )

    def _test_ATAinv(self):
        # TODO: why this test will running out of the memory?
        ATAinv = np.linalg.pinv(self.A.T.dot(self.A).todense())
        S = self.A.dot(self.Y)
        testing_Y = ATAinv.dot(self.A.T).dot(S)
        np.testing.assert_allclose(
            testing_Y, self.Y,
            err_msg='ATAinv * AT * S should be the same as original Y'
        )

    def _test_Rk(self):
        # TODO: Need to understand what Rk means.
        pass

class TestAkRkNbkFromToyLaplacian(BaseTestARkNeighbors):
    def generate_laplacian(self):

# Path: megaman/relaxation/tests/utils.py
# def generate_toy_laplacian(n=1000):
#     neighbor_counts = 10
#     adjacency_mat = np.zeros((n,n))
#     for i in range(n):
#         x = np.ones(neighbor_counts,dtype=np.int32)*i
#         y = np.random.choice(n, neighbor_counts, replace=False)
#         adjacency_mat[(x,y)] = 1
# 
#     np.fill_diagonal(adjacency_mat,0)
#     adjacency_mat = (adjacency_mat.T + adjacency_mat) / 2
#     degree = np.sum(adjacency_mat,axis=1)
#     degree_mat = np.diag(degree)
# 
#     return sp.sparse.csc_matrix(degree_mat - adjacency_mat)


# Path: megaman/relaxation/tests/test_precomputed_S.py
from megaman.relaxation.precomputed import *
from .utils import generate_toy_laplacian


    def test_pairs(self):
        np.testing.assert_array_equal(
            self.pairs, self.correct_pairs,
            err_msg='Sorted pairs should be the same.'
        )

    def test_A(self):
        testing_S = self.A.dot(self.Y)
        np.testing.assert_allclose(
            testing_S, self.correct_S,
            err_msg='A*y should be the same as yj-yi for all j>i'
        )

    def _test_ATAinv(self):
        # TODO: why this test will running out of the memory?
        ATAinv = np.linalg.pinv(self.A.T.dot(self.A).todense())
        S = self.A.dot(self.Y)
        testing_Y = ATAinv.dot(self.A.T).dot(S)
        np.testing.assert_allclose(
            testing_Y, self.Y,
            err_msg='ATAinv * AT * S should be the same as original Y'
        )

    def _test_Rk(self):
        # TODO: Need to understand what Rk means.
        pass

class TestAkRkNbkFromToyLaplacian(BaseTestARkNeighbors):
    def generate_laplacian(self):

        return generate_toy_laplacian(n=200)