summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Rouvreau <vincent.rouvreau@inria.fr>2022-02-10 16:16:14 +0100
committerVincent Rouvreau <vincent.rouvreau@inria.fr>2022-02-10 16:16:14 +0100
commit37a141533397568e7070c734e21ef9c4dc85d132 (patch)
tree0f73790d48faf129ab228576fe6984279b0018ab
parent7f1b8eb706c72921141b53e607d6e2aa28e2bf19 (diff)
Add SimplexTree copy method and its test
-rw-r--r--src/python/gudhi/simplex_tree.pxd1
-rw-r--r--src/python/gudhi/simplex_tree.pyx14
-rwxr-xr-xsrc/python/test/test_simplex_tree.py19
3 files changed, 33 insertions, 1 deletions
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<Gudhi::Simplex_tree_options_full_featured>":
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 = <intptr_t>(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