summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-03-28 21:20:01 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-03-28 21:20:01 +0000
commit20d67edb518e21a93c73f39251588c7e9b03c4f1 (patch)
treea9fe8dea22b3ec2e61e61dfb27d9c240644acd33
parent3c751ee1c84a81b6a7ee2f14769f82a0e7d490ee (diff)
Use only insert (simplex and subfaces)
Remove useless initialize_filtration git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@2276 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: eed1a67e2f83e3a1945cc24b11454ed1ef024ba6
-rw-r--r--CMakeLists.txt56
-rw-r--r--src/cython/cython/simplex_tree.pyx20
-rw-r--r--src/cython/doc/simplex_tree_user.rst30
-rw-r--r--src/cython/include/Simplex_tree_interface.h11
-rwxr-xr-xsrc/cython/test/test_simplex_tree.py34
5 files changed, 68 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 18cd0ca2..ff4df053 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,34 +53,34 @@ include_directories(src/Subsampling/include/)
include_directories(src/Tangential_complex/include/)
include_directories(src/Witness_complex/include/)
-add_subdirectory(src/common/example)
-add_subdirectory(src/common/test)
-add_subdirectory(src/Simplex_tree/test)
-add_subdirectory(src/Simplex_tree/example)
-add_subdirectory(src/Persistent_cohomology/test)
-add_subdirectory(src/Persistent_cohomology/example)
-add_subdirectory(src/Persistent_cohomology/benchmark)
-add_subdirectory(src/Skeleton_blocker/test)
-add_subdirectory(src/Skeleton_blocker/example)
-add_subdirectory(src/Contraction/example)
-add_subdirectory(src/Witness_complex/test)
-add_subdirectory(src/Witness_complex/example)
-add_subdirectory(src/Bitmap_cubical_complex/test)
-add_subdirectory(src/Bitmap_cubical_complex/example)
-add_subdirectory(src/Alpha_complex/example)
-add_subdirectory(src/Alpha_complex/test)
-add_subdirectory(src/Spatial_searching/example)
-add_subdirectory(src/Spatial_searching/test)
-add_subdirectory(src/Subsampling/example)
-add_subdirectory(src/Subsampling/test)
-add_subdirectory(src/Tangential_complex/example)
-add_subdirectory(src/Tangential_complex/test)
-add_subdirectory(src/Tangential_complex/benchmark)
-add_subdirectory(src/Bottleneck_distance/example)
-add_subdirectory(src/Bottleneck_distance/test)
-add_subdirectory(src/Bottleneck_distance/benchmark)
-add_subdirectory(src/Rips_complex/example)
-add_subdirectory(src/Rips_complex/test)
+#add_subdirectory(src/common/example)
+#add_subdirectory(src/common/test)
+#add_subdirectory(src/Simplex_tree/test)
+#add_subdirectory(src/Simplex_tree/example)
+#add_subdirectory(src/Persistent_cohomology/test)
+#add_subdirectory(src/Persistent_cohomology/example)
+#add_subdirectory(src/Persistent_cohomology/benchmark)
+#add_subdirectory(src/Skeleton_blocker/test)
+#add_subdirectory(src/Skeleton_blocker/example)
+#add_subdirectory(src/Contraction/example)
+#add_subdirectory(src/Witness_complex/test)
+#add_subdirectory(src/Witness_complex/example)
+#add_subdirectory(src/Bitmap_cubical_complex/test)
+#add_subdirectory(src/Bitmap_cubical_complex/example)
+#add_subdirectory(src/Alpha_complex/example)
+#add_subdirectory(src/Alpha_complex/test)
+#add_subdirectory(src/Spatial_searching/example)
+#add_subdirectory(src/Spatial_searching/test)
+#add_subdirectory(src/Subsampling/example)
+#add_subdirectory(src/Subsampling/test)
+#add_subdirectory(src/Tangential_complex/example)
+#add_subdirectory(src/Tangential_complex/test)
+#add_subdirectory(src/Tangential_complex/benchmark)
+#add_subdirectory(src/Bottleneck_distance/example)
+#add_subdirectory(src/Bottleneck_distance/test)
+#add_subdirectory(src/Bottleneck_distance/benchmark)
+#add_subdirectory(src/Rips_complex/example)
+#add_subdirectory(src/Rips_complex/test)
# data points generator
add_subdirectory(data/points/generator)
diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx
index 148227e1..d26a1a93 100644
--- a/src/cython/cython/simplex_tree.pyx
+++ b/src/cython/cython/simplex_tree.pyx
@@ -46,7 +46,6 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
bint find_simplex(vector[int] simplex)
bint insert_simplex_and_subfaces(vector[int] simplex,
double filtration)
- bint insert_simplex(vector[int] simplex, double filtration)
vector[pair[vector[int], double]] get_filtered_tree()
vector[pair[vector[int], double]] get_skeleton_tree(int dimension)
vector[pair[vector[int], double]] get_star(vector[int] simplex)
@@ -197,24 +196,7 @@ cdef class SimplexTree:
complex.push_back(i)
return self.thisptr.find_simplex(complex)
- def insert_simplex(self, simplex, filtration=0.0):
- """This function inserts the given N-simplex with the given filtration
- value (default value is '0.0').
-
- :param simplex: The N-simplex to insert, represented by a list of
- vertex.
- :type simplex: list of int.
- :param filtration: The filtration value of the simplex.
- :type filtration: float.
- :returns: true if the simplex was found, false otherwise.
- :rtype: bool
- """
- cdef vector[int] complex
- for i in simplex:
- complex.push_back(i)
- return self.thisptr.insert_simplex(complex, <double>filtration)
-
- def insert_simplex_and_subfaces(self, simplex, filtration=0.0):
+ def insert(self, simplex, filtration=0.0):
"""This function inserts the given N-simplex and its subfaces with the
given filtration value (default value is '0.0').
diff --git a/src/cython/doc/simplex_tree_user.rst b/src/cython/doc/simplex_tree_user.rst
index cbfd34a7..c4e4c1b5 100644
--- a/src/cython/doc/simplex_tree_user.rst
+++ b/src/cython/doc/simplex_tree_user.rst
@@ -35,9 +35,9 @@ Example
import gudhi
st = gudhi.SimplexTree()
- if st.insert_simplex([0, 1]):
+ if st.insert([0, 1]):
print("[0, 1] inserted")
- if st.insert_simplex_and_subfaces([0, 1, 2], filtration=4.0):
+ if st.insert([0, 1, 2], filtration=4.0):
print("[0, 1, 2] inserted")
if st.find([0, 1]):
print("[0, 1] found")
@@ -54,16 +54,16 @@ The output is:
.. testoutput::
- [0, 1] inserted
- [0, 1, 2] inserted
- [0, 1] found
- num_vertices=3
- num_simplices=7
- skeleton_tree(2) =
- ([0, 1, 2], 4.0)
- ([0, 1], 0.0)
- ([0, 2], 4.0)
- ([0], 0.0)
- ([1, 2], 4.0)
- ([1], 4.0)
- ([2], 4.0)
+ [0, 1] inserted
+ [0, 1, 2] inserted
+ [0, 1] found
+ num_vertices=3
+ num_simplices=7
+ skeleton_tree(2) =
+ ([0, 1, 2], 4.0)
+ ([0, 1], 0.0)
+ ([0, 2], 4.0)
+ ([0], 0.0)
+ ([1, 2], 4.0)
+ ([1], 0.0)
+ ([2], 4.0)
diff --git a/src/cython/include/Simplex_tree_interface.h b/src/cython/include/Simplex_tree_interface.h
index 4266b3ef..154005ae 100644
--- a/src/cython/include/Simplex_tree_interface.h
+++ b/src/cython/include/Simplex_tree_interface.h
@@ -52,29 +52,30 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
return (Base::find(vh) != Base::null_simplex());
}
+ bool insert(const Simplex& simplex, Filtration_value filtration = 0) {
+ Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration);
+ return (result.second);
+ }
+
bool insert_simplex(const Simplex& simplex, Filtration_value filtration = 0) {
Insertion_result result = Base::insert_simplex(simplex, filtration);
- Base::initialize_filtration();
return (result.second);
}
bool insert_simplex_and_subfaces(const Simplex& simplex, Filtration_value filtration = 0) {
Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration);
- Base::initialize_filtration();
return (result.second);
}
// Do not interface this function, only used in strong witness interface for complex creation
bool insert_simplex(const std::vector<std::size_t>& complex, Filtration_value filtration = 0) {
Insertion_result result = Base::insert_simplex(complex, filtration);
- Base::initialize_filtration();
return (result.second);
}
// Do not interface this function, only used in strong witness interface for complex creation
bool insert_simplex_and_subfaces(const std::vector<std::size_t>& complex, Filtration_value filtration = 0) {
Insertion_result result = Base::insert_simplex_and_subfaces(complex, filtration);
- Base::initialize_filtration();
return (result.second);
}
@@ -88,6 +89,7 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
}
Complex get_filtered_tree() {
+ Base::initialize_filtration();
Complex filtered_tree;
for (auto f_simplex : Base::filtration_simplex_range()) {
Simplex simplex;
@@ -140,6 +142,7 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
}
void create_persistence(Gudhi::Persistent_cohomology_interface<Base>* pcoh) {
+ Base::initialize_filtration();
pcoh = new Gudhi::Persistent_cohomology_interface<Base>(*this);
}
};
diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py
index af5b639a..db61f84c 100755
--- a/src/cython/test/test_simplex_tree.py
+++ b/src/cython/test/test_simplex_tree.py
@@ -33,8 +33,8 @@ def test_insertion():
assert st.__is_persistence_defined() == False
# insert test
- assert st.insert_simplex([0, 1]) == True
- assert st.insert_simplex_and_subfaces([0, 1, 2], filtration=4.0) == True
+ assert st.insert([0, 1]) == True
+ assert st.insert([0, 1, 2], filtration=4.0) == True
# FIXME: Remove this line
st.set_dimension(2)
assert st.num_simplices() == 7
@@ -62,24 +62,24 @@ def test_insertion():
assert st.filtration([2]) == 4.0
assert st.filtration([0, 1]) == 0.0
assert st.filtration([0]) == 0.0
- assert st.filtration([1]) == 4.0
+ assert st.filtration([1]) == 0.0
# skeleton_tree test
assert st.get_skeleton_tree(2) == \
[([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0),
- ([0], 0.0), ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)]
+ ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]
assert st.get_skeleton_tree(1) == \
[([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0),
- ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)]
+ ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]
assert st.get_skeleton_tree(0) == \
- [([0], 0.0), ([1], 4.0), ([2], 4.0)]
+ [([0], 0.0), ([1], 0.0), ([2], 4.0)]
# remove_maximal_simplex test
assert st.get_cofaces([0, 1, 2], 1) == []
st.remove_maximal_simplex([0, 1, 2])
assert st.get_skeleton_tree(2) == \
[([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0),
- ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)]
+ ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]
assert st.find([0, 1, 2]) == False
assert st.find([0, 1]) == True
assert st.find([0, 2]) == True
@@ -103,16 +103,16 @@ def test_expansion():
assert st.__is_persistence_defined() == False
# insert test
- assert st.insert_simplex_and_subfaces([3, 2], 0.1) == True
- assert st.insert_simplex_and_subfaces([2, 0], 0.2) == True
- assert st.insert_simplex_and_subfaces([1, 0], 0.3) == True
- assert st.insert_simplex_and_subfaces([3, 1], 0.4) == True
- assert st.insert_simplex_and_subfaces([2, 1], 0.5) == True
- assert st.insert_simplex_and_subfaces([6, 5], 0.6) == True
- assert st.insert_simplex_and_subfaces([4, 2], 0.7) == True
- assert st.insert_simplex_and_subfaces([3, 0], 0.8) == True
- assert st.insert_simplex_and_subfaces([6, 4], 0.9) == True
- assert st.insert_simplex_and_subfaces([6, 3], 1.0) == True
+ assert st.insert([3, 2], 0.1) == True
+ assert st.insert([2, 0], 0.2) == True
+ assert st.insert([1, 0], 0.3) == True
+ assert st.insert([3, 1], 0.4) == True
+ assert st.insert([2, 1], 0.5) == True
+ assert st.insert([6, 5], 0.6) == True
+ assert st.insert([4, 2], 0.7) == True
+ assert st.insert([3, 0], 0.8) == True
+ assert st.insert([6, 4], 0.9) == True
+ assert st.insert([6, 3], 1.0) == True
assert st.num_vertices() == 7
assert st.num_simplices() == 17