コード例 #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)
コード例 #2
0
ファイル: test_sparse.py プロジェクト: jeffrey-cochran/nutils
 def test_dedup(self):
   for inplace in False, True:
     with self.subTest(inplace=inplace), chunksize(self.data.itemsize * 3):
       dedup = sparse.dedup(self.data, inplace=inplace)
       (self.assertIs if inplace else self.assertIsNot)(dedup, self.data)
       self.assertEqual(dedup.tolist(),
         [((0,),60), ((1,),40), ((2,),80), ((3,),0), ((4,),30)])