From 6acbc89d185d1c537778fb2d4a8503bab61fca31 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Fri, 3 Apr 2020 21:04:52 +0200 Subject: Split compute_persistence from get_persistence. --- .../include/Persistent_cohomology_interface.h | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/python/include') diff --git a/src/python/include/Persistent_cohomology_interface.h b/src/python/include/Persistent_cohomology_interface.h index 8c79e6f3..a29ebbee 100644 --- a/src/python/include/Persistent_cohomology_interface.h +++ b/src/python/include/Persistent_cohomology_interface.h @@ -23,6 +23,7 @@ template class Persistent_cohomology_interface : public persistent_cohomology::Persistent_cohomology { private: + typedef persistent_cohomology::Persistent_cohomology Base; /* * Compare two intervals by dimension, then by length. */ @@ -43,25 +44,28 @@ persistent_cohomology::Persistent_cohomology(*stptr), + : Base(*stptr), stptr_(stptr) { } Persistent_cohomology_interface(FilteredComplex* stptr, bool persistence_dim_max) - : persistent_cohomology::Persistent_cohomology(*stptr, persistence_dim_max), + : Base(*stptr, persistence_dim_max), stptr_(stptr) { } - std::vector>> get_persistence(int homology_coeff_field, - double min_persistence) { - persistent_cohomology::Persistent_cohomology::init_coefficients(homology_coeff_field); - persistent_cohomology::Persistent_cohomology::compute_persistent_cohomology(min_persistence); + void compute_persistence(int homology_coeff_field, double min_persistence) { + Base::init_coefficients(homology_coeff_field); + Base::compute_persistent_cohomology(min_persistence); + } + + void maybe_compute_persistence(int homology_coeff_field, double min_persistence) { + // Currently get_persistent_pairs safely returns an empty vector before compute_persistent_cohomology + if(Base::get_persistent_pairs().empty()) + compute_persistence(homology_coeff_field, min_persistence); + } + std::vector>> get_persistence() { // Custom sort and output persistence cmp_intervals_by_dim_then_length cmp(stptr_); - auto persistent_pairs = persistent_cohomology::Persistent_cohomology::get_persistent_pairs(); + auto persistent_pairs = Base::get_persistent_pairs(); std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp); std::vector>> persistence; @@ -74,8 +78,7 @@ persistent_cohomology::Persistent_cohomology, std::vector>> persistence_pairs() { - auto pairs = persistent_cohomology::Persistent_cohomology::get_persistent_pairs(); + auto pairs = Base::get_persistent_pairs(); std::vector, std::vector>> persistence_pairs; persistence_pairs.reserve(pairs.size()); -- cgit v1.2.3