def test_larger_row_echelon_form(self): # create matrix test_mat = sp.lil_matrix((6, 10), dtype=np.int8) test_mat.rows = [[6, 9], [5, 6, 9], [0, 2, 6, 7], [2, 3, 6, 8], [0, 1, 5], [4, 5, 6, 7, 9]] test_mat.data = [[1]*len(row) for row in test_mat.rows] # row echelon form test_mat_ref, rank = ref_mod2(test_mat.copy(), augment=1, eliminate=False) # verify rank self.assertEqual(rank, 6) sol = backsubstitute_mod2(test_mat_ref) self.assertEqual(sol, [6, 2]) colsum = sp.lil_matrix((6, 1), dtype=np.int8) for n in sol: colsum += test_mat[:, n] colsum.data = [[x % 2 for x in row] for row in colsum.data] self.assertFalse(any(colsum != test_mat.getcol(-1)))
def test_independent_set_larger(self): # create matrix test_mat = sp.lil_matrix((6, 10), dtype=np.int8) test_mat.rows = [[0, 1, 8], [1, 5], [0, 2, 4], [9], [0, 6], [0, 2, 6, 8]] test_mat.data = [[1]*len(row) for row in test_mat.rows] # row echelon form test_mat_ref, rank = ref_mod2(test_mat.copy(), augment=1, eliminate=True) # verify rank self.assertEqual(rank, 5) sol = backsubstitute_mod2(test_mat_ref) self.assertEqual(sol, [9])
def test_independent_set_small(self): # create matrix test_mat = sp.lil_matrix((3, 5), dtype=np.int8) test_mat.rows = [[0, 1, 4], [1, 3, 4], [4]] test_mat.data = [[1]*len(row) for row in test_mat.rows] # row echelon form test_mat_ref, rank = ref_mod2(test_mat.copy(), augment=1, eliminate=False) # verify rank self.assertEqual(rank, 2) sol = backsubstitute_mod2(test_mat_ref) self.assertEqual(sol, [4, 1])
def test_row_echelon_form_all(self): # create matrix test_mat = sp.lil_matrix((4, 5), dtype=np.int8) test_mat.rows = [[2, 4], [0, 4], [3, 4], [1, 4]] test_mat.data = [[1]*len(row) for row in test_mat.rows] # row echelon form test_mat_ref, rank = ref_mod2(test_mat.copy(), augment=1, eliminate=False) # verify rank self.assertEqual(rank, 4) sol = backsubstitute_mod2(test_mat_ref) self.assertEqual(sol, [3, 2, 1, 0]) colsum = sp.lil_matrix((4, 1), dtype=np.int8) for n in sol: colsum += test_mat[:, n] self.assertFalse(any(colsum != test_mat.getcol(-1)))