From a5454ea066a0b148c9f423fc8862e26aae79eefe Mon Sep 17 00:00:00 2001 From: Arnur Nigmetov Date: Fri, 16 Mar 2018 13:52:36 +0100 Subject: Minor changes (indentation, etc) --- .../wasserstein/example/wasserstein_dist_dipha.cpp | 5 +- .../wasserstein/include/basic_defs_ws.hpp | 5 +- geom_matching/wasserstein/include/diagram_reader.h | 136 ++++++++++----------- 3 files changed, 69 insertions(+), 77 deletions(-) diff --git a/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp b/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp index a9029fe..cd8c61a 100644 --- a/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp +++ b/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp @@ -1,6 +1,7 @@ /* Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov +Copyright (c) 2018, G. Spreemann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -49,12 +50,12 @@ int main(int argc, char* argv[]) hera::AuctionParams params; if (argc < 4 ) { - std::cerr << "Usage: " << argv[0] << " file1 file2 ph_degree [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; + std::cerr << "Usage: " << argv[0] << " file1 file2 ph_dim [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl; return 1; } unsigned int dim = std::stoul(argv[3]); - + if (!hera::read_diagram_dipha(argv[1], dim, diagramA)) { std::exit(1); } diff --git a/geom_matching/wasserstein/include/basic_defs_ws.hpp b/geom_matching/wasserstein/include/basic_defs_ws.hpp index de25d48..1750b4e 100644 --- a/geom_matching/wasserstein/include/basic_defs_ws.hpp +++ b/geom_matching/wasserstein/include/basic_defs_ws.hpp @@ -1,6 +1,7 @@ /* Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov +Copyright (c) 2018, G. Spreemann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -205,7 +206,7 @@ template inline void reverse_endianness(T & x) uint8_t * p = reinterpret_cast(&x); std::reverse(p, p + sizeof(T)); } - + template inline T read_le(std::istream & s) { T result; @@ -215,5 +216,5 @@ template inline T read_le(std::istream & s) #endif return result; } - + } // hera diff --git a/geom_matching/wasserstein/include/diagram_reader.h b/geom_matching/wasserstein/include/diagram_reader.h index b6ec635..84bf49c 100644 --- a/geom_matching/wasserstein/include/diagram_reader.h +++ b/geom_matching/wasserstein/include/diagram_reader.h @@ -1,6 +1,7 @@ /* Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov +Copyright (c) 2018, G. Spreemann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -202,84 +203,73 @@ bool read_diagram_point_set(const std::string& fname, ContType_& result) return read_diagram_point_set(fname.c_str(), result, decPrecision); } - template > > - bool read_diagram_dipha(const std::string& fname, unsigned int degree, ContType_& result) +template > > +bool read_diagram_dipha(const std::string& fname, unsigned int dim, ContType_& result) { - std::ifstream file; - file.open(fname, std::ios::in | std::ios::binary); - - if (!file.is_open()) - { - #ifndef FOR_R_TDA - std::cerr << "Could not open file " << fname << "." << std::endl; - #endif - return false; - } - - if (read_le(file) != DIPHA_MAGIC) - { - #ifndef FOR_R_TDA - std::cerr << "File " << fname << " is not a valid DIPHA file." << std::endl; - #endif - file.close(); - return false; - } - - if (read_le(file) != DIPHA_PERSISTENCE_DIAGRAM) - { - #ifndef FOR_R_TDA - std::cerr << "File " << fname << " is not a valid DIPHA persistence diagram file." << std::endl; - #endif - file.close(); - return false; - } - - result.clear(); - - int n = read_le(file); - - for (int i = 0; i < n; ++i) - { - int tmp_d = read_le(file); - double birth = read_le(file); - double death = read_le(file); - - if (death < birth) - { - #ifndef FOR_R_TDA - std::cerr << "File " << fname << " is malformed." << std::endl; - #endif - file.close(); - return false; + std::ifstream file; + file.open(fname, std::ios::in | std::ios::binary); + + if (!file.is_open()) { +#ifndef FOR_R_TDA + std::cerr << "Could not open file " << fname << "." << std::endl; +#endif + return false; } - - int d = 0; - if (tmp_d < 0) - { - d = -tmp_d - 1; - death = std::numeric_limits::infinity(); + + if (read_le(file) != DIPHA_MAGIC) { +#ifndef FOR_R_TDA + std::cerr << "File " << fname << " is not a valid DIPHA file." << std::endl; +#endif + file.close(); + return false; + } + + if (read_le(file) != DIPHA_PERSISTENCE_DIAGRAM) { +#ifndef FOR_R_TDA + std::cerr << "File " << fname << " is not a valid DIPHA persistence diagram file." << std::endl; +#endif + file.close(); + return false; } - else - d = tmp_d; - - if ((unsigned int)d == degree) - { - if (death == birth) - { - #ifndef FOR_R_TDA - std::cerr << "Warning: point with 0 persistence ignored in " << fname << "." << std::endl; - #endif - } - else - { - result.push_back(std::make_pair(birth, death)); - } + + result.clear(); + + int n = read_le(file); + + for (int i = 0; i < n; ++i) { + int tmp_d = read_le(file); + double birth = read_le(file); + double death = read_le(file); + + if (death < birth) { +#ifndef FOR_R_TDA + std::cerr << "File " << fname << " is malformed." << std::endl; +#endif + file.close(); + return false; + } + + int d = 0; + if (tmp_d < 0) { + d = -tmp_d - 1; + death = std::numeric_limits::infinity(); + } else + d = tmp_d; + + if ((unsigned int)d == dim) { + if (death == birth) { +#ifndef FOR_R_TDA + std::cerr << "Warning: point with 0 persistence ignored in " << fname << "." << std::endl; +#endif + } else { + result.push_back(std::make_pair(birth, death)); + } + } } - } - file.close(); - - return true; + file.close(); + + return true; } -- cgit v1.2.3