summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Bauer <ulrich.bauer@tum.de>2016-07-17 16:27:15 +0200
committerUlrich Bauer <ulrich.bauer@tum.de>2016-07-17 16:27:15 +0200
commit6765b225ea83ab7fbba32cddff6e92012fbd833d (patch)
tree5cdf33b560123c5fe2b3e7d4765db9c0c576f46a
parent0ed9c960fe33375e8ec40dc78913d145b1d8fdac (diff)
parent37097e6fbff2f32b5b9b06f1834b83cec8af2fef (diff)
Merge branch 'google-sparse-hash-map' into dev
* google-sparse-hash-map: use google sparse hash map
-rw-r--r--ripser.cpp24
-rw-r--r--ripser.xcodeproj/project.pbxproj2
2 files changed, 20 insertions, 6 deletions
diff --git a/ripser.cpp b/ripser.cpp
index db1b20b..3661b9c 100644
--- a/ripser.cpp
+++ b/ripser.cpp
@@ -8,12 +8,24 @@
//#define FILE_FORMAT_UPPER_TRIANGULAR_CSV
//#define FILE_FORMAT_DIPHA
+//#define USE_GOOGLE_HASHMAP
+
#include <iostream>
#include <fstream>
#include <cassert>
#include <queue>
#include <unordered_map>
+#ifdef USE_GOOGLE_HASHMAP
+#include <sparsehash/sparse_hash_map>
+template <class Key, class T> class hash_map : public google::sparse_hash_map<Key, T> {
+public:
+ inline void reserve(size_t hint) { this->resize(hint); }
+};
+#else
+template <class Key, class T> class hash_map : public std::unordered_map<Key, T> {};
+#endif
+
typedef float value_t;
// typedef uint16_t value_t;
@@ -382,7 +394,7 @@ template <typename Heap> diameter_entry_t get_pivot(Heap& column, coefficient_t
template <typename Comparator>
void assemble_columns_to_reduce(std::vector<diameter_index_t>& columns_to_reduce,
- std::unordered_map<index_t, index_t>& pivot_column_index,
+ hash_map<index_t, index_t>& pivot_column_index,
const Comparator& comp, index_t dim, index_t n, value_t threshold,
const binomial_coeff_table& binomial_coeff) {
index_t num_simplices = binomial_coeff(n, dim + 2);
@@ -449,10 +461,10 @@ void push_entry(Heap& column, index_t i, coefficient_t c, value_t diameter) {
template <typename DistanceMatrix, typename ComparatorCofaces, typename Comparator>
void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce,
- std::unordered_map<index_t, index_t>& pivot_column_index,
- const DistanceMatrix& dist, const ComparatorCofaces& comp,
- const Comparator& comp_prev, index_t dim, index_t n, value_t threshold,
- coefficient_t modulus, const std::vector<coefficient_t>& multiplicative_inverse,
+ hash_map<index_t, index_t>& pivot_column_index, const DistanceMatrix& dist,
+ const ComparatorCofaces& comp, const Comparator& comp_prev, index_t dim,
+ index_t n, value_t threshold, coefficient_t modulus,
+ const std::vector<coefficient_t>& multiplicative_inverse,
const binomial_coeff_table& binomial_coeff) {
#ifdef PRINT_PERSISTENCE_PAIRS
@@ -800,7 +812,7 @@ int main(int argc, char** argv) {
rips_filtration_comparator<decltype(dist)> comp(dist, dim + 1, binomial_coeff);
rips_filtration_comparator<decltype(dist)> comp_prev(dist, dim, binomial_coeff);
- std::unordered_map<index_t, index_t> pivot_column_index;
+ hash_map<index_t, index_t> pivot_column_index;
pivot_column_index.reserve(columns_to_reduce.size());
compute_pairs(columns_to_reduce, pivot_column_index, dist, comp, comp_prev, dim, n,
diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj
index ed401e8..d924596 100644
--- a/ripser.xcodeproj/project.pbxproj
+++ b/ripser.xcodeproj/project.pbxproj
@@ -160,6 +160,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
+ HEADER_SEARCH_PATHS = /opt/local/include;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -196,6 +197,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
+ HEADER_SEARCH_PATHS = /opt/local/include;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;