summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology/include
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2019-11-09 21:41:06 +0100
committerMarc Glisse <marc.glisse@inria.fr>2019-11-09 21:41:06 +0100
commit1e5d0ca3f84f1e5c132014d3cfc96bfe0aa3d7ee (patch)
tree5f14590c34a510fbb9d4475233ffa9f943bbc39c /src/Persistent_cohomology/include
parentdb405e686cc859e510b894dca45562158cb5c963 (diff)
Empty complexes have 0 (not -1) Betti numbers
Diffstat (limited to 'src/Persistent_cohomology/include')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 944b6d35..0f1876d0 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -600,8 +600,10 @@ class Persistent_cohomology {
* @return A vector of Betti numbers.
*/
std::vector<int> betti_numbers() const {
+ // Don't allocate a vector of negative size for an empty complex
+ int siz = std::max(dim_max_, 0);
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(dim_max_, 0);
+ std::vector<int> betti_numbers(siz);
for (auto pair : persistent_pairs_) {
// Count never ended persistence intervals
@@ -639,8 +641,10 @@ class Persistent_cohomology {
* @return A vector of persistent Betti numbers.
*/
std::vector<int> persistent_betti_numbers(Filtration_value from, Filtration_value to) const {
+ // Don't allocate a vector of negative size for an empty complex
+ int siz = std::max(dim_max_, 0);
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(dim_max_, 0);
+ std::vector<int> betti_numbers(siz);
for (auto pair : persistent_pairs_) {
// Count persistence intervals that covers the given interval
// null_simplex test : if the function is called with to=+infinity, we still get something useful. And it will