summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h32
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h35
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h11
3 files changed, 31 insertions, 47 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 8bd265d8..896a7a9f 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -336,18 +336,18 @@ class Persistent_cohomology {
if (ds_parent_[key] == key // root of its tree
&& zero_cocycles_.find(key) == zero_cocycles_.end()) {
- persistent_pairs_.push_back(
- Persistent_interval(cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic()));
+ persistent_pairs_.emplace_back(
+ cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic());
}
}
for (auto zero_idx : zero_cocycles_) {
- persistent_pairs_.push_back(
- Persistent_interval(cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic()));
+ persistent_pairs_.emplace_back(
+ cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic());
}
// Compute infinite interval of dimension > 0
for (auto cocycle : transverse_idx_) {
- persistent_pairs_.push_back(
- Persistent_interval(cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_));
+ persistent_pairs_.emplace_back(
+ cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_);
}
}
@@ -387,8 +387,8 @@ class Persistent_cohomology {
if (cpx_->filtration(cpx_->simplex(idx_coc_u))
< cpx_->filtration(cpx_->simplex(idx_coc_v))) { // Kill cocycle [idx_coc_v], which is younger.
if (interval_length_policy(cpx_->simplex(idx_coc_v), sigma)) {
- persistent_pairs_.push_back(
- Persistent_interval(cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic()));
+ persistent_pairs_.emplace_back(
+ cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic());
}
// Maintain the index of the 0-cocycle alive.
if (kv != idx_coc_v) {
@@ -402,8 +402,8 @@ class Persistent_cohomology {
}
} else { // Kill cocycle [idx_coc_u], which is younger.
if (interval_length_policy(cpx_->simplex(idx_coc_u), sigma)) {
- persistent_pairs_.push_back(
- Persistent_interval(cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic()));
+ persistent_pairs_.emplace_back(
+ cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic());
}
// Maintain the index of the 0-cocycle alive.
if (ku != idx_coc_u) {
@@ -553,9 +553,9 @@ class Persistent_cohomology {
Arith_element charac) {
// Create a finite persistent interval for which the interval exists
if (interval_length_policy(cpx_->simplex(death_key), sigma)) {
- persistent_pairs_.push_back(Persistent_interval(cpx_->simplex(death_key) // creator
- , sigma // destructor
- , charac)); // fields
+ persistent_pairs_.emplace_back(cpx_->simplex(death_key) // creator
+ , sigma // destructor
+ , charac); // fields
}
auto death_key_row = transverse_idx_.find(death_key); // Find the beginning of the row.
@@ -695,7 +695,7 @@ class Persistent_cohomology {
void output_diagram(std::ostream& ostream = std::cout) {
cmp_intervals_by_length cmp(cpx_);
- persistent_pairs_.sort(cmp);
+ std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp);
bool has_infinity = std::numeric_limits<Filtration_value>::has_infinity;
for (auto pair : persistent_pairs_) {
// Special case on windows, inf is "1.#INF" (cf. unitary tests and R package TDA)
@@ -714,7 +714,7 @@ class Persistent_cohomology {
{
std::ofstream diagram_out(diagram_name.c_str());
cmp_intervals_by_length cmp( cpx_ );
- persistent_pairs_.sort( cmp );
+ std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp);
for(auto pair : persistent_pairs_)
{
diagram_out << cpx_->dimension(get<0>(pair)) << " "
@@ -761,7 +761,7 @@ class Persistent_cohomology {
/* Key -> row. */
std::map<Simplex_key, cocycle> transverse_idx_;
/* Persistent intervals. */
- std::list<Persistent_interval> persistent_pairs_;
+ std::vector<Persistent_interval> persistent_pairs_;
length_interval interval_length_policy;
boost::object_pool<Column> column_pool_;
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 61e07f84..2916ca97 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -881,40 +881,25 @@ class Simplex_tree {
static void intersection(std::vector<std::pair<Vertex_handle, Node> >& intersection,
Dictionary_it begin1, Dictionary_it end1,
Dictionary_it begin2, Dictionary_it end2,
- Filtration_value filtration) {
+ Filtration_value filtration_) {
if (begin1 == end1 || begin2 == end2)
return; // ----->>
while (true) {
if (begin1->first == begin2->first) {
- intersection.push_back(std::pair<Vertex_handle, Node>(begin1->first,
- Node(NULL,
- maximum(begin1->second.filtration(),
- begin2->second.filtration(), filtration))));
- ++begin1;
- ++begin2;
- if (begin1 == end1 || begin2 == end2)
+ Filtration_value filt = (std::max)({begin1->second.filtration(), begin2->second.filtration(), filtration_});
+ intersection.push_back(std::pair<Vertex_handle, Node>(begin1->first, Node(NULL, filt)));
+ if (++begin1 == end1 || ++begin2 == end2)
+ return; // ----->>
+ } else if (begin1->first < begin2->first) {
+ if (++begin1 == end1)
+ return;
+ } else /* begin1->first > begin2->first */ {
+ if (++begin2 == end2)
return; // ----->>
- } else {
- if (begin1->first < begin2->first) {
- ++begin1;
- if (begin1 == end1)
- return;
- } else {
- ++begin2;
- if (begin2 == end2)
- return; // ----->>
- }
}
}
}
- /** Maximum over 3 values.*/
- static Filtration_value maximum(Filtration_value a, Filtration_value b,
- Filtration_value c) {
- Filtration_value max = (a < b) ? b : a;
- return ((max < c) ? c : max);
- }
-
public:
/** \brief Write the hasse diagram of the simplicial complex in os.
*
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
index 977fafa1..d6cbacaa 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
@@ -77,8 +77,8 @@ class Simplex_tree_siblings {
parent_(parent),
members_(boost::container::ordered_unique_range, members.begin(),
members.end()) {
- for (auto map_it = members_.begin(); map_it != members_.end(); map_it++) {
- map_it->second.assign_children(this);
+ for (auto& map_el : members_) {
+ map_el.second.assign_children(this);
}
}
@@ -96,8 +96,7 @@ class Simplex_tree_siblings {
return;
}
if (sh == members_.end()) {
- members_.insert(
- std::pair<Vertex_handle, Node>(v, Node(this, filtration_value)));
+ members_.emplace(v, Node(this, filtration_value));
return;
}
}
@@ -110,7 +109,7 @@ class Simplex_tree_siblings {
return oncles_;
}
- Vertex_handle parent() {
+ Vertex_handle parent() const {
return parent_;
}
@@ -118,7 +117,7 @@ class Simplex_tree_siblings {
return members_;
}
- size_t size() {
+ size_t size() const {
return members_.size();
}