Example #1
0
 def setUp(self):
     self.n = 50000
     self.A = PysparseMatrix(matrix=poisson.poisson1d_sym(self.n))
     
     self.x_exact = numpy.ones(self.n)/math.sqrt(self.n)
     self.normx = 1.0/math.sqrt(self.n)
     self.b = self.A * self.x_exact
     
     lmbd_min = 4.0 * math.sin(math.pi/2.0/self.n) ** 2
     lmbd_max = 4.0 * math.sin((self.n - 1)*math.pi/2.0/self.n) ** 2
     cond = lmbd_max/lmbd_min
     self.tol = cond * macheps()
     self.LU = None
     self.relerr = 0.0
     self.descr = ''
     self.fmt = '\t%10s  %8.2e  %8.2e  %8d  %8d  %6.2f  %6.2f\n'
Example #2
0
 def testSubmatrix(self):
     n = self.n
     Psym = poisson.poisson1d_sym(n)
     P = poisson.poisson1d(n)
     for i in range(n):
         P[i,i] = 4.0
         Psym[i,i] = 4.0
     # read and test diagonal blocks
     for i in range(n):
         self.failUnless(llmat_isEqual(self.A[n*i:n*(i+1),n*i:n*(i+1)], P))
         self.failUnless(llmat_isEqual(self.S[n*i:n*(i+1),n*i:n*(i+1)], P))
         self.failUnless(llmat_isEqual(self.A[n*i:n*(i+1),n*i:n*(i+1)], Psym))
         self.failUnless(llmat_isEqual(self.S[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get diagonal blocks
     R = spmatrix_util.ll_mat_rand(n*n, n*n, 0.01) # random matrix
     for i in range(n):
         R[n*i:n*(i+1),n*i:n*(i+1)] = P
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], P))
         R[n*i:n*(i+1),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get off-diagonal blocks
     for i in range(n-1):
         R[n*i:n*(i+1),n*(i+1):n*(i+2)] = P
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*(i+1):n*(i+2)], P))
         R[n*i:n*(i+1),n*(i+1):n*(i+2)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*(i+1):n*(i+2)], Psym))
     # store and get diagonal blocks in symmetric matrix
     R = spmatrix.ll_mat_sym(n*n)
     for i in range(n):
         R[n*i:n*(i+1),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get off-diagonal blocks in symmetric matrix
     for i in range(n-1):
         R[n*(i+1):n*(i+2),n*i:n*(i+1)] = P
         self.failUnless(llmat_isEqual(R[n*(i+1):n*(i+2),n*i:n*(i+1)], P))
         R[n*(i+1):n*(i+2),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*(i+1):n*(i+2),n*i:n*(i+1)], Psym))