def testSolvingComplexAxbWithCholeskyAndForwardBackwardSolve(self): R = md.cholesky(self.complexA, self.n) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual( self.complexR[i][j].tolist(), R[i][j].tolist(), 14, "expected " + str(self.complexR[i][j]) + " was " + str(R[i][j])) RT = mynp.conjugatetranspose(R) y = ls.forwardSolve(RT, self.complexb, self.n) for i in range(self.n): self.assertAlmostEqual( self.complexy[i].tolist(), y[i].tolist(), 14, "expected " + str(self.complexy[i]) + " was " + str(y[i])) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual( self.complexx[i].tolist(), x[i].tolist(), 14, "expected " + str(self.complexx[i]) + " was " + str(x[i]))
def testIfCholeskyRIsAsExpected(self): R = md.cholesky(self.A, self.n) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual(self.R[i][j].tolist(), R[i][j].tolist(), 14, "expected " + str(self.R[i][j]) + " was " + str(R[i][j].real))
def testIfCholeskyRIsAsExpected(self): R = md.cholesky(self.A, self.n) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual( self.R[i][j].tolist(), R[i][j].tolist(), 14, "expected " + str(self.R[i][j]) + " was " + str(R[i][j].real))
def testRTransposedTimesRIsEqualA(self): R = md.cholesky(self.A, self.n) RT = mynp.conjugatetranspose(R) A = mynp.dot(RT, R) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual(self.A[i][j].tolist(), A[i][j].tolist(), 15, "expected " + str(self.A[i][j]) + " was " + str(A[i][j]))
def testRTransposedTimesRIsEqualA(self): R = md.cholesky(self.A, self.n) RT = mynp.conjugatetranspose(R) A = mynp.dot(RT, R) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual( self.A[i][j].tolist(), A[i][j].tolist(), 15, "expected " + str(self.A[i][j]) + " was " + str(A[i][j]))
def testCholesky(self): # cho_solve(cho_factor(R), a) self.R = np.array([[3, 2], [2, 3]], dtype=complex) self.a = np.array([7, 7], dtype=complex) self.n = 2 Ria = np.linalg.solve(self.R, self.a) U = md.cholesky(self.R, self.n) UT = U.conjugate().transpose() y = ls.forwardSolve(UT, self.a, self.n) x = ls.backtrackSolve(U, y, self.n) self.almostEqual(Ria, x)
def testCholesky(self): # cho_solve(cho_factor(R), a) self.R = np.array([[3,2],[2,3]],dtype=complex) self.a = np.array([7,7],dtype=complex) self.n = 2 Ria = np.linalg.solve(self.R, self.a) U = md.cholesky(self.R, self.n) UT = U.conjugate().transpose() y = ls.forwardSolve(UT, self.a, self.n) x = ls.backtrackSolve(U, y, self.n) self.almostEqual(Ria, x)
def testSolvingAxbWithCholeskyAndForwardBackwardSolve(self): R = md.cholesky(self.A, self.n) RT = mynp.conjugatetranspose(R) y = ls.forwardSolve(RT, self.b1, self.n) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual(self.x1[i].tolist(), x[i].tolist(), 14, "expected " + str(self.x1[i]) + " was " + str(x[i])) y = ls.forwardSolve(RT, self.b2, self.n) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual(self.x2[i].tolist(), x[i].tolist(), 14, "expected " + str(self.x2[i]) + " was " + str(x[i]))
def testSolvingAxbWithCholeskyAndForwardBackwardSolve(self): R = md.cholesky(self.A, self.n) RT = mynp.conjugatetranspose(R) y = ls.forwardSolve(RT, self.b1, self.n) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual( self.x1[i].tolist(), x[i].tolist(), 14, "expected " + str(self.x1[i]) + " was " + str(x[i])) y = ls.forwardSolve(RT, self.b2, self.n) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual( self.x2[i].tolist(), x[i].tolist(), 14, "expected " + str(self.x2[i]) + " was " + str(x[i]))
def testSolvingComplexAxbWithCholeskyAndForwardBackwardSolve(self): R = md.cholesky(self.complexA, self.n) for i in range(self.n): for j in range(self.n): self.assertAlmostEqual(self.complexR[i][j].tolist(), R[i][j].tolist(), 14, "expected " + str(self.complexR[i][j]) + " was " + str(R[i][j])) RT = mynp.conjugatetranspose(R) y = ls.forwardSolve(RT, self.complexb, self.n) for i in range(self.n): self.assertAlmostEqual(self.complexy[i].tolist(), y[i].tolist(), 14, "expected " + str(self.complexy[i]) + " was " + str(y[i])) x = ls.backtrackSolve(R, y, self.n) for i in range(self.n): self.assertAlmostEqual(self.complexx[i].tolist(), x[i].tolist(), 14, "expected " + str(self.complexx[i]) + " was " + str(x[i]))