From bf4b4eeda9762ed9e99c2b24f19331fa0111fcfe Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 27 Jan 2020 10:43:16 +0100 Subject: Code review: Use std::clog instead of std::cout --- src/Toplex_map/benchmark/benchmark_tm.cpp | 20 +++--- src/Toplex_map/example/simple_toplex_map.cpp | 54 ++++++++-------- src/Toplex_map/test/lazy_toplex_map_unit_test.cpp | 76 +++++++++++------------ src/Toplex_map/test/toplex_map_unit_test.cpp | 50 +++++++-------- 4 files changed, 100 insertions(+), 100 deletions(-) (limited to 'src/Toplex_map') diff --git a/src/Toplex_map/benchmark/benchmark_tm.cpp b/src/Toplex_map/benchmark/benchmark_tm.cpp index feb5d01c..d078fcf8 100644 --- a/src/Toplex_map/benchmark/benchmark_tm.cpp +++ b/src/Toplex_map/benchmark/benchmark_tm.cpp @@ -25,10 +25,10 @@ typedef std::pair::Simplex_handle, bool> typePairSimplexBool; class ST_wrapper { public: void insert_simplex(const Simplex& tau) { - /*std::cout << "insert_simplex - " << simplexTree.num_simplices() << " - "; + /*std::clog << "insert_simplex - " << simplexTree.num_simplices() << " - "; for (auto v : tau) - std::cout << v << ", "; - std::cout << std::endl; + std::clog << v << ", "; + std::clog << std::endl; */ simplexTree.insert_simplex_and_subfaces(tau); } @@ -104,22 +104,22 @@ void chrono(int n, int d) { auto c2 = std::chrono::duration_cast(end - start).count(); if (c3 > 0) - std::cout << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_maximal_simplices() << std::endl; + std::clog << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_maximal_simplices() << std::endl; else - std::cout << c1 << "\t \t" << c2 << "\t \tN/A\t \t" << K.num_maximal_simplices() << std::endl; + std::clog << c1 << "\t \t" << c2 << "\t \tN/A\t \t" << K.num_maximal_simplices() << std::endl; } int main() { for (int d = 5; d <= 40; d += 5) { - std::cout << "d=" << d << " \t Insertions \t Membership \t Contractions \t Size" << std::endl; - std::cout << "T Map \t \t"; + std::clog << "d=" << d << " \t Insertions \t Membership \t Contractions \t Size" << std::endl; + std::clog << "T Map \t \t"; chrono(n, d); - std::cout << "Lazy \t \t"; + std::clog << "Lazy \t \t"; chrono(n, d); if (d <= 15) { - std::cout << "ST \t \t"; + std::clog << "ST \t \t"; chrono(n, d); } - std::cout << std::endl; + std::clog << std::endl; } } diff --git a/src/Toplex_map/example/simple_toplex_map.cpp b/src/Toplex_map/example/simple_toplex_map.cpp index 7538c989..c432608e 100644 --- a/src/Toplex_map/example/simple_toplex_map.cpp +++ b/src/Toplex_map/example/simple_toplex_map.cpp @@ -31,72 +31,72 @@ int main(int argc, char* const argv[]) { /* o---o */ /* 1 3 */ - std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() + std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; // Browse maximal cofaces Simplex sigma3 = {2, 3}; - std::cout << "Maximal cofaces of {2, 3} are :" << std::endl; + std::clog << "Maximal cofaces of {2, 3} are :" << std::endl; for (auto simplex_ptr : tm.maximal_cofaces(sigma3, 2)) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } Simplex sigma4 = {1, 3}; assert(tm.membership(sigma4)); Gudhi::Toplex_map::Vertex v = tm.contraction(1, 3); - std::cout << "After contraction(1, 3) - " << v << std::endl; + std::clog << "After contraction(1, 3) - " << v << std::endl; /* Simplex is: */ /* 2 4 */ /* o---o */ /* \5/ */ /* o */ /* 3 */ - std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() + std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } Simplex sigma5 = {3, 4}; assert(tm.membership(sigma5)); v = tm.contraction(3, 4); - std::cout << "After contraction(3, 4) - " << v << std::endl; + std::clog << "After contraction(3, 4) - " << v << std::endl; /* Simplex is: */ /* 2 4 */ /* o---o */ /* \X/ */ /* o */ /* 5 */ - std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() + std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } tm.insert_simplex(sigma1); @@ -109,44 +109,44 @@ int main(int argc, char* const argv[]) { /* 1 3 */ tm.remove_simplex(sigma1); - std::cout << "After remove_simplex(1, 2, 3)" << std::endl; + std::clog << "After remove_simplex(1, 2, 3)" << std::endl; /* Simplex is: */ /* 2 4 */ /* o---o */ /* / \5/ */ /* o---o */ /* 1 3 */ - std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() + std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } tm.remove_vertex(1); - std::cout << "After remove_vertex(1)" << std::endl; + std::clog << "After remove_vertex(1)" << std::endl; /* Simplex is: */ /* 2 4 */ /* o---o */ /* \5/ */ /* o */ /* 3 */ - std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() + std::clog << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; } return 0; diff --git a/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp b/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp index 639bf35a..994cee8e 100644 --- a/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp +++ b/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp @@ -20,43 +20,43 @@ BOOST_AUTO_TEST_CASE(toplex_map) { using Vertex = Gudhi::Lazy_toplex_map::Vertex; Gudhi::Lazy_toplex_map tm; - std::cout << "insert_simplex {1, 2, 3, 4}" << std::endl; + std::clog << "insert_simplex {1, 2, 3, 4}" << std::endl; std::vector sigma1 = {1, 2, 3, 4}; tm.insert_simplex(sigma1); - std::cout << "insert_simplex {5, 2, 3, 6}" << std::endl; + std::clog << "insert_simplex {5, 2, 3, 6}" << std::endl; std::vector sigma2 = {5, 2, 3, 6}; tm.insert_simplex(sigma2); - std::cout << "insert_simplex {5}" << std::endl; + std::clog << "insert_simplex {5}" << std::endl; std::vector sigma3 = {5}; tm.insert_simplex(sigma3); - std::cout << "insert_simplex {4, 5, 3}" << std::endl; + std::clog << "insert_simplex {4, 5, 3}" << std::endl; std::vector sigma6 = {4, 5, 3}; tm.insert_simplex(sigma6); - std::cout << "insert_simplex {4, 5, 9}" << std::endl; + std::clog << "insert_simplex {4, 5, 9}" << std::endl; std::vector sigma7 = {4, 5, 9}; tm.insert_simplex(sigma7); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 5); std::vector sigma4 = {5, 2, 3}; std::vector sigma5 = {5, 2, 7}; BOOST_CHECK(tm.membership(sigma4)); BOOST_CHECK(!tm.membership(sigma5)); - std::cout << "insert_simplex {5, 2, 7}" << std::endl; + std::clog << "insert_simplex {5, 2, 7}" << std::endl; tm.insert_simplex(sigma5); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 6); BOOST_CHECK(tm.membership(sigma5)); - std::cout << "contraction(4,5)" << std::endl; + std::clog << "contraction(4,5)" << std::endl; auto r = tm.contraction(4, 5); - std::cout << "r=" << r << std::endl; + std::clog << "r=" << r << std::endl; BOOST_CHECK(r == 5); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 6); std::vector sigma8 = {1, 2, 3}; @@ -68,11 +68,11 @@ BOOST_AUTO_TEST_CASE(toplex_map) { BOOST_CHECK(tm.membership(sigma8)); BOOST_CHECK(tm.membership(sigma9)); - std::cout << "remove_simplex({2, 7, r = 5})" << std::endl; + std::clog << "remove_simplex({2, 7, r = 5})" << std::endl; tm.remove_simplex(sigma9); BOOST_CHECK(!tm.membership(sigma9)); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 8); // {2, 7, 5} is removed, but verify its edges are still there @@ -88,71 +88,71 @@ BOOST_AUTO_TEST_CASE(toplex_map_empty_toplex) { using Vertex = Gudhi::Lazy_toplex_map::Vertex; Gudhi::Lazy_toplex_map tm; - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 0); - std::cout << "num_vertices = " << tm.num_vertices() << std::endl; + std::clog << "num_vertices = " << tm.num_vertices() << std::endl; BOOST_CHECK(tm.num_vertices() == 0); - std::cout << "Check an empty simplex is a member." << std::endl; + std::clog << "Check an empty simplex is a member." << std::endl; std::vector empty_sigma = {}; BOOST_CHECK(tm.membership(empty_sigma)); - std::cout << "Check the edge 2,7 is not a member." << std::endl; + std::clog << "Check the edge 2,7 is not a member." << std::endl; std::vector edge = {2, 7}; BOOST_CHECK(!tm.membership(edge)); - std::cout << "Insert an empty simplex." << std::endl; + std::clog << "Insert an empty simplex." << std::endl; tm.insert_simplex(empty_sigma); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 0); - std::cout << "num_vertices = " << tm.num_vertices() << std::endl; + std::clog << "num_vertices = " << tm.num_vertices() << std::endl; BOOST_CHECK(tm.num_vertices() == 0); - std::cout << "Check an empty simplex is a member." << std::endl; + std::clog << "Check an empty simplex is a member." << std::endl; BOOST_CHECK(tm.membership(empty_sigma)); - std::cout << "Check the edge 2,7 is not a member." << std::endl; + std::clog << "Check the edge 2,7 is not a member." << std::endl; BOOST_CHECK(!tm.membership(edge)); - std::cout << "Insert edge 2,7." << std::endl; + std::clog << "Insert edge 2,7." << std::endl; tm.insert_simplex(edge); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 1); - std::cout << "num_vertices = " << tm.num_vertices() << std::endl; + std::clog << "num_vertices = " << tm.num_vertices() << std::endl; BOOST_CHECK(tm.num_vertices() == 2); - std::cout << "Check an empty simplex is a member." << std::endl; + std::clog << "Check an empty simplex is a member." << std::endl; BOOST_CHECK(tm.membership(empty_sigma)); - std::cout << "Check the edge 2,7 is a member." << std::endl; + std::clog << "Check the edge 2,7 is a member." << std::endl; BOOST_CHECK(tm.membership(edge)); - std::cout << "contraction(2,7)" << std::endl; + std::clog << "contraction(2,7)" << std::endl; auto r = tm.contraction(2, 7); - std::cout << "r=" << r << std::endl; + std::clog << "r=" << r << std::endl; BOOST_CHECK(r == 7); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 1); - std::cout << "num_vertices = " << tm.num_vertices() << std::endl; + std::clog << "num_vertices = " << tm.num_vertices() << std::endl; BOOST_CHECK(tm.num_vertices() == 1); - std::cout << "Check an empty simplex is a member." << std::endl; + std::clog << "Check an empty simplex is a member." << std::endl; BOOST_CHECK(tm.membership(empty_sigma)); - std::cout << "Check the edge 2,7 is not a member." << std::endl; + std::clog << "Check the edge 2,7 is not a member." << std::endl; BOOST_CHECK(!tm.membership(edge)); - std::cout << "Remove the vertex 7." << std::endl; + std::clog << "Remove the vertex 7." << std::endl; std::vector vertex = {7}; tm.remove_simplex(vertex); - std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 0); - std::cout << "num_vertices = " << tm.num_vertices() << std::endl; + std::clog << "num_vertices = " << tm.num_vertices() << std::endl; BOOST_CHECK(tm.num_vertices() == 0); - std::cout << "Check an empty simplex is a member." << std::endl; + std::clog << "Check an empty simplex is a member." << std::endl; BOOST_CHECK(tm.membership(empty_sigma)); - std::cout << "Check the edge 2,7 is not a member." << std::endl; + std::clog << "Check the edge 2,7 is not a member." << std::endl; BOOST_CHECK(!tm.membership(edge)); } diff --git a/src/Toplex_map/test/toplex_map_unit_test.cpp b/src/Toplex_map/test/toplex_map_unit_test.cpp index 24ec679b..0d0751ff 100644 --- a/src/Toplex_map/test/toplex_map_unit_test.cpp +++ b/src/Toplex_map/test/toplex_map_unit_test.cpp @@ -20,31 +20,31 @@ BOOST_AUTO_TEST_CASE(toplex_map) { using Vertex = Gudhi::Toplex_map::Vertex; Gudhi::Toplex_map tm; - std::cout << "insert_simplex {1, 2, 3, 4}" << std::endl; + std::clog << "insert_simplex {1, 2, 3, 4}" << std::endl; std::vector sigma1 = {1, 2, 3, 4}; tm.insert_simplex(sigma1); - std::cout << "insert_simplex {5, 2, 3, 6}" << std::endl; + std::clog << "insert_simplex {5, 2, 3, 6}" << std::endl; std::vector sigma2 = {5, 2, 3, 6}; tm.insert_simplex(sigma2); - std::cout << "insert_simplex {5}" << std::endl; + std::clog << "insert_simplex {5}" << std::endl; std::vector sigma3 = {5}; tm.insert_simplex(sigma3); - std::cout << "insert_simplex {4, 5, 3}" << std::endl; + std::clog << "insert_simplex {4, 5, 3}" << std::endl; std::vector sigma6 = {4, 5, 3}; tm.insert_simplex(sigma6); - std::cout << "insert_simplex {4, 5, 9}" << std::endl; + std::clog << "insert_simplex {4, 5, 9}" << std::endl; std::vector sigma7 = {4, 5, 9}; tm.insert_simplex(sigma7); - std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 4); // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; BOOST_CHECK(tm.maximality(*simplex_ptr)); } @@ -58,37 +58,37 @@ BOOST_AUTO_TEST_CASE(toplex_map) { std::vector sigma5 = {5, 2, 7}; BOOST_CHECK(tm.membership(sigma4)); BOOST_CHECK(!tm.membership(sigma5)); - std::cout << "insert_simplex {5, 2, 7}" << std::endl; + std::clog << "insert_simplex {5, 2, 7}" << std::endl; tm.insert_simplex(sigma5); - std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 5); // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; BOOST_CHECK(tm.maximality(*simplex_ptr)); } BOOST_CHECK(tm.membership(sigma5)); - std::cout << "contraction(4,5)" << std::endl; + std::clog << "contraction(4,5)" << std::endl; auto r = tm.contraction(4, 5); - std::cout << "r=" << r << std::endl; + std::clog << "r=" << r << std::endl; BOOST_CHECK(r == 5); - std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 4); // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; BOOST_CHECK(tm.maximality(*simplex_ptr)); } @@ -101,19 +101,19 @@ BOOST_AUTO_TEST_CASE(toplex_map) { BOOST_CHECK(tm.membership(sigma8)); BOOST_CHECK(tm.membership(sigma9)); - std::cout << "remove_simplex({2, 7, r = 5})" << std::endl; + std::clog << "remove_simplex({2, 7, r = 5})" << std::endl; tm.remove_simplex(sigma9); BOOST_CHECK(!tm.membership(sigma9)); - std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; + std::clog << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl; BOOST_CHECK(tm.num_maximal_simplices() == 5); // Browse maximal simplices - std::cout << "Maximal simplices are :" << std::endl; + std::clog << "Maximal simplices are :" << std::endl; for (auto simplex_ptr : tm.maximal_simplices()) { for (auto v : *simplex_ptr) { - std::cout << v << ", "; + std::clog << v << ", "; } - std::cout << std::endl; + std::clog << std::endl; BOOST_CHECK(tm.maximality(*simplex_ptr)); } // {2, 7, 5} is removed, but verify its edges are still there -- cgit v1.2.3