def test_pickle(self): import pickle tests = ((hg.RegularGraph1d, (3, ), ((-1, ), (1, ))), (hg.RegularGraph2d, (3, 2), ((-1, 0), (1, 0))), (hg.RegularGraph3d, (3, 2, 1), ((-1, 0, -1), (1, 0, 1))), (hg.RegularGraph4d, (3, 2, 1, 2), ((-1, 0, -1, 0), (1, 0, 1, 0))), (hg.RegularGraph5d, (3, 2, 1, 2, 1), ((-1, 0, -1, 0, 1), (1, 0, 1, 0, -1)))) for c, s, n in tests: e = c(s, n) hg.set_attribute(e, "test", (1, 2, 3)) hg.add_tag(e, "foo") data = pickle.dumps(e) e2 = pickle.loads(data) self.assertTrue(np.all(e.shape() == e2.shape())) self.assertTrue(np.all(e.neighbour_list() == e2.neighbour_list())) self.assertTrue( hg.get_attribute(e, "test") == hg.get_attribute(e2, "test")) self.assertTrue(e.test == e2.test) self.assertTrue(hg.has_tag(e2, "foo"))
def validate(cls, canonical_element): """ Check if the given canonical is tagged with the given Concept (class on which the `validate` function is called). :param canonical_element: :return: """ if canonical_element is None: return False return hg.has_tag(canonical_element, cls)
def test_pickle(self): import pickle tree = hg.Tree((4, 4, 5, 5, 6, 6, 6)) lca = hg.LCAFast(tree) hg.set_attribute(lca, "test", (1, 2, 3)) hg.add_tag(lca, "foo") data = pickle.dumps(lca) lca2 = pickle.loads(data) res = lca2.lca((0, 0, 1, 3), (0, 3, 0, 0)) self.assertTrue(np.all(res == (0, 6, 4, 6))) self.assertTrue( hg.get_attribute(lca, "test") == hg.get_attribute(lca2, "test")) self.assertTrue(lca.test == lca2.test) self.assertTrue(hg.has_tag(lca2, "foo"))
def test_pickle(self): import pickle g = TestUndirectedGraph.test_graph() hg.set_attribute(g, "test", (1, 2, 3)) hg.add_tag(g, "foo") data = pickle.dumps(g) g2 = pickle.loads(data) self.assertTrue(g.num_vertices() == g2.num_vertices()) gs, gt = g.edge_list() g2s, g2t = g2.edge_list() self.assertTrue(np.all(gs == g2s)) self.assertTrue(np.all(gt == g2t)) self.assertTrue(hg.get_attribute(g, "test") == hg.get_attribute(g2, "test")) self.assertTrue(g.test == g2.test) self.assertTrue(hg.has_tag(g2, "foo"))
def test_pickle(self): import pickle t = hg.Tree((5, 5, 6, 6, 6, 7, 7, 7)) hg.set_attribute(t, "test", (1, 2, 3)) hg.add_tag(t, "foo") data = pickle.dumps(t) t2 = pickle.loads(data) self.assertTrue(np.all(t.parents() == t2.parents())) for v in t.vertices(): self.assertTrue(np.all(t.children(v) == t2.children(v))) self.assertTrue( hg.get_attribute(t, "test") == hg.get_attribute(t2, "test")) self.assertTrue(t.test == t2.test) self.assertTrue(hg.has_tag(t2, "foo"))
def test_pickle(self): import pickle tree = hg.Tree((4, 4, 5, 5, 6, 6, 6)) for lca_t in [hg.LCA_rmq_sparse_table, hg.LCA_rmq_sparse_table_block]: with self.subTest(lca_type=lca_t): lca = lca_t(tree) hg.set_attribute(lca, "test", (1, 2, 3)) hg.add_tag(lca, "foo") data = pickle.dumps(lca) lca2 = pickle.loads(data) res = lca2.lca((0, 0, 1, 3), (0, 3, 0, 0)) self.assertTrue(np.all(res == (0, 6, 4, 6))) self.assertTrue(hg.get_attribute(lca, "test") == hg.get_attribute(lca2, "test")) self.assertTrue(lca.test == lca2.test) self.assertTrue(hg.has_tag(lca2, "foo"))
def test_pickle(self): import pickle tests = ((hg.EmbeddingGrid1d, (3, )), (hg.EmbeddingGrid2d, (3, 2)), (hg.EmbeddingGrid3d, (3, 2, 1)), (hg.EmbeddingGrid4d, (3, 2, 1, 2)), (hg.EmbeddingGrid5d, (3, 2, 1, 2, 1))) for c, s in tests: e = c(s) hg.set_attribute(e, "test", (1, 2, 3)) hg.add_tag(e, "foo") data = pickle.dumps(e) e2 = pickle.loads(data) self.assertTrue(np.all(e.shape() == e2.shape())) self.assertTrue( hg.get_attribute(e, "test") == hg.get_attribute(e2, "test")) self.assertTrue(e.test == e2.test) self.assertTrue(hg.has_tag(e2, "foo"))