" << std::endl
#ifdef USE_COEFFICIENTS
<< " --modulus compute homology with coefficients in the prime field Z/
Z"
#endif
<< std::endl;
exit(exit_code);
}
int main(int argc, char** argv) {
const char* filename = nullptr;
file_format format = DISTANCE_MATRIX;
index_t dim_max = 1;
value_t threshold = std::numeric_limits::max();
float ratio = 1;
#ifdef USE_COEFFICIENTS
coefficient_t modulus = 2;
#else
const coefficient_t modulus = 2;
#endif
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") {
std::string parameter = std::string(argv[++i]);
size_t next_pos;
dim_max = std::stol(parameter, &next_pos);
if (next_pos != parameter.size()) print_usage_and_exit(-1);
} else if (arg == "--threshold") {
std::string parameter = std::string(argv[++i]);
size_t next_pos;
threshold = std::stof(parameter, &next_pos);
if (next_pos != parameter.size()) print_usage_and_exit(-1);
} else if (arg == "--ratio") {
std::string parameter = std::string(argv[++i]);
size_t next_pos;
ratio = std::stof(parameter, &next_pos);
if (next_pos != parameter.size()) print_usage_and_exit(-1);
} else if (arg == "--format") {
std::string parameter = std::string(argv[++i]);
if (parameter == "lower-distance")
format = LOWER_DISTANCE_MATRIX;
else if (parameter == "upper-distance")
format = UPPER_DISTANCE_MATRIX;
else if (parameter == "distance")
format = DISTANCE_MATRIX;
else if (parameter == "point-cloud")
format = POINT_CLOUD;
else if (parameter == "dipha")
format = DIPHA;
else if (parameter == "ripser")
format = RIPSER;
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];
}
}
std::ifstream file_stream(filename);
if (filename && file_stream.fail()) {
std::cerr << "couldn't open file " << filename << std::endl;
exit(-1);
}
compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format);
value_t min = std::numeric_limits::infinity(),
max = -std::numeric_limits::infinity(), max_finite = max;
int num_edges = 0;
value_t enclosing_radius = std::numeric_limits::infinity();
for (index_t i = 0; i < dist.size(); ++i) {
value_t r_i = -std::numeric_limits::infinity();
for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j));
enclosing_radius = std::min(enclosing_radius, r_i);
}
if (threshold == std::numeric_limits::max()) threshold = enclosing_radius;
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_finite << "]" << std::endl;
std::cout << "distance matrix with " << dist.size() << " points" << std::endl;
ripser(std::move(dist), dim_max, threshold, ratio, modulus).compute_barcodes();
}