From 740992e73b581c646f0f381789264f2504e76e8b Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Sep 2017 19:16:08 +0200 Subject: use sparse distance matrix only when threshold is below maximum value --- ripser.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 688df6a..5acc32e 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1089,10 +1089,9 @@ int main(int argc, char** argv) { file_format format = DISTANCE_MATRIX; index_t dim_max = 1; - value_t threshold = std::numeric_limits::infinity(); - - float ratio = 1; + value_t threshold = std::numeric_limits::max(); + float ratio = 1; #ifdef USE_COEFFICIENTS coefficient_t modulus = 2; @@ -1156,28 +1155,30 @@ int main(int argc, char** argv) { compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); - std::cout << "distance matrix with " << dist.size() << " points" << std::endl; + value_t min = std::numeric_limits::infinity(), + max = -std::numeric_limits::infinity(), max_finite = max; + int num_edges = 0; - value_t min = std::numeric_limits::infinity(), max = -std::numeric_limits::infinity(); - - for (auto d: dist.distances) { - if (d != std::numeric_limits::infinity() ) { - min = std::min(min, d); - max = std::max(max, d); - } else { - threshold = std::min(threshold, std::numeric_limits::max()); - } + for (auto d : dist.distances) { + min = std::min(min, d); + max = std::max(max, d); + max_finite = d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; + if (d <= threshold) ++num_edges; } - - std::cout << "value range: [" << min << "," << max << "]" - << std::endl; - if (threshold == std::numeric_limits::infinity()) - ripser(std::move(dist), dim_max, threshold, ratio, modulus) - .compute_barcodes(); - else + std::cout << "value range: [" << min << "," << max_finite << "]" << std::endl; + + if (threshold >= max) { + std::cout << "distance matrix with " << dist.size() << " points" << std::endl; + ripser(std::move(dist), dim_max, threshold, ratio, + modulus) + .compute_barcodes(); + } else { + std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges + << " entries" << std::endl; + ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, threshold, ratio, modulus) - .compute_barcodes(); - + .compute_barcodes(); + } } -- cgit v1.2.3