def test_ForwardEliminationZeroColumnMulti(self): multi_pool = Pool(3) ge.enableMultiprocessing(multi_pool) test_arr = np.array([[3, 0, 0, 1], [3, 0, 1, 1], [0, 0, 1, 1]], float) expected = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy) self.assertTrue(len(res) == 4) self.assertTrue(np.array_equiv(arr_cpy, expected)) multi_pool.close()
def test_SimpleEliminationMulti(self): multi_pool = Pool(3) ge.enableMultiprocessing(multi_pool) test_arr = np.array([[3, 0, 1], [3, 1, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy) self.assertTrue(res is not None) self.assertTrue(len(res) == 2) self.assertTrue( np.array_equiv(arr_cpy, np.array([[1, 0, 1 / 3], [0, 1, 0]], float))) multi_pool.close()
def test_FullEliminationMulti(self): multi_pool = Pool(3) ge.enableMultiprocessing(multi_pool) test_arr = np.array([[21, 16, 13], [21, 18, 38], [24, 24, 6]], float) expected = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy, True) expected = np.around(expected, 13) arr_cpy = np.around(arr_cpy, 13) self.assertEqual(len(res), 5) self.assertTrue( np.array_equiv(arr_cpy, expected), "np.array_equiv was false for arrays: " + str(arr_cpy) + "\n" + str(expected)) multi_pool.close()
def test_ForwardEliminationZeroColumn(self): test_arr = np.array([[3, 0, 0, 1], [3, 0, 1, 1], [0, 0, 1, 1]], float) expected = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy) self.assertTrue(len(res) == 4) self.assertTrue(np.array_equiv(arr_cpy, expected))
def test_SimpleElimination(self): test_arr = np.array([[3, 0, 1], [3, 1, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy) self.assertTrue(res is not None) self.assertTrue(len(res) == 2) self.assertTrue( np.array_equiv(arr_cpy, np.array([[1, 0, 1 / 3], [0, 1, 0]], float))) pass
def test_FullElimination(self): test_arr = np.array([[21, 16, 13], [21, 18, 38], [24, 24, 6]], float) expected = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], float) arr_cpy = test_arr.copy() res = ge.gaussian_elimination(arr_cpy) expected = np.around(expected, 13) arr_cpy = np.around(arr_cpy, 13) self.assertEqual(len(res), 5) self.assertTrue( np.array_equiv(arr_cpy, expected), "np.array_equiv was false for arrays: " + str(arr_cpy) + "\n" + str(expected))
def test_SwapZeroColumn(self): test_arr = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]], float) arr_cpy = test_arr.copy() res = ge.swap_nonzero(arr_cpy, 0, 0) self.assertTrue(res is not None) self.assertTrue(isinstance(res, tuple)) self.assertTrue(len(res) == 2) self.assertTrue(callable(res[1][0])) equiv_arr = np.array_equiv(arr_cpy, np.array([[1, 0, 0], [0, 1, 0], [0, 0, 0]])) self.assertTrue(np.all(equiv_arr)) arr_cpy = test_arr.copy() res[1][0](arr_cpy, *res[1][1]) equiv_arr = np.array_equiv(test_arr, arr_cpy) self.assertFalse(np.all(equiv_arr))
def test_identifyNoSolution(self): test_mat = np.array([[2, 3], [2, 3]], float) res_col = np.array([[10], [12]], float) hist = ge.gaussian_elimination(test_mat) ge.execute_history(hist, res_col, False) self.assertEqual(mms.systemSolveStatus(test_mat, res_col)[0], 2)
def test_identifyInfiniteSolution(self): test_mat = np.array([[-1, -2, 1], [2, 3, 0], [0, 1, -2]], float) res_col = np.array([[-1], [2], [0]], float) hist = ge.gaussian_elimination(test_mat) ge.execute_history(hist, res_col, False) self.assertEqual(mms.systemSolveStatus(test_mat, res_col)[0], 1)
def test_identifySingleSolutionMoreComplicated(self): test_mat = np.array([[5, 3, 9], [-2, 3, -1], [-1, -4, 5]], float) res_col = np.array([[-1], [-4], [1]], float) hist = ge.gaussian_elimination(test_mat) ge.execute_history(hist, res_col, False) self.assertEqual(mms.systemSolveStatus(test_mat, res_col)[0], 0)
def test_identifySingleSolution(self): test_mat = np.array([[1, 1, 1], [0, 2, 5], [2, 5, -1]], float) res_col = np.array([[6], [-4], [27]], float) hist = ge.gaussian_elimination(test_mat) ge.execute_history(hist, res_col, False) self.assertEqual(mms.systemSolveStatus(test_mat, res_col)[0], 0)