summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-04-25 06:50:12 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-04-25 06:50:12 +0000
commit62861adfd2de672d3d90e2fbade499fe76e5bca7 (patch)
tree69262efeabc666188543182aef8342fb3a0e2c5a /src
parent3ce013afc21df5d05d663dd17a6640cec9af4aed (diff)
persistence_pairs Python version
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/python_2.1.0_fix_vincent@3393 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5ee633545ca5754b605cdd789ca9720f5936998a
Diffstat (limited to 'src')
-rw-r--r--src/cython/cython/simplex_tree.pyx20
-rw-r--r--src/cython/include/Persistent_cohomology_interface.h26
2 files changed, 46 insertions, 0 deletions
diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx
index 0cb575d2..755cdc02 100644
--- a/src/cython/cython/simplex_tree.pyx
+++ b/src/cython/cython/simplex_tree.pyx
@@ -64,6 +64,7 @@ cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
vector[int] persistent_betti_numbers(double from_value, double to_value)
vector[pair[double,double]] intervals_in_dimension(int dimension)
void write_output_diagram(string diagram_file_name)
+ vector[pair[vector[int], vector[int]]] persistence_pairs()
# SimplexTree python interface
cdef class SimplexTree:
@@ -486,6 +487,25 @@ cdef class SimplexTree:
" to be launched first.")
return intervals_result
+ def persistence_pairs(self):
+ """This function returns the persistence pairs of the simplicial
+ complex.
+
+ :returns: The persistence intervals.
+ :rtype: list of pair of list of int
+
+ :note: intervals_in_dim function requires
+ :func:`persistence()<gudhi.SimplexTree.persistence>`
+ function to be launched first.
+ """
+ cdef vector[pair[vector[int],vector[int]]] persistence_pairs_result
+ if self.pcohptr != NULL:
+ persistence_pairs_result = self.pcohptr.persistence_pairs()
+ else:
+ print("persistence_pairs function requires persistence function"
+ " to be launched first.")
+ return persistence_pairs_result
+
def write_persistence_diagram(self, persistence_file=''):
"""This function writes the persistence intervals of the simplicial
complex in a user given file name.
diff --git a/src/cython/include/Persistent_cohomology_interface.h b/src/cython/include/Persistent_cohomology_interface.h
index 55028fd0..e8889444 100644
--- a/src/cython/include/Persistent_cohomology_interface.h
+++ b/src/cython/include/Persistent_cohomology_interface.h
@@ -85,6 +85,32 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
return persistence;
}
+ std::vector<std::pair<std::vector<int>, std::vector<int>>> persistence_pairs() {
+ auto pairs = persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::get_persistent_pairs();
+
+ std::vector<std::pair<std::vector<int>, std::vector<int>>> persistence_pairs;
+ persistence_pairs.reserve(pairs.size());
+ for (auto pair : pairs) {
+ std::vector<int> birth;
+ if (get<0>(pair) != stptr_->null_simplex()) {
+ for (auto vertex : stptr_->simplex_vertex_range(get<0>(pair))) {
+ birth.push_back(vertex);
+ }
+ }
+
+ std::vector<int> death;
+ if (get<1>(pair) != stptr_->null_simplex()) {
+ for (auto vertex : stptr_->simplex_vertex_range(get<1>(pair))) {
+ death.push_back(vertex);
+ }
+ }
+
+ persistence_pairs.push_back(std::make_pair(birth,death));
+ }
+ return persistence_pairs;
+ }
+
private:
// A copy
FilteredComplex* stptr_;