Ejemplo n.º 1
0
 def setUp(self):
     self.n = 50000
     self.B = poisson.poisson1d(self.n).to_csr()
     
     self.b = numpy.zeros(self.n, 'd')
     self.x = numpy.zeros(self.n, 'd')
     self.x_exact = numpy.ones(self.n, 'd')
     self.x_exact /= math.sqrt(self.n)
     self.B.matvec(self.x_exact, self.b)
     
     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()
Ejemplo n.º 2
0
 def setUp(self):
     import numpy
     
     self.n = 30
     self.P = poisson.poisson1d(self.n)
     for i in range(self.n):
         self.P[i,i] = 4.0
     self.A = poisson.poisson2d(self.n)
     self.S = poisson.poisson2d_sym(self.n)
     self.I = spmatrix.ll_mat_sym(self.n)
     for i in range(self.n):
         self.I[i,i] = -1.0
     self.mask = numpy.zeros(self.n**2, 'l')
     self.mask[self.n/2*self.n:(self.n/2 + 1)*self.n] = 1
     self.mask1 = numpy.zeros(self.n**2, 'l')
     self.mask1[(self.n/2 + 1)*self.n:(self.n/2 + 2)*self.n] = 1
Ejemplo n.º 3
0
 def setUp(self):
     self.n = 50000
     self.B = PysparseMatrix( matrix=poisson.poisson1d(self.n) )
     
     self.x_exact = numpy.ones(self.n)/math.sqrt(self.n)
     self.normx = 1.0/math.sqrt(self.n)
     self.b = self.B * 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.relerr = 0.0
     self.nnz = self.B.getNnz()
     self.LU = None
     self.fmt = '\t%8.2e  %8.2e  %8d  %8d  %8d  %6.2f  %6.2f\n'
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
 def testNormGeneral(self):
     A = poisson.poisson2d(self.n)
     self.failUnless(A.norm('1') == 8)
     self.failUnless(A.norm('inf') == 8)
     self.failUnless(poisson.poisson1d(3).norm('fro') == 4)