From da9a4c65fab5e201e56d08322e4971c925db2b9f Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 23 Jul 2016 15:43:39 +0200 Subject: file parsing more robust --- examples/projective_plane.lower_distance_matrix | 24 ++++++++++++------------ ripser.cpp | 19 ++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/examples/projective_plane.lower_distance_matrix b/examples/projective_plane.lower_distance_matrix index 29134ec..a7ad7e6 100644 --- a/examples/projective_plane.lower_distance_matrix +++ b/examples/projective_plane.lower_distance_matrix @@ -1,13 +1,13 @@ -1, -1,2, -1,2,2, -1,2,2,2, -1,1,2,1,2, -1,2,1,2,1,2, -1,1,2,2,1,2,2, -1,2,1,1,2,2,2,2, -2,1,1,2,2,1,1,1,1, -2,2,2,2,2,1,1,2,2,1, -2,2,2,2,2,2,2,1,1,1,2, -2,2,2,1,1,1,1,1,1,2,1,1, \ No newline at end of file +1 +1,2 +1,2,2 +1,2,2,2 +1,1,2,1,2 +1,2,1,2,1,2 +1,1,2,2,1,2,2 +1,2,1,1,2,2,2,2 +2,1,1,2,2,1,1,1,1 +2,2,2,2,2,1,1,2,2,1 +2,2,2,2,2,2,2,1,1,1,2 +2,2,2,1,1,1,1,1,1,2,1,1 \ No newline at end of file diff --git a/ripser.cpp b/ripser.cpp index e228ba9..68d0811 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -367,7 +367,7 @@ template diameter_entry_t pop_pivot(Heap& column, coefficient_t return diameter_entry_t(-1); else pivot = column.top(); - } + } } while (!column.empty() && get_index(column.top()) == get_index(pivot)); if (get_index(pivot) != -1) { set_coefficient(pivot, coefficient); } #else @@ -722,8 +722,8 @@ int main(int argc, char** argv) { for (index_t i = 1; i < argc; ++i) { const std::string arg(argv[i]); if (arg == "--help") { - print_usage_and_exit(0); - } else if (arg == "--dim") { + print_usage_and_exit(0); + } else if (arg == "--dim") { std::string parameter = std::string(argv[++i]); size_t next_pos; dim_max = std::stol(parameter, &next_pos); @@ -772,8 +772,7 @@ int main(int argc, char** argv) { dist_full.distances = std::vector>(n, std::vector(n)); for (int i = 0; i < n; ++i) - for (int j = 0; j < n; ++j) - dist_full.distances[i][j] = read(input_stream); + for (int j = 0; j < n; ++j) dist_full.distances[i][j] = read(input_stream); std::cout << "distance matrix with " << n << " points" << std::endl; compressed_lower_distance_matrix_adapter dist(diameters, dist_full); @@ -782,9 +781,8 @@ int main(int argc, char** argv) { #ifdef FILE_FORMAT_UPPER_TRIANGULAR_CSV std::vector distances; - std::string value_string; - while (std::getline(input_stream, value_string, ',')) - distances.push_back(std::stod(value_string)); + value_t value; + while ((input_stream >> value).ignore()) distances.push_back(value); compressed_upper_distance_matrix_adapter dist_upper(distances); @@ -797,9 +795,8 @@ int main(int argc, char** argv) { #ifdef FILE_FORMAT_LOWER_TRIANGULAR_CSV std::vector& distances = diameters; - std::string value_string; - while (std::getline(input_stream, value_string, ',')) - distances.push_back(std::stod(value_string)); + value_t value; + while ((input_stream >> value).ignore()) distances.push_back(value); compressed_lower_distance_matrix_adapter dist(distances); -- cgit v1.2.3