summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-03 12:11:23 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-03 12:11:23 +0000
commit5bd222a6472e383ac8aa12cfe47e4c6daef62876 (patch)
treea3a57c42d0024111ce60e2ccd189d69b2069a945
parent46d1ac72c72dca16693d6b5f12752f231a699798 (diff)
parentf904023210531c72c2762a07c59d68c5b2a0d048 (diff)
backmerge of trunk
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@722 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 10b585b7050b993a1c2a4e7876ba9f6d85339ad9
-rw-r--r--src/Bottleneck/test/bottleneck_unit_test.cpp6
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h32
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h18
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h6
-rw-r--r--src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp11
-rw-r--r--src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp11
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h23
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp12
8 files changed, 52 insertions, 67 deletions
diff --git a/src/Bottleneck/test/bottleneck_unit_test.cpp b/src/Bottleneck/test/bottleneck_unit_test.cpp
index 068b8690..c60f5d8a 100644
--- a/src/Bottleneck/test/bottleneck_unit_test.cpp
+++ b/src/Bottleneck/test/bottleneck_unit_test.cpp
@@ -1,6 +1,6 @@
-#define BOOST_TEST_MODULE bottleneck test
-
-#include <boost/test/included/unit_test.hpp>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "bottleneck"
+#include <boost/test/unit_test.hpp>
#include "gudhi/Graph_matching.h"
#include <iostream>
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/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
index 2a4c8692..a12019f8 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
@@ -41,9 +41,7 @@ class Field_Zp {
Field_Zp()
: Prime(0),
- inverse_(),
- mult_id_all(1),
- add_id_all(0) {
+ inverse_() {
}
void init(int charac) {
@@ -81,14 +79,14 @@ class Field_Zp {
}
/** \brief Returns the additive idendity \f$0_{\Bbbk}\f$ of the field.*/
- const Element& additive_identity() const {
- return add_id_all;
+ Element additive_identity() const {
+ return 0;
}
/** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/
- const Element& multiplicative_identity(Element = 0) const {
- return mult_id_all;
+ Element multiplicative_identity(Element = 0) const {
+ return 1;
}
- /** Returns the inverse in the field. Modifies P.*/
+ /** Returns the inverse in the field. Modifies P. ??? */
std::pair<Element, Element> inverse(Element x, Element P) {
return std::pair<Element, Element>(inverse_[x], P);
} // <------ return the product of field characteristic for which x is invertible
@@ -101,7 +99,7 @@ class Field_Zp {
}
/** \brief Returns the characteristic \f$p\f$ of the field.*/
- const int& characteristic() const {
+ int characteristic() const {
return Prime;
}
@@ -109,8 +107,6 @@ class Field_Zp {
int Prime;
/** Property map Element -> Element, which associate to an element its inverse in the field.*/
std::vector<Element> inverse_;
- const Element mult_id_all;
- const Element add_id_all;
};
} // namespace persistent_cohomology
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
index c6fd5282..555d696f 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
@@ -142,7 +142,7 @@ class Multi_field {
return prod_characteristics_;
}
- /** Returns the inverse in the field. Modifies P.*/
+ /** Returns the inverse in the field. Modifies P. ??? */
std::pair<Element, Element> inverse(Element x, Element QS) {
Element QR;
mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t()); // QR <- gcd(x,QS)
@@ -153,12 +153,12 @@ class Multi_field {
mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t());
assert(prod_characteristics_ > 0); // division by zero + non negative values
- return std::pair<Element, Element>(
- (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT);
+ return { (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT };
}
/** Returns -x * y.*/
Element times_minus(const Element& x, const Element& y) {
assert(prod_characteristics_ > 0); // division by zero + non negative values
+ /* This assumes that (x*y)%pc cannot be zero, but Field_Zp has specific code for the 0 case ??? */
return prod_characteristics_ - ((x * y) % prod_characteristics_);
}
diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
index 55bc7066..194b3e74 100644
--- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
+++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
@@ -1,15 +1,14 @@
-#define BOOST_TEST_MODULE persistent_cohomology test
-#include <boost/test/included/unit_test.hpp>
-#include <boost/system/error_code.hpp>
-#include <boost/chrono/thread_clock.hpp>
#include <iostream>
#include <string>
-
+#include <algorithm>
#include <utility> // std::pair, std::make_pair
-
#include <cmath> // float comparison
#include <limits>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "persistent_cohomology"
+#include <boost/test/unit_test.hpp>
+
#include "gudhi/graph_simplicial_complex.h"
#include "gudhi/reader_utils.h"
#include "gudhi/Simplex_tree.h"
diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
index 18a4725e..703682e1 100644
--- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
+++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
@@ -1,15 +1,14 @@
-#define BOOST_TEST_MODULE persistent_cohomology_multi_field test
-#include <boost/test/included/unit_test.hpp>
-#include <boost/system/error_code.hpp>
-#include <boost/chrono/thread_clock.hpp>
#include <iostream>
#include <string>
-
+#include <algorithm>
#include <utility> // std::pair, std::make_pair
-
#include <cmath> // float comparison
#include <limits>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "persistent_cohomology_multi_field"
+#include <boost/test/unit_test.hpp>
+
#include "gudhi/graph_simplicial_complex.h"
#include "gudhi/reader_utils.h"
#include "gudhi/Simplex_tree.h"
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..de350f2d 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);
}
}
@@ -90,19 +90,12 @@ class Simplex_tree_siblings {
* present in the node.
*/
void insert(Vertex_handle v, Filtration_value filtration_value) {
- typename Dictionary::iterator sh = members_.find(v);
- if (sh != members_.end() && sh->second.filtration() > filtration_value) {
- sh->second.assign_filtration(filtration_value);
- return;
- }
- if (sh == members_.end()) {
- members_.insert(
- std::pair<Vertex_handle, Node>(v, Node(this, filtration_value)));
- return;
- }
+ auto ins = members_.emplace(v, Node(this, filtration_value));
+ if (!ins.second && filtration(ins.first) > filtration_value)
+ ins.first->second.assign_filtration(filtration_value);
}
- typename Dictionary::iterator find(Vertex_handle v) {
+ Dictionary_it find(Vertex_handle v) {
return members_.find(v);
}
@@ -110,7 +103,7 @@ class Simplex_tree_siblings {
return oncles_;
}
- Vertex_handle parent() {
+ Vertex_handle parent() const {
return parent_;
}
@@ -118,7 +111,7 @@ class Simplex_tree_siblings {
return members_;
}
- size_t size() {
+ size_t size() const {
return members_.size();
}
diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
index 7f2172a2..566d6d90 100644
--- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
@@ -1,17 +1,14 @@
-#define BOOST_TEST_MODULE simplex_tree test
-#include <boost/test/included/unit_test.hpp>
-#include <boost/range/adaptor/reversed.hpp>
-#include <boost/system/error_code.hpp>
-#include <boost/chrono/thread_clock.hpp>
#include <iostream>
#include <string>
#include <algorithm>
-
#include <utility> // std::pair, std::make_pair
-
#include <cmath> // float comparison
#include <limits>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "simplex_tree"
+#include <boost/test/unit_test.hpp>
+
#include "gudhi/graph_simplicial_complex.h"
#include "gudhi/reader_utils.h"
#include "gudhi/Simplex_tree.h"
@@ -112,6 +109,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_from_file) {
// Size of simplex
int size = 0;
for (auto vertex : st.simplex_vertex_range(f_simplex)) {
+ (void) vertex;
size++;
}
BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex), (0.1 * size))); // Specific test: filtration = 0.1 * simplex_size