summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology/include
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-11-13 20:07:20 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-11-13 20:07:20 +0000
commitccf7f9e5b8840f57c68dec83e2153c3cc5804b61 (patch)
tree59664e190c2790c203ba338a523f56b3464039be /src/Persistent_cohomology/include
parentfc91de9f736c13f38d096fc1da78c688e7992fe7 (diff)
Clean-up.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@912 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5652acf2ed5eb6f11428d2907963b5d1a1359be
Diffstat (limited to 'src/Persistent_cohomology/include')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 3875afc6..2d6a85c1 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -431,13 +431,14 @@ class Persistent_cohomology {
std::map<Simplex_key, Arith_element> & map_a_ds, Simplex_handle sigma,
int dim_sigma) {
// traverses the boundary of sigma, keeps track of the annotation vectors,
- // with multiplicity.
-#if 0
- std::vector<std::pair<Column *, int>> annotations_in_boundary;
-#else
- static std::vector<std::pair<Column *, int>> annotations_in_boundary;
- annotations_in_boundary.clear();
-#endif
+ // with multiplicity. We used to sum the coefficients directly in
+ // annotations_in_boundary by using a map, we now do it later.
+ typedef std::pair<Column *, int> annotation_t;
+ std::vector<annotation_t> annotations_in_boundary;
+ /* A small speed boost is possible with the following non-thread-safe:
+ static std::vector<std::pair<Column *, int>> annotations_in_boundary;
+ annotations_in_boundary.clear();
+ */
int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the
// alternate sum in the boundary.
Simplex_key key;
@@ -454,18 +455,18 @@ class Persistent_cohomology {
}
sign = -sign;
}
- std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first<b.first;});
+ // Place identical annotations consecutively so we can easily sum their multiplicities.
+ std::sort(annotations_in_boundary.begin(), annotations_in_boundary.end(),
+ [](annotation_t& a, annotation_t& b) { return a.first < b.first; });
+
// Sum the annotations with multiplicity, using a map<key,coeff>
// to represent a sparse vector.
std::pair<typename std::map<Simplex_key, Arith_element>::iterator, bool> result_insert_a_ds;
- auto ann_it = annotations_in_boundary.begin();
- while (ann_it != annotations_in_boundary.end()) {
- auto col = ann_it->first;
+ for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) {
+ Column* col = ann_it->first;
int coef = ann_it->second;
- for (;;) {
- if (++ann_it == annotations_in_boundary.end() || ann_it->first != col)
- break;
+ while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) {
coef += ann_it->second;
}
// The following test is just a heuristic, it is not required, and it is fine that is misses p == 0.