Exemple #1
0
    def test_sparsity(self):
        topo, geom = mesh.rectilinear([6] * self.ndim)
        topo = topo.refined_by(
            set(
                map(
                    topo.transforms.index,
                    itertools.chain(topo[1:3].transforms,
                                    topo[-2:].transforms))))

        ns = function.Namespace()
        ns.x = geom
        ns.tbasis = topo.basis('th-spline',
                               degree=2,
                               truncation_tolerance=1e-14)
        ns.tnotol = topo.basis('th-spline', degree=2, truncation_tolerance=0)
        ns.hbasis = topo.basis('h-spline', degree=2)

        tA, tA_tol, hA = topo.sample('gauss', 5).integrate_sparse([
            ns.eval_ij('tbasis_i,k tbasis_j,k'),
            ns.eval_ij('tnotol_i,k tnotol_j,k'),
            ns.eval_ij('hbasis_i,k hbasis_j,k')
        ])

        tA_nnz, tA_tol_nnz, hA_nnz = self.vals[self.ndim]
        self.assertEqual(len(sparse.prune(sparse.dedup(tA))), tA_nnz)
        self.assertEqual(len(sparse.prune(sparse.dedup(tA_tol))), tA_tol_nnz)
        self.assertEqual(len(sparse.prune(sparse.dedup(hA))), hA_nnz)
 def test_prune(self):
   for inplace in False, True:
     with self.subTest(inplace=inplace), chunksize(self.data.itemsize * 3):
       prune = sparse.prune(self.data, inplace=inplace)
       (self.assertIs if inplace else self.assertIsNot)(prune, self.data)
       self.assertEqual(prune.tolist(),
         [((4,),10), ((4,),20), ((3,),1), ((2,),30), ((1,),40), ((2,),50), ((3,),-1), ((0,),60)])
Exemple #3
0
 def setUpContext(self, stack):
     super().setUpContext(stack)
     if self.backend:
         stack.enter_context(self.backend)
         self.exact = 2 * numpy.eye(self.n) - numpy.eye(
             self.n, self.n, -1) - numpy.eye(self.n, self.n, +1)
         data = sparse.prune(sparse.fromarray(self.exact), inplace=True)
         assert len(data) == self.n * 3 - 2
         self.matrix = matrix.fromsparse(data, inplace=True)
Exemple #4
0
 def setUp(self):
   super().setUp()
   try:
     self.enter_context(matrix.backend(self.backend))
   except matrix.BackendNotAvailable:
     self.skipTest('backend is unavailable')
   self.exact = 2 * numpy.eye(self.n) - numpy.eye(self.n, self.n, -1) - numpy.eye(self.n, self.n, +1)
   data = sparse.prune(sparse.fromarray(self.exact), inplace=True)
   assert len(data) == self.n*3-2
   self.matrix = matrix.fromsparse(data, inplace=True)