From 37a141533397568e7070c734e21ef9c4dc85d132 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau Date: Thu, 10 Feb 2022 16:16:14 +0100 Subject: Add SimplexTree copy method and its test --- src/python/gudhi/simplex_tree.pxd | 1 + src/python/gudhi/simplex_tree.pyx | 14 ++++++++++++++ src/python/test/test_simplex_tree.py | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd index 006a24ed..92139db4 100644 --- a/src/python/gudhi/simplex_tree.pxd +++ b/src/python/gudhi/simplex_tree.pxd @@ -45,6 +45,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": cdef cppclass Simplex_tree_interface_full_featured "Gudhi::Simplex_tree_interface": Simplex_tree_interface_full_featured() nogil + Simplex_tree_interface_full_featured(Simplex_tree_interface_full_featured&) nogil double simplex_filtration(vector[int] simplex) nogil void assign_simplex_filtration(vector[int] simplex, double filtration) nogil void initialize_filtration() nogil diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index c3720936..6b3116a4 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -63,6 +63,20 @@ cdef class SimplexTree: """ return self.pcohptr != NULL + def copy(self): + """ + :returns: A simplex tree that is a deep copy itself. + :rtype: SimplexTree + """ + stree = SimplexTree() + cdef Simplex_tree_interface_full_featured* stree_ptr + cdef Simplex_tree_interface_full_featured* self_ptr=self.get_ptr() + with nogil: + stree_ptr = new Simplex_tree_interface_full_featured(dereference(self_ptr)) + + stree.thisptr = (stree_ptr) + return stree + def filtration(self, simplex): """This function returns the filtration value for a given N-simplex in this simplicial complex, or +infinity if it is not in the complex. diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py index 31c46213..dac45288 100755 --- a/src/python/test/test_simplex_tree.py +++ b/src/python/test/test_simplex_tree.py @@ -447,4 +447,21 @@ def test_persistence_intervals_in_dimension(): assert np.array_equal(H2, np.array([[ 0., float("inf")]])) # Test empty case assert st.persistence_intervals_in_dimension(3).shape == (0, 2) - \ No newline at end of file + +def test_simplex_tree_copy(): + st = SimplexTree() + st .insert([1,2,3], 0.) + a = st.copy() + # TODO(VR): when #463 is merged, replace with + # assert a == st + assert a.num_vertices() == st.num_vertices() + assert a.num_simplices() == st.num_simplices() + st_filt_list = list(st.get_filtration()) + assert list(a.get_filtration()) == st_filt_list + + a.remove_maximal_simplex([1, 2, 3]) + a_filt_list = list(a.get_filtration()) + assert len(a_filt_list) < len(st_filt_list) + + for a_splx in a_filt_list: + assert a_splx in st_filt_list -- cgit v1.2.3