def test_sparse_symmetric_reverse_permute(): "Sparse: Symmetric Reverse Permute" # CSR version A = rand_dm(25, 0.5) perm = np.random.permutation(25) x = sp_permute(A.data, perm, perm) B = sp_reverse_permute(x, perm, perm) assert_equal((A.full() - B.toarray()).all(), 0) # CSC version B = A.data.tocsc() perm = np.random.permutation(25) x = sp_permute(B, perm, perm) B = sp_reverse_permute(x, perm, perm) assert_equal((A.full() - B.toarray()).all(), 0)
def test_sparse_nonsymmetric_reverse_permute(): "Sparse: Nonsymmetric Reverse Permute" # CSR square array check A = rand_dm(25, 0.5) rperm = np.random.permutation(25) cperm = np.random.permutation(25) x = sp_permute(A.data, rperm, cperm) B = sp_reverse_permute(x, rperm, cperm) assert_equal((A.full() - B.toarray()).all(), 0) # CSC square array check A = rand_dm(25, 0.5) rperm = np.random.permutation(25) cperm = np.random.permutation(25) B = A.data.tocsc() x = sp_permute(B, rperm, cperm) B = sp_reverse_permute(x, rperm, cperm) assert_equal((A.full() - B.toarray()).all(), 0) # CSR column vector check A = coherent(25, 1) rperm = np.random.permutation(25) x = sp_permute(A.data, rperm, []) B = sp_reverse_permute(x, rperm, []) assert_equal((A.full() - B.toarray()).all(), 0) # CSC column vector check A = coherent(25, 1) rperm = np.random.permutation(25) B = A.data.tocsc() x = sp_permute(B, rperm, []) B = sp_reverse_permute(x, rperm, []) assert_equal((A.full() - B.toarray()).all(), 0) # CSR row vector check A = coherent(25, 1).dag() cperm = np.random.permutation(25) x = sp_permute(A.data, [], cperm) B = sp_reverse_permute(x, [], cperm) assert_equal((A.full() - B.toarray()).all(), 0) # CSC row vector check A = coherent(25, 1).dag() cperm = np.random.permutation(25) B = A.data.tocsc() x = sp_permute(B, [], cperm) B = sp_reverse_permute(x, [], cperm) assert_equal((A.full() - B.toarray()).all(), 0)