diff options
-rw-r--r-- | ripser.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -36,7 +36,9 @@ */ -#define INDICATE_PROGRESS +#define USE_COEFFICIENTS + +//#define INDICATE_PROGRESS #define PRINT_PERSISTENCE_PAIRS //#define USE_GOOGLE_HASHMAP @@ -108,6 +110,8 @@ std::vector<coefficient_t> multiplicative_inverse_vector(const coefficient_t m) return inverse; } +#ifdef USE_COEFFICIENTS + struct __attribute__((packed)) entry_t { index_t index : 8 * (sizeof(index_t) - sizeof(coefficient_t)); coefficient_t coefficient; @@ -132,6 +136,16 @@ std::ostream& operator<<(std::ostream& stream, const entry_t& e) { return stream; } +#else + +typedef index_t entry_t; +const index_t get_index(const entry_t& i) { return i; } +index_t get_coefficient(const entry_t& i) { return 1; } +entry_t make_entry(index_t _index, coefficient_t _value) { return entry_t(_index); } +void set_coefficient(entry_t& e, const coefficient_t c) {} + +#endif + const entry_t& get_entry(const entry_t& e) { return e; } struct entry_hash { @@ -314,6 +328,7 @@ public: }; template <typename Column> diameter_entry_t pop_pivot(Column& column, coefficient_t modulus) { +#ifdef USE_COEFFICIENTS diameter_entry_t pivot(-1); while (!column.empty()) { if (get_coefficient(pivot) == 0) @@ -326,6 +341,21 @@ template <typename Column> diameter_entry_t pop_pivot(Column& column, coefficien column.pop(); } if (get_coefficient(pivot) == 0) pivot = -1; +#else + if (column.empty()) return diameter_entry_t(-1); + + auto pivot = column.top(); + column.pop(); + while (!column.empty() && get_index(column.top()) == get_index(pivot)) { + column.pop(); + if (column.empty()) + return diameter_entry_t(-1); + else { + pivot = column.top(); + column.pop(); + } + } +#endif return pivot; } @@ -965,7 +995,9 @@ void print_usage_and_exit(int exit_code) { << std::endl << " --dim <k> compute persistent homology up to dimension k" << std::endl << " --threshold <t> compute Rips complexes up to diameter t" << std::endl +#ifdef USE_COEFFICIENTS << " --modulus <p> compute homology with coefficients in the prime field Z/pZ" +#endif << std::endl << " --ratio <r> only show persistence pairs with death/birth ratio > r" << std::endl; exit(exit_code); @@ -1018,11 +1050,13 @@ int main(int argc, char** argv) { format = BINARY; else print_usage_and_exit(-1); +#ifdef USE_COEFFICIENTS } else if (arg == "--modulus") { std::string parameter = std::string(argv[++i]); size_t next_pos; modulus = std::stol(parameter, &next_pos); if (next_pos != parameter.size() || !is_prime(modulus)) print_usage_and_exit(-1); +#endif } else { if (filename) { print_usage_and_exit(-1); } filename = argv[i]; |