def test_zero_columns_assert(self): A = sps.csr_matrix(np.array([[0, 0, 0], [1, 0, 0], [0, 0, 3]])) try: sparse_mat.zero_columns(A, 1) except ValueError: return None self.assertTrue(False)
def zero_1_column(self): A = sps.csc_matrix((np.array([1, 2, 3]), (np.array( [0, 2, 1]), np.array([0, 1, 2]))), shape=(3, 3)) sparse_mat.zero_columns(A, 0) assert np.all(A.A == np.array([[0, 0, 0], [0, 0, 3], [0, 2, 0]])) assert A.nnz == 3 assert A.getformat() == 'csc'
def zero_2_columns(self): A = sps.csc_matrix( (np.array([1, 2, 3]), (np.array([0, 2, 1]), np.array([0, 1, 2]))), shape=(3, 3), ) sparse_mat.zero_columns(A, np.array([0, 2])) self.assertTrue(np.all(A.A == np.array([[0, 0, 0], [0, 0, 0], [0, 2, 0]]))) self.assertTrue(A.nnz == 3) self.assertTrue(A.getformat() == "csc")
def test_zero_columns(self): # Test slicing of csr_matrix A = sps.csc_matrix(np.array([[0, 0, 0], [1, 0, 0], [0, 0, 3]])) A0_t = sps.csc_matrix(np.array([[0, 0, 0], [0, 0, 0], [0, 0, 3]])) A2_t = sps.csc_matrix(np.array([[0, 0, 0], [1, 0, 0], [0, 0, 0]])) A0_2_t = sps.csc_matrix(np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])) A0 = A.copy() A2 = A.copy() A0_2 = A.copy() sparse_mat.zero_columns(A0, np.array([0], dtype=int)) sparse_mat.zero_columns(A2, 2) sparse_mat.zero_columns(A0_2, np.array([0, 1, 2])) assert np.sum(A0 != A0_t) == 0 assert np.sum(A2 != A2_t) == 0 assert np.sum(A0_2 != A0_2_t) == 0