def test_same_num_iter_all(self): M = to_sparse(self.A) x0 = self.x0.copy() res_s = iterative(M, self.b, x0, self.acc, self.omega) x0 = self.x0.copy() res = iterative(self.A, self.b, x0, self.acc, self.omega) self.assertTrue(res_s['j_num_iter'] == res['j_num_iter']) self.assertTrue(res_s['gs_num_iter'] == res['gs_num_iter']) self.assertTrue(res_s['sor_num_iter'] == res['sor_num_iter'])
def test_same_solutions_sparse(self): M = to_sparse(self.A) x0 = self.x0.copy() x_j, _ = iterative_jacobi(M, self.b, x0, self.acc) x0 = self.x0.copy() x_gs, _ = iterative_gauss_seidel(M, self.b, x0, self.acc) x0 = self.x0.copy() x_sor, _ = iterative_sor(M, self.b, x0, self.acc, self.omega) assert_array_almost_equal(x_j, x_gs) assert_array_almost_equal(x_gs, x_sor)
def test_correct_solution_sparse(self): x_expected = np.array([1, 1, 1, 1]) M = to_sparse(self.A) res = iterative(M, self.b, self.x0, self.acc, self.omega) assert_array_almost_equal(x_expected, res['x'])
def test_num_iter_sparse(self): M = to_sparse(self.A) res = iterative(M, self.b, self.x0, self.acc, self.omega) self.assertTrue(res['j_num_iter'] > res['gs_num_iter']) self.assertTrue(res['gs_num_iter'] > res['sor_num_iter'])
def test_construct_M(self): M_expected = np.array([[0, 2, -1], [-1, 2, -1], [-1, 2, -1], [-1, 2, 0]]) M = to_sparse(self.A) assert_array_equal(M_expected, M)
def test_is_sparse(self): self.assertFalse(_is_sparse(self.A)) M = to_sparse(self.A) self.assertTrue(_is_sparse(M))
def test_dot_sparse(self): x = np.array([1, 1, 1, 1]) M = to_sparse(self.A) expected_b = _dot_sparse(M, x) assert_array_equal(expected_b, self.b)