From ec52ef51a64b6a3ff90df88ead4b856239d632af Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 9 Dec 2023 16:21:34 +0100 Subject: [PATCH] Rename collapse_edges --- src/python/CMakeLists.txt | 4 ++-- src/python/doc/edge_collapse.rst | 2 +- src/python/doc/rips_complex_user.rst | 4 ++-- src/python/gudhi/flag_filtration/__init__.py | 0 src/python/gudhi/{ => flag_filtration}/edge_collapse.py | 4 ++-- src/python/test/test_collapse_edges.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 src/python/gudhi/flag_filtration/__init__.py rename src/python/gudhi/{ => flag_filtration}/edge_collapse.py (95%) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index df7a0433d8..6ab25f43f8 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -55,7 +55,6 @@ if(PYTHONINTERP_FOUND) # Cython modules set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'off_utils', ") set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'simplex_tree', ") - set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'edge_collapse', ") set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'rips_complex', ") set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'cubical_complex', ") set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'periodic_cubical_complex', ") @@ -78,6 +77,7 @@ if(PYTHONINTERP_FOUND) set(GUDHI_PYTHON_MODULES_EXTRA "${GUDHI_PYTHON_MODULES_EXTRA}'weighted_rips_complex', ") set(GUDHI_PYTHON_MODULES_EXTRA "${GUDHI_PYTHON_MODULES_EXTRA}'dtm_rips_complex', ") set(GUDHI_PYTHON_MODULES_EXTRA "${GUDHI_PYTHON_MODULES_EXTRA}'cover_complex', ") + set(GUDHI_PYTHON_MODULES_EXTRA "${GUDHI_PYTHON_MODULES_EXTRA}'flag_filtration', ") add_gudhi_debug_info("Python version ${PYTHON_VERSION_STRING}") add_gudhi_debug_info("Cython version ${CYTHON_VERSION}") @@ -330,7 +330,7 @@ if(PYTHONINTERP_FOUND) file(COPY "gudhi/hera/__init__.py" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi/hera") file(COPY "gudhi/datasets" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi" FILES_MATCHING PATTERN "*.py") file(COPY "gudhi/sklearn" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi/") - file(COPY "gudhi/edge_collapse.py" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi") + file(COPY "gudhi/flag_filtration" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi/") # Some files for pip package diff --git a/src/python/doc/edge_collapse.rst b/src/python/doc/edge_collapse.rst index 9d727b7aa6..ad2990476b 100644 --- a/src/python/doc/edge_collapse.rst +++ b/src/python/doc/edge_collapse.rst @@ -5,4 +5,4 @@ Edge collapse ============= -.. autofunction:: gudhi.collapse_edges +.. automodule:: gudhi.flag_filtration.edge_collapse diff --git a/src/python/doc/rips_complex_user.rst b/src/python/doc/rips_complex_user.rst index a4e83462e9..3e7d356464 100644 --- a/src/python/doc/rips_complex_user.rst +++ b/src/python/doc/rips_complex_user.rst @@ -54,7 +54,7 @@ regular Rips complex. Another option which is especially useful if you want to compute persistent homology in "high" dimension (2 or more, sometimes even 1), is to build the Rips complex only up to dimension 1 (a graph), then use -:func:`~gudhi.SimplexTree.collapse_edges` to reduce the size of this graph, and finally call +:func:`~gudhi.SimplexTree.flag_filtration.edge_collapse.reduce_graph` to reduce the size of this graph, and finally call :func:`~gudhi.SimplexTree.expansion` to get a simplicial complex of a suitable dimension to compute its homology. This trick gives the same persistence diagram as one would get with a plain use of `RipsComplex`, with a complex that is often significantly smaller and thus faster to process. @@ -157,7 +157,7 @@ or cplx.expansion(2) -This way, you can easily add a call to :func:`~gudhi.SimplexTree.collapse_edges` before the expansion, +This way, you can easily add a call to :func:`~gudhi.SimplexTree.flag_filtration.edge_collapse.reduce_graph` before the expansion, use a different metric to compute the matrix, or other variations. Distance matrix diff --git a/src/python/gudhi/flag_filtration/__init__.py b/src/python/gudhi/flag_filtration/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/python/gudhi/edge_collapse.py b/src/python/gudhi/flag_filtration/edge_collapse.py similarity index 95% rename from src/python/gudhi/edge_collapse.py rename to src/python/gudhi/flag_filtration/edge_collapse.py index e1ac90c1c6..553ff2c197 100644 --- a/src/python/gudhi/edge_collapse.py +++ b/src/python/gudhi/flag_filtration/edge_collapse.py @@ -7,10 +7,10 @@ # Modification(s): # - YYYY/MM Author: Description of the modification -from ._edge_collapse import _collapse_edges +from .._edge_collapse import _collapse_edges -def collapse_edges(input_edges, nb_iterations=1): +def reduce_graph(input_edges, nb_iterations=1): """Simplify a clique filtration, preserving its persistent homology. The clique filtration is represented as a sparse weighted graph, giving for each edge its 2 vertices and its filtration value, and the output is in the same format. An edge may be represented arbitrarily as (i, j) diff --git a/src/python/test/test_collapse_edges.py b/src/python/test/test_collapse_edges.py index 67e31acbf0..58168cf0f0 100644 --- a/src/python/test/test_collapse_edges.py +++ b/src/python/test/test_collapse_edges.py @@ -8,7 +8,7 @@ - YYYY/MM Author: Description of the modification """ -from gudhi import collapse_edges +from gudhi.flag_filtration.edge_collapse import reduce_graph as collapse_edges import numpy as np from scipy.sparse import coo_matrix import pytest