Ejemplo n.º 1
0
 def testNoScaling(self):
     self.LU = PysparseUmfpackSolver(self.A, scale='none')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 2
0
 def testSymmetric(self):
     self.LU = PysparseUmfpackSolver(self.A, strategy='symmetric')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 3
0
 def test2by2(self):
     self.LU = PysparseUmfpackSolver(self.A, strategy='2by2')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 4
0
 def testPoisson2dUnsymmetric(self):
     self.LU = PysparseUmfpackSolver(self.B, strategy='unsymmetric')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 5
0
 def testVanilla(self):
     self.LU = PysparseUmfpackSolver(self.A)
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 6
0
class SpDiagsTestCase(unittest.TestCase):
    def setUp(self):
        self.n = 10000
        self.e = numpy.ones(self.n)
        self.A = PysparseSpDiagsMatrix(size=self.n,
                                       vals=(-2 * self.e, self.e, 2 * self.e),
                                       pos=(-1, 0, 1))
        self.b = self.A * self.e
        self.tol = 100 * macheps()
        self.LU = None
        self.err = 0.0
        self.fmt = '\t%8.2e  %8.2e  %8d  %8d  %8d  %6.2f  %6.2f\n'

    def tearDown(self):
        self.LU.fetch_lunz()
        sys.stdout.write(
            self.fmt %
            (self.err, self.tol, self.A.getNnz(), self.LU.lnz, self.LU.unz,
             self.LU.factorizationTime, self.LU.solutionTime))

    def computeError(self, x):
        self.err = numpy.linalg.norm(x - self.e, ord=numpy.inf)
        return self.err

    def testVanilla(self):
        self.LU = PysparseUmfpackSolver(self.A)
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testUnsymmetric(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='unsymmetric')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testSymmetric(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='symmetric')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def test2by2(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='2by2')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testNoScaling(self):
        self.LU = PysparseUmfpackSolver(self.A, scale='none')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testScaleMax(self):
        self.LU = PysparseUmfpackSolver(self.A, scale='max')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 7
0
 def testPoisson2dDefault(self):
     self.LU = PysparseUmfpackSolver(self.B)
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 8
0
 def testScaleMax(self):
     self.LU = PysparseUmfpackSolver(self.A, scale='max')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
 def test2by2(self):
     self.LU = PysparseUmfpackSolver(self.A, strategy='2by2')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 11
0
 def testNoScaling(self):
     self.LU = PysparseUmfpackSolver(self.A, scale='none')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 12
0
 def testSymmetric(self):
     self.LU = PysparseUmfpackSolver(self.A, strategy='symmetric')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 13
0
 def testVanilla(self):
     self.LU = PysparseUmfpackSolver(self.A)
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 14
0
 def testPoisson2dUnsymmetric(self):
     self.LU = PysparseUmfpackSolver(self.B, strategy='unsymmetric')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 15
0
 def testScaleMax(self):
     self.LU = PysparseUmfpackSolver(self.A, scale='max')
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 16
0
class SpDiagsTestCase(unittest.TestCase):
    def setUp(self):
        self.n = 10000
        self.e = numpy.ones(self.n)
        self.A = PysparseSpDiagsMatrix(size=self.n,
                                       vals=(-2*self.e,self.e,2*self.e),
                                       pos=(-1,0,1))
        self.b = self.A * self.e
        self.tol = 100*macheps()
        self.LU = None
        self.err = 0.0
        self.fmt = '\t%8.2e  %8.2e  %8d  %8d  %8d  %6.2f  %6.2f\n'

    def tearDown(self):
        self.LU.fetch_lunz()
        sys.stdout.write(self.fmt % (self.err, self.tol, self.A.getNnz(),
                                     self.LU.lnz, self.LU.unz,
                                     self.LU.factorizationTime,
                                     self.LU.solutionTime))
        
    def computeError(self, x):
        self.err = numpy.linalg.norm(x - self.e, ord=numpy.inf)
        return self.err

    def testVanilla(self):
        self.LU = PysparseUmfpackSolver(self.A)
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testUnsymmetric(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='unsymmetric')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testSymmetric(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='symmetric')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def test2by2(self):
        self.LU = PysparseUmfpackSolver(self.A, strategy='2by2')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testNoScaling(self):
        self.LU = PysparseUmfpackSolver(self.A, scale='none')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testScaleMax(self):
        self.LU = PysparseUmfpackSolver(self.A, scale='max')
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
 def testPoisson2dDefault(self):
     self.LU = PysparseUmfpackSolver(self.B)
     self.LU.solve(self.b)
     self.failUnless(self.computeError(self.LU.sol) < self.tol)