Пример #1
0
 def test_pickle(self):
     s = pickle.dumps(self.matrix)
     mat = pickle.loads(s)
     self.assertIsInstance(mat, type(self.matrix))
     numpy.testing.assert_equal(mat.export('dense'), self.exact)
     with self.subTest('cross-pickle'), matrix.Numpy():
         mat = pickle.loads(s)
         self.assertIsInstance(mat, matrix.NumpyMatrix)
         numpy.testing.assert_equal(mat.export('dense'), self.exact)
Пример #2
0
 def project(self, projection):
     ns = fn.Namespace()
     for name, func in self._kwargs.items():
         setattr(ns, name, func)
     for p, (name, func) in zip(projection, self._defaults.items()):
         if p is not None:
             func = fn.matmat(p, func)
         setattr(ns, name, func)
     integrand = getattr(ns, self._evaluator)(self._code)
     domain, geom, ischeme = self.prop('domain', 'geometry', 'ischeme')
     with matrix.Numpy():
         retval = domain.integrate(integrand * fn.J(geom), ischeme=ischeme)
     return NumpyArrayIntegrand(retval)
Пример #3
0
 def project(self, projection):
     obj = self.obj
     s = slice(None)
     for i, p in enumerate(projection):
         if p is None:
             continue
         obj = obj[(s,)*i + (_,s,Ellipsis)]
         obj = obj * p[(_,)*i + (s,s) + (_,) * (self.ndim - i - 1)]
         obj = obj.sum(i+1)
     domain, geom, ischeme = self.prop('domain', 'geometry', 'ischeme')
     with matrix.Numpy():
         retval = domain.integrate(obj * fn.J(geom), ischeme=ischeme)
     return NumpyArrayIntegrand(retval)
Пример #4
0
 def test_matrix_numpy(self):
     self._test_matrix(matrix.Numpy())
Пример #5
0
 def assemble(self, data, index, shape):
     if len(shape) > 2:
         return matrix.Numpy().assemble(data, index, shape)
     return super().assemble(data, index, shape)
Пример #6
0
 def test_deprecated_context(self):
     with self.assertWarns(warnings.NutilsDeprecationWarning):
         with matrix.Numpy():
             pass
Пример #7
0
    def test_pickle(self):
        s = pickle.dumps(self.matrix)
        mat = pickle.loads(s)
        self.assertIsInstance(mat, type(self.matrix))
        numpy.testing.assert_equal(mat.export('dense'), self.exact)
        with self.subTest('cross-pickle'), matrix.Numpy():
            mat = pickle.loads(s)
            self.assertIsInstance(mat, matrix.NumpyMatrix)
            numpy.testing.assert_equal(mat.export('dense'), self.exact)

    @ifsupported
    def test_diagonal(self):
        self.assertAllEqual(self.matrix.diagonal(), numpy.diag(self.exact))


solver('numpy', backend=matrix.Numpy(), args=[{}])
solver('scipy',
       backend=matrix.Scipy(),
       args=[{},
             dict(solver='gmres', atol=1e-5, restart=100, precon='spilu'),
             dict(solver='gmres', atol=1e-5, precon='splu'),
             dict(solver='cg', atol=1e-5, precon='diag')] + [
                 dict(solver=s, atol=1e-5)
                 for s in ('bicg', 'bicgstab', 'cg', 'cgs', 'lgmres', 'minres')
             ])
for threading in matrix.MKL.Threading.SEQUENTIAL, matrix.MKL.Threading.TBB:
    solver('mkl:{}'.format(threading.name.lower()),
           backend=matrix.MKL(threading=threading),
           args=[{},
                 dict(solver='fgmres', atol=1e-8),
                 dict(solver='fgmres', atol=1e-8, precon='diag')])