From ca6b3d72f2114cdd2d0899fd44dba19303dd3bb2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 28 Sep 2016 11:15:34 +0000 Subject: Add rips complex module and first modification step git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1577 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc949570c6cffa4756f84a15c41fadc8c45b2af2 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Simplex_tree') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 63e3f0e5..206b2fba 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -28,7 +28,7 @@ #include #include -#include +//#include #include #include -- cgit v1.2.3 From 29499b02d1b6eafcc6419a0b6b4469152ea20a09 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 30 Sep 2016 14:24:41 +0000 Subject: Fix compilation issues git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1596 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 343308ef914e6a6617890f49a55eb0bb8db15ee9 --- CMakeLists.txt | 1 + src/GudhUI/utils/Persistence_compute.h | 35 ++-- src/Persistent_cohomology/benchmark/CMakeLists.txt | 14 ++ .../benchmark/performance_rips_persistence.cpp | 217 +++++++++++++++++++++ src/Persistent_cohomology/example/CMakeLists.txt | 4 - .../example/alpha_complex_3d_persistence.cpp | 3 +- .../example/alpha_complex_persistence.cpp | 2 + .../example/performance_rips_persistence.cpp | 214 -------------------- .../periodic_alpha_complex_3d_persistence.cpp | 1 + .../persistence_from_simple_simplex_tree.cpp | 17 +- .../example/rips_multifield_persistence.cpp | 21 +- .../example/rips_persistence.cpp | 20 +- .../rips_persistence_via_boundary_matrix.cpp | 50 +++-- ...persistent_cohomology_unit_test_multi_field.cpp | 4 +- src/Rips_complex/include/gudhi/Rips_complex.h | 2 +- src/Simplex_tree/example/simple_simplex_tree.cpp | 13 +- .../example/simplex_tree_from_cliques_of_graph.cpp | 9 +- src/Simplex_tree/include/gudhi/Simplex_tree.h | 2 +- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 69 +++---- .../example/witness_complex_from_file.cpp | 2 +- .../include/gudhi/Witness_complex.h | 2 +- .../test/simple_witness_complex.cpp | 2 +- .../test/witness_complex_points.cpp | 2 +- src/common/include/gudhi/reader_utils.h | 3 +- 24 files changed, 376 insertions(+), 333 deletions(-) create mode 100644 src/Persistent_cohomology/benchmark/CMakeLists.txt create mode 100644 src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/performance_rips_persistence.cpp (limited to 'src/Simplex_tree') diff --git a/CMakeLists.txt b/CMakeLists.txt index 972df204..cecad3e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,7 @@ else() add_subdirectory(src/Simplex_tree/example) add_subdirectory(src/Persistent_cohomology/test) add_subdirectory(src/Persistent_cohomology/example) + add_subdirectory(src/Persistent_cohomology/benchmark) add_subdirectory(src/Skeleton_blocker/test) add_subdirectory(src/Skeleton_blocker/example) add_subdirectory(src/Contraction/example) diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index 97165490..fa5bafc1 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -69,22 +70,26 @@ template class Persistence_compute { points.emplace_back(std::move(pt_to_add)); } + using Simplex_tree = Gudhi::Simplex_tree<>; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; + using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; + using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; + + Rips_complex rips_complex(points, params.threshold, euclidean_distance); - Graph_t prox_graph = compute_proximity_graph(points, params.threshold, euclidean_distance); - Gudhi::Simplex_tree<> st; - st.insert_graph(prox_graph); - st.expansion(params.max_dim); - - Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>, - Gudhi::persistent_cohomology::Field_Zp > pcoh(st); - // initializes the coefficient field for homology - pcoh.init_coefficients(params.p); - // put params.min_pers - pcoh.compute_persistent_cohomology(params.min_pers); - stream << "persistence: \n"; - stream << "p dimension birth death: \n"; - - pcoh.output_diagram(stream); + Simplex_tree st; + if (rips_complex.create_complex(st, params.max_dim)) { + Persistent_cohomology pcoh(st); + // initializes the coefficient field for homology + pcoh.init_coefficients(params.p); + // put params.min_pers + pcoh.compute_persistent_cohomology(params.min_pers); + stream << "persistence: \n"; + stream << "p dimension birth death: \n"; + + pcoh.output_diagram(stream); + } } }; diff --git a/src/Persistent_cohomology/benchmark/CMakeLists.txt b/src/Persistent_cohomology/benchmark/CMakeLists.txt new file mode 100644 index 00000000..ea792c89 --- /dev/null +++ b/src/Persistent_cohomology/benchmark/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.6) +project(Persistent_cohomology_benchmark) + + +if(GMP_FOUND) + if(GMPXX_FOUND) + add_executable ( performance_rips_persistence EXCLUDE_FROM_ALL performance_rips_persistence.cpp ) + target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + if (TBB_FOUND) + target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + file(COPY "${CMAKE_SOURCE_DIR}/data/points/Kl.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + endif(GMPXX_FOUND) +endif(GMP_FOUND) diff --git a/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp new file mode 100644 index 00000000..99fcad41 --- /dev/null +++ b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp @@ -0,0 +1,217 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Multi_field = Gudhi::persistent_cohomology::Multi_field; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; + +/* Compute the persistent homology of the complex cpx with coefficients in Z/pZ. */ +template< typename FilteredComplex> +void timing_persistence(FilteredComplex & cpx + , int p); + +/* Compute multi-field persistent homology of the complex cpx with coefficients in + * Z/rZ for all prime number r in [p;q].*/ +template< typename FilteredComplex> +void timing_persistence(FilteredComplex & cpx + , int p + , int q); + +/* Timings for the computation of persistent homology with different + * representations of a Rips complex and different coefficient fields. The + * Rips complex is built on a set of 10000 points sampling a Klein bottle embedded + * in dimension 5. + * We represent complexes with a simplex tree and + * with a Hasse diagram. The Hasse diagram represents explicitly all + * codimension 1 incidence relations in the complex, and hence leads to + * a faster computation of persistence because boundaries are precomputed. + * Hovewer, the simplex tree may be constructed directly from a point cloud and + * is more compact. + * We compute persistent homology with coefficient fields Z/2Z and Z/1223Z. + * We present also timings for the computation of multi-field persistent + * homology in all fields Z/rZ for r prime between 2 and 1223. + */ +int main(int argc, char * argv[]) { + std::chrono::time_point start, end; + int elapsed_sec; + { + + std::string off_file_points = "Kl.off"; + Filtration_value threshold = 0.27; + int dim_max = 3; + int p = 2; + int q = 1223; + + // Extract the points from the file off_file_points + Points_off_reader off_reader(off_file_points); + + // Compute the proximity graph of the points + start = std::chrono::system_clock::now(); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, + euclidean_distance); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n"; + + // Construct the Rips complex in a Simplex Tree + Simplex_tree st; + start = std::chrono::system_clock::now(); + + // insert the proximity graph in the simplex tree + // expand the graph until dimension dim_max + rips_complex_from_file.create_complex(st, dim_max); + + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Compute Rips complex in " << elapsed_sec << " ms.\n"; + std::cout << " - dimension = " << st.dimension() << std::endl; + std::cout << " - number of simplices = " << st.num_simplices() << std::endl; + + // Sort the simplices in the order of the filtration + start = std::chrono::system_clock::now(); + st.initialize_filtration(); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n"; + + // Copy the keys inside the simplices + start = std::chrono::system_clock::now(); + { + int count = 0; + for (auto sh : st.filtration_simplex_range()) + st.assign_key(sh, count++); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Copied the keys inside the simplices in " << elapsed_sec << " ms.\n"; + + // Convert the simplex tree into a hasse diagram + start = std::chrono::system_clock::now(); + Gudhi::Hasse_complex<> hcpx(st); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n"; + + + std::cout << "Timings when using a simplex tree: \n"; + timing_persistence(st, p); + timing_persistence(st, q); + timing_persistence(st, p, q); + + std::cout << "Timings when using a Hasse complex: \n"; + timing_persistence(hcpx, p); + timing_persistence(hcpx, q); + timing_persistence(hcpx, p, q); + + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Running the complex destructors in " << elapsed_sec << " ms.\n"; + return 0; +} + +template< typename FilteredComplex> +void +timing_persistence(FilteredComplex & cpx + , int p) { + std::chrono::time_point start, end; + int elapsed_sec; + { + start = std::chrono::system_clock::now(); + Gudhi::persistent_cohomology::Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; + // initializes the coefficient field for homology + start = std::chrono::system_clock::now(); + pcoh.init_coefficients(p); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; + + start = std::chrono::system_clock::now(); + + pcoh.compute_persistent_cohomology(INFINITY); + + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Compute persistent homology in Z/" << p << "Z in " << elapsed_sec << " ms.\n"; + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; +} + +template< typename FilteredComplex> +void +timing_persistence(FilteredComplex & cpx + , int p + , int q) { + std::chrono::time_point start, end; + int elapsed_sec; + { + start = std::chrono::system_clock::now(); + Gudhi::persistent_cohomology::Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; + // initializes the coefficient field for homology + start = std::chrono::system_clock::now(); + pcoh.init_coefficients(p, q); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; + // compute persistent homology, disgarding persistent features of life shorter than min_persistence + + start = std::chrono::system_clock::now(); + + pcoh.compute_persistent_cohomology(INFINITY); + + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " + << "with p in [" << p << ";" << q << "] in " << elapsed_sec << " ms.\n"; + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; +} diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index d97d1b63..75f3c5d4 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -39,13 +39,9 @@ if(GMP_FOUND) if(GMPXX_FOUND) add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) - add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) - target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) if (TBB_FOUND) target_link_libraries(rips_multifield_persistence ${TBB_LIBRARIES}) - target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES}) endif(TBB_FOUND) - add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 2 -q 71 -m 100) endif(GMPXX_FOUND) endif(GMP_FOUND) diff --git a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp index 48fbb91a..f7e8f800 100644 --- a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp @@ -64,6 +64,7 @@ typedef std::list Vertex_list; // gudhi type definition typedef Gudhi::Simplex_tree ST; +typedef ST::Filtration_value Filtration_value; typedef ST::Vertex_handle Simplex_tree_vertex; typedef std::map Alpha_shape_simplex_tree_map; typedef std::pair Alpha_shape_simplex_tree_pair; @@ -132,7 +133,7 @@ int main(int argc, char * const argv[]) { int coeff_field_characteristic = atoi(argv[2]); Filtration_value min_persistence = 0.0; - int returnedScanValue = sscanf(argv[3], "%lf", &min_persistence); + int returnedScanValue = sscanf(argv[3], "%f", &min_persistence); if ((returnedScanValue == EOF) || (min_persistence < -1.0)) { std::cerr << "Error: " << argv[3] << " is not correct\n"; usage(argv[0]); diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp index cb181936..24315144 100644 --- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp @@ -9,6 +9,8 @@ #include #include // for numeric_limits +using Filtration_value = double; + void program_options(int argc, char * argv[] , std::string & off_file_points , std::string & output_file_diag diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp deleted file mode 100644 index b4d282ac..00000000 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace Gudhi; -using namespace Gudhi::persistent_cohomology; - -/* Compute the persistent homology of the complex cpx with coefficients in Z/pZ. */ -template< typename FilteredComplex> -void timing_persistence(FilteredComplex & cpx - , int p); - -/* Compute multi-field persistent homology of the complex cpx with coefficients in - * Z/rZ for all prime number r in [p;q].*/ -template< typename FilteredComplex> -void timing_persistence(FilteredComplex & cpx - , int p - , int q); - -/* Timings for the computation of persistent homology with different - * representations of a Rips complex and different coefficient fields. The - * Rips complex is built on a set of 10000 points sampling a Klein bottle embedded - * in dimension 5. - * We represent complexes with a simplex tree and - * with a Hasse diagram. The Hasse diagram represents explicitly all - * codimension 1 incidence relations in the complex, and hence leads to - * a faster computation of persistence because boundaries are precomputed. - * Hovewer, the simplex tree may be constructed directly from a point cloud and - * is more compact. - * We compute persistent homology with coefficient fields Z/2Z and Z/1223Z. - * We present also timings for the computation of multi-field persistent - * homology in all fields Z/rZ for r prime between 2 and 1223. - */ -int main(int argc, char * argv[]) { - std::chrono::time_point start, end; - int elapsed_sec; - { - - std::string filepoints = "../../../data/points/Kl.txt"; - Filtration_value threshold = 0.27; - int dim_max = 3; - int p = 2; - int q = 1223; - - // Extract the points from the file filepoints - typedef std::vector Point_t; - std::vector< Point_t > points; - read_points(filepoints, points); - - // Compute the proximity graph of the points - start = std::chrono::system_clock::now(); - Graph_t prox_graph = compute_proximity_graph(points, threshold - , euclidean_distance); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n"; - - // Construct the Rips complex in a Simplex Tree - Simplex_tree st; - start = std::chrono::system_clock::now(); - - // insert the proximity graph in the simplex tree - st.insert_graph(prox_graph); - // expand the graph until dimension dim_max - st.expansion(dim_max); - - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips complex in " << elapsed_sec << " ms.\n"; - std::cout << " - dimension = " << st.dimension() << std::endl; - std::cout << " - number of simplices = " << st.num_simplices() << std::endl; - - // Sort the simplices in the order of the filtration - start = std::chrono::system_clock::now(); - st.initialize_filtration(); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n"; - - // Copy the keys inside the simplices - start = std::chrono::system_clock::now(); - { - int count = 0; - for (auto sh : st.filtration_simplex_range()) - st.assign_key(sh, count++); - } - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Copied the keys inside the simplices in " << elapsed_sec << " ms.\n"; - - // Convert the simplex tree into a hasse diagram - start = std::chrono::system_clock::now(); - Hasse_complex<> hcpx(st); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n"; - - - std::cout << "Timings when using a simplex tree: \n"; - timing_persistence(st, p); - timing_persistence(st, q); - timing_persistence(st, p, q); - - std::cout << "Timings when using a Hasse complex: \n"; - timing_persistence(hcpx, p); - timing_persistence(hcpx, q); - timing_persistence(hcpx, p, q); - - start = std::chrono::system_clock::now(); - } - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Running the complex destructors in " << elapsed_sec << " ms.\n"; - return 0; -} - -template< typename FilteredComplex> -void -timing_persistence(FilteredComplex & cpx - , int p) { - std::chrono::time_point start, end; - int elapsed_sec; - { - start = std::chrono::system_clock::now(); - Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; - // initializes the coefficient field for homology - start = std::chrono::system_clock::now(); - pcoh.init_coefficients(p); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; - - start = std::chrono::system_clock::now(); - - pcoh.compute_persistent_cohomology(INFINITY); - - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Compute persistent homology in Z/" << p << "Z in " << elapsed_sec << " ms.\n"; - start = std::chrono::system_clock::now(); - } - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; -} - -template< typename FilteredComplex> -void -timing_persistence(FilteredComplex & cpx - , int p - , int q) { - std::chrono::time_point start, end; - int elapsed_sec; - { - start = std::chrono::system_clock::now(); - Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; - // initializes the coefficient field for homology - start = std::chrono::system_clock::now(); - pcoh.init_coefficients(p, q); - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; - // compute persistent homology, disgarding persistent features of life shorter than min_persistence - - start = std::chrono::system_clock::now(); - - pcoh.compute_persistent_cohomology(INFINITY); - - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in [" << p << ";" << q << "] in " << elapsed_sec << " ms.\n"; - start = std::chrono::system_clock::now(); - } - end = std::chrono::system_clock::now(); - elapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; -} diff --git a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp index a199fea1..5184ef52 100644 --- a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp @@ -70,6 +70,7 @@ using Vertex_list = std::list; // gudhi type definition using ST = Gudhi::Simplex_tree; +using Filtration_value = ST::Filtration_value; using Simplex_tree_vertex = ST::Vertex_handle; using Alpha_shape_simplex_tree_map = std::map; using Alpha_shape_simplex_tree_pair = std::pair; diff --git a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp index ba772f04..817aac4d 100644 --- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp +++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp @@ -29,13 +29,12 @@ #include #include -using namespace Gudhi; -using namespace Gudhi::persistent_cohomology; - -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::pair typeSimplex; -typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; -typedef Simplex_tree<> typeST; +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using typeVectorVertex = std::vector< Simplex_tree::Vertex_handle >; void usage(char * const progName) { std::cerr << "Usage: " << progName << " coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; @@ -66,7 +65,7 @@ int main(int argc, char * const argv[]) { // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF INSERTION" << std::endl; - typeST st; + Simplex_tree st; // ++ FIRST std::cout << " - INSERT (0,1,2)" << std::endl; @@ -166,7 +165,7 @@ int main(int argc, char * const argv[]) { std::cout << "**************************************************************" << std::endl; // Compute the persistence diagram of the complex - persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); + Persistent_cohomology pcoh(st); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index d4a07bb6..f4adc7a9 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -25,14 +25,21 @@ #include #include #include +#include #include #include #include - -typedef double Filtration_value; +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Multi_field = Gudhi::persistent_cohomology::Multi_field; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; void program_options(int argc, char * argv[] , std::string & off_file_points @@ -54,22 +61,22 @@ int main(int argc, char * argv[]) { program_options(argc, argv, off_file_points, filediag, threshold, dim_max, min_p, max_p, min_persistence); - Gudhi::rips_complex::Rips_complex<> rips_complex_from_file(off_file_points); + Points_off_reader off_reader(off_file_points); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, + euclidean_distance); // Construct the Rips complex in a Simplex Tree - using Simplex_tree = Gudhi::Simplex_tree; Simplex_tree simplex_tree; - if (rips_complex_from_file.create_complex(simplex_tree, threshold, dim_max, euclidean_distance>)) { + if (rips_complex_from_file.create_complex(simplex_tree, dim_max)) { std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); - using Multi_field = Gudhi::persistent_cohomology::Multi_field; // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(min_p, max_p); diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index e3ab5927..97bab14c 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -32,7 +33,14 @@ #include #include // infinity -typedef double Filtration_value; +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; void program_options(int argc, char * argv[] , std::string & off_file_points @@ -52,22 +60,22 @@ int main(int argc, char * argv[]) { program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); - Gudhi::rips_complex::Rips_complex<> rips_complex_from_file(off_file_points); + Points_off_reader off_reader(off_file_points); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, + euclidean_distance); // Construct the Rips complex in a Simplex Tree - using Simplex_tree = Gudhi::Simplex_tree; Simplex_tree simplex_tree; - if (rips_complex_from_file.create_complex(simplex_tree, threshold, dim_max, euclidean_distance>)) { + if (rips_complex_from_file.create_complex(simplex_tree, dim_max)) { std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); - using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology pcoh(simplex_tree); + Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(p); diff --git a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp index 4c6656f5..991ed4f0 100644 --- a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp @@ -21,12 +21,12 @@ * along with this program. If not, see . */ -#include -#include -#include #include #include +#include #include +#include +#include #include @@ -44,14 +44,16 @@ // // //////////////////////////////////////////////////////////////// -using namespace Gudhi; -using namespace Gudhi::persistent_cohomology; - -typedef int Vertex_handle; -typedef double Filtration_value; +// Types definition +using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; void program_options(int argc, char * argv[] - , std::string & filepoints + , std::string & off_file_points , std::string & filediag , Filtration_value & threshold , int & dim_max @@ -59,30 +61,22 @@ void program_options(int argc, char * argv[] , Filtration_value & min_persistence); int main(int argc, char * argv[]) { - std::string filepoints; + std::string off_file_points; std::string filediag; Filtration_value threshold; int dim_max; int p; Filtration_value min_persistence; - program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence); - - // Extract the points from the file filepoints - typedef std::vector Point_t; - std::vector< Point_t > points; - read_points(filepoints, points); + program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); - // Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph(points, threshold - , euclidean_distance); + Points_off_reader off_reader(off_file_points); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, + euclidean_distance); // Construct the Rips complex in a Simplex Tree - Simplex_tree<>& st = *new Simplex_tree<>; - // insert the proximity graph in the simplex tree - st.insert_graph(prox_graph); - // expand the graph until dimension dim_max - st.expansion(dim_max); + Simplex_tree& st = *new Simplex_tree; + rips_complex_from_file.create_complex(st, dim_max); std::cout << "The complex contains " << st.num_simplices() << " simplices \n"; std::cout << " and has dimension " << st.dimension() << " \n"; @@ -99,7 +93,7 @@ int main(int argc, char * argv[]) { st.assign_key(sh, count++); // Convert to a more convenient representation. - Hasse_complex<> hcpx(st); + Gudhi::Hasse_complex<> hcpx(st); #ifdef GUDHI_USE_TBB ts.terminate(); @@ -109,7 +103,7 @@ int main(int argc, char * argv[]) { delete &st; // Compute the persistence diagram of the complex - persistent_cohomology::Persistent_cohomology< Hasse_complex<>, Field_Zp > pcoh(hcpx); + Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Hasse_complex<>, Field_Zp > pcoh(hcpx); // initializes the coefficient field for homology pcoh.init_coefficients(p); @@ -126,7 +120,7 @@ int main(int argc, char * argv[]) { } void program_options(int argc, char * argv[] - , std::string & filepoints + , std::string & off_file_points , std::string & filediag , Filtration_value & threshold , int & dim_max @@ -135,7 +129,7 @@ void program_options(int argc, char * argv[] namespace po = boost::program_options; po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), + ("input-file", po::value(&off_file_points), "Name of file containing a point set. Format is one point per line: X1 ... Xd "); po::options_description visible("Allowed options", 100); diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp index 703682e1..1a6e3296 100644 --- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp +++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp @@ -21,7 +21,7 @@ using namespace boost::unit_test; typedef Simplex_tree<> typeST; -std::string test_rips_persistence(int min_coefficient, int max_coefficient, int min_persistence) { +std::string test_rips_persistence(int min_coefficient, int max_coefficient, double min_persistence) { // file name is given as parameter from CMakeLists.txt const std::string inputFile(framework::master_test_suite().argv[1]); @@ -74,7 +74,7 @@ void test_rips_persistence_in_dimension(int min_dimension, int max_dimension) { std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_MULTI_FIELD MIN_DIM=" << min_dimension << " MAX_DIM=" << max_dimension << " MIN_PERS=0" << std::endl; - std::string str_rips_persistence = test_rips_persistence(min_dimension, max_dimension, static_cast (0.0)); + std::string str_rips_persistence = test_rips_persistence(min_dimension, max_dimension, 0.0); std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl; BOOST_CHECK(str_rips_persistence.find(value0) != std::string::npos); // Check found diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h index 10f674e5..9eb22d03 100644 --- a/src/Rips_complex/include/gudhi/Rips_complex.h +++ b/src/Rips_complex/include/gudhi/Rips_complex.h @@ -47,7 +47,7 @@ namespace rips_complex { * \ingroup rips_complex * * \details - * The data structure is a 1-skeleton graph constructed from a point cloud, containing edges when the edge length is + * The data structure is a one skeleton graph constructed from a point cloud, containing edges when the edge length is * less or equal to a given threshold. Edge length is computed from a user given function. * * The complex is a template class requiring a Filtration_value type. diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index 5146b906..bf6dc470 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -27,10 +27,11 @@ #include // for pair #include -using namespace Gudhi; - -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; +using Simplex_tree = Gudhi::Simplex_tree<>; +using Vertex_handle = Simplex_tree::Vertex_handle; +using Filtration_value = Simplex_tree::Filtration_value; +using typeVectorVertex = std::vector< Vertex_handle >; +using typePairSimplexBool = std::pair< Simplex_tree::Simplex_handle, bool >; int main(int argc, char * const argv[]) { const Filtration_value FIRST_FILTRATION_VALUE = 0.1; @@ -42,7 +43,7 @@ int main(int argc, char * const argv[]) { std::cout << "********************************************************************" << std::endl; std::cout << "EXAMPLE OF SIMPLE INSERTION" << std::endl; // Construct the Simplex Tree - Simplex_tree<> simplexTree; + Simplex_tree simplexTree; /* Simplex to be inserted: */ /* 1 */ @@ -212,7 +213,7 @@ int main(int argc, char * const argv[]) { // ------------------------------------------------------------------------------------------------------------------ // Find in the simplex_tree // ------------------------------------------------------------------------------------------------------------------ - Simplex_tree<>::Simplex_handle simplexFound = simplexTree.find(secondSimplexVector); + Simplex_tree::Simplex_handle simplexFound = simplexTree.find(secondSimplexVector); std::cout << "**************IS THE SIMPLEX {1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) std::cout << "***+ YES IT IS!\n"; diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp index 58085014..8d729c56 100644 --- a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -29,6 +29,13 @@ using namespace Gudhi; +typedef int Vertex_handle; +typedef double Filtration_value; +typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, + boost::property < vertex_filtration_t, Filtration_value >, + boost::property < edge_filtration_t, Filtration_value > > Graph_t; +typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; + int main(int argc, char * const argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] @@ -43,7 +50,7 @@ int main(int argc, char * const argv[]) { Simplex_tree<> st; start = clock(); - auto g = read_graph(filegraph); + auto g = read_graph(filegraph); // insert the graph in the simplex tree as 1-skeleton st.insert_graph(g); end = clock(); diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 206b2fba..63e3f0e5 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -28,7 +28,7 @@ #include #include -//#include +#include #include #include diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 28bf202b..b06d7ec9 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include // std::pair, std::make_pair @@ -19,19 +20,19 @@ using namespace Gudhi; typedef boost::mpl::list, Simplex_tree> list_of_tested_variants; -const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle) - 1; -const Filtration_value DEFAULT_FILTRATION_VALUE = (const Filtration_value) 0.0; template void test_empty_simplex_tree(typeST& tst) { - BOOST_CHECK(tst.null_vertex() == DEFAULT_VERTEX_HANDLE); - BOOST_CHECK(tst.filtration() == DEFAULT_FILTRATION_VALUE); + typedef typename typeST::Vertex_handle Vertex_handle; + const Vertex_handle DEFAULT_VERTEX_VALUE = Vertex_handle(- 1); + BOOST_CHECK(tst.null_vertex() == DEFAULT_VERTEX_VALUE); + BOOST_CHECK(tst.filtration() == 0.0); BOOST_CHECK(tst.num_vertices() == (size_t) 0); BOOST_CHECK(tst.num_simplices() == (size_t) 0); typename typeST::Siblings* STRoot = tst.root(); BOOST_CHECK(STRoot != nullptr); BOOST_CHECK(STRoot->oncles() == nullptr); - BOOST_CHECK(STRoot->parent() == DEFAULT_VERTEX_HANDLE); + BOOST_CHECK(STRoot->parent() == DEFAULT_VERTEX_VALUE); BOOST_CHECK(tst.dimension() == -1); } @@ -59,7 +60,7 @@ void test_iterators_on_empty_simplex_tree(typeST& tst) { BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_when_empty, typeST, list_of_tested_variants) { typedef std::pair typePairSimplexBool; - typedef std::vector typeVectorVertex; + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; @@ -72,8 +73,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_when_empty, typeST, list_of_tested_va std::cout << "TEST OF EMPTY INSERTION" << std::endl; typeVectorVertex simplexVectorEmpty; BOOST_CHECK(simplexVectorEmpty.empty() == true); - typePairSimplexBool returnEmptyValue = st.insert_simplex(simplexVectorEmpty, - DEFAULT_FILTRATION_VALUE); + typePairSimplexBool returnEmptyValue = st.insert_simplex(simplexVectorEmpty, 0.0); BOOST_CHECK(returnEmptyValue.first == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(returnEmptyValue.second == true); @@ -141,12 +141,13 @@ void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int p template void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) { BOOST_CHECK(returnValue.second == true); - typename typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + // Simplex_handle = boost::container::flat_map< typeST::Vertex_handle, Node >::iterator + typename typeST::Simplex_handle shReturned = returnValue.first; BOOST_CHECK(shReturned != typename typeST::Simplex_handle(nullptr)); } // Global variables -Filtration_value max_fil = DEFAULT_FILTRATION_VALUE; +double max_fil = 0.0; int dim_max = -1; template @@ -179,8 +180,9 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons } BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_variants) { + typedef typename typeST::Filtration_value Filtration_value; typedef std::pair typePairSimplexBool; - typedef std::vector typeVectorVertex; + typedef std::vector typeVectorVertex; typedef std::pair typeSimplex; const Filtration_value FIRST_FILTRATION_VALUE = 0.1; const Filtration_value SECOND_FILTRATION_VALUE = 0.2; @@ -188,7 +190,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_var const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; // reset since we run the test several times dim_max = -1; - max_fil = DEFAULT_FILTRATION_VALUE; + max_fil = 0.0; // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; @@ -303,7 +305,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_var returnValue = st.insert_simplex(tenthSimplex.first, tenthSimplex.second); BOOST_CHECK(returnValue.second == false); - typename typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + // Simplex_handle = boost::container::flat_map< typeST::Vertex_handle, Node >::iterator + typename typeST::Simplex_handle shReturned = returnValue.first; BOOST_CHECK(shReturned == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! BOOST_CHECK(st.dimension() == dim_max); @@ -317,7 +320,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_var returnValue = st.insert_simplex(eleventhSimplex.first, eleventhSimplex.second); BOOST_CHECK(returnValue.second == false); - shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + // Simplex_handle = boost::container::flat_map< typeST::Vertex_handle, Node >::iterator + shReturned = returnValue.first; BOOST_CHECK(shReturned == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! BOOST_CHECK(st.dimension() == dim_max); @@ -375,8 +379,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_var BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_of_tested_variants) { typedef std::pair typePairSimplexBool; - typedef std::vector typeVectorVertex; - typedef std::pair typeSimplex; + typedef std::vector typeVectorVertex; + typedef std::pair typeSimplex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF RECURSIVE INSERTION" << std::endl; typeST st; @@ -394,7 +398,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector1.begin(), SimplexVector1.end(), std::greater()); + std::sort(SimplexVector1.begin(), SimplexVector1.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector1[position] << std::endl; @@ -413,7 +417,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector2.begin(), SimplexVector2.end(), std::greater()); + std::sort(SimplexVector2.begin(), SimplexVector2.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector2[position] << std::endl; @@ -432,7 +436,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector3.begin(), SimplexVector3.end(), std::greater()); + std::sort(SimplexVector3.begin(), SimplexVector3.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector3[position] << std::endl; @@ -462,7 +466,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector5.begin(), SimplexVector5.end(), std::greater()); + std::sort(SimplexVector5.begin(), SimplexVector5.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector5[position] << std::endl; @@ -481,7 +485,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector6.begin(), SimplexVector6.end(), std::greater()); + std::sort(SimplexVector6.begin(), SimplexVector6.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector6[position] << std::endl; @@ -504,12 +508,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_o /* A facet [3,4,5] */ /* A cell [0,1,6,7] */ - typeSimplex simplexPair1 = std::make_pair(SimplexVector1, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair2 = std::make_pair(SimplexVector2, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair3 = std::make_pair(SimplexVector3, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair4 = std::make_pair(SimplexVector4, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair5 = std::make_pair(SimplexVector5, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair6 = std::make_pair(SimplexVector6, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair1 = std::make_pair(SimplexVector1, 0.0); + typeSimplex simplexPair2 = std::make_pair(SimplexVector2, 0.0); + typeSimplex simplexPair3 = std::make_pair(SimplexVector3, 0.0); + typeSimplex simplexPair4 = std::make_pair(SimplexVector4, 0.0); + typeSimplex simplexPair5 = std::make_pair(SimplexVector5, 0.0); + typeSimplex simplexPair6 = std::make_pair(SimplexVector6, 0.0); test_simplex_tree_contains(st, simplexPair1, 6); // (2,1,0) is in position 6 test_simplex_tree_contains(st, simplexPair2, 7); // (3) is in position 7 test_simplex_tree_contains(st, simplexPair3, 8); // (3,0) is in position 8 @@ -600,7 +604,7 @@ void test_cofaces(typeST& st, const std::vector& expected, int di } BOOST_AUTO_TEST_CASE_TEMPLATE(coface_on_simplex_tree, typeST, list_of_tested_variants) { - typedef std::vector typeVectorVertex; + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST COFACE ALGORITHM" << std::endl; typeST st; @@ -629,7 +633,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(coface_on_simplex_tree, typeST, list_of_tested_var // FIXME st.set_dimension(3); - std::vector simplex_result; + std::vector simplex_result; std::vector result; std::cout << "First test - Star of (3):" << std::endl; @@ -649,7 +653,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(coface_on_simplex_tree, typeST, list_of_tested_var result.push_back(st.find(simplex_result)); simplex_result.clear(); - std::vector vertex = {3}; + std::vector vertex = {3}; test_cofaces(st, vertex, 0, result); vertex.clear(); result.clear(); @@ -699,7 +703,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(coface_on_simplex_tree, typeST, list_of_tested_var } BOOST_AUTO_TEST_CASE_TEMPLATE(copy_move_on_simplex_tree, typeST, list_of_tested_variants) { - typedef std::vector typeVectorVertex; + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST COPY MOVE CONSTRUCTORS" << std::endl; typeST st; @@ -771,12 +775,11 @@ void test_simplex_is_vertex(typeST& st, typename typeST::Simplex_handle sh, type BOOST_AUTO_TEST_CASE(non_contiguous) { typedef Simplex_tree<> typeST; - typedef typeST::Vertex_handle Vertex_handle; typedef typeST::Simplex_handle Simplex_handle; std::cout << "********************************************************************" << std::endl; std::cout << "TEST NON-CONTIGUOUS VERTICES" << std::endl; typeST st; - Vertex_handle e[] = {3,-7}; + typeST::Vertex_handle e[] = {3,-7}; std::cout << "Insert" << std::endl; st.insert_simplex_and_subfaces(e); BOOST_CHECK(st.num_vertices() == 2); diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 53207ad2..392ad55d 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -34,7 +34,7 @@ #include #include -typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::vector< int > typeVectorVertex; typedef std::vector< std::vector > Point_Vector; /** diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 489cdf11..2cec921a 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -72,7 +72,7 @@ class Witness_complex { typedef std::vector< Point_t > Point_Vector; typedef std::vector< Vertex_handle > typeVectorVertex; - typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; + //typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; typedef std::pair< Simplex_handle, bool > typePairSimplexBool; typedef int Witness_id; diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp index 03df78ee..adaadfb0 100644 --- a/src/Witness_complex/test/simple_witness_complex.cpp +++ b/src/Witness_complex/test/simple_witness_complex.cpp @@ -33,7 +33,7 @@ #include typedef Gudhi::Simplex_tree<> Simplex_tree; -typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::vector< int > typeVectorVertex; typedef Gudhi::witness_complex::Witness_complex WitnessComplex; BOOST_AUTO_TEST_CASE(simple_witness_complex) { diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index bd3df604..03c9adc0 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -34,7 +34,7 @@ #include typedef std::vector Point; -typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::vector< int > typeVectorVertex; typedef Gudhi::Simplex_tree<> Simplex_tree; typedef Gudhi::witness_complex::Witness_complex WitnessComplex; diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 899f9df6..4154acc9 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -77,6 +77,7 @@ inline void read_points(std::string file_name, std::vector< std::vector< double * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ +template< typename Graph_t, typename Edge_t, typename Filtration_value, typename Vertex_handle > inline Graph_t read_graph(std::string file_name) { std::ifstream in_(file_name.c_str(), std::ios::in); if (!in_.is_open()) { @@ -130,7 +131,7 @@ inline Graph_t read_graph(std::string file_name) { Graph_t skel_graph(edges.begin(), edges.end(), edges_fil.begin(), vertices.size()); auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); - boost::graph_traits::vertex_iterator vi, vi_end; + typename boost::graph_traits::vertex_iterator vi, vi_end; auto v_it = vertices.begin(); for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi, ++v_it) { boost::put(vertex_prop, *vi, v_it->second); -- cgit v1.2.3 From ede6f875e8340fb72d114ad9db3b54862566594f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 17 Nov 2016 09:52:03 +0000 Subject: Modify examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1757 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4b6f26947ad16f440ea4d4b7cb5e145a58f28dcb --- .../example/alpha_complex_3d_persistence.cpp | 2 +- .../example/alpha_complex_persistence.cpp | 7 +- .../periodic_alpha_complex_3d_persistence.cpp | 2 +- .../persistence_from_simple_simplex_tree.cpp | 4 +- .../example/rips_multifield_persistence.cpp | 2 +- .../example/rips_persistence.cpp | 2 +- .../rips_persistence_via_boundary_matrix.cpp | 3 +- src/Rips_complex/doc/Intro_rips_complex.h | 6 +- src/Rips_complex/include/gudhi/Rips_complex.h | 2 +- src/Simplex_tree/example/simple_simplex_tree.cpp | 2 +- .../example/simplex_tree_from_cliques_of_graph.cpp | 2 +- .../example/witness_complex_from_file.cpp | 6 +- .../example/witness_complex_sphere.cpp | 2 +- .../gudhi/Construct_closest_landmark_table.h | 2 +- .../gudhi/Landmark_choice_by_furthest_point.h | 105 --------------------- .../gudhi/Landmark_choice_by_random_point.h | 96 ------------------- .../include/gudhi/Witness_complex.h | 1 - .../test/simple_witness_complex.cpp | 2 +- .../test/witness_complex_points.cpp | 2 +- .../include/gudhi/graph_simplicial_complex.h | 57 ----------- 20 files changed, 24 insertions(+), 283 deletions(-) delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h (limited to 'src/Simplex_tree') diff --git a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp index f7e8f800..978dc942 100644 --- a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2014 INRIA Saclay (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp index bca4b66c..9e84e91f 100644 --- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp @@ -11,7 +11,8 @@ #include #include // for numeric_limits -using Filtration_value = double; +using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; void program_options(int argc, char * argv[] , std::string & off_file_points @@ -36,7 +37,7 @@ int main(int argc, char **argv) { using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); - Gudhi::Simplex_tree<> simplex; + Simplex_tree simplex; if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { // ---------------------------------------------------------------------------- // Display information about the alpha complex @@ -50,7 +51,7 @@ int main(int argc, char **argv) { std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>, + Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); diff --git a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp index 5184ef52..6c03afce 100644 --- a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2014 INRIA Saclay (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp index 817aac4d..7ca9410a 100644 --- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp +++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ #include // Types definition -using Simplex_tree = Gudhi::Simplex_tree; +using Simplex_tree = Gudhi::Simplex_tree<>; using Filtration_value = Simplex_tree::Filtration_value; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 8e5c83a1..6db85d16 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Clément Maria * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index b74d0094..709c2eab 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Clément Maria * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp index ee6577f4..b7daf6ae 100644 --- a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp @@ -4,8 +4,7 @@ * * Author(s): Clément Maria, Marc Glisse * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France), - * 2015 INRIA Saclay Île de France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Rips_complex/doc/Intro_rips_complex.h b/src/Rips_complex/doc/Intro_rips_complex.h index bd9f5fad..a71946b5 100644 --- a/src/Rips_complex/doc/Intro_rips_complex.h +++ b/src/Rips_complex/doc/Intro_rips_complex.h @@ -2,9 +2,9 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clément Maria & Vincent Rouvreau + * Author(s): Clément Maria, Vincent Rouvreau * - * Copyright (C) 2015 INRIA + * Copyright (C) 2016 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ namespace rips_complex { /** \defgroup rips_complex Rips complex * - * \author Clément Maria and Vincent Rouvreau + * \author Clément Maria, Vincent Rouvreau * * @{ * diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h index aee6c969..da755b7c 100644 --- a/src/Rips_complex/include/gudhi/Rips_complex.h +++ b/src/Rips_complex/include/gudhi/Rips_complex.h @@ -2,7 +2,7 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clément Maria & Vincent Rouvreau + * Author(s): Clément Maria, Vincent Rouvreau * * Copyright (C) 2016 INRIA * diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index bf6dc470..60f9a35e 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp index 8d729c56..13c700c6 100644 --- a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -4,7 +4,7 @@ * * Author(s): Clément Maria * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 59dd28e0..5dd18d0a 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2015 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,9 +36,9 @@ #include #include -typedef std::vector< int > typeVectorVertex; -typedef std::vector< std::vector > Point_Vector; typedef Gudhi::Simplex_tree<> Simplex_tree; +typedef std::vector< Simplex_tree::Vertex_handle > typeVectorVertex; +typedef std::vector< std::vector > Point_Vector; int main(int argc, char * const argv[]) { if (argc != 3) { diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 7ab86cc0..60e02225 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2015 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h b/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h index ec93ae71..1ae2e393 100644 --- a/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h +++ b/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2015 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h deleted file mode 100644 index bcb89e00..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h +++ /dev/null @@ -1,105 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ -#define LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ - -#include - -#include // for numeric_limits<> -#include -#include // for sort -#include - -namespace Gudhi { - -namespace witness_complex { - - typedef std::vector typeVectorVertex; - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the furthest witness from the - * current landmark set as the new landmark. - * \details It chooses nbL landmarks from a random access range `points` and - * writes {witness}*{closest landmarks} matrix in `knn`. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges - * - */ - - template - void landmark_choice_by_furthest_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nb_points = boost::size(points); - assert(nb_points >= nbL); - // distance matrix witness x landmarks - std::vector> wit_land_dist(nb_points, std::vector()); - // landmark list - typeVectorVertex chosen_landmarks; - - knn = KNearestNeighbours(nb_points, std::vector()); - int current_number_of_landmarks = 0; // counter for landmarks - double curr_max_dist = 0; // used for defining the furhest point from L - const double infty = std::numeric_limits::infinity(); // infinity (see next entry) - std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from points - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - // or better yet std::uniform_int_distribution - int rand_int = rand() % nb_points; - int curr_max_w = rand_int; // For testing purposes a pseudo-random number is used here - - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - // curr_max_w at this point is the next landmark - chosen_landmarks.push_back(curr_max_w); - unsigned i = 0; - for (auto& p : points) { - double curr_dist = euclidean_distance(p, *(std::begin(points) + chosen_landmarks[current_number_of_landmarks])); - wit_land_dist[i].push_back(curr_dist); - knn[i].push_back(current_number_of_landmarks); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - curr_max_dist = 0; - for (i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - for (int i = 0; i < nb_points; ++i) - std::sort(std::begin(knn[i]), - std::end(knn[i]), - [&wit_land_dist, i](int a, int b) { - return wit_land_dist[i][a] < wit_land_dist[i][b]; }); - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h deleted file mode 100644 index b5aab9d5..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h +++ /dev/null @@ -1,96 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LANDMARK_CHOICE_BY_RANDOM_POINT_H_ -#define LANDMARK_CHOICE_BY_RANDOM_POINT_H_ - -#include - -#include // for priority_queue<> -#include // for pair<> -#include -#include -#include - -namespace Gudhi { - -namespace witness_complex { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs a matrix {witness}*{closest landmarks} in knn. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges and - * Vertex_handle is the label type of a vertex in a simplicial complex. - * Closest_landmark_range needs to have push_back operation. - */ - - template - void landmark_choice_by_random_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nbP = boost::size(points); - assert(nbP >= nbL); - std::set landmarks; - int current_number_of_landmarks = 0; // counter for landmarks - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - int chosen_landmark = rand() % nbP; - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - while (landmarks.find(chosen_landmark) != landmarks.end()) - chosen_landmark = rand() % nbP; - landmarks.insert(chosen_landmark); - } - - int dim = boost::size(*std::begin(points)); - typedef std::pair dist_i; - typedef bool (*comp)(dist_i, dist_i); - knn = KNearestNeighbours(nbP); - for (int points_i = 0; points_i < nbP; points_i++) { - std::priority_queue, comp> l_heap([](dist_i j1, dist_i j2) { - return j1.first > j2.first; - }); - std::set::iterator landmarks_it; - int landmarks_i = 0; - for (landmarks_it = landmarks.begin(), landmarks_i = 0; landmarks_it != landmarks.end(); - ++landmarks_it, landmarks_i++) { - dist_i dist = std::make_pair(euclidean_distance(points[points_i], points[*landmarks_it]), landmarks_i); - l_heap.push(dist); - } - for (int i = 0; i < dim + 1; i++) { - dist_i dist = l_heap.top(); - knn[points_i].push_back(dist.second); - l_heap.pop(); - } - } - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 2cec921a..1eb126f1 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -72,7 +72,6 @@ class Witness_complex { typedef std::vector< Point_t > Point_Vector; typedef std::vector< Vertex_handle > typeVectorVertex; - //typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; typedef std::pair< Simplex_handle, bool > typePairSimplexBool; typedef int Witness_id; diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp index adaadfb0..6be39f58 100644 --- a/src/Witness_complex/test/simple_witness_complex.cpp +++ b/src/Witness_complex/test/simple_witness_complex.cpp @@ -33,7 +33,7 @@ #include typedef Gudhi::Simplex_tree<> Simplex_tree; -typedef std::vector< int > typeVectorVertex; +typedef std::vector< Simplex_tree::Vertex_handle > typeVectorVertex; typedef Gudhi::witness_complex::Witness_complex WitnessComplex; BOOST_AUTO_TEST_CASE(simple_witness_complex) { diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index b7067f87..92f53417 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -34,8 +34,8 @@ #include typedef std::vector Point; -typedef std::vector< int > typeVectorVertex; typedef Gudhi::Simplex_tree<> Simplex_tree; +typedef std::vector< Simplex_tree::Vertex_handle > typeVectorVertex; typedef Gudhi::witness_complex::Witness_complex WitnessComplex; BOOST_AUTO_TEST_CASE(witness_complex_points) { diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 773889d9..9dbcd891 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -39,61 +39,4 @@ struct vertex_filtration_t { typedef boost::vertex_property_tag kind; }; -/*typedef int Vertex_handle; -typedef double Filtration_value; -typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS -, boost::property < vertex_filtration_t, Filtration_value > -, boost::property < edge_filtration_t, Filtration_value > -> Graph_t; -typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; -*/ -/** \brief Output the proximity graph of the points. - * - * If points contains n elements, the proximity graph is the graph - * with n vertices, and an edge [u,v] iff the distance function between - * points u and v is smaller than threshold. - * - * The type PointCloud furnishes .begin() and .end() methods, that return - * iterators with value_type Point. - */ -/*template< typename PointCloud -, typename Point > -Graph_t compute_proximity_graph(PointCloud &points - , Filtration_value threshold - , Filtration_value distance(Point p1, Point p2)) { - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; - std::map< Vertex_handle, Filtration_value > vertices; - - Vertex_handle idx_u, idx_v; - Filtration_value fil; - idx_u = 0; - for (auto it_u = points.begin(); it_u != points.end(); ++it_u) { - idx_v = idx_u + 1; - for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) { - fil = distance(*it_u, *it_v); - if (fil <= threshold) { - edges.emplace_back(idx_u, idx_v); - edges_fil.push_back(fil); - } - } - ++idx_u; - } - - Graph_t skel_graph(edges.begin() - , edges.end() - , edges_fil.begin() - , idx_u); // number of points labeled from 0 to idx_u-1 - - auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); - - boost::graph_traits::vertex_iterator vi, vi_end; - for (std::tie(vi, vi_end) = boost::vertices(skel_graph); - vi != vi_end; ++vi) { - boost::put(vertex_prop, *vi, 0.); - } - - return skel_graph; -}*/ - #endif // GRAPH_SIMPLICIAL_COMPLEX_H_ -- cgit v1.2.3 From 69907a03283337e76d7763f82250b4e2a6b8f631 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 23 Nov 2016 07:35:46 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1771 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 994e3bf769d236d230ac2f7e751aa310dabb74bb --- src/GudhUI/utils/Persistence_compute.h | 3 +-- .../example/rips_distance_matrix_persistence.cpp | 8 ++++---- .../example/rips_multifield_persistence.cpp | 8 ++++---- .../example/rips_persistence.cpp | 8 ++++---- ...ample_one_skeleton_rips_from_distance_matrix.cpp | 3 ++- .../example_one_skeleton_rips_from_points.cpp | 3 ++- ...e_rips_complex_from_csv_distance_matrix_file.cpp | 1 + .../example/example_rips_complex_from_off_file.cpp | 1 + src/Rips_complex/include/gudhi/Rips_complex.h | 21 ++++++++------------- .../example/simplex_tree_from_cliques_of_graph.cpp | 1 + src/common/include/gudhi/distance_functions.h | 4 ++-- src/common/include/gudhi/reader_utils.h | 3 +-- 12 files changed, 31 insertions(+), 33 deletions(-) (limited to 'src/Simplex_tree') diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index f7048c28..d2973d84 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -75,7 +75,7 @@ template class Persistence_compute { using Rips_complex = Gudhi::rips_complex::Rips_complex; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; - + Rips_complex rips_complex(points, params.threshold, euclidean_distance); Simplex_tree st; @@ -87,7 +87,6 @@ template class Persistence_compute { pcoh.compute_persistent_cohomology(params.min_pers); stream << "persistence: \n"; stream << "p dimension birth death: \n"; - pcoh.output_diagram(stream); } } diff --git a/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp b/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp index 7a9e9c8b..ee236d61 100644 --- a/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp @@ -66,17 +66,17 @@ int main(int argc, char * argv[]) { if (rips_complex_from_file.create_complex(simplex_tree, dim_max)) { std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - + // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); - + // Compute the persistence diagram of the complex Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(p); - + pcoh.compute_persistent_cohomology(min_persistence); - + // Output the diagram in filediag if (filediag.empty()) { pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 6db85d16..aaa71db9 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -71,17 +71,17 @@ int main(int argc, char * argv[]) { if (rips_complex_from_file.create_complex(simplex_tree, dim_max)) { std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - + // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); - + // Compute the persistence diagram of the complex Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(min_p, max_p); - + pcoh.compute_persistent_cohomology(min_persistence); - + // Output the diagram in filediag if (filediag.empty()) { pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 3fa8aa30..0b1873d4 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -70,17 +70,17 @@ int main(int argc, char * argv[]) { if (rips_complex_from_file.create_complex(simplex_tree, dim_max)) { std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - + // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); - + // Compute the persistence diagram of the complex Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(p); - + pcoh.compute_persistent_cohomology(min_persistence); - + // Output the diagram in filediag if (filediag.empty()) { pcoh.output_diagram(); diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp index 54fa3aa1..b1ba494e 100644 --- a/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp +++ b/src/Rips_complex/example/example_one_skeleton_rips_from_distance_matrix.cpp @@ -5,6 +5,7 @@ #include #include +#include #include // for std::numeric_limits void usage(int nbArgs, char * const progName) { @@ -38,7 +39,7 @@ int main(int argc, char **argv) { distances.push_back({0.77, 0.26}); distances.push_back({0.99, 0.99, 0.28}); distances.push_back({0.11, 0.39, 0.97, 0.30}); - + // ---------------------------------------------------------------------------- // Init of a rips complex from points // ---------------------------------------------------------------------------- diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp index 26517876..68fc3629 100644 --- a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp +++ b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp @@ -5,6 +5,7 @@ #include #include +#include #include // for std::numeric_limits void usage(int nbArgs, char * const progName) { @@ -33,7 +34,7 @@ int main(int argc, char **argv) { points.push_back({0.0, 14.0}); points.push_back({2.0, 19.0}); points.push_back({9.0, 17.0}); - + // ---------------------------------------------------------------------------- // Init of a rips complex from points // ---------------------------------------------------------------------------- diff --git a/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp b/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp index cfada84a..730bfc7c 100644 --- a/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp +++ b/src/Rips_complex/example/example_rips_complex_from_csv_distance_matrix_file.cpp @@ -7,6 +7,7 @@ #include #include +#include void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; diff --git a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp index 60050cea..469de403 100644 --- a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp +++ b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp @@ -7,6 +7,7 @@ #include #include +#include void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h index 63207892..f98a6993 100644 --- a/src/Rips_complex/include/gudhi/Rips_complex.h +++ b/src/Rips_complex/include/gudhi/Rips_complex.h @@ -64,7 +64,6 @@ class Rips_complex { typedef int Vertex_handle; public: - /** \brief Rips_complex constructor from a list of points. * * @param[in] points Range of points. @@ -87,7 +86,7 @@ class Rips_complex { */ template Rips_complex(const InputDistanceRange& distance_matrix, Filtration_value threshold) { - compute_proximity_graph(boost::irange((size_t)0,distance_matrix.size()), threshold, + compute_proximity_graph(boost::irange((size_t)0, distance_matrix.size()), threshold, [&](size_t i, size_t j){return distance_matrix[j][i];}); } @@ -106,7 +105,7 @@ class Rips_complex { bool create_complex(SimplicialComplexForRips& complex, int dim_max) { if (complex.num_vertices() > 0) { std::cerr << "Rips_complex create_complex - complex is not empty\n"; - return false; // ----- >> + return false; // ----- >> } // insert the proximity graph in the simplicial complex @@ -118,7 +117,7 @@ class Rips_complex { return true; } - public: + private: /** \brief Output the proximity graph of the points. * * If points contains n elements, the proximity graph is the graph @@ -133,20 +132,17 @@ class Rips_complex { Distance distance) { std::vector< std::pair< Vertex_handle, Vertex_handle > > edges; std::vector< Filtration_value > edges_fil; - std::map< Vertex_handle, Filtration_value > vertices; // Compute the proximity graph of the points. // If points contains n elements, the proximity graph is the graph with n vertices, and an edge [u,v] iff the // distance function between points u and v is smaller than threshold. // -------------------------------------------------------------------------------------------- // Creates the vector of edges and its filtration values (returned by distance function) - Vertex_handle idx_u, idx_v; - Filtration_value fil; - idx_u = 0; + Vertex_handle idx_u = 0; for (auto it_u = std::begin(points); it_u != std::end(points); ++it_u) { - idx_v = idx_u + 1; + Vertex_handle idx_v = idx_u + 1; for (auto it_v = it_u + 1; it_v != std::end(points); ++it_v, ++idx_v) { - fil = distance(*it_u, *it_v); + Filtration_value fil = distance(*it_u, *it_v); if (fil <= threshold) { edges.emplace_back(idx_u, idx_v); edges_fil.push_back(fil); @@ -172,11 +168,10 @@ class Rips_complex { private: Graph_t rips_skeleton_graph_; - }; -} // namespace rips_complex +} // namespace rips_complex -} // namespace Gudhi +} // namespace Gudhi #endif // RIPS_COMPLEX_H_ diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp index 13c700c6..1dff4529 100644 --- a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // for std::pair using namespace Gudhi; diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index ed2c1f5d..58a513e7 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -32,12 +32,12 @@ /** @brief Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to * have the same dimension. */ template< typename Filtration_value, typename Point > -Filtration_value euclidean_distance(const Point &p1,const Point &p2) { +Filtration_value euclidean_distance(const Point &p1, const Point &p2) { Filtration_value dist = 0.; auto it1 = p1.begin(); auto it2 = p2.begin(); for (; it1 != p1.end(); ++it1, ++it2) { - Filtration_value tmp = (double)(*it1) - (double)(*it2); + Filtration_value tmp = static_cast(*it1) - static_cast(*it2); dist += tmp*tmp; } return std::sqrt(dist); diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index ddec5ba7..2d774d4d 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -222,7 +222,7 @@ bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundar **/ template< typename Filtration_value > std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(const std::string& filename, - const char separator=';') { + const char separator = ';') { #ifdef DEBUG_TRACES std::cout << "Using procedure read_lower_triangular_matrix_from_csv_file \n"; #endif // DEBUG_TRACES @@ -273,7 +273,6 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from } if (!values_in_this_line.empty())result.push_back(values_in_this_line); ++number_of_line; - } in.close(); -- cgit v1.2.3 From ccc1ca066fa7c1fb35929eceb52f2f36179aea37 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Dec 2016 17:02:26 +0000 Subject: Remove inline from read_graph (now inline) Remove Edge_t template (not needed) Add documentation on template params git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1839 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a011b11cddf1a20e29743e6b170dac054ac79c12 --- src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp | 3 +-- src/common/include/gudhi/reader_utils.h | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/Simplex_tree') diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp index 1dff4529..d1b8b2de 100644 --- a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -35,7 +35,6 @@ typedef double Filtration_value; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, boost::property < vertex_filtration_t, Filtration_value >, boost::property < edge_filtration_t, Filtration_value > > Graph_t; -typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; int main(int argc, char * const argv[]) { if (argc != 3) { @@ -51,7 +50,7 @@ int main(int argc, char * const argv[]) { Simplex_tree<> st; start = clock(); - auto g = read_graph(filegraph); + auto g = read_graph(filegraph); // insert the graph in the simplex tree as 1-skeleton st.insert_graph(g); end = clock(); diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 2d774d4d..4c8d85cd 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -74,6 +74,10 @@ inline void read_points(std::string file_name, std::vector< std::vector< double /** * @brief Read a graph from a file. * + * \tparam Graph_t Type for the return graph. Must be constructible from iterators on pairs of Vertex_handle + * \tparam Filtration_value Type for the value of the read filtration + * \tparam Vertex_handle Type for the value of the read vertices + * * File format: 1 simplex per line
* Dim1 X11 X12 ... X1d Fil1
* Dim2 X21 X22 ... X2d Fil2
@@ -83,13 +87,14 @@ inline void read_points(std::string file_name, std::vector< std::vector< double * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ -template< typename Graph_t, typename Edge_t, typename Filtration_value, typename Vertex_handle > -inline Graph_t read_graph(std::string file_name) { +template< typename Graph_t, typename Filtration_value, typename Vertex_handle > +Graph_t read_graph(std::string file_name) { std::ifstream in_(file_name.c_str(), std::ios::in); if (!in_.is_open()) { std::cerr << "Unable to open file " << file_name << std::endl; } + typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; std::vector< Edge_t > edges; std::vector< Filtration_value > edges_fil; std::map< Vertex_handle, Filtration_value > vertices; -- cgit v1.2.3 From 3b83c563f5a9992b2eb9a82738e6eebbe471b3e4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 6 Jan 2017 13:58:04 +0000 Subject: Test of thread_local solution git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/thread_local_no_static@1932 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a1f31ab16d2a086d38d0d019bbdc59152f8e02e7 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 3 +-- src/Simplex_tree/include/gudhi/Simplex_tree.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Simplex_tree') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index bc8099e6..b3339b7d 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -300,8 +300,7 @@ class Persistent_cohomology { // with multiplicity. We used to sum the coefficients directly in // annotations_in_boundary by using a map, we now do it later. typedef std::pair annotation_t; - // Danger: not thread-safe! - static std::vector annotations_in_boundary; + thread_local std::vector annotations_in_boundary; annotations_in_boundary.clear(); int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 63e3f0e5..317bce23 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -1029,7 +1029,7 @@ class Simplex_tree { Dictionary_it next = siblings->members().begin(); ++next; - static std::vector > inter; // static, not thread-safe. + thread_local std::vector > inter; for (Dictionary_it s_h = siblings->members().begin(); s_h != siblings->members().end(); ++s_h, ++next) { Simplex_handle root_sh = find_vertex(s_h->first); -- cgit v1.2.3