Skip to content

Commit

Permalink
pretty-print
Browse files Browse the repository at this point in the history
  • Loading branch information
ubauer committed Sep 30, 2016
1 parent 57079b5 commit dea2c3d
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions ripser.cpp
Expand Up @@ -18,7 +18,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */



//#define ASSEMBLE_REDUCTION_MATRIX //#define ASSEMBLE_REDUCTION_MATRIX
//#define USE_COEFFICIENTS //#define USE_COEFFICIENTS


Expand Down Expand Up @@ -167,7 +166,7 @@ typedef index_t entry_t;
const index_t get_index(entry_t i) { return i; } const index_t get_index(entry_t i) { return i; }
index_t get_coefficient(entry_t i) { return 1; } index_t get_coefficient(entry_t i) { return 1; }
entry_t make_entry(index_t _index, coefficient_t _value) { return entry_t(_index); } entry_t make_entry(index_t _index, coefficient_t _value) { return entry_t(_index); }
void set_coefficient(index_t& e, const coefficient_t c) { } void set_coefficient(index_t& e, const coefficient_t c) {}


#endif #endif


Expand All @@ -177,7 +176,7 @@ template <typename Entry> struct smaller_index {
bool operator()(const Entry& a, const Entry& b) { return get_index(a) < get_index(b); } bool operator()(const Entry& a, const Entry& b) { return get_index(a) < get_index(b); }
}; };


class diameter_index_t: public std::pair<value_t, index_t> { class diameter_index_t : public std::pair<value_t, index_t> {
public: public:
diameter_index_t() : std::pair<value_t, index_t>() {} diameter_index_t() : std::pair<value_t, index_t>() {}
diameter_index_t(std::pair<value_t, index_t> p) : std::pair<value_t, index_t>(p) {} diameter_index_t(std::pair<value_t, index_t> p) : std::pair<value_t, index_t>(p) {}
Expand Down Expand Up @@ -284,7 +283,8 @@ template <class DistanceMatrix> class simplex_coboundary_enumerator {
value_t coface_diameter = get_diameter(simplex); value_t coface_diameter = get_diameter(simplex);
for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w));
coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus;
return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v--, k + 1) + idx_below, coface_coefficient); return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v--, k + 1) + idx_below,
coface_coefficient);
} }
}; };


Expand Down Expand Up @@ -503,9 +503,10 @@ void assemble_columns_to_reduce(std::vector<diameter_index_t>& columns_to_reduce
value_t diameter = comp.diameter(index); value_t diameter = comp.diameter(index);
if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index));
#ifdef INDICATE_PROGRESS #ifdef INDICATE_PROGRESS
if ((index + 1) % 1000 == 0) if ((index + 1) % 1000 == 0)
std::cout << "\033[K" std::cout << "\033[K"
<< "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" << num_simplices << " columns" << std::flush << "\r"; << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/"
<< num_simplices << " columns" << std::flush << "\r";
#endif #endif
} }
} }
Expand All @@ -525,8 +526,7 @@ void assemble_columns_to_reduce(std::vector<diameter_index_t>& columns_to_reduce
template <typename DistanceMatrix, typename ComparatorCofaces, typename Comparator> template <typename DistanceMatrix, typename ComparatorCofaces, typename Comparator>
void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<index_t, index_t>& pivot_column_index, void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<index_t, index_t>& pivot_column_index,
index_t dim, index_t n, value_t threshold, coefficient_t modulus, index_t dim, index_t n, value_t threshold, coefficient_t modulus,
const std::vector<coefficient_t>& multiplicative_inverse, const std::vector<coefficient_t>& multiplicative_inverse, const DistanceMatrix& dist,
const DistanceMatrix& dist,
const ComparatorCofaces& comp, const Comparator& comp_prev, const ComparatorCofaces& comp, const Comparator& comp_prev,
const binomial_coeff_table& binomial_coeff) { const binomial_coeff_table& binomial_coeff) {


Expand Down Expand Up @@ -596,8 +596,7 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in
#endif #endif
#endif #endif


for (auto it = coeffs_begin; it != coeffs_end; ++it) for (auto it = coeffs_begin; it != coeffs_end; ++it) {
{
diameter_entry_t simplex = *it; diameter_entry_t simplex = *it;
set_coefficient(simplex, get_coefficient(simplex) * factor % modulus); set_coefficient(simplex, get_coefficient(simplex) * factor % modulus);


Expand Down Expand Up @@ -927,8 +926,7 @@ int main(int argc, char** argv) {


if (u != v) { if (u != v) {
#ifdef PRINT_PERSISTENCE_PAIRS #ifdef PRINT_PERSISTENCE_PAIRS
if (get_diameter(e) > 0) if (get_diameter(e) > 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl;
std::cout << " [0," << get_diameter(e) << ")" << std::endl;
#endif #endif
dset.link(u, v); dset.link(u, v);
} else } else
Expand All @@ -949,8 +947,8 @@ int main(int argc, char** argv) {
hash_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()); pivot_column_index.reserve(columns_to_reduce.size());


compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, dist,
dist, comp, comp_prev, binomial_coeff); comp, comp_prev, binomial_coeff);


if (dim < dim_max) { if (dim < dim_max) {
assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, comp, dim, n, threshold, binomial_coeff); assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, comp, dim, n, threshold, binomial_coeff);
Expand Down

0 comments on commit dea2c3d

Please sign in to comment.