summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Bauer <ulrich.bauer@tum.de>2016-07-23 15:43:39 +0200
committerUlrich Bauer <ulrich.bauer@tum.de>2016-07-23 15:43:39 +0200
commitda9a4c65fab5e201e56d08322e4971c925db2b9f (patch)
tree105b6cfb859fa6b928df4ca5be4f7c15a994ed2d
parent506dee4d45e28297efc73cec29a714b776b84d18 (diff)
file parsing more robust
-rw-r--r--examples/projective_plane.lower_distance_matrix24
-rw-r--r--ripser.cpp19
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 <typename Heap> 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<std::vector<value_t>>(n, std::vector<value_t>(n));
for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- dist_full.distances[i][j] = read<double>(input_stream);
+ for (int j = 0; j < n; ++j) dist_full.distances[i][j] = read<double>(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<value_t> 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<value_t>& 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);