From 0655678ef9fe9626757e6dfdd39e1443499446bc Mon Sep 17 00:00:00 2001 From: hschreiber Date: Wed, 8 Jan 2025 14:19:17 +0100 Subject: [PATCH] merge upstream part1 --- .../concept/ZigzagOptions.h | 2 +- ...mple_usage_filtered_zigzag_persistence.cpp | 16 +- ...ltered_zigzag_persistence_with_storage.cpp | 16 +- .../example_usage_zigzag_persistence.cpp | 16 +- ...xample_zigzag_filtration_as_input_loop.cpp | 10 +- .../example_zzfiltration_from_file.cpp | 8 +- .../gudhi/Oscillating_rips_persistence.h | 14 +- .../gudhi/filtered_zigzag_persistence.h | 184 +++++++++--------- .../include/gudhi/zigzag_persistence.h | 113 +++++------ .../test/test_filtered_zigzag_persistence.cpp | 64 +++--- .../test/test_zigzag_persistence.cpp | 25 ++- 11 files changed, 223 insertions(+), 245 deletions(-) diff --git a/src/Zigzag_persistence/concept/ZigzagOptions.h b/src/Zigzag_persistence/concept/ZigzagOptions.h index 79ee25995..98f894364 100644 --- a/src/Zigzag_persistence/concept/ZigzagOptions.h +++ b/src/Zigzag_persistence/concept/ZigzagOptions.h @@ -34,7 +34,7 @@ struct FilteredZigzagOptions { * @brief Type for the face IDs used at insertion and in the boundaries given as argument. * Has to be usable as key in a hashtable, so "hashable" and comparable. */ - using Face_key = unspecified; + using Cell_key = unspecified; /** * @brief Type for filtration values. diff --git a/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence.cpp b/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence.cpp index 0419dd79f..77141485c 100644 --- a/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence.cpp +++ b/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence.cpp @@ -30,21 +30,21 @@ int main() { // filtration values are monotonous (ie., either only increasing or only decreasing). // inserts vertex 2 at filtration value 0.1 -> birth at 0.1 of 0-cycle - zp.insert_face(2, {}, 0, 0.1); + zp.insert_cell(2, {}, 0, 0.1); // inserts vertex 4 at filtration value 0.1 -> birth at 0.1 of 0-cycle - zp.insert_face(4, {}, 0, 0.1); + zp.insert_cell(4, {}, 0, 0.1); // inserts edge 5 = (2,4) at filtration value 0.3 -> death at 0.3 -> outputs (0, 0.1, 0.3) - zp.insert_face(5, {2, 4}, 1, 0.3); + zp.insert_cell(5, {2, 4}, 1, 0.3); // inserts vertex 3 at filtration value 0.4 -> birth at 0.4 of 0-cycle - zp.insert_face(3, {}, 0, 0.4); + zp.insert_cell(3, {}, 0, 0.4); // inserts edge 6 = (2,3) at filtration value 0.4 -> death at 0.4 of the cycle born at 0.4 -> outputs nothing - zp.insert_face(6, {2, 3}, 1, 0.4); + zp.insert_cell(6, {2, 3}, 1, 0.4); // inserts edge 9 = (3,4) at filtration value 1.2 -> birth at 1.2 of 1-cycle - zp.insert_face(9, {4, 3}, 1, 1.2); + zp.insert_cell(9, {4, 3}, 1, 1.2); // removes edge 6 at filtration value 1.5 -> death at 1.5 -> outputs (1, 1.2, 1.5) - zp.remove_face(6, 1.5); + zp.remove_cell(6, 1.5); // removes edge 5 at filtration value 2.0 -> birth at 2.0 of 0-cycle - zp.remove_face(5, 2.0); + zp.remove_cell(5, 2.0); // Only the closed bars where output so far, so the open/infinite bars still need to be retrieved. diff --git a/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence_with_storage.cpp b/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence_with_storage.cpp index 7cc0c866e..2ce788714 100644 --- a/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence_with_storage.cpp +++ b/src/Zigzag_persistence/example/example_usage_filtered_zigzag_persistence_with_storage.cpp @@ -25,21 +25,21 @@ int main() { // filtration values are monotonous (ie., either only increasing or only decreasing). // inserts vertex 2 at filtration value 0.1 -> birth at 0.1 of 0-cycle - zp.insert_face(2, {}, 0, 0.1); + zp.insert_cell(2, {}, 0, 0.1); // inserts vertex 4 at filtration value 0.1 -> birth at 0.1 of 0-cycle - zp.insert_face(4, {}, 0, 0.1); + zp.insert_cell(4, {}, 0, 0.1); // inserts edge 5 = (2,4) at filtration value 0.3 -> death at 0.3 -> stores (0, 0.1, 0.3) - zp.insert_face(5, {2, 4}, 1, 0.3); + zp.insert_cell(5, {2, 4}, 1, 0.3); // inserts vertex 3 at filtration value 0.4 -> birth at 0.4 of 0-cycle - zp.insert_face(3, {}, 0, 0.4); + zp.insert_cell(3, {}, 0, 0.4); // inserts edge 6 = (2,3) at filtration value 0.4 -> death at 0.4 of the cycle born at 0.4 -> stores nothing - zp.insert_face(6, {2, 3}, 1, 0.4); + zp.insert_cell(6, {2, 3}, 1, 0.4); // inserts edge 9 = (3,4) at filtration value 1.2 -> birth at 1.2 of 1-cycle - zp.insert_face(9, {4, 3}, 1, 1.2); + zp.insert_cell(9, {4, 3}, 1, 1.2); // removes edge 6 at filtration value 1.5 -> death at 1.5 -> stores (1, 1.2, 1.5) - zp.remove_face(6, 1.5); + zp.remove_cell(6, 1.5); // removes edge 5 at filtration value 2.0 -> birth at 2.0 of 0-cycle - zp.remove_face(5, 2.0); + zp.remove_cell(5, 2.0); // The bars are stored within the class and where not output at all for now. diff --git a/src/Zigzag_persistence/example/example_usage_zigzag_persistence.cpp b/src/Zigzag_persistence/example/example_usage_zigzag_persistence.cpp index e987b90ef..47881a0ab 100644 --- a/src/Zigzag_persistence/example/example_usage_zigzag_persistence.cpp +++ b/src/Zigzag_persistence/example/example_usage_zigzag_persistence.cpp @@ -29,21 +29,21 @@ int main() { // A face has to be identified in the boundaries by the operation number the face was inserted with in the sequence. // inserts vertex 0 -> birth at 0 of 0-cycle - zp.insert_face({}, 0); + zp.insert_cell({}, 0); // inserts vertex 1 -> birth at 1 of 0-cycle - zp.insert_face({}, 0); + zp.insert_cell({}, 0); // inserts edge 2 = (0,1) -> death at 2 -> outputs (0, 1, 2) - zp.insert_face({0, 1}, 1); + zp.insert_cell({0, 1}, 1); // inserts vertex 3 -> birth at 3 of 0-cycle - zp.insert_face({}, 0); + zp.insert_cell({}, 0); // inserts edge 4 = (0,3) -> death at 4 -> outputs (0, 3, 4) - zp.insert_face({0, 3}, 1); + zp.insert_cell({0, 3}, 1); // inserts edge 5 = (1,3) -> birth at 5 of 1-cycle - zp.insert_face({1, 3}, 1); + zp.insert_cell({1, 3}, 1); // removes edge 4 -> death at 6 -> outputs (1, 5, 6) - zp.remove_face(4); + zp.remove_cell(4); // removes edge 2 -> birth at 7 of 0-cycle - zp.remove_face(2); + zp.remove_cell(2); // Only the closed bars were output so far, so the open/infinite bars still need to be retrieved. diff --git a/src/Zigzag_persistence/example/example_zigzag_filtration_as_input_loop.cpp b/src/Zigzag_persistence/example/example_zigzag_filtration_as_input_loop.cpp index 046e599b8..e98dae969 100644 --- a/src/Zigzag_persistence/example/example_zigzag_filtration_as_input_loop.cpp +++ b/src/Zigzag_persistence/example/example_zigzag_filtration_as_input_loop.cpp @@ -14,7 +14,7 @@ #include using ZP = Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage<>; -using Face_handle = ZP::Face_key; +using Cell_handle = ZP::Cell_key; using Filtration_value = ZP::Filtration_value; using Interval_filtration = ZP::Filtration_value_interval; @@ -50,7 +50,7 @@ void print_indices(ZP& zp) { } } -std::vector > get_boundaries() { +std::vector > get_boundaries() { return {{}, {}, {}, @@ -114,7 +114,7 @@ int main(int argc, char* const argv[]) { ZP zp; - std::vector > simplices = get_boundaries(); + std::vector > simplices = get_boundaries(); std::vector fils = get_filtration_values(); std::vector dirs = get_directions(); @@ -125,10 +125,10 @@ int main(int argc, char* const argv[]) { } if (dirs[i]) { int dim = simplices[i].size() == 0 ? 0 : simplices[i].size() - 1; - zp.insert_face(i, simplices[i], dim, fils[i]); + zp.insert_cell(i, simplices[i], dim, fils[i]); } else { auto id = simplices[i][0]; - zp.remove_face(id, fils[i]); + zp.remove_cell(id, fils[i]); } } diff --git a/src/Zigzag_persistence/example/example_zzfiltration_from_file.cpp b/src/Zigzag_persistence/example/example_zzfiltration_from_file.cpp index 4e04f2b00..dc14363c5 100644 --- a/src/Zigzag_persistence/example/example_zzfiltration_from_file.cpp +++ b/src/Zigzag_persistence/example/example_zzfiltration_from_file.cpp @@ -16,7 +16,7 @@ #include using ZP = Gudhi::zigzag_persistence::Filtered_zigzag_persistence<>; -using ID_handle = ZP::Face_key; +using ID_handle = ZP::Cell_key; using Filtration_value = ZP::Filtration_value; using Dimension = ZP::Dimension; @@ -89,7 +89,7 @@ int main(int argc, char* const argv[]) { while (getline(file, line, '\n') && read_operation(line, data, timestamp) == COMMENT); double lastTimestamp = timestamp; // first operation has to be an insertion. - zp.insert_face(id, data, 0, timestamp); + zp.insert_cell(id, data, 0, timestamp); while (getline(file, line, '\n')) { type = read_operation(line, data, timestamp); @@ -100,10 +100,10 @@ int main(int argc, char* const argv[]) { if (type == INCLUSION) { ++id; int dim = data.size() == 0 ? 0 : data.size() - 1; - zp.insert_face(id, data, dim, timestamp); + zp.insert_cell(id, data, dim, timestamp); } else if (type == REMOVAL) { ++id; - zp.remove_face(data[0], timestamp); + zp.remove_cell(data[0], timestamp); } } diff --git a/src/Zigzag_persistence/include/gudhi/Oscillating_rips_persistence.h b/src/Zigzag_persistence/include/gudhi/Oscillating_rips_persistence.h index 01dadce6c..ba3169bf0 100644 --- a/src/Zigzag_persistence/include/gudhi/Oscillating_rips_persistence.h +++ b/src/Zigzag_persistence/include/gudhi/Oscillating_rips_persistence.h @@ -68,16 +68,16 @@ struct Simplex_tree_options_oscillating_rips { template struct Default_oscillating_rips_zigzag_options : Default_filtered_zigzag_options { - using Face_key = typename StableFilteredComplex::Simplex_handle; + using Cell_key = typename StableFilteredComplex::Simplex_handle; using Filtration_value = typename StableFilteredComplex::Filtration_value; using Dimension = int; // it is `int` in the simplex tree struct Hash { - std::size_t operator()(const Face_key& sh) const { + std::size_t operator()(const Cell_key& sh) const { return sh->second.key(); } }; struct KeyEqual { - bool operator()(const Face_key& sh1, const Face_key& sh2) const { + bool operator()(const Cell_key& sh1, const Cell_key& sh2) const { return sh1->second.key() == sh2->second.key(); } }; @@ -154,12 +154,12 @@ void compute_oscillating_rips_persistence( for (const auto& t : OscillatingRipsSimplexRange::get_iterator_range(start, end, st, maxDim)) { if (std::get<2>(t)) - zp.insert_face(std::get<0>(t), + zp.insert_cell(std::get<0>(t), st.boundary_simplex_range(std::get<0>(t)), st.dimension(std::get<0>(t)), std::get<1>(t)); else - zp.remove_face(std::get<0>(t), std::get<1>(t)); + zp.remove_cell(std::get<0>(t), std::get<1>(t)); } zp.get_current_infinite_intervals([&](Dimension dim, Filtration_value birth) { outStream(dim, birth, Bar::inf); }); @@ -233,12 +233,12 @@ compute_oscillating_rips_persistence( for (const auto& t : OscillatingRipsSimplexRange::get_iterator_range(start, end, st, maxDim)) { if (std::get<2>(t)) - zp.insert_face(std::get<0>(t), + zp.insert_cell(std::get<0>(t), st.boundary_simplex_range(std::get<0>(t)), st.dimension(std::get<0>(t)), std::get<1>(t)); else - zp.remove_face(std::get<0>(t), std::get<1>(t)); + zp.remove_cell(std::get<0>(t), std::get<1>(t)); } return zp.get_persistence_diagram(); diff --git a/src/Zigzag_persistence/include/gudhi/filtered_zigzag_persistence.h b/src/Zigzag_persistence/include/gudhi/filtered_zigzag_persistence.h index bf8d6e4ba..d07cef5b9 100644 --- a/src/Zigzag_persistence/include/gudhi/filtered_zigzag_persistence.h +++ b/src/Zigzag_persistence/include/gudhi/filtered_zigzag_persistence.h @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -41,18 +40,11 @@ namespace zigzag_persistence { * * @brief Default options for @ref Filtered_zigzag_persistence_with_storage and @ref Filtered_zigzag_persistence. */ -struct Default_filtered_zigzag_options { - using Internal_key = int; /**< Face ID used internally, must be signed. */ - using Face_key = int; /**< Face ID used in the given boundaries. */ - using Filtration_value = double; /**< Filtration value type. */ - using Dimension = int; /**< Dimension value type. */ - using Hash = std::hash; /**< Hash method for Face_key */ - using KeyEqual = std::equal_to; /**< Equality comparator for Face_key */ - /** - * @brief Column type use by the internal matrix. - */ - static const Gudhi::persistence_matrix::Column_types column_type = - Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR; +struct Default_filtered_zigzag_options : Default_zigzag_options { + using Cell_key = int; /**< Cell ID used in the given boundaries. */ + using Filtration_value = double; /**< Filtration value type. */ + using Hash = std::hash; /**< Hash method for Cell_key */ + using KeyEqual = std::equal_to; /**< Equality comparator for Cell_key */ }; /** @@ -63,7 +55,7 @@ struct Default_filtered_zigzag_options { * stored during the whole process and not removed. It is therefore suited for smaller filtrations where the clean * ups produce a higher overhead than the memory consumption. * @details After construction of the class, the zigzag filtration should be given in a streaming like way, i.e., - * call @ref insert_face, @ref remove_face or @ref apply_identity for each step of the filtration in order of + * call @ref insert_cell, @ref remove_cell or @ref apply_identity for each step of the filtration in order of * the filtration. To retrieve the current persistence diagram at any moment of the filtration, * use @ref get_persistence_diagram or @ref get_index_persistence_diagram. * @@ -89,25 +81,25 @@ struct Default_filtered_zigzag_options { * // In all cases, it is important that the operations of insertions and removals are made **in the same order** * // as in the zigzag filtration ones wants to compute the barcode from. * - * // A face can be identified in the boundaries by any given numerical label, it is just important that the given + * // A cell can be identified in the boundaries by any given numerical label, it is just important that the given * // filtration values are monotonous (ie., either only increasing or only decreasing). * * //inserts vertex 2 at filtration value 0.1 -> birth at 0.1 of 0-cycle - * zp.insert_face(2, {}, 0, 0.1); + * zp.insert_cell(2, {}, 0, 0.1); * //inserts vertex 4 at filtration value 0.1 -> birth at 0.1 of 0-cycle - * zp.insert_face(4, {}, 0, 0.1); + * zp.insert_cell(4, {}, 0, 0.1); * //inserts edge 5 = (2,4) at filtration value 0.3 -> death at 0.3 -> outputs/stores (0, 0.1, 0.3) - * zp.insert_face(5, {2, 4}, 1, 0.3); + * zp.insert_cell(5, {2, 4}, 1, 0.3); * //inserts vertex 3 at filtration value 0.4 -> birth at 0.4 of 0-cycle - * zp.insert_face(3, {}, 0, 0.4); + * zp.insert_cell(3, {}, 0, 0.4); * //inserts edge 6 = (2,3) at filtration value 0.4 -> death at 0.4 of the cycle born at 0.4 -> outputs/stores nothing - * zp.insert_face(6, {2, 3}, 1, 0.4); + * zp.insert_cell(6, {2, 3}, 1, 0.4); * //inserts edge 9 = (3,4) at filtration value 1.2 -> birth at 1.2 of 1-cycle - * zp.insert_face(9, {4, 3}, 1, 1.2); + * zp.insert_cell(9, {4, 3}, 1, 1.2); * //removes edge 6 at filtration value 1.5 -> death at 1.5 -> outputs/stores (1, 1.2, 1.5) - * zp.remove_face(6, 1.5); + * zp.remove_cell(6, 1.5); * //removes edge 5 at filtration value 2.0 -> birth at 2.0 of 0-cycle - * zp.remove_face(5, 2.0); + * zp.remove_cell(5, 2.0); * ``` * * #### Finalizations @@ -132,7 +124,7 @@ class Filtered_zigzag_persistence_with_storage public: using Options = FilteredZigzagOptions; /**< Zigzag options. */ using Internal_key = typename Options::Internal_key; /**< Key and index type, has to be signed. */ - using Face_key = typename Options::Face_key; /**< Face ID type from external inputs. */ + using Cell_key = typename Options::Cell_key; /**< Cell ID type from external inputs. */ using Filtration_value = typename Options::Filtration_value; /**< Type for filtration values. */ using Dimension = typename Options::Dimension; /**< Type for dimension values. */ @@ -148,13 +140,13 @@ class Filtered_zigzag_persistence_with_storage /** * @brief Constructor. * @details After construction of the class, the zigzag filtration should be given in a streaming like way, i.e., - * call @ref insert_face, @ref remove_face or @ref apply_identity for each step of the filtration in order of + * call @ref insert_cell, @ref remove_cell or @ref apply_identity for each step of the filtration in order of * the filtration. To retrieve the current persistence diagram at any moment of the filtration, * use @ref get_persistence_diagram or @ref get_index_persistence_diagram. * - * @param preallocationSize Reserves space for @p preallocationSize faces in the internal data structure. + * @param preallocationSize Reserves space for @p preallocationSize cells in the internal data structure. * This is optional and just helps skip a few reallocations. The optimal value (no reallocation, no wasted space) is - * the number of faces in the biggest complex of the filtration. + * the number of cells in the biggest complex of the filtration. * Default value: 0. * @param ignoreCyclesAboveDim Ignores cycles in dimension larger or equal in the final diagram. * If -1, no cycles are ignored. Default value: -1. @@ -173,21 +165,21 @@ class Filtered_zigzag_persistence_with_storage preallocationSize) {} /** - * @brief Updates the zigzag persistence diagram after the insertion of the given face. + * @brief Updates the zigzag persistence diagram after the insertion of the given cell. * * @tparam BoundaryRange Range type needing size, begin and end members. - * @param faceID ID representing the inserted face. - * @param boundary Boundary of the inserted face. The range should be composed of the IDs of all faces contained in - * the boundary (i.e. with non-zero coefficients), using the ID specified as `faceID` when the corresponding face - * was previously inserted (recall that the faces should be inserted in order of filtration). - * @param dimension Dimension of the inserted face. - * @param filtrationValue Filtration value associated to the face. + * @param cellID ID representing the inserted cell. + * @param boundary Boundary of the inserted cell. The range should be composed of the IDs of all cells contained in + * the boundary (i.e. with non-zero coefficients), using the ID specified as `cellID` when the corresponding cell + * was previously inserted (recall that the cells should be inserted in order of filtration). + * @param dimension Dimension of the inserted cell. + * @param filtrationValue Filtration value associated to the cell. * Assumed to be always larger or equal to previously used filtration values or always smaller or equal than previous * values, ie. the changes are monotonous. * @return Number of the operation. */ - template > - Internal_key insert_face(Face_key faceID, + template > + Internal_key insert_cell(Cell_key cellID, const BoundaryRange& boundary, Dimension dimension, Filtration_value filtrationValue) @@ -200,34 +192,36 @@ class Filtered_zigzag_persistence_with_storage _store_filtration_value(filtrationValue); - [[maybe_unused]] auto res = handleToKey_.try_emplace(faceID, numArrow_); + [[maybe_unused]] auto res = handleToKey_.try_emplace(cellID, numArrow_); - GUDHI_CHECK(res.second, "Zigzag_persistence::insert_face - face already in the complex"); + GUDHI_CHECK(res.second, "Zigzag_persistence::insert_cell - cell already in the complex"); - // Compute the keys of the faces of the boundary. - std::set translatedBoundary; // set maintains the natural order on indices + // Compute the keys of the cells of the boundary. + std::vector translatedBoundary; + translatedBoundary.reserve(dimension * 2); // boundary does not have to have `size()` for (auto b : boundary) { - translatedBoundary.insert(handleToKey_.at(b)); // TODO: add possibilities of coefficients + translatedBoundary.push_back(handleToKey_.at(b)); // TODO: add possibilities of coefficients } + std::sort(translatedBoundary.begin(), translatedBoundary.end()); - pers_.insert_face(translatedBoundary, dimension); + pers_.insert_cell(translatedBoundary, dimension); return numArrow_; } /** - * @brief Updates the zigzag persistence diagram after the removal of the given face if the face was contained - * in the current complex (note that it will not contain faces of dimension > ignoreCyclesAboveDim if the latter was + * @brief Updates the zigzag persistence diagram after the removal of the given cell if the cell was contained + * in the current complex (note that it will not contain cells of dimension > ignoreCyclesAboveDim if the latter was * non negative at construction of the class). Otherwise, just increases the operation count by one. * - * @param faceID ID representing the face to remove. Should be the same than the one used to insert it. + * @param cellID ID representing the cell to remove. Should be the same than the one used to insert it. * @param filtrationValue Filtration value associated to the removal. * Assumed to be always larger or equal to previously used filtration values or always smaller or equal than previous * values, ie. the changes are monotonous. * @return Number of the operation. */ - Internal_key remove_face(Face_key faceID, Filtration_value filtrationValue) { - auto it = handleToKey_.find(faceID); + Internal_key remove_cell(Cell_key cellID, Filtration_value filtrationValue) { + auto it = handleToKey_.find(cellID); if (it == handleToKey_.end()) { return apply_identity(); @@ -237,14 +231,14 @@ class Filtered_zigzag_persistence_with_storage _store_filtration_value(filtrationValue); - pers_.remove_face(it->second); + pers_.remove_cell(it->second); handleToKey_.erase(it); return numArrow_; } /** - * @brief To use when a face is neither inserted nor removed, but the filtration moves along the identity operator + * @brief To use when a cell is neither inserted nor removed, but the filtration moves along the identity operator * on homology level. Useful to keep the birth/death indices aligned when insertions/removals are purposely skipped * to avoid useless computation. * @return Number of the operation. @@ -306,18 +300,18 @@ class Filtered_zigzag_persistence_with_storage /** * @brief Map from input keys to internal keys. */ - std::unordered_map handleToKey_; + std::unordered_map handleToKey_; Dimension dimMax_; /**< Maximal dimension of a bar to record. */ std::vector persistenceDiagram_; /**< Stores current closed persistence intervals. */ Internal_key numArrow_; /**< Current arrow number. */ Filtration_value previousFiltrationValue_; /**< Filtration value of the previous arrow. */ /** * @brief filtrationValues_ stores consecutive pairs (i,f) , (j,f') with f != f', - * meaning that all inserted faces with key in [i;j-1] have filtration value f, - * i is the smallest face index whose face has filtration value f. + * meaning that all inserted cells with key in [i;j-1] have filtration value f, + * i is the smallest cell index whose cell has filtration value f. */ std::vector > filtrationValues_; - Zigzag_persistence pers_; /**< Class computing the pairs. */ + Zigzag_persistence pers_; /**< Class computing the pairs. */ /** * @brief Stores the filtration value if the value is new. Assumes that the given value is either greater (or equal) @@ -328,7 +322,7 @@ class Filtered_zigzag_persistence_with_storage void _store_filtration_value(Filtration_value filtrationValue) { if (filtrationValue != previousFiltrationValue_) // check whether the filt value has changed { - // consecutive pairs (i,f), (j,f') mean faces of index k in [i,j-1] have filtration value f + // consecutive pairs (i,f), (j,f') mean cells of index k in [i,j-1] have filtration value f previousFiltrationValue_ = filtrationValue; filtrationValues_.emplace_back(numArrow_, previousFiltrationValue_); } @@ -384,7 +378,7 @@ class Filtered_zigzag_persistence_with_storage * * @brief Class computing the zigzag persistent homology of a zigzag filtration. Algorithm based on \cite zigzag. * @details After construction of the class, the zigzag filtration should be given in a streaming like way, i.e., - * call @ref insert_face, @ref remove_face or @ref apply_identity for each step of the filtration in order of + * call @ref insert_cell, @ref remove_cell or @ref apply_identity for each step of the filtration in order of * the filtration. The bars of the diagram are retrieved via the given callback method every time * a pair with non-zero length is closed. To retrieve the open/infinite bars, use @ref get_current_infinite_intervals. * @@ -415,25 +409,25 @@ class Filtered_zigzag_persistence_with_storage * // In all cases, it is important that the operations of insertions and removals are made **in the same order** * // as in the zigzag filtration ones wants to compute the barcode from. * - * // A face can be identified in the boundaries by any given numerical label, it is just important that the given + * // A cell can be identified in the boundaries by any given numerical label, it is just important that the given * // filtration values are monotonous (ie., either only increasing or only decreasing). * * //inserts vertex 2 at filtration value 0.1 -> birth at 0.1 of 0-cycle - * zp.insert_face(2, {}, 0, 0.1); + * zp.insert_cell(2, {}, 0, 0.1); * //inserts vertex 4 at filtration value 0.1 -> birth at 0.1 of 0-cycle - * zp.insert_face(4, {}, 0, 0.1); + * zp.insert_cell(4, {}, 0, 0.1); * //inserts edge 5 = (2,4) at filtration value 0.3 -> death at 0.3 -> outputs/stores (0, 0.1, 0.3) - * zp.insert_face(5, {2, 4}, 1, 0.3); + * zp.insert_cell(5, {2, 4}, 1, 0.3); * //inserts vertex 3 at filtration value 0.4 -> birth at 0.4 of 0-cycle - * zp.insert_face(3, {}, 0, 0.4); + * zp.insert_cell(3, {}, 0, 0.4); * //inserts edge 6 = (2,3) at filtration value 0.4 -> death at 0.4 of the cycle born at 0.4 -> outputs/stores nothing - * zp.insert_face(6, {2, 3}, 1, 0.4); + * zp.insert_cell(6, {2, 3}, 1, 0.4); * //inserts edge 9 = (3,4) at filtration value 1.2 -> birth at 1.2 of 1-cycle - * zp.insert_face(9, {4, 3}, 1, 1.2); + * zp.insert_cell(9, {4, 3}, 1, 1.2); * //removes edge 6 at filtration value 1.5 -> death at 1.5 -> outputs/stores (1, 1.2, 1.5) - * zp.remove_face(6, 1.5); + * zp.remove_cell(6, 1.5); * //removes edge 5 at filtration value 2.0 -> birth at 2.0 of 0-cycle - * zp.remove_face(5, 2.0); + * zp.remove_cell(5, 2.0); * ``` * * #### Finalizations @@ -454,14 +448,14 @@ class Filtered_zigzag_persistence { public: using Options = FilteredZigzagOptions; /**< Zigzag options. */ using Internal_key = typename Options::Internal_key; /**< Key and index type, has to be signed. */ - using Face_key = typename Options::Face_key; /**< Face ID type from external inputs. */ + using Cell_key = typename Options::Cell_key; /**< Cell ID type from external inputs. */ using Filtration_value = typename Options::Filtration_value; /**< Type for filtration values. */ using Dimension = typename Options::Dimension; /**< Type for dimension values. */ /** * @brief Constructor. * @details After construction of the class, the zigzag filtration should be given in a streaming like way, i.e., - * call @ref insert_face, @ref remove_face or @ref apply_identity for each step of the filtration in order of + * call @ref insert_cell, @ref remove_cell or @ref apply_identity for each step of the filtration in order of * the filtration. The bars of the diagram are retrieved via the given callback method every time * a pair with non-zero length is closed. To retrieve the open/infinite bars, use @ref get_current_infinite_intervals. * @@ -469,9 +463,9 @@ class Filtered_zigzag_persistence { * Has to take three arguments as input: first the dimension of the cycle, then the birth value of the cycle * and third the death value of the cycle. The values corresponds to the filtration values which were given at * insertions or removals. Note that bars of length 0 will not be token into account. - * @param preallocationSize Reserves space for @p preallocationSize faces in the internal data structure. + * @param preallocationSize Reserves space for @p preallocationSize cells in the internal data structure. * This is optional and just helps skip a few reallocations. The optimal value (no reallocation, no wasted space) is - * the number of faces in the biggest complex of the filtration. + * the number of cells in the biggest complex of the filtration. * Default value: 0. * @tparam F Type of callback method. */ @@ -493,67 +487,69 @@ class Filtered_zigzag_persistence { preallocationSize) {} /** - * @brief Updates the zigzag persistence diagram after the insertion of the given face. + * @brief Updates the zigzag persistence diagram after the insertion of the given cell. * * @tparam BoundaryRange Range type needing size, begin and end members. - * @param faceID ID representing the inserted face. - * @param boundary Boundary of the inserted face. The range should be composed of the IDs of all faces contained in - * the boundary (i.e. with non-zero coefficients), using the ID specified as `faceID` when the corresponding face - * was previously inserted (recall that the faces should be inserted in order of filtration). - * @param dimension Dimension of the inserted face. - * @param filtrationValue Filtration value associated to the face. + * @param cellID ID representing the inserted cell. + * @param boundary Boundary of the inserted cell. The range should be composed of the IDs of all cells contained in + * the boundary (i.e. with non-zero coefficients), using the ID specified as `cellID` when the corresponding cell + * was previously inserted (recall that the cells should be inserted in order of filtration). + * @param dimension Dimension of the inserted cell. + * @param filtrationValue Filtration value associated to the cell. * Assumed to be always larger or equal to previously used filtration values or always smaller or equal than previous * values, ie. the changes are monotonous. */ - template > - Internal_key insert_face(Face_key faceID, + template > + Internal_key insert_cell(Cell_key cellID, const BoundaryRange& boundary, Dimension dimension, Filtration_value filtrationValue) { ++numArrow_; - [[maybe_unused]] auto res = handleToKey_.try_emplace(faceID, numArrow_); + [[maybe_unused]] auto res = handleToKey_.try_emplace(cellID, numArrow_); - GUDHI_CHECK(res.second, "Zigzag_persistence::insert_face - face already in the complex"); + GUDHI_CHECK(res.second, "Zigzag_persistence::insert_cell - cell already in the complex"); keyToFiltrationValue_.try_emplace(numArrow_, filtrationValue); - // Compute the keys of the faces of the boundary. - std::set translatedBoundary; // set maintains the natural order on indices + // Compute the keys of the cells of the boundary. + std::vector translatedBoundary; + translatedBoundary.reserve(dimension * 2); // boundary does not have to have `size()` for (auto b : boundary) { - translatedBoundary.insert(handleToKey_.at(b)); // TODO: add possibilities of coefficients + translatedBoundary.push_back(handleToKey_.at(b)); // TODO: add possibilities of coefficients } + std::sort(translatedBoundary.begin(), translatedBoundary.end()); - pers_.insert_face(translatedBoundary, dimension); + pers_.insert_cell(translatedBoundary, dimension); return numArrow_; } /** - * @brief Updates the zigzag persistence diagram after the removal of the given face. + * @brief Updates the zigzag persistence diagram after the removal of the given cell. *preallocationSize - * @param faceID ID representing the face to remove. Should be the same than the one used to insert it. + * @param cellID ID representing the cell to remove. Should be the same than the one used to insert it. * @param filtrationValue Filtration value associated to the removal. * Assumed to be always larger or equal to previously used filtration values or always smaller or equal than previous * values, ie. the changes are monotonous. */ - Internal_key remove_face(Face_key faceID, Filtration_value filtrationValue) { + Internal_key remove_cell(Cell_key cellID, Filtration_value filtrationValue) { ++numArrow_; - auto it = handleToKey_.find(faceID); - GUDHI_CHECK(it != handleToKey_.end(), "Zigzag_persistence::remove_face - face not in the complex"); + auto it = handleToKey_.find(cellID); + GUDHI_CHECK(it != handleToKey_.end(), "Zigzag_persistence::remove_cell - cell not in the complex"); keyToFiltrationValue_.try_emplace(numArrow_, filtrationValue); - pers_.remove_face(it->second); + pers_.remove_cell(it->second); handleToKey_.erase(it); return numArrow_; } /** - * @brief To use when a face is neither inserted nor removed, but the filtration moves along the identity operator + * @brief To use when a cell is neither inserted nor removed, but the filtration moves along the identity operator * on homology level. Useful to keep the birth/death indices aligned when insertions/removals are purposely skipped * to avoid useless computation. */ @@ -581,10 +577,10 @@ class Filtered_zigzag_persistence { /** * @brief Map from input keys to internal keys. */ - std::unordered_map handleToKey_; - Internal_key numArrow_; /**< Current arrow number. */ - std::unordered_map keyToFiltrationValue_; /**< Face Key to filtration value map. */ - Zigzag_persistence pers_; /**< Class computing the pairs. */ + std::unordered_map handleToKey_; + Internal_key numArrow_; /**< Current arrow number. */ + std::unordered_map keyToFiltrationValue_; /**< Cell Key to filtration value map. */ + Zigzag_persistence pers_; /**< Class computing the pairs. */ }; // end class Filtered_zigzag_persistence } // namespace zigzag_persistence diff --git a/src/Zigzag_persistence/include/gudhi/zigzag_persistence.h b/src/Zigzag_persistence/include/gudhi/zigzag_persistence.h index cdb32a6fe..e704587de 100644 --- a/src/Zigzag_persistence/include/gudhi/zigzag_persistence.h +++ b/src/Zigzag_persistence/include/gudhi/zigzag_persistence.h @@ -62,24 +62,22 @@ struct Zigzag_matrix_options : Gudhi::persistence_matrix::Default_options birth at 0 of 0-cycle - * zp.insert_face({}, 0); + * zp.insert_cell({}, 0); * //inserts vertex 1 -> birth at 1 of 0-cycle - * zp.insert_face({}, 0); + * zp.insert_cell({}, 0); * //inserts edge 2 = (0,1) -> death at 2 -> outputs (0, 1, 2) - * zp.insert_face({0, 1}, 1); + * zp.insert_cell({0, 1}, 1); * //inserts vertex 3 -> birth at 3 of 0-cycle - * zp.insert_face({}, 0); + * zp.insert_cell({}, 0); * //inserts edge 4 = (0,3) -> death at 4 -> outputs (0, 3, 4) - * zp.insert_face({0, 3}, 1); + * zp.insert_cell({0, 3}, 1); * //inserts edge 5 = (1,3) -> birth at 5 of 1-cycle - * zp.insert_face({1, 3}, 1); + * zp.insert_cell({1, 3}, 1); * //removes edge 4 -> death at 6 -> outputs (1, 5, 6) - * zp.remove_face(4); + * zp.remove_cell(4); * //removes edge 2 -> birth at 7 of 0-cycle - * zp.remove_face(2); + * zp.remove_cell(2); * ``` * * #### Finalizations @@ -146,7 +144,7 @@ struct Default_zigzag_options { * * @tparam ZigzagOptions Structure following the @ref ZigzagOptions concept. Default value: @ref Default_zigzag_options. */ -template +template class Zigzag_persistence { public: @@ -248,18 +246,18 @@ class Zigzag_persistence /** * @brief Constructor of the Zigzag_persistence class. * @details After construction of the class, the zigzag filtration should be given in a streaming like way, i.e., - * call @ref insert_face, @ref remove_face or @ref apply_identity for each step of the filtration in order of + * call @ref insert_cell, @ref remove_cell or @ref apply_identity for each step of the filtration in order of * the filtration. The pairs of birth and death indices are retrieved via the given callback method every time * a pair is closed. To retrieve the open pairs (corresponding to infinite bars), * use @ref get_current_infinite_intervals. * * @param stream_interval Callback method to process the birth and death index pairs. Has to take three arguments * as input: first the dimension of the cycle, then the birth index of the cycle and third the death index of the - * cycle. An index always corresponds to the arrow number the event occurred (one call to @ref insert_face, - * @ref remove_face or @ref apply_identity is equal to one arrow and increases the arrow count by one). - * @param preallocationSize Reserves space for @p preallocationSize faces in the internal data structure. + * cycle. An index always corresponds to the arrow number the event occurred (one call to @ref insert_cell, + * @ref remove_cell or @ref apply_identity is equal to one arrow and increases the arrow count by one). + * @param preallocationSize Reserves space for @p preallocationSize cells in the internal data structure. * This is optional and just helps skip a few reallocations. The optimal value (no reallocation, no wasted space) is - * the number of faces in the biggest complex of the filtration. + * the number of cells in the biggest complex of the filtration. * Default value: 0. */ Zigzag_persistence(std::function stream_interval, @@ -276,37 +274,37 @@ class Zigzag_persistence numArrow_(-1), stream_interval_(std::move(stream_interval)) {} /** - * @brief Updates the zigzag persistence diagram after the insertion of the given face. + * @brief Updates the zigzag persistence diagram after the insertion of the given cell. * * @tparam BoundaryRange Range type needing size, begin and end members. - * @param boundary Boundary of the inserted face. The boundary should be represented by all the faces with - * non-zero coefficients generating it. A face should be represented by the arrow number when the face appeared for - * the first time in the filtration (if a face was inserted and then removed and reinserted etc., only the last - * insertion counts). The face range should be ordered by increasing arrow numbers. - * @param dimension Dimension of the inserted face. + * @param boundary Boundary of the inserted cell. The boundary should be represented by all the cells with + * non-zero coefficients generating it. A cell should be represented by the arrow number when the cell appeared for + * the first time in the filtration (if a cell was inserted and then removed and reinserted etc., only the last + * insertion counts). The cell range should be ordered by increasing arrow numbers. + * @param dimension Dimension of the inserted cell. * @return Number of the operation. */ template > - Index insert_face(const BoundaryRange& boundary, Dimension dimension) { + Index insert_cell(const BoundaryRange& boundary, Dimension dimension) { ++numArrow_; _process_forward_arrow(boundary, dimension); return numArrow_; } /** - * @brief Updates the zigzag persistence diagram after the removal of the given face. + * @brief Updates the zigzag persistence diagram after the removal of the given cell. * - * @param arrowNumber Arrow number of when the face to remove was inserted for the last time. + * @param arrowNumber Arrow number of when the cell to remove was inserted for the last time. * @return Number of the operation. */ - Index remove_face(Index arrowNumber) { + Index remove_cell(Index arrowNumber) { ++numArrow_; _process_backward_arrow(arrowNumber); return numArrow_; } /** - * @brief To use when a face is neither inserted nor removed, but the filtration moves along the identity operator + * @brief To use when a cell is neither inserted nor removed, but the filtration moves along the identity operator * on homology level. Useful to keep the birth/death indices aligned when insertions/removals are purposely skipped * to avoid useless computation. Increases the arrow number by one. * @return Number of the operation. @@ -324,30 +322,19 @@ class Zigzag_persistence template void get_current_infinite_intervals(F&& stream_infinite_interval) { for (auto& p : births_) { - if constexpr (erase_birth_history) { - auto& col = matrix_.get_column(p.first); - stream_infinite_interval(col.get_dimension(), p.second); - } else { - try { - auto& col = matrix_.get_column(p.first); - if (!col.is_paired()) { - stream_infinite_interval(col.get_dimension(), p.second); - } - } catch (const std::out_of_range&) { - continue; - } - } + auto& col = matrix_.get_column(p.first); + stream_infinite_interval(col.get_dimension(), p.second); } } private: /** - * @brief Express the boundary cycle of the new face as a sum of cycles in a matrix. + * @brief Express the boundary cycle of the new cell as a sum of cycles in a matrix. * If some cycles are not boundary cycles, i.e., columns with F-index * in the matrix, it applies a surjective diamond to the zigzag module. * - * @param boundary Boundary of the inserted face. - * @param dim Dimension of the inserted face. + * @param boundary Boundary of the inserted cell. + * @param dim Dimension of the inserted cell. */ template void _process_forward_arrow(const BoundaryRange& boundary, Dimension dim) { @@ -369,7 +356,7 @@ class Zigzag_persistence * the boundary in _process_forward_arrow(...). It is equivalent to decreasing death index * order w.r.t. the & chainsInF) { @@ -438,27 +425,25 @@ class Zigzag_persistence } // birth not available anymore, do not } // modify *chain_f_it. - if constexpr (erase_birth_history) { - birthOrdering_.remove_birth(maxb); - births_.erase(chainFp); - } + birthOrdering_.remove_birth(maxb); + births_.erase(chainFp); // Update persistence diagram with left interval [fil(b_max) ; fil(m)) stream_interval_(dim - 1, maxb, numArrow_); } /** - * @brief Removes the given face by pushing up the matrix the corresponding column and erasing it. + * @brief Removes the given cell by pushing up the matrix the corresponding column and erasing it. * - * @param faceID Internal ID of the face to remove. + * @param cellID Internal ID of the cell to remove. */ - void _process_backward_arrow(Index faceID) { - // column whose key is the one of the removed face - Matrix_index currCol = matrix_.get_column_with_pivot(faceID); + void _process_backward_arrow(Index cellID) { + // column whose key is the one of the removed cell + Matrix_index currCol = matrix_.get_column_with_pivot(cellID); // Record all columns that get affected by the transpositions, i.e., have a coeff std::vector modifiedColumns; - const auto& row = matrix_.get_row(faceID); + const auto& row = matrix_.get_row(cellID); modifiedColumns.reserve(row.size()); std::transform(row.begin(), row.end(), std::back_inserter(modifiedColumns), [](const auto& cell) { return cell.get_column_index(); }); @@ -477,23 +462,21 @@ class Zigzag_persistence if (!col.is_paired()) { // in F auto it = births_.find(currCol); stream_interval_(col.get_dimension(), it->second, numArrow_); - if constexpr (erase_birth_history) { - birthOrdering_.remove_birth(it->second); - births_.erase(it); - } + birthOrdering_.remove_birth(it->second); + births_.erase(it); } else { // in H -> paired with c_g, that now belongs to F now // maintain the <=b order birthOrdering_.add_birth_backward(numArrow_); births_[col.get_paired_chain_index()] = numArrow_; } - // cannot be in G as the removed face is maximal - matrix_.remove_maximal_face(faceID, {}); // also un-pairs c_g if in H + // cannot be in G as the removed cell is maximal + matrix_.remove_maximal_cell(cellID, {}); // also un-pairs c_g if in H } private: Matrix matrix_; /**< Matrix storing a base of the current chain complex. */ - Birth_dictionary births_; /**< Map face index in F to corresponding birth. */ + Birth_dictionary births_; /**< Map cell index in F to corresponding birth. */ Birth_ordering birthOrdering_; /**< Maintains stream_interval_; /**< Callback method for closed pairs. */ diff --git a/src/Zigzag_persistence/test/test_filtered_zigzag_persistence.cpp b/src/Zigzag_persistence/test/test_filtered_zigzag_persistence.cpp index 4e20047a5..6d03c0cc9 100644 --- a/src/Zigzag_persistence/test/test_filtered_zigzag_persistence.cpp +++ b/src/Zigzag_persistence/test/test_filtered_zigzag_persistence.cpp @@ -128,7 +128,7 @@ std::vector get_filtration_values() { template void test_filtered_zigzag_with_storage() { - using face_handle = typename ZP::Face_key; + using cell_handle = typename ZP::Cell_key; using Filtration_value = typename ZP::Filtration_value; using Interval_index = typename ZP::Index_interval; using Interval_filtration = typename ZP::Filtration_value_interval; @@ -139,11 +139,11 @@ void test_filtered_zigzag_with_storage() { realIndices.reserve(13); realBarcode.reserve(9); - std::vector > simplices = get_boundaries(); + std::vector > simplices = get_boundaries(); std::vector filValues = get_filtration_values(); for (unsigned int i = 0; i < 14; ++i) { - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } realIndices.emplace_back(1, 3, 0); @@ -160,11 +160,11 @@ void test_filtered_zigzag_with_storage() { for (unsigned int i = 14; i < 16; ++i) { auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } for (unsigned int i = 16; i < 24; ++i) { - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } realIndices.emplace_back(5, 16, 0); @@ -179,19 +179,19 @@ void test_filtered_zigzag_with_storage() { for (unsigned int i = 24; i < 27; ++i) { auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } realIndices.emplace_back(24, 25, 1); realBarcode.emplace_back(8, 9, 1); - zp.insert_face(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); + zp.insert_cell(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); realIndices.emplace_back(23, 27, 2); realBarcode.emplace_back(7, 9, 2); auto id = simplices[28][0]; - zp.remove_face(id, filValues[28]); + zp.remove_cell(id, filValues[28]); realBarcode.emplace_back(0, Interval_filtration::inf, 0); realBarcode.emplace_back(9, Interval_filtration::inf, 0); @@ -203,7 +203,7 @@ void test_filtered_zigzag_with_storage() { template void test_filtered_zigzag_with_storage_max1() { - using face_handle = typename ZP::Face_key; + using cell_handle = typename ZP::Cell_key; using Filtration_value = typename ZP::Filtration_value; using Interval_index = typename ZP::Index_interval; using Interval_filtration = typename ZP::Filtration_value_interval; @@ -214,11 +214,11 @@ void test_filtered_zigzag_with_storage_max1() { realIndices.reserve(5); realBarcode.reserve(3); - std::vector > simplices = get_boundaries(); + std::vector > simplices = get_boundaries(); std::vector filValues = get_filtration_values(); for (unsigned int i = 0; i < 14; ++i) { - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } realIndices.emplace_back(1, 3, 0); @@ -231,11 +231,11 @@ void test_filtered_zigzag_with_storage_max1() { for (unsigned int i = 14; i < 16; ++i) { auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } for (unsigned int i = 16; i < 24; ++i) { - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } realIndices.emplace_back(5, 16, 0); @@ -243,12 +243,12 @@ void test_filtered_zigzag_with_storage_max1() { for (unsigned int i = 24; i < 27; ++i) { auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } - zp.insert_face(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); + zp.insert_cell(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); auto id = simplices[28][0]; - zp.remove_face(id, filValues[28]); + zp.remove_cell(id, filValues[28]); realBarcode.emplace_back(0, Interval_filtration::inf, 0); realBarcode.emplace_back(9, Interval_filtration::inf, 0); @@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(filtered_zigzag_persistence_with_storage) { template void test_filtered_zigzag() { - using face_handle = typename ZP::Face_key; + using cell_handle = typename ZP::Cell_key; using Filtration_value = typename ZP::Filtration_value; using Dimension = typename ZP::Dimension; using Interval = std::tuple; @@ -308,37 +308,37 @@ void test_filtered_zigzag() { realBarcode.emplace_back(2, 7, 9); //23-27 realBarcode.emplace_back(3, 0, 28); //dummy - std::vector > simplices = get_boundaries(); + std::vector > simplices = get_boundaries(); std::vector filValues = get_filtration_values(); for (unsigned int i = 0; i < 14; ++i) { interval = realBarcode[i]; - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } for (unsigned int i = 14; i < 16; ++i) { interval = realBarcode[i]; auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } for (unsigned int i = 16; i < 24; ++i) { interval = realBarcode[i]; - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } for (unsigned int i = 24; i < 27; ++i) { interval = realBarcode[i]; auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } interval = realBarcode[27]; - zp.insert_face(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); + zp.insert_cell(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); interval = realBarcode[28]; auto id = simplices[28][0]; - zp.remove_face(id, filValues[28]); + zp.remove_cell(id, filValues[28]); //there is no real guarantee on the order of the infinite bars std::vector infiniteBars; @@ -364,7 +364,7 @@ void test_filtered_zigzag() { template void test_filtered_zigzag_max1() { - using face_handle = typename ZP::Face_key; + using cell_handle = typename ZP::Cell_key; using Filtration_value = typename ZP::Filtration_value; using Dimension = typename ZP::Dimension; using Interval = std::tuple; @@ -412,37 +412,37 @@ void test_filtered_zigzag_max1() { realBarcode.emplace_back(2, 7, 9); //23-27 realBarcode.emplace_back(1, 0, 28); //dummy - std::vector > simplices = get_boundaries(); + std::vector > simplices = get_boundaries(); std::vector filValues = get_filtration_values(); for (unsigned int i = 0; i < 14; ++i) { interval = realBarcode[i]; - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } for (unsigned int i = 14; i < 16; ++i) { interval = realBarcode[i]; auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } for (unsigned int i = 16; i < 24; ++i) { interval = realBarcode[i]; - zp.insert_face(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); + zp.insert_cell(i, simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1, filValues[i]); } for (unsigned int i = 24; i < 27; ++i) { interval = realBarcode[i]; auto id = simplices[i][0]; - zp.remove_face(id, filValues[i]); + zp.remove_cell(id, filValues[i]); } interval = realBarcode[27]; - zp.insert_face(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); + zp.insert_cell(27, simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1, filValues[27]); interval = realBarcode[28]; auto id = simplices[28][0]; - zp.remove_face(id, filValues[28]); + zp.remove_cell(id, filValues[28]); //there is no real guarantee on the order of the infinite bars std::vector infiniteBars; diff --git a/src/Zigzag_persistence/test/test_zigzag_persistence.cpp b/src/Zigzag_persistence/test/test_zigzag_persistence.cpp index c589fa57b..0f1edb9a2 100644 --- a/src/Zigzag_persistence/test/test_zigzag_persistence.cpp +++ b/src/Zigzag_persistence/test/test_zigzag_persistence.cpp @@ -17,7 +17,6 @@ #include using ZP = Gudhi::zigzag_persistence::Zigzag_persistence<>; -// using ZP = Gudhi::zigzag_persistence::Zigzag_persistence; struct Interval { Interval() {} @@ -97,7 +96,7 @@ BOOST_AUTO_TEST_CASE(zigzag_persistence_single) { std::vector > simplices = get_boundaries(); for (unsigned int i = 0; i < 14; ++i) { - zp.insert_face(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); + zp.insert_cell(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); } realIndices.emplace_back(0, 1, 3); @@ -109,11 +108,11 @@ BOOST_AUTO_TEST_CASE(zigzag_persistence_single) { for (unsigned int i = 14; i < 16; ++i) { auto id = simplices[i][0]; - zp.remove_face(id); + zp.remove_cell(id); } for (unsigned int i = 16; i < 24; ++i) { - zp.insert_face(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); + zp.insert_cell(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); } realIndices.emplace_back(0, 5, 16); @@ -124,17 +123,17 @@ BOOST_AUTO_TEST_CASE(zigzag_persistence_single) { for (unsigned int i = 24; i < 27; ++i) { auto id = simplices[i][0]; - zp.remove_face(id); + zp.remove_cell(id); } realIndices.emplace_back(1, 24, 25); - zp.insert_face(simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1); + zp.insert_cell(simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1); realIndices.emplace_back(2, 23, 27); auto id = simplices[28][0]; - zp.remove_face(id); + zp.remove_cell(id); realIndices.emplace_back(0, 0, -1); realIndices.emplace_back(0, 26, -1); @@ -165,7 +164,7 @@ BOOST_AUTO_TEST_CASE(zigzag_persistence_single_max1) { std::vector > simplices = get_boundaries(); for (unsigned int i = 0; i < 14; ++i) { - zp.insert_face(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); + zp.insert_cell(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); } realIndices.emplace_back(0, 1, 3); @@ -175,23 +174,23 @@ BOOST_AUTO_TEST_CASE(zigzag_persistence_single_max1) { for (unsigned int i = 14; i < 16; ++i) { auto id = simplices[i][0]; - zp.remove_face(id); + zp.remove_cell(id); } for (unsigned int i = 16; i < 24; ++i) { - zp.insert_face(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); + zp.insert_cell(simplices[i], simplices[i].size() == 0 ? 0 : simplices[i].size() - 1); } realIndices.emplace_back(0, 5, 16); for (unsigned int i = 24; i < 27; ++i) { auto id = simplices[i][0]; - zp.remove_face(id); + zp.remove_cell(id); } - zp.insert_face(simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1); + zp.insert_cell(simplices[27], simplices[27].size() == 0 ? 0 : simplices[27].size() - 1); auto id = simplices[28][0]; - zp.remove_face(id); + zp.remove_cell(id); realIndices.emplace_back(0, 0, -1); realIndices.emplace_back(0, 26, -1);