diff options
author | Arnur Nigmetov <nigmetov@tugraz.at> | 2020-02-19 17:42:41 +0100 |
---|---|---|
committer | Arnur Nigmetov <nigmetov@tugraz.at> | 2020-02-19 17:42:41 +0100 |
commit | f62d98e76b9dff173f9144caddff1217d0bb81a9 (patch) | |
tree | 4ea6a6d894114c0d98c91079edfcc59d0611eb14 | |
parent | be93a006a3f2c630abf9d0169a70e6292ac7504f (diff) |
Require first file line specify the format.
1. Input format must be in the first line
of input file, as in RIVET.
2. Disable more unnecessary output.
3. Get rid of some warnings.
-rw-r--r-- | matching/include/bifiltration.h | 4 | ||||
-rw-r--r-- | matching/include/common_defs.h | 1 | ||||
-rw-r--r-- | matching/src/bifiltration.cpp | 40 | ||||
-rw-r--r-- | matching/src/main.cpp | 22 | ||||
-rw-r--r-- | matching/src/simplex.cpp | 1 | ||||
-rw-r--r-- | matching/src/tests/prism_1.bif | 1 | ||||
-rw-r--r-- | matching/src/tests/prism_2.bif | 1 | ||||
-rw-r--r-- | matching/src/tests/test_matching_distance.cpp | 4 |
8 files changed, 53 insertions, 21 deletions
diff --git a/matching/include/bifiltration.h b/matching/include/bifiltration.h index bdb7a4e..f505ed9 100644 --- a/matching/include/bifiltration.h +++ b/matching/include/bifiltration.h @@ -27,9 +27,7 @@ namespace md { Bifiltration& operator=(Bifiltration&& other) = default; - Bifiltration(const std::string& fname, - BifiltrationFormat input_format = BifiltrationFormat::rivet); // read from file - + Bifiltration(const std::string& fname); // read from file template<class Iter> Bifiltration(Iter begin, Iter end) diff --git a/matching/include/common_defs.h b/matching/include/common_defs.h index 4a71615..3f3d937 100644 --- a/matching/include/common_defs.h +++ b/matching/include/common_defs.h @@ -7,5 +7,4 @@ //#define MD_DO_CHECKS //#define MD_DO_FULL_CHECK - #endif //MATCHING_DISTANCE_DEF_DEBUG_H diff --git a/matching/src/bifiltration.cpp b/matching/src/bifiltration.cpp index 676b0cc..4131e6b 100644 --- a/matching/src/bifiltration.cpp +++ b/matching/src/bifiltration.cpp @@ -29,7 +29,7 @@ namespace md { bounding_box_ = Box(lower_left, upper_right); } - Bifiltration::Bifiltration(const std::string& fname, BifiltrationFormat input_format) + Bifiltration::Bifiltration(const std::string& fname ) { std::ifstream ifstr {fname.c_str()}; if (!ifstr.good()) { @@ -38,6 +38,23 @@ namespace md { throw std::runtime_error(error_message); } + BifiltrationFormat input_format; + + std::string s; + + while(ignore_line(s)) { + std::getline(ifstr, s); + } + + if (s == "bifiltration") { + input_format = BifiltrationFormat::rivet; + } else if (s == "bifiltration_phat_like") { + input_format = BifiltrationFormat::phat_like; + } else { + std::cerr << "Unknown format: '" << s << "' in file " << fname << std::endl; + throw std::runtime_error("unknown bifiltration format"); + } + switch(input_format) { case BifiltrationFormat::rivet : rivet_format_reader(ifstr); @@ -46,22 +63,27 @@ namespace md { phat_like_format_reader(ifstr); break; } + + ifstr.close(); + init(); } void Bifiltration::rivet_format_reader(std::ifstream& ifstr) { std::string s; - std::getline(ifstr, s); - assert(s == std::string("bifiltration")); + // read axes names std::getline(ifstr, parameter_1_name_); std::getline(ifstr, parameter_2_name_); Index index = 0; while(std::getline(ifstr, s)) { - if (not ignore_line(s)) + if (!ignore_line(s)) { simplices_.emplace_back(index++, s, BifiltrationFormat::rivet); + } } + + } void Bifiltration::phat_like_format_reader(std::ifstream& ifstr) @@ -70,11 +92,17 @@ namespace md { // read stream line by line; do not use >> operator std::string s; std::getline(ifstr, s); + + // first line contains number of simplices long n_simplices = std::stol(s); - for(Index index = 0; index < n_simplices; index++) { + // all other lines represent a simplex + Index index = 0; + while(index < n_simplices) { std::getline(ifstr, s); - simplices_.emplace_back(index, s, BifiltrationFormat::phat_like); + if (!ignore_line(s)) { + simplices_.emplace_back(index++, s, BifiltrationFormat::phat_like); + } } spd::debug("Read {} simplices from file", n_simplices); } diff --git a/matching/src/main.cpp b/matching/src/main.cpp index 7e74475..f1472be 100644 --- a/matching/src/main.cpp +++ b/matching/src/main.cpp @@ -22,9 +22,9 @@ using namespace md; namespace fs = std::experimental::filesystem;
+#ifdef PRINT_HEAT_MAP
void print_heat_map(const md::HeatMaps& hms, std::string fname, const CalculationParams& params)
{
-#ifdef PRINT_HEAT_MAP
spd::debug("Entered print_heat_map");
std::set<Real> mu_vals, lambda_vals;
auto hm_iter = hms.end();
@@ -130,23 +130,25 @@ void print_heat_map(const md::HeatMaps& hms, std::string fname, const Calculatio ofs.close();
spd::debug("Exit print_heat_map");
-#endif
}
+#endif
int main(int argc, char** argv)
{
spdlog::set_level(spdlog::level::info);
- //spdlog::set_pattern("[%L] %v");
using opts::Option;
using opts::PosOption;
opts::Options ops;
bool help = false;
- bool heatmap_only = false;
bool no_stop_asap = false;
CalculationParams params;
+#ifdef PRINT_HEAT_MAP
+ bool heatmap_only = false;
+#endif
+
std::string bounds_list_str = "local_combined";
std::string traverse_list_str = "BFS";
@@ -176,13 +178,13 @@ int main(int argc, char** argv) auto bounds_list = split_by_delim(bounds_list_str, ',');
auto traverse_list = split_by_delim(traverse_list_str, ',');
- Bifiltration bif_a(fname_a, BifiltrationFormat::phat_like);
- Bifiltration bif_b(fname_b, BifiltrationFormat::phat_like);
+ Bifiltration bif_a(fname_a);
+ Bifiltration bif_b(fname_b);
bif_a.sanity_check();
bif_b.sanity_check();
- spd::info("Read bifiltrations {} {}", fname_a, fname_b);
+ spd::debug("Read bifiltrations {} {}", fname_a, fname_b);
std::vector<BoundStrategy> bound_strategies;
std::vector<TraverseStrategy> traverse_strategies;
@@ -195,13 +197,15 @@ int main(int argc, char** argv) traverse_strategies.push_back(ts_from_string(s));
}
+
+#ifdef EXPERIMENTAL_TIMING
+
for(auto bs : bound_strategies) {
for(auto ts : traverse_strategies) {
spd::info("Will test combination {} {}", bs, ts);
}
}
-#ifdef EXPERIMENTAL_TIMING
struct ExperimentResult {
CalculationParams params {CalculationParams()};
int n_hera_calls {0};
@@ -360,6 +364,8 @@ int main(int argc, char** argv) params.bound_strategy = bound_strategies.back();
params.traverse_strategy = traverse_strategies.back();
+ spd::debug("Will use {} bound, {} traverse strategy", params.bound_strategy, params.traverse_strategy);
+
Real dist = matching_distance(bif_a, bif_b, params);
std::cout << dist << std::endl;
#endif
diff --git a/matching/src/simplex.cpp b/matching/src/simplex.cpp index b490db0..6b53680 100644 --- a/matching/src/simplex.cpp +++ b/matching/src/simplex.cpp @@ -62,7 +62,6 @@ namespace md { void Simplex::init_rivet(std::string s) { -// throw std::runtime_error("Not implemented"); auto delim_pos = s.find_first_of(";"); assert(delim_pos > 0); std::string vertices_str = s.substr(0, delim_pos); diff --git a/matching/src/tests/prism_1.bif b/matching/src/tests/prism_1.bif index 416c40c..b37e807 100644 --- a/matching/src/tests/prism_1.bif +++ b/matching/src/tests/prism_1.bif @@ -1,3 +1,4 @@ +bifiltration_phat_like 26 0 0 0 0 0 0 diff --git a/matching/src/tests/prism_2.bif b/matching/src/tests/prism_2.bif index e11faa9..49885e6 100644 --- a/matching/src/tests/prism_2.bif +++ b/matching/src/tests/prism_2.bif @@ -1,3 +1,4 @@ +bifiltration_phat_like 27 0 0 0 0 0 0 diff --git a/matching/src/tests/test_matching_distance.cpp b/matching/src/tests/test_matching_distance.cpp index 7cd71b2..df9345e 100644 --- a/matching/src/tests/test_matching_distance.cpp +++ b/matching/src/tests/test_matching_distance.cpp @@ -115,8 +115,8 @@ TEST_CASE("Bifiltrations from file", "[matching_distance][small_example][lesnick fname_a = "../src/tests/prism_1.bif"; fname_b = "../src/tests/prism_2.bif"; - Bifiltration bif_a(fname_a, BifiltrationFormat::phat_like); - Bifiltration bif_b(fname_b, BifiltrationFormat::phat_like); + Bifiltration bif_a(fname_a); + Bifiltration bif_b(fname_b); CalculationParams params; |