summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2021-03-23 16:10:24 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2021-03-23 16:10:24 +0100
commit0313c98f32363bfc75162613b3cfa9b7efa4081b (patch)
treeba7cd142cdd99ba8681809e274161b09e6474e6c
parentecb217234aaedc8ed04c26b09764da151c9fc77a (diff)
Add simplex tree equality operator to be able to test alpha complex
-rw-r--r--src/python/gudhi/simplex_tree.pxd1
-rw-r--r--src/python/gudhi/simplex_tree.pyx9
-rwxr-xr-xsrc/python/test/test_alpha_complex.py37
-rwxr-xr-xsrc/python/test/test_simplex_tree.py12
4 files changed, 59 insertions, 0 deletions
diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd
index 000323af..2aa435b1 100644
--- a/src/python/gudhi/simplex_tree.pxd
+++ b/src/python/gudhi/simplex_tree.pxd
@@ -74,6 +74,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
Simplex_tree_skeleton_iterator get_skeleton_iterator_begin(int dimension) nogil
Simplex_tree_skeleton_iterator get_skeleton_iterator_end(int dimension) nogil
pair[Simplex_tree_boundary_iterator, Simplex_tree_boundary_iterator] get_boundary_iterators(vector[int] simplex) nogil except +
+ bint operator==(Simplex_tree_interface_full_featured) nogil
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>":
diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx
index d7991417..b5a938d5 100644
--- a/src/python/gudhi/simplex_tree.pyx
+++ b/src/python/gudhi/simplex_tree.pyx
@@ -639,3 +639,12 @@ cdef class SimplexTree:
self.thisptr = <intptr_t>(ptr.collapse_edges(nb_iter))
# Delete old pointer
del ptr
+
+ def __eq__(self, other):
+ """Simplex tree equality operator using C++ depth first search operator==
+
+ :returns: True if the 2 simplex trees are equal, False otherwise.
+ :rtype: bool
+ """
+ cdef intptr_t other_int_ptr=other.thisptr
+ return dereference(self.get_ptr()) == dereference(<Simplex_tree_interface_full_featured*>other_int_ptr) \ No newline at end of file
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index 35059339..a0de46c3 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -316,3 +316,40 @@ def test_inconsistency_off_weight_file():
with pytest.raises(ValueError):
alpha = gd.AlphaComplex(off_file="alphacomplexdoc.off",
weights=[1., 2., 3., 4., 5., 6.])
+
+def _with_or_without_weight_file(precision):
+ off_file = open("weightalphacomplex.off", "w")
+ off_file.write("OFF \n" \
+ "5 0 0 \n" \
+ "1. -1. -1. \n" \
+ "-1. 1. -1. \n" \
+ "-1. -1. 1. \n" \
+ "1. 1. 1. \n" \
+ "2. 2. 2.")
+ off_file.close()
+
+ weight_file = open("weightalphacomplex.wgt", "w")
+ weight_file.write("4.0\n" \
+ "4.0\n" \
+ "4.0\n" \
+ "4.0\n" \
+ "1.0\n" )
+ weight_file.close()
+
+ stree_from_files = gd.AlphaComplex(off_file="weightalphacomplex.off",
+ weight_file="weightalphacomplex.wgt",
+ precision = precision).create_simplex_tree()
+
+ stree_from_values = gd.AlphaComplex(points=[[ 1., -1., -1.],
+ [-1., 1., -1.],
+ [-1., -1., 1.],
+ [ 1., 1., 1.],
+ [ 2., 2., 2.]],
+ weights = [4., 4., 4., 4., 1.],
+ precision = precision).create_simplex_tree()
+
+ assert stree_from_files == stree_from_values
+
+def test_with_or_without_weight_file():
+ for precision in ['fast', 'safe', 'exact']:
+ _with_or_without_weight_file(precision)
diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py
index a3eacaa9..83b5c268 100755
--- a/src/python/test/test_simplex_tree.py
+++ b/src/python/test/test_simplex_tree.py
@@ -404,3 +404,15 @@ def test_boundaries_iterator():
with pytest.raises(RuntimeError):
list(st.get_boundaries([6])) # (6) does not exist
+
+def test_equality_operator():
+ st1 = SimplexTree()
+ st2 = SimplexTree()
+
+ assert st1 == st2
+
+ st1.insert([1,2,3], 4.)
+ assert st1 != st2
+
+ st2.insert([1,2,3], 4.)
+ assert st1 == st2