diff options
Diffstat (limited to 'src/cython')
36 files changed, 407 insertions, 393 deletions
diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt index 9dcb2cf4..96c2acb3 100644 --- a/src/cython/CMakeLists.txt +++ b/src/cython/CMakeLists.txt @@ -1,47 +1,8 @@ cmake_minimum_required(VERSION 2.8) project(Cython) -macro( find_the_lib placeholder THE_LIBS ) - set (THE_LIB_WE_FOUND "NO") - foreach(THE_LIB ${THE_LIBS}) - if(EXISTS ${THE_LIB}) - get_filename_component(THE_LIB_WE ${THE_LIB} NAME_WE) - if (NOT THE_LIB_WE_FOUND) - set (THE_LIB_WE_FOUND "YES") - set(returnValue "${THE_LIB_WE}") - endif(NOT THE_LIB_WE_FOUND) - endif(EXISTS ${THE_LIB}) - endforeach(THE_LIB ${THE_LIBS}) -endmacro( find_the_lib ) - -# Find the correct Python interpreter. Can be set with -DPYTHON_EXECUTABLE=/usr/bin/python3 for instance. -if(PYTHON_EXECUTABLE) - if(NOT EXISTS "${PYTHON_EXECUTABLE}") - message(FATAL_ERROR "ERROR: ${PYTHON_EXECUTABLE} does not exist.") - endif(NOT EXISTS "${PYTHON_EXECUTABLE}") -endif(PYTHON_EXECUTABLE) -include(FindPythonInterp) - -if(PYTHONINTERP_FOUND) - if(PYTHON_VERSION_MAJOR EQUAL 2) - FIND_PROGRAM(CYTHON_PATH cython) - # Unitary tests are available through py.test - find_program( PYTEST_PATH py.test ) - # Documentation generation is available through sphinx - find_program( SPHINX_PATH sphinx-build ) - elseif(PYTHON_VERSION_MAJOR EQUAL 3) - FIND_PROGRAM(CYTHON_PATH cython3) - # Unitary tests are available through py.test - find_program( PYTEST_PATH py.test ) - # Documentation generation is available through sphinx - set(SPHINX_PATH "${CMAKE_CURRENT_BINARY_DIR}/doc/python3-sphinx-build") - else() - message(FATAL_ERROR "ERROR: Try to compile the Cython interface. Python version ${PYTHON_VERSION_STRING} is not valid.") - endif(PYTHON_VERSION_MAJOR EQUAL 2) -endif(PYTHONINTERP_FOUND) - -if(CYTHON_PATH) - message("${PYTHON_EXECUTABLE} v.${PYTHON_VERSION_STRING} - Cython is ${CYTHON_PATH} - py.test is ${PYTEST_PATH} - Sphinx is ${SPHINX_PATH}") +if(CYTHON_FOUND) + message("++ ${PYTHON_EXECUTABLE} v.${PYTHON_VERSION_STRING} - Cython is ${CYTHON_EXECUTABLE} - py.test is ${PYTEST_PATH} - Sphinx is ${SPHINX_PATH}") set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_RESULT_OF_USE_DECLTYPE', ") set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_ALL_NO_LIB', ") @@ -179,8 +140,8 @@ if(CYTHON_PATH) # Specific for Mac if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-mmacosx-version-min=10.9', ") - set(GUDHI_CYTHON_EXTRA_LINK_ARGS "${GUDHI_CYTHON_EXTRA_LINK_ARGS}'-mmacosx-version-min=10.9', ") + set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-mmacosx-version-min=10.12', ") + set(GUDHI_CYTHON_EXTRA_LINK_ARGS "${GUDHI_CYTHON_EXTRA_LINK_ARGS}'-mmacosx-version-min=10.12', ") endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Loop on INCLUDE_DIRECTORIES PROPERTY @@ -215,9 +176,89 @@ if(CYTHON_PATH) COMMENT "Do not forget to add ${CMAKE_CURRENT_BINARY_DIR}/ to your PYTHONPATH before using examples or tests") if(UNIX) - set( ENV{PYTHONPATH} $ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}/ ) + set( ENV{PYTHONPATH} $ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}/ ) endif(UNIX) + # Test examples + add_test(NAME alpha_complex_from_points_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/alpha_complex_from_points_example.py") + set_tests_properties(alpha_complex_from_points_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) + set_tests_properties(alpha_complex_diagram_persistence_from_off_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME alpha_rips_persistence_bottleneck_distance_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/alpha_rips_persistence_bottleneck_distance.py" + -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -t 0.15 -d 3) + set_tests_properties(alpha_rips_persistence_bottleneck_distance_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME bottleneck_basic_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/bottleneck_basic_example.py") + set_tests_properties(bottleneck_basic_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + set_tests_properties(euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + set_tests_properties(euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME periodic_cubical_complex_barcode_persistence_from_perseus_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py" + --no-barcode -f ${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt) + set_tests_properties(periodic_cubical_complex_barcode_persistence_from_perseus_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME random_cubical_complex_persistence_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/random_cubical_complex_persistence_example.py" + 10 10 10) + set_tests_properties(random_cubical_complex_persistence_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) + set_tests_properties(rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) + set_tests_properties(rips_complex_diagram_persistence_from_off_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME rips_complex_from_points_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/example/rips_complex_from_points_example.py) + set_tests_properties(rips_complex_from_points_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME simplex_tree_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/example/simplex_tree_example.py) + set_tests_properties(simplex_tree_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) + set_tests_properties(tangential_complex_plain_homology_from_off_file_example_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + + add_test(NAME witness_complex_from_nearest_landmark_table_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/example/witness_complex_from_nearest_landmark_table.py) + set_tests_properties(witness_complex_from_nearest_landmark_table_py_test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}") + # Unitary tests are available through py.test if(PYTEST_PATH) add_test( @@ -240,4 +281,4 @@ if(CYTHON_PATH) COMMAND make.bat html doctest) endif (UNIX) endif(SPHINX_PATH) -endif(CYTHON_PATH) +endif(CYTHON_FOUND) diff --git a/src/cython/cython/bottleneck_distance.pyx b/src/cython/cython/bottleneck_distance.pyx index ee3e6ef9..9fb377ff 100644 --- a/src/cython/cython/bottleneck_distance.pyx +++ b/src/cython/cython/bottleneck_distance.pyx @@ -33,7 +33,7 @@ cdef extern from "Bottleneck_distance_interface.h" namespace "Gudhi::persistence double bottleneck(vector[pair[double, double]], vector[pair[double, double]], double) double bottleneck(vector[pair[double, double]], vector[pair[double, double]]) -def bottleneck_distance(diagram_1, diagram_2, e=0.0): +def bottleneck_distance(diagram_1, diagram_2, e=None): """This function returns the point corresponding to a given vertex. :param diagram_1: The first diagram. @@ -53,7 +53,9 @@ def bottleneck_distance(diagram_1, diagram_2, e=0.0): :rtype: float :returns: the bottleneck distance. """ - if e is 0.0: + if e is None: + # Default value is the smallest double value (not 0, 0 is for exact version) return bottleneck(diagram_1, diagram_2) else: + # Can be 0 for exact version return bottleneck(diagram_1, diagram_2, e) diff --git a/src/cython/cython/cubical_complex.pyx b/src/cython/cython/cubical_complex.pyx index 1ed6bc5e..ffc85130 100644 --- a/src/cython/cython/cubical_complex.pyx +++ b/src/cython/cython/cubical_complex.pyx @@ -60,16 +60,16 @@ cdef class CubicalComplex: def __init__(self, dimensions=None, top_dimensional_cells=None, perseus_file=''): """CubicalComplex constructor from dimensions and - top_dimensional_cells or from a perseus file style name. + top_dimensional_cells or from a Perseus-style file name. :param dimensions: A list of number of top dimensional cells. :type dimensions: list of int - :param top_dimensional_cells: A list of top dimensional cells. + :param top_dimensional_cells: A list of cells filtration values. :type top_dimensional_cells: list of double Or - :param perseus_file: A perseus file style name. + :param perseus_file: A Perseus-style file name. :type perseus_file: string """ @@ -85,7 +85,7 @@ cdef class CubicalComplex: print("file " + perseus_file + " not found.") else: print("CubicalComplex can be constructed from dimensions and " - "top_dimensional_cells or from a perseus file style name.") + "top_dimensional_cells or from a Perseus-style file name.") def __dealloc__(self): if self.thisptr != NULL: diff --git a/src/cython/cython/periodic_cubical_complex.pyx b/src/cython/cython/periodic_cubical_complex.pyx index 88cb4395..581c7b69 100644 --- a/src/cython/cython/periodic_cubical_complex.pyx +++ b/src/cython/cython/periodic_cubical_complex.pyx @@ -60,16 +60,16 @@ cdef class PeriodicCubicalComplex: def __init__(self, dimensions=None, top_dimensional_cells=None, perseus_file=''): """PeriodicCubicalComplex constructor from dimensions and - top_dimensional_cells or from a perseus file style name. + top_dimensional_cells or from a Perseus-style file name. :param dimensions: A list of number of top dimensional cells. :type dimensions: list of int - :param top_dimensional_cells: A list of top dimensional cells. + :param top_dimensional_cells: A list of cells filtration values. :type top_dimensional_cells: list of double Or - :param perseus_file: A perseus file style name. + :param perseus_file: A Perseus-style file name. :type perseus_file: string """ @@ -85,7 +85,7 @@ cdef class PeriodicCubicalComplex: print("file " + perseus_file + " not found.") else: print("CubicalComplex can be constructed from dimensions and " - "top_dimensional_cells or from a perseus file style name.") + "top_dimensional_cells or from a Perseus-style file name.") def __dealloc__(self): if self.thisptr != NULL: diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx index 148227e1..9d40a8b5 100644 --- a/src/cython/cython/simplex_tree.pyx +++ b/src/cython/cython/simplex_tree.pyx @@ -46,9 +46,8 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": bint find_simplex(vector[int] simplex) bint insert_simplex_and_subfaces(vector[int] simplex, double filtration) - bint insert_simplex(vector[int] simplex, double filtration) - vector[pair[vector[int], double]] get_filtered_tree() - vector[pair[vector[int], double]] get_skeleton_tree(int dimension) + vector[pair[vector[int], double]] get_filtration() + vector[pair[vector[int], double]] get_skeleton(int dimension) vector[pair[vector[int], double]] get_star(vector[int] simplex) vector[pair[vector[int], double]] get_cofaces(vector[int] simplex, int dimension) @@ -103,14 +102,6 @@ cdef class SimplexTree: """ return self.pcohptr != NULL - def get_filtration(self): - """This function returns the main simplicial complex filtration value. - - :returns: The simplicial complex filtration value. - :rtype: float - """ - return self.thisptr.filtration() - def filtration(self, simplex): """This function returns the simplicial complex filtration value for a given N-simplex. @@ -137,7 +128,7 @@ cdef class SimplexTree: .. note:: This function must be launched before persistence, betti_numbers, - persistent_betti_numbers or get_filtered_tree after inserting or + persistent_betti_numbers or get_filtration after inserting or removing simplices. """ self.thisptr.initialize_filtration() @@ -197,24 +188,7 @@ cdef class SimplexTree: complex.push_back(i) return self.thisptr.find_simplex(complex) - def insert_simplex(self, simplex, filtration=0.0): - """This function inserts the given N-simplex with the given filtration - value (default value is '0.0'). - - :param simplex: The N-simplex to insert, represented by a list of - vertex. - :type simplex: list of int. - :param filtration: The filtration value of the simplex. - :type filtration: float. - :returns: true if the simplex was found, false otherwise. - :rtype: bool - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.insert_simplex(complex, <double>filtration) - - def insert_simplex_and_subfaces(self, simplex, filtration=0.0): + def insert(self, simplex, filtration=0.0): """This function inserts the given N-simplex and its subfaces with the given filtration value (default value is '0.0'). @@ -232,36 +206,36 @@ cdef class SimplexTree: return self.thisptr.insert_simplex_and_subfaces(complex, <double>filtration) - def get_filtered_tree(self): - """This function returns the tree sorted by increasing filtration - values. + def get_filtration(self): + """This function returns a list of all simplices with their given + filtration values. - :returns: The tree sorted by increasing filtration values. + :returns: The simplices sorted by increasing filtration values. :rtype: list of tuples(simplex, filtration) """ - cdef vector[pair[vector[int], double]] filtered_tree \ - = self.thisptr.get_filtered_tree() + cdef vector[pair[vector[int], double]] filtration \ + = self.thisptr.get_filtration() ct = [] - for filtered_complex in filtered_tree: + for filtered_complex in filtration: v = [] for vertex in filtered_complex.first: v.append(vertex) ct.append((v, filtered_complex.second)) return ct - def get_skeleton_tree(self, dimension): - """This function returns the tree skeleton of a maximum given - dimension. + def get_skeleton(self, dimension): + """This function returns the (simplices of the) skeleton of a maximum + given dimension. :param dimension: The skeleton dimension value. :type dimension: int. - :returns: The skeleton tree of a maximum dimension. + :returns: The (simplices of the) skeleton of a maximum dimension. :rtype: list of tuples(simplex, filtration) """ - cdef vector[pair[vector[int], double]] sk_tree \ - = self.thisptr.get_skeleton_tree(<int>dimension) + cdef vector[pair[vector[int], double]] skeletons \ + = self.thisptr.get_skeleton(<int>dimension) ct = [] - for filtered_complex in sk_tree: + for filtered_complex in skeletons: v = [] for vertex in filtered_complex.first: v.append(vertex) @@ -273,7 +247,7 @@ cdef class SimplexTree: :param simplex: The N-simplex, represented by a list of vertex. :type simplex: list of int. - :returns: The star tree of a simplex. + :returns: The (simplices of the) star of a simplex. :rtype: list of tuples(simplex, filtration) """ cdef vector[int] complex @@ -298,7 +272,7 @@ cdef class SimplexTree: :param codimension: The codimension. If codimension = 0, all cofaces are returned (equivalent of get_star function) :type codimension: int. - :returns: The coface tree of a simplex. + :returns: The (simplices of the) cofaces of a simplex :rtype: list of tuples(simplex, filtration) """ cdef vector[int] complex diff --git a/src/cython/doc/_templates/layout.html b/src/cython/doc/_templates/layout.html index af0eef64..b11c1236 100644 --- a/src/cython/doc/_templates/layout.html +++ b/src/cython/doc/_templates/layout.html @@ -205,8 +205,8 @@ <ul class="dropdown"> <li><a href="http://gudhi.gforge.inria.fr/doc/latest/">C++ documentation</a></li> <li><a href="http://gudhi.gforge.inria.fr/doc/latest/installation.html">C++ installation manual</a></li> - <li><a href="http://gudhi.gforge.inria.fr/cython/latest/">Cython documentation</a></li> - <li><a href="http://gudhi.gforge.inria.fr/cython/latest/installation.html">Cython installation manual</a></li> + <li><a href="http://gudhi.gforge.inria.fr/python/latest/">Python documentation</a></li> + <li><a href="http://gudhi.gforge.inria.fr/python/latest/installation.html">Python installation manual</a></li> </ul> </li> <li class="divider"></li> diff --git a/src/cython/doc/alpha_complex_sum.rst b/src/cython/doc/alpha_complex_sum.rst index 8437e901..a5f6420a 100644 --- a/src/cython/doc/alpha_complex_sum.rst +++ b/src/cython/doc/alpha_complex_sum.rst @@ -16,7 +16,7 @@ | | complex. | | | | | | This package requires having CGAL version 4.7 or higher (4.8.1 is | -| | advised for better perfomances). | +| | advised for better performance). | +----------------------------------------------------------------+------------------------------------------------------------------------+ | :doc:`alpha_complex_user` | :doc:`alpha_complex_ref` | +----------------------------------------------------------------+------------------------------------------------------------------------+ diff --git a/src/cython/doc/alpha_complex_user.rst b/src/cython/doc/alpha_complex_user.rst index 68e53a77..e8268ef1 100644 --- a/src/cython/doc/alpha_complex_user.rst +++ b/src/cython/doc/alpha_complex_user.rst @@ -1,4 +1,3 @@ -========================= Alpha complex user manual ========================= Definition @@ -30,39 +29,40 @@ This example builds the Delaunay triangulation from the given points, and initia repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) The output is: .. testoutput:: Alpha complex is of dimension 2 - 25 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 6.25) - ([4, 5], 7.25) - ([0, 2], 8.5) - ([0, 1], 9.25) - ([1, 3], 10.0) - ([1, 2], 11.25) - ([1, 2, 3], 12.5) - ([0, 1, 2], 12.995867768595042) - ([5, 6], 13.25) - ([2, 4], 20.0) - ([4, 6], 22.736686390532547) - ([4, 5, 6], 22.736686390532547) - ([3, 6], 30.25) - ([2, 6], 36.5) - ([2, 3, 6], 36.5) - ([2, 4, 6], 37.24489795918368) - ([0, 4], 59.710743801652896) - ([0, 2, 4], 59.710743801652896) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 6.25 + [4, 5] -> 7.25 + [0, 2] -> 8.50 + [0, 1] -> 9.25 + [1, 3] -> 10.00 + [1, 2] -> 11.25 + [1, 2, 3] -> 12.50 + [0, 1, 2] -> 13.00 + [5, 6] -> 13.25 + [2, 4] -> 20.00 + [4, 6] -> 22.74 + [4, 5, 6] -> 22.74 + [3, 6] -> 30.25 + [2, 6] -> 36.50 + [2, 3, 6] -> 36.50 + [2, 4, 6] -> 37.24 + [0, 4] -> 59.71 + [0, 2, 4] -> 59.71 Algorithm @@ -164,39 +164,39 @@ Then, it is asked to display information about the alpha complex: repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) the program output is: .. testoutput:: Alpha complex is of dimension 2 - 23 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 6.25) - ([4, 5], 7.25) - ([0, 2], 8.5) - ([0, 1], 9.25) - ([1, 3], 10.0) - ([1, 2], 11.25) - ([1, 2, 3], 12.5) - ([0, 1, 2], 12.995867768595042) - ([5, 6], 13.25) - ([2, 4], 20.0) - ([4, 6], 22.736686390532547) - ([4, 5, 6], 22.736686390532547) - ([3, 6], 30.25) - ([2, 6], 36.5) - ([2, 3, 6], 36.5) - ([2, 4, 6], 37.24489795918368) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 6.25 + [4, 5] -> 7.25 + [0, 2] -> 8.50 + [0, 1] -> 9.25 + [1, 3] -> 10.00 + [1, 2] -> 11.25 + [1, 2, 3] -> 12.50 + [0, 1, 2] -> 13.00 + [5, 6] -> 13.25 + [2, 4] -> 20.00 + [4, 6] -> 22.74 + [4, 5, 6] -> 22.74 + [3, 6] -> 30.25 + [2, 6] -> 36.50 + [2, 3, 6] -> 36.50 + [2, 4, 6] -> 37.24 -============== CGAL citations ============== diff --git a/src/cython/doc/bottleneck_distance_user.rst b/src/cython/doc/bottleneck_distance_user.rst index 3bc170f4..0066992f 100644 --- a/src/cython/doc/bottleneck_distance_user.rst +++ b/src/cython/doc/bottleneck_distance_user.rst @@ -1,4 +1,3 @@ -=============================== Bottleneck distance user manual =============================== Definition @@ -23,15 +22,15 @@ This example computes the bottleneck distance from 2 persistence diagrams: diag1 = [[2.7, 3.7],[9.6, 14.],[34.2, 34.974], [3.,float('Inf')]] diag2 = [[2.8, 4.45],[9.5, 14.1],[3.2,float('Inf')]] - message = "Bottleneck distance approximation=" + repr(gudhi.bottleneck_distance(diag1, diag2, 0.1)) + message = "Bottleneck distance approximation=" + '%.2f' % gudhi.bottleneck_distance(diag1, diag2, 0.1) print(message) - message = "Bottleneck distance exact value=" + repr(gudhi.bottleneck_distance(diag1, diag2)) + message = "Bottleneck distance exact value=" + '%.2f' % gudhi.bottleneck_distance(diag1, diag2, 0) print(message) The output is: .. testoutput:: - Bottleneck distance approximation=0.8081763781405569 + Bottleneck distance approximation=0.81 Bottleneck distance exact value=0.75 diff --git a/src/cython/doc/cubical_complex_user.rst b/src/cython/doc/cubical_complex_user.rst index 692acdd9..344b9554 100644 --- a/src/cython/doc/cubical_complex_user.rst +++ b/src/cython/doc/cubical_complex_user.rst @@ -1,4 +1,3 @@ -=========================== Cubical complex user manual =========================== Definition @@ -154,7 +153,7 @@ Examples. End user programs are available in cython/example/ folder. Bibliography -************ +============ .. bibliography:: bibliography.bib :filter: docnames diff --git a/src/cython/doc/img/average_landscape.png b/src/cython/doc/img/average_landscape.png Binary files differdeleted file mode 100644 index ea59926b..00000000 --- a/src/cython/doc/img/average_landscape.png +++ /dev/null diff --git a/src/cython/doc/index.rst b/src/cython/doc/index.rst index fca63d65..f6d10567 100644 --- a/src/cython/doc/index.rst +++ b/src/cython/doc/index.rst @@ -1,5 +1,5 @@ -GUDHI documentation -################### +GUDHI Python module documentation +################################# .. image:: img/Gudhi_banner.png :align: center @@ -7,9 +7,9 @@ GUDHI documentation Introduction ************ -The Gudhi library (Geometry Understanding in Higher Dimensions) is a generic -open source `C++ library <http://gudhi.gforge.inria.fr/doc/latest/>`_, with a -`Cython interface <http://gudhi.gforge.inria.fr/cython/latest/>`_, for +The Python interface for the Gudhi library (Geometry Understanding in Higher +Dimensions) is a generic open source +`Python module <http://gudhi.gforge.inria.fr/python/latest/>`_, for Computational Topology and Topological Data Analysis (`TDA <https://en.wikipedia.org/wiki/Topological_data_analysis>`_). The GUDHI library intends to help the development of new algorithmic solutions @@ -20,12 +20,11 @@ data structures. The current release of the GUDHI library includes: * Data structures to represent, construct and manipulate simplicial complexes. -* Algorithms to compute persistent homology and multi-field persistent homology. -* Simplication of simplicial complexes by edge contraction. +* Simplification of simplicial complexes by edge contraction. +* Algorithms to compute persistent homology and bottleneck distance. -All data-structures are generic and several of their aspects can be -parameterized via template classes. We refer to :cite:`gudhilibrary_ICMS14` -for a detailed description of the design of the library. +We refer to :cite:`gudhilibrary_ICMS14` for a detailed description of the +design of the library. Data structures *************** diff --git a/src/cython/doc/installation.rst b/src/cython/doc/installation.rst index e7d8c210..f98a5039 100644 --- a/src/cython/doc/installation.rst +++ b/src/cython/doc/installation.rst @@ -4,12 +4,19 @@ Installation Compiling ********* -The library uses c++11 and requires `Boost <http://www.boost.org/>`_ with version -1.48.0 or more recent. It is a multi-platform library and compiles on Linux, -Mac OSX and Visual Studio 2015. +The library uses c++11 and requires `Boost <http://www.boost.org/>`_ with +version 1.48.0 or more recent. It is a multi-platform library and compiles on +Linux, Mac OSX and Visual Studio 2015. It also requires cmake to generate makefiles, and cython to compile the library. +On `Windows <https://wiki.python.org/moin/WindowsCompilers>`_ , only Python +3.5 and 3.6 are available because of the required Visual Studio version. + +On other systems, if you have several Python/cython installed, the version 2.X +will be used by default, but you can force it by adding +:code:`-DPython_ADDITIONAL_VERSIONS=3` to the cmake command. + GUDHI Cythonization =================== @@ -23,20 +30,18 @@ To build the GUDHI cython module, run the following commands in a terminal: cmake .. make cython -A list of examples is available here. - Test suites =========== -To test your build, `py.test <http://doc.pytest.org>`_ is required. Run the +To test your build, `py.test <http://doc.pytest.org>`_ is optional. Run the following command in a terminal: .. code-block:: bash - cd /path-to-gudhi/build/src/cython + cd /path-to-gudhi/build/cython # For windows, you have to set PYTHONPATH environment variable - export PYTHONPATH='$PYTHONPATH:/path-to-gudhi/build/src/cython' - py.test + export PYTHONPATH='$PYTHONPATH:/path-to-gudhi/build/cython' + ctest -R py_test Documentation ============= diff --git a/src/cython/doc/persistence_graphical_tools_user.rst b/src/cython/doc/persistence_graphical_tools_user.rst index f713e971..cae18323 100644 --- a/src/cython/doc/persistence_graphical_tools_user.rst +++ b/src/cython/doc/persistence_graphical_tools_user.rst @@ -1,4 +1,3 @@ -======================================= Persistence graphical tools user manual ======================================= Definition diff --git a/src/cython/doc/persistent_cohomology_user.rst b/src/cython/doc/persistent_cohomology_user.rst index 69be3b86..72f1a7f7 100644 --- a/src/cython/doc/persistent_cohomology_user.rst +++ b/src/cython/doc/persistent_cohomology_user.rst @@ -1,4 +1,3 @@ -================================= Persistent cohomology user manual ================================= Definition @@ -108,7 +107,7 @@ We provide several example files: run these examples with -h for details on thei * :download:`tangential_complex_plain_homology_from_off_file_example.py <../example/tangential_complex_plain_homology_from_off_file_example.py>` Bibliography -************ +============ .. bibliography:: bibliography.bib :filter: docnames diff --git a/src/cython/doc/rips_complex_user.rst b/src/cython/doc/rips_complex_user.rst index 027c3bf7..f9760976 100644 --- a/src/cython/doc/rips_complex_user.rst +++ b/src/cython/doc/rips_complex_user.rst @@ -1,4 +1,3 @@ -========================= Rips complex user manual ========================= Definition @@ -60,8 +59,9 @@ Finally, it is asked to display information about the simplicial complex. repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) When launching (Rips maximal distance between 2 points is 12.0, is expanded until dimension 1 - one skeleton graph in other words), the output is: @@ -69,24 +69,24 @@ until dimension 1 - one skeleton graph in other words), the output is: .. testoutput:: Rips complex is of dimension 1 - 18 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 5.0) - ([4, 5], 5.385164807134504) - ([0, 2], 5.830951894845301) - ([0, 1], 6.082762530298219) - ([1, 3], 6.324555320336759) - ([1, 2], 6.708203932499369) - ([5, 6], 7.280109889280518) - ([2, 4], 8.94427190999916) - ([0, 3], 9.433981132056603) - ([4, 6], 9.486832980505138) - ([3, 6], 11.0) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 5.00 + [4, 5] -> 5.39 + [0, 2] -> 5.83 + [0, 1] -> 6.08 + [1, 3] -> 6.32 + [1, 2] -> 6.71 + [5, 6] -> 7.28 + [2, 4] -> 8.94 + [0, 3] -> 9.43 + [4, 6] -> 9.49 + [3, 6] -> 11.00 Example from OFF file ^^^^^^^^^^^^^^^^^^^^^ @@ -107,32 +107,33 @@ Finally, it is asked to display information about the Rips complex. repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) the program output is: .. testoutput:: Rips complex is of dimension 1 - 18 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 5.0) - ([4, 5], 5.385164807134504) - ([0, 2], 5.830951894845301) - ([0, 1], 6.082762530298219) - ([1, 3], 6.324555320336759) - ([1, 2], 6.708203932499369) - ([5, 6], 7.280109889280518) - ([2, 4], 8.94427190999916) - ([0, 3], 9.433981132056603) - ([4, 6], 9.486832980505138) - ([3, 6], 11.0) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 5.00 + [4, 5] -> 5.39 + [0, 2] -> 5.83 + [0, 1] -> 6.08 + [1, 3] -> 6.32 + [1, 2] -> 6.71 + [5, 6] -> 7.28 + [2, 4] -> 8.94 + [0, 3] -> 9.43 + [4, 6] -> 9.49 + [3, 6] -> 11.00 Distance matrix --------------- @@ -162,8 +163,9 @@ Finally, it is asked to display information about the simplicial complex. repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) When launching (Rips maximal distance between 2 points is 12.0, is expanded until dimension 1 - one skeleton graph in other words), the output is: @@ -171,24 +173,24 @@ until dimension 1 - one skeleton graph in other words), the output is: .. testoutput:: Rips complex is of dimension 1 - 18 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 5.0) - ([4, 5], 5.3851648071) - ([0, 2], 5.8309518948) - ([0, 1], 6.0827625303) - ([1, 3], 6.3245553203) - ([1, 2], 6.7082039325) - ([5, 6], 7.2801098893) - ([2, 4], 8.94427191) - ([0, 3], 9.4339811321) - ([4, 6], 9.4868329805) - ([3, 6], 11.0) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 5.00 + [4, 5] -> 5.39 + [0, 2] -> 5.83 + [0, 1] -> 6.08 + [1, 3] -> 6.32 + [1, 2] -> 6.71 + [5, 6] -> 7.28 + [2, 4] -> 8.94 + [0, 3] -> 9.43 + [4, 6] -> 9.49 + [3, 6] -> 11.00 Example from csv file ^^^^^^^^^^^^^^^^^^^^^ @@ -209,29 +211,30 @@ Finally, it is asked to display information about the Rips complex. repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in simplex_tree.get_filtered_tree(): - print(filtered_value) + fmt = '%s -> %.2f' + for filtered_value in simplex_tree.get_filtration(): + print(fmt % tuple(filtered_value)) the program output is: .. testoutput:: Rips complex is of dimension 1 - 18 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([2], 0.0) - ([3], 0.0) - ([4], 0.0) - ([5], 0.0) - ([6], 0.0) - ([2, 3], 5.0) - ([4, 5], 5.3851648071) - ([0, 2], 5.8309518948) - ([0, 1], 6.0827625303) - ([1, 3], 6.3245553203) - ([1, 2], 6.7082039325) - ([5, 6], 7.2801098893) - ([2, 4], 8.94427191) - ([0, 3], 9.4339811321) - ([4, 6], 9.4868329805) - ([3, 6], 11.0) + [0] -> 0.00 + [1] -> 0.00 + [2] -> 0.00 + [3] -> 0.00 + [4] -> 0.00 + [5] -> 0.00 + [6] -> 0.00 + [2, 3] -> 5.00 + [4, 5] -> 5.39 + [0, 2] -> 5.83 + [0, 1] -> 6.08 + [1, 3] -> 6.32 + [1, 2] -> 6.71 + [5, 6] -> 7.28 + [2, 4] -> 8.94 + [0, 3] -> 9.43 + [4, 6] -> 9.49 + [3, 6] -> 11.00 diff --git a/src/cython/doc/simplex_tree_user.rst b/src/cython/doc/simplex_tree_user.rst index cbfd34a7..4b1dde19 100644 --- a/src/cython/doc/simplex_tree_user.rst +++ b/src/cython/doc/simplex_tree_user.rst @@ -1,4 +1,3 @@ -======================== Simplex tree user manual ======================== Definition @@ -35,9 +34,9 @@ Example import gudhi st = gudhi.SimplexTree() - if st.insert_simplex([0, 1]): + if st.insert([0, 1]): print("[0, 1] inserted") - if st.insert_simplex_and_subfaces([0, 1, 2], filtration=4.0): + if st.insert([0, 1, 2], filtration=4.0): print("[0, 1, 2] inserted") if st.find([0, 1]): print("[0, 1] found") @@ -45,8 +44,8 @@ Example print(result_str) result_str = 'num_simplices=' + repr(st.num_simplices()) print(result_str) - print("skeleton_tree(2) =") - for sk_value in st.get_skeleton_tree(2): + print("skeleton(2) =") + for sk_value in st.get_skeleton(2): print(sk_value) @@ -54,16 +53,16 @@ The output is: .. testoutput:: - [0, 1] inserted - [0, 1, 2] inserted - [0, 1] found - num_vertices=3 - num_simplices=7 - skeleton_tree(2) = - ([0, 1, 2], 4.0) - ([0, 1], 0.0) - ([0, 2], 4.0) - ([0], 0.0) - ([1, 2], 4.0) - ([1], 4.0) - ([2], 4.0) + [0, 1] inserted + [0, 1, 2] inserted + [0, 1] found + num_vertices=3 + num_simplices=7 + skeleton(2) = + ([0, 1, 2], 4.0) + ([0, 1], 0.0) + ([0, 2], 4.0) + ([0], 0.0) + ([1, 2], 4.0) + ([1], 0.0) + ([2], 4.0) diff --git a/src/cython/doc/tangential_complex_user.rst b/src/cython/doc/tangential_complex_user.rst index 6a7e6e41..03f9fea6 100644 --- a/src/cython/doc/tangential_complex_user.rst +++ b/src/cython/doc/tangential_complex_user.rst @@ -1,4 +1,3 @@ -============================== Tangential complex user manual ============================== .. include:: tangential_complex_sum.rst @@ -133,8 +132,8 @@ This example builds the Tangential complex of point set read in an OFF file. ' - ' + repr(st.num_simplices()) + ' simplices - ' + \ repr(st.num_vertices()) + ' vertices.' print(result_str) - for filtered_value in st.get_filtered_tree(): - print(filtered_value) + for filtered_value in st.get_filtration(): + print(filtered_value[0]) The output is: @@ -142,21 +141,21 @@ The output is: Tangential contains 12 simplices - 7 vertices. Simplex tree is of dimension 1 - 15 simplices - 7 vertices. - ([0], 0.0) - ([1], 0.0) - ([0, 1], 0.0) - ([2], 0.0) - ([0, 2], 0.0) - ([1, 2], 0.0) - ([3], 0.0) - ([1, 3], 0.0) - ([4], 0.0) - ([2, 4], 0.0) - ([5], 0.0) - ([4, 5], 0.0) - ([6], 0.0) - ([3, 6], 0.0) - ([5, 6], 0.0) + [0] + [1] + [0, 1] + [2] + [0, 2] + [1, 2] + [3] + [1, 3] + [4] + [2, 4] + [5] + [4, 5] + [6] + [3, 6] + [5, 6] Example with perturbation @@ -187,8 +186,9 @@ The output is: Tangential contains 4 vertices. Inconsistencies has been fixed. + Bibliography -************ +============ .. bibliography:: bibliography.bib :filter: docnames diff --git a/src/cython/doc/witness_complex_user.rst b/src/cython/doc/witness_complex_user.rst index 07945361..aa9cbb2c 100644 --- a/src/cython/doc/witness_complex_user.rst +++ b/src/cython/doc/witness_complex_user.rst @@ -1,12 +1,8 @@ -=========================== Witness complex user manual =========================== -Definition ----------- .. include:: witness_complex_sum.rst - Definitions ----------- @@ -128,7 +124,7 @@ Here is an example of constructing a strong witness complex filtration and compu * :download:`euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py <../example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py>` Bibliography -************ +============ .. bibliography:: bibliography.bib :filter: docnames diff --git a/src/cython/example/alpha_complex_from_points_example.py b/src/cython/example/alpha_complex_from_points_example.py index 688edb65..7d6278ce 100755 --- a/src/cython/example/alpha_complex_from_points_example.py +++ b/src/cython/example/alpha_complex_from_points_example.py @@ -59,7 +59,7 @@ else: print("[4] Not found...") print("dimension=", simplex_tree.dimension()) -print("filtered_tree=", simplex_tree.get_filtered_tree()) +print("filtrations=", simplex_tree.get_filtration()) print("star([0])=", simplex_tree.get_star([0])) print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1)) diff --git a/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py index 2474fc87..2371c36c 100755 --- a/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py @@ -32,7 +32,7 @@ __license__ = "GPL v3" parser = argparse.ArgumentParser(description='EuclideanStrongWitnessComplex creation from ' 'points read in a OFF file.', epilog='Example: ' - 'example/witness_complex_diagram_persistence_from_off_file_example.py ' + 'example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py ' '-f ../data/points/tore3D_300.off -a 1.0 -n 20 -d 2' '- Constructs a strong witness complex with the ' 'points from the given OFF file.') diff --git a/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py index 5a75417b..5748aa8a 100755 --- a/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py @@ -32,7 +32,7 @@ __license__ = "GPL v3" parser = argparse.ArgumentParser(description='EuclideanWitnessComplex creation from ' 'points read in a OFF file.', epilog='Example: ' - 'example/witness_complex_diagram_persistence_from_off_file_example.py ' + 'example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py ' '-f ../data/points/tore3D_300.off -a 1.0 -n 20 -d 2' '- Constructs a weak witness complex with the ' 'points from the given OFF file.') diff --git a/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index db530161..00334121 100755 --- a/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py +++ b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -49,7 +49,7 @@ def is_file_perseus(file): return False parser = argparse.ArgumentParser(description='Periodic cubical complex from a ' - 'perseus file style name.', + 'Perseus-style file name.', epilog='Example: ' './periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py' ' -f ../data/bitmap/CubicalTwoSphere.txt') diff --git a/src/cython/example/random_cubical_complex_persistence_example.py b/src/cython/example/random_cubical_complex_persistence_example.py index 1c55f777..c832d6bf 100755 --- a/src/cython/example/random_cubical_complex_persistence_example.py +++ b/src/cython/example/random_cubical_complex_persistence_example.py @@ -2,6 +2,7 @@ import gudhi import numpy +from functools import reduce import argparse import operator @@ -54,4 +55,4 @@ if dimension_multiplication > 1: print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) print("betti_numbers()=") - print(cubical_complex.betti_numbers())
\ No newline at end of file + print(cubical_complex.betti_numbers()) diff --git a/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py index 664eb5c4..984dbf1b 100755 --- a/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py +++ b/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py @@ -43,29 +43,22 @@ parser.add_argument('--no-diagram', default=False, action='store_true' , help='F args = parser.parse_args() -with open(args.file, 'r') as f: - first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): - print("#####################################################################") - print("RipsComplex creation from distance matrix read in a csv file") - - message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length) - print(message) - - rips_complex = gudhi.RipsComplex(off_file=args.file, max_edge_length=args.max_edge_length) - simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension) - - message = "Number of simplices=" + repr(simplex_tree.num_simplices()) - print(message) - - diag = simplex_tree.persistence() - - print("betti_numbers()=") - print(simplex_tree.betti_numbers()) - - if args.no_diagram == False: - gudhi.plot_persistence_diagram(diag) - else: - print(args.file, "is not a valid OFF file") - - f.close() +print("#####################################################################") +print("RipsComplex creation from distance matrix read in a csv file") + +message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length) +print(message) + +rips_complex = gudhi.RipsComplex(csv_file=args.file, max_edge_length=args.max_edge_length) +simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension) + +message = "Number of simplices=" + repr(simplex_tree.num_simplices()) +print(message) + +diag = simplex_tree.persistence() + +print("betti_numbers()=") +print(simplex_tree.betti_numbers()) + +if args.no_diagram == False: + gudhi.plot_persistence_diagram(diag) diff --git a/src/cython/example/rips_complex_from_points_example.py b/src/cython/example/rips_complex_from_points_example.py index 9b7fc79d..5d411b1a 100755 --- a/src/cython/example/rips_complex_from_points_example.py +++ b/src/cython/example/rips_complex_from_points_example.py @@ -35,6 +35,6 @@ rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], simplex_tree = rips.create_simplex_tree(max_dimension=1) -print("filtered_tree=", simplex_tree.get_filtered_tree()) +print("filtrations=", simplex_tree.get_filtration()) print("star([0])=", simplex_tree.get_star([0])) print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1)) diff --git a/src/cython/example/simplex_tree_example.py b/src/cython/example/simplex_tree_example.py index bf5f17a2..3af20fcf 100755 --- a/src/cython/example/simplex_tree_example.py +++ b/src/cython/example/simplex_tree_example.py @@ -61,6 +61,6 @@ print("filtration[4, 2]=", st.filtration([4, 2])) print("num_simplices=", st.num_simplices()) print("num_vertices=", st.num_vertices()) -print("skeleton_tree[2]=", st.get_skeleton_tree(2)) -print("skeleton_tree[1]=", st.get_skeleton_tree(1)) -print("skeleton_tree[0]=", st.get_skeleton_tree(0)) +print("skeleton[2]=", st.get_skeleton(2)) +print("skeleton[1]=", st.get_skeleton(1)) +print("skeleton[0]=", st.get_skeleton(0)) diff --git a/src/cython/include/Rips_complex_interface.h b/src/cython/include/Rips_complex_interface.h index 1879bd74..6d813f4a 100644 --- a/src/cython/include/Rips_complex_interface.h +++ b/src/cython/include/Rips_complex_interface.h @@ -49,7 +49,7 @@ class Rips_complex_interface { if (euclidean) { // Rips construction where values is a vector of points rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold, - Euclidean_distance()); + Gudhi::Euclidean_distance()); } else { // Rips construction where values is a distance matrix rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold); @@ -61,7 +61,8 @@ class Rips_complex_interface { // Rips construction where file_name is an OFF file Gudhi::Points_off_reader<Point_d> off_reader(file_name); rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(off_reader.get_point_cloud(), - threshold, Euclidean_distance()); + threshold, + Gudhi::Euclidean_distance()); } else { // Rips construction where values is a distance matrix Distance_matrix distances = diff --git a/src/cython/include/Simplex_tree_interface.h b/src/cython/include/Simplex_tree_interface.h index 4266b3ef..45ce1916 100644 --- a/src/cython/include/Simplex_tree_interface.h +++ b/src/cython/include/Simplex_tree_interface.h @@ -52,29 +52,32 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> { return (Base::find(vh) != Base::null_simplex()); } + bool insert(const Simplex& simplex, Filtration_value filtration = 0) { + Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration); + return (result.second); + } + + // Do not interface this function, only used in alpha complex interface for complex creation bool insert_simplex(const Simplex& simplex, Filtration_value filtration = 0) { Insertion_result result = Base::insert_simplex(simplex, filtration); - Base::initialize_filtration(); return (result.second); } + // Do not interface this function, only used in interface for complex creation bool insert_simplex_and_subfaces(const Simplex& simplex, Filtration_value filtration = 0) { Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration); - Base::initialize_filtration(); return (result.second); } // Do not interface this function, only used in strong witness interface for complex creation bool insert_simplex(const std::vector<std::size_t>& complex, Filtration_value filtration = 0) { Insertion_result result = Base::insert_simplex(complex, filtration); - Base::initialize_filtration(); return (result.second); } // Do not interface this function, only used in strong witness interface for complex creation bool insert_simplex_and_subfaces(const std::vector<std::size_t>& complex, Filtration_value filtration = 0) { Insertion_result result = Base::insert_simplex_and_subfaces(complex, filtration); - Base::initialize_filtration(); return (result.second); } @@ -87,28 +90,29 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> { Base::initialize_filtration(); } - Complex get_filtered_tree() { - Complex filtered_tree; + Complex get_filtration() { + Base::initialize_filtration(); + Complex filtrations; for (auto f_simplex : Base::filtration_simplex_range()) { Simplex simplex; for (auto vertex : Base::simplex_vertex_range(f_simplex)) { simplex.insert(simplex.begin(), vertex); } - filtered_tree.push_back(std::make_pair(simplex, Base::filtration(f_simplex))); + filtrations.push_back(std::make_pair(simplex, Base::filtration(f_simplex))); } - return filtered_tree; + return filtrations; } - Complex get_skeleton_tree(int dimension) { - Complex skeleton_tree; + Complex get_skeleton(int dimension) { + Complex skeletons; for (auto f_simplex : Base::skeleton_simplex_range(dimension)) { Simplex simplex; for (auto vertex : Base::simplex_vertex_range(f_simplex)) { simplex.insert(simplex.begin(), vertex); } - skeleton_tree.push_back(std::make_pair(simplex, Base::filtration(f_simplex))); + skeletons.push_back(std::make_pair(simplex, Base::filtration(f_simplex))); } - return skeleton_tree; + return skeletons; } Complex get_star(const Simplex& simplex) { @@ -140,6 +144,7 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> { } void create_persistence(Gudhi::Persistent_cohomology_interface<Base>* pcoh) { + Base::initialize_filtration(); pcoh = new Gudhi::Persistent_cohomology_interface<Base>(*this); } }; diff --git a/src/cython/include/Subsampling_interface.h b/src/cython/include/Subsampling_interface.h index 1c6032c0..b0f4a50a 100644 --- a/src/cython/include/Subsampling_interface.h +++ b/src/cython/include/Subsampling_interface.h @@ -46,7 +46,7 @@ std::vector<std::vector<double>> subsampling_n_farthest_points(const std::vector unsigned nb_points) { std::vector<std::vector<double>> landmarks; Subsampling_dynamic_kernel k; - choose_n_farthest_points(k, points, nb_points, std::back_inserter(landmarks)); + choose_n_farthest_points(k, points, nb_points, random_starting_point, std::back_inserter(landmarks)); return landmarks; } diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py index 2625d529..2c76d9d7 100755 --- a/src/cython/test/test_alpha_complex.py +++ b/src/cython/test/test_alpha_complex.py @@ -42,7 +42,7 @@ def test_infinite_alpha(): assert simplex_tree.num_simplices() == 11 assert simplex_tree.num_vertices() == 4 - assert simplex_tree.get_filtered_tree() == \ + assert simplex_tree.get_filtration() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), ([2, 3], 0.25), ([1, 2], 0.5), ([0, 1, 2], 0.5), @@ -76,7 +76,7 @@ def test_filtered_alpha(): assert filtered_alpha.get_point(4) == [] assert filtered_alpha.get_point(125) == [] - assert simplex_tree.get_filtered_tree() == \ + assert simplex_tree.get_filtration() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), ([2, 3], 0.25)] diff --git a/src/cython/test/test_cubical_complex.py b/src/cython/test/test_cubical_complex.py index c8df8089..2e281ee4 100755 --- a/src/cython/test/test_cubical_complex.py +++ b/src/cython/test/test_cubical_complex.py @@ -45,7 +45,7 @@ def test_dimension_or_perseus_file_constructor(): test_file.write('2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n') test_file.close() # CubicalComplex can be constructed from dimensions and - # top_dimensional_cells OR from a perseus file style name. + # top_dimensional_cells OR from a Perseus-style file name. cub = CubicalComplex(dimensions=[3, 3], top_dimensional_cells = [1,2,3,4,5,6,7,8,9], perseus_file='CubicalOneSphere.txt') diff --git a/src/cython/test/test_euclidean_witness_complex.py b/src/cython/test/test_euclidean_witness_complex.py index 0947cc09..737f1ef4 100755 --- a/src/cython/test/test_euclidean_witness_complex.py +++ b/src/cython/test/test_euclidean_witness_complex.py @@ -42,7 +42,7 @@ def test_witness_complex(): assert landmarks[1] == euclidean_witness_complex.get_point(1) assert landmarks[2] == euclidean_witness_complex.get_point(2) - assert simplex_tree.get_filtered_tree() == [([0], 0.0), ([1], 0.0), + assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0), ([0, 1], 0.0), ([2], 0.0), ([0, 2], 0.0), ([1, 2], 0.0), ([0, 1, 2], 0.0)] @@ -61,11 +61,11 @@ def test_strong_witness_complex(): assert landmarks[1] == euclidean_strong_witness_complex.get_point(1) assert landmarks[2] == euclidean_strong_witness_complex.get_point(2) - assert simplex_tree.get_filtered_tree() == [([0], 0.0), ([1], 0.0), ([2], 0.0)] + assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0), ([2], 0.0)] simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(max_alpha_square=100.0) - assert simplex_tree.get_filtered_tree() == [([0], 0.0), ([1], 0.0), + assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0), ([2], 0.0), ([1, 2], 15.0), ([0, 2], 34.0), ([0, 1], 37.0), ([0, 1, 2], 37.0)] diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py index 286a645b..c7d2ead4 100755 --- a/src/cython/test/test_rips_complex.py +++ b/src/cython/test/test_rips_complex.py @@ -44,7 +44,7 @@ def test_rips_from_points(): assert simplex_tree.num_simplices() == 10 assert simplex_tree.num_vertices() == 4 - assert simplex_tree.get_filtered_tree() == \ + assert simplex_tree.get_filtration() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0), ([1, 2], 1.4142135623730951), @@ -83,7 +83,7 @@ def test_rips_from_distance_matrix(): assert simplex_tree.num_simplices() == 10 assert simplex_tree.num_vertices() == 4 - assert simplex_tree.get_filtered_tree() == \ + assert simplex_tree.get_filtration() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0), ([1, 2], 1.4142135623730951), diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py index af5b639a..3ae537e3 100755 --- a/src/cython/test/test_simplex_tree.py +++ b/src/cython/test/test_simplex_tree.py @@ -33,8 +33,8 @@ def test_insertion(): assert st.__is_persistence_defined() == False # insert test - assert st.insert_simplex([0, 1]) == True - assert st.insert_simplex_and_subfaces([0, 1, 2], filtration=4.0) == True + assert st.insert([0, 1]) == True + assert st.insert([0, 1, 2], filtration=4.0) == True # FIXME: Remove this line st.set_dimension(2) assert st.num_simplices() == 7 @@ -55,31 +55,30 @@ def test_insertion(): # filtration test st.set_filtration(5.0) st.initialize_filtration() - assert st.get_filtration() == 5.0 assert st.filtration([0, 1, 2]) == 4.0 assert st.filtration([0, 2]) == 4.0 assert st.filtration([1, 2]) == 4.0 assert st.filtration([2]) == 4.0 assert st.filtration([0, 1]) == 0.0 assert st.filtration([0]) == 0.0 - assert st.filtration([1]) == 4.0 + assert st.filtration([1]) == 0.0 - # skeleton_tree test - assert st.get_skeleton_tree(2) == \ + # skeleton test + assert st.get_skeleton(2) == \ [([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0), - ([0], 0.0), ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)] - assert st.get_skeleton_tree(1) == \ + ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] + assert st.get_skeleton(1) == \ [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)] - assert st.get_skeleton_tree(0) == \ - [([0], 0.0), ([1], 4.0), ([2], 4.0)] + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] + assert st.get_skeleton(0) == \ + [([0], 0.0), ([1], 0.0), ([2], 4.0)] # remove_maximal_simplex test assert st.get_cofaces([0, 1, 2], 1) == [] st.remove_maximal_simplex([0, 1, 2]) - assert st.get_skeleton_tree(2) == \ + assert st.get_skeleton(2) == \ [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 4.0), ([2], 4.0)] + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] assert st.find([0, 1, 2]) == False assert st.find([0, 1]) == True assert st.find([0, 2]) == True @@ -103,20 +102,20 @@ def test_expansion(): assert st.__is_persistence_defined() == False # insert test - assert st.insert_simplex_and_subfaces([3, 2], 0.1) == True - assert st.insert_simplex_and_subfaces([2, 0], 0.2) == True - assert st.insert_simplex_and_subfaces([1, 0], 0.3) == True - assert st.insert_simplex_and_subfaces([3, 1], 0.4) == True - assert st.insert_simplex_and_subfaces([2, 1], 0.5) == True - assert st.insert_simplex_and_subfaces([6, 5], 0.6) == True - assert st.insert_simplex_and_subfaces([4, 2], 0.7) == True - assert st.insert_simplex_and_subfaces([3, 0], 0.8) == True - assert st.insert_simplex_and_subfaces([6, 4], 0.9) == True - assert st.insert_simplex_and_subfaces([6, 3], 1.0) == True + assert st.insert([3, 2], 0.1) == True + assert st.insert([2, 0], 0.2) == True + assert st.insert([1, 0], 0.3) == True + assert st.insert([3, 1], 0.4) == True + assert st.insert([2, 1], 0.5) == True + assert st.insert([6, 5], 0.6) == True + assert st.insert([4, 2], 0.7) == True + assert st.insert([3, 0], 0.8) == True + assert st.insert([6, 4], 0.9) == True + assert st.insert([6, 3], 1.0) == True assert st.num_vertices() == 7 assert st.num_simplices() == 17 - assert st.get_filtered_tree() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), + assert st.get_filtration() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), ([1, 2], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)] @@ -126,7 +125,7 @@ def test_expansion(): assert st.num_simplices() == 22 st.initialize_filtration() - assert st.get_filtered_tree() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), + assert st.get_filtration() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), ([1, 2], 0.5), ([0, 1, 2], 0.5), ([1, 2, 3], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([0, 1, 3], 0.8), diff --git a/src/cython/test/test_tangential_complex.py b/src/cython/test/test_tangential_complex.py index c191baa4..8aa4023c 100755 --- a/src/cython/test/test_tangential_complex.py +++ b/src/cython/test/test_tangential_complex.py @@ -40,7 +40,7 @@ def test_tangential(): assert st.num_simplices() == 6 assert st.num_vertices() == 4 - assert st.get_filtered_tree() == \ + assert st.get_filtration() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([0, 2], 0.0), ([3], 0.0), ([1, 3], 0.0)] assert st.get_cofaces([0], 1) == [([0, 2], 0.0)] |