class Poisson1dTestCase(unittest.TestCase): 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' def computeError(self, x): absErr = numpy.linalg.norm(x - self.x_exact, ord=numpy.inf) self.relerr = absErr/(1 + self.normx) return self.relerr def tearDown(self): self.LU.fetch_lunz() sys.stdout.write(self.fmt % (self.relerr, self.tol, self.nnz, self.LU.lnz, self.LU.unz, self.LU.factorizationTime, self.LU.solutionTime)) def testPoisson1dDefault(self): self.LU = PysparseUmfpackSolver(self.B) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dUnsymmetric(self): self.LU = PysparseUmfpackSolver(self.B, strategy='unsymmetric') self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dSymmetric(self): self.LU = PysparseUmfpackSolver(self.B, strategy='symmetric') self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1d2by2(self): self.LU = PysparseUmfpackSolver(self.B, strategy='2by2') self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dNoScaling(self): self.LU = PysparseUmfpackSolver(self.B, scale='none') self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dScaleMax(self): self.LU = PysparseUmfpackSolver(self.B, scale='max') self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol)
class Poisson1dTestCase(unittest.TestCase): 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' def tearDown(self): self.LU.fetch_lunz() sys.stdout.write(self.fmt % (self.descr, self.relerr, self.tol, self.A.getNnz(), self.LU.lunz, self.LU.factorizationTime, self.LU.solutionTime)) def computeError(self, x): absErr = numpy.linalg.norm(x-self.x_exact, ord=numpy.inf) self.relerr = absErr/(1+self.normx) return self.relerr def testPoisson1dDefault(self): self.descr = 'poi1d-dflt' self.LU = PysparseSuperLUSolver(self.A) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dThresh(self): self.descr = 'poi1d-trsh' self.LU = PysparseSuperLUSolver(self.A, diag_pivot_thresh=0.5) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dRelax(self): self.descr = 'poi1d-relx' self.LU = PysparseSuperLUSolver(self.A, relax=20) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dPanel(self): self.descr = 'poi1d-size' self.LU = PysparseSuperLUSolver(self.A, panel_size=1) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dperm0(self): self.descr = 'poi1d-prm0' self.LU = PysparseSuperLUSolver(self.A, permc_spec=0) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dperm1(self): self.descr = 'poi1d-prm1' self.LU = PysparseSuperLUSolver(self.A, permc_spec=1) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dperm2(self): self.descr = 'poi1d-prm2' self.LU = PysparseSuperLUSolver(self.A, permc_spec=2) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol) def testPoisson1dperm3(self): self.descr = 'poi1d-prm3' self.LU = PysparseSuperLUSolver(self.A, permc_spec=3) self.LU.solve(self.b) self.failUnless(self.computeError(self.LU.sol) < self.tol)