Пример #1
0
 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'
Пример #2
0
 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'
Пример #3
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)
Пример #4
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)
Пример #5
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.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):
        self.relerr = numpy.linalg.norm(x - self.e, ord=numpy.inf)
        return self.relerr

    #def testVanilla(self):
    #    self.descr = 'spdgs-dflt'
    #    self.LU = PysparseSuperLUSolver(self.A)
    #    self.LU.solve(self.b)
    #    self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testTrivialThresh(self):
        self.descr = 'spdgs-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 testTrivialRelax(self):
    #    self.descr = 'spdgs-relx'
    #    self.LU = PysparseSuperLUSolver(self.A, relax=20)
    #    self.LU.solve(self.b)
    #    self.failUnless(self.computeError(self.LU.sol) < self.tol)

    #def testTrivialPanel(self):
    #    self.descr = 'spdgs-size'
    #    self.LU = PysparseSuperLUSolver(self.A, panel_size=1)
    #    self.LU.solve(self.b)
    #    self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testTrivialperm0(self):
        self.descr = 'spdgs-prm0'
        self.LU = PysparseSuperLUSolver(self.A, permc_spec=0)
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testTrivialperm1(self):
        self.descr = 'spdgs-prm1'
        self.LU = PysparseSuperLUSolver(self.A, permc_spec=1)
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)

    #def testTrivialperm2(self):
    #    self.descr = 'spdgs-prm2'
    #    self.LU = PysparseSuperLUSolver(self.A, permc_spec=2)
    #    self.LU.solve(self.b)
    #    self.failUnless(self.computeError(self.LU.sol) < self.tol)

    def testTrivialperm3(self):
        self.descr = 'spdgs-prm3'
        self.LU = PysparseSuperLUSolver(self.A, permc_spec=3)
        self.LU.solve(self.b)
        self.failUnless(self.computeError(self.LU.sol) < self.tol)