Exemple #1
0
    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]))
Exemple #2
0
 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]))
Exemple #3
0
    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]))
Exemple #4
0
    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)
Exemple #5
0
   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)
Exemple #6
0
   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]))
Exemple #7
0
 def testForwardSolve(self):
    
    x = ls.forwardSolve(mynp.conjugatetranspose(self.C), self.b1c, self.n)
    self.assertListEqual(self.x1cT.tolist(), x.tolist(), "Error in forward solve")