From 9a64c2097b262c790f957447fb1bcbb494a5a776 Mon Sep 17 00:00:00 2001 From: hschreiber Date: Thu, 18 Apr 2024 18:09:54 +0200 Subject: [PATCH 1/2] change pointer to std::function to store also lambda function in chain_vine_swap --- .../Persistence_matrix/chain_vine_swap.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h index 9a45723497..0e5a77b8fb 100644 --- a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h +++ b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h @@ -20,6 +20,7 @@ #include //std::swap & std::move #include +#include //std::function #include "chain_pairing.h" @@ -256,9 +257,8 @@ class Chain_vine_swap : public std::conditional - Chain_vine_swap(EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator = _no_G_death_comparator); + Chain_vine_swap(std::function birthComparator, + std::function deathComparator = _no_G_death_comparator); /** * @brief Copy constructor. * @@ -326,8 +326,8 @@ class Chain_vine_swap : public std::conditional birthComp_; /**< for F x F & H x H. */ + std::function deathComp_; /**< for G x G. */ bool _is_negative_in_pair(index columnIndex); @@ -341,17 +341,16 @@ class Chain_vine_swap : public std::conditional -inline Chain_vine_swap::Chain_vine_swap() : CP(), birthComp_(nullptr), deathComp_(nullptr) +inline Chain_vine_swap::Chain_vine_swap() : CP(), birthComp_(), deathComp_() { static_assert(Master_matrix::Option_list::has_column_pairings, "If barcode is not stored, at least a birth comparator has to be specified."); } template -template -inline Chain_vine_swap::Chain_vine_swap(EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) - : CP(), birthComp_(&birthComparator), deathComp_(&deathComparator) +inline Chain_vine_swap::Chain_vine_swap(std::function birthComparator, + std::function deathComparator) + : CP(), birthComp_(std::move(birthComparator)), deathComp_(std::move(deathComparator)) {} template From aca2e02c752bcad6a55ffd278624744282caee6b Mon Sep 17 00:00:00 2001 From: hschreiber Date: Fri, 19 Apr 2024 13:57:09 +0200 Subject: [PATCH 2/2] vineyard fix --- .../gudhi/Persistence_matrix/chain_matrix.h | 47 ++++++++++--------- .../Persistence_matrix/chain_vine_swap.h | 19 +++----- .../overlay_ididx_to_matidx.h | 47 ++++++++++--------- .../overlay_posidx_to_matidx.h | 47 ++++++++++--------- src/Persistence_matrix/include/gudhi/matrix.h | 39 +++++++-------- .../gudhi/persistence_matrix_options.h | 1 + ...ence_matrix_matrix_tests_z2_chain_vine.cpp | 1 + 7 files changed, 99 insertions(+), 102 deletions(-) diff --git a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_matrix.h b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_matrix.h index 67ed642384..3a1c06399f 100644 --- a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_matrix.h +++ b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_matrix.h @@ -119,7 +119,8 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -131,11 +132,11 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Chain_matrix(Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Constructs a new matrix from the given ranges of @ref Matrix::cell_rep_type. Each range corresponds to a * column (the order of the ranges are preserved). The content of the ranges is assumed to be sorted by increasing @@ -146,7 +147,8 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @tparam Boundary_type Range type for @ref Matrix::cell_rep_type ranges. * Assumed to have a begin(), end() and size() method. * @param orderedBoundaries Range of boundaries: @p orderedBoundaries is interpreted as a boundary matrix of a @@ -158,7 +160,7 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * All dimensions up to the maximal dimension of interest have to be present. If only a higher dimension is of * interest and not everything should be stored, then use the @ref insert_boundary method instead * (after creating the matrix with the @ref Chain_matrix(unsigned int, Field_operators*, Cell_constructor*, - * EventComparatorFunction&&, EventComparatorFunction&&) constructor preferably). + * const BirthComparatorFunction&, const DeathComparatorFunction&) constructor preferably). * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -170,12 +172,12 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Chain_matrix(const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Constructs a new empty matrix and reserves space for the given number of columns. * @@ -184,7 +186,8 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param numberOfColumns Number of columns to reserve space for. * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. @@ -197,12 +200,12 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Chain_matrix(unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Copy constructor. If @p operators or @p cellConstructor is not a null pointer, its value is kept * instead of the one in the copied matrix. @@ -605,11 +608,11 @@ inline Chain_matrix::Chain_matrix(unsigned int numberOfColumns, } template -template +template inline Chain_matrix::Chain_matrix(Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : dim_opt(-1), pair_opt(), swap_opt(birthComparator, deathComparator), @@ -621,12 +624,12 @@ inline Chain_matrix::Chain_matrix(Field_operators* operators, {} template -template +template inline Chain_matrix::Chain_matrix(const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : dim_opt(-1), pair_opt(), swap_opt(birthComparator, deathComparator), @@ -648,12 +651,12 @@ inline Chain_matrix::Chain_matrix(const std::vector -template +template inline Chain_matrix::Chain_matrix(unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : dim_opt(-1), pair_opt(), swap_opt(birthComparator, deathComparator), diff --git a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h index 0e5a77b8fb..c38a3940a9 100644 --- a/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h +++ b/src/Persistence_matrix/include/gudhi/Persistence_matrix/chain_vine_swap.h @@ -53,9 +53,9 @@ struct Dummy_chain_vine_swap { friend void swap([[maybe_unused]] Dummy_chain_vine_swap& d1, [[maybe_unused]] Dummy_chain_vine_swap& d2) {} Dummy_chain_vine_swap() {} - template - Dummy_chain_vine_swap([[maybe_unused]] EventComparatorFunction&& birthComparator, - [[maybe_unused]] EventComparatorFunction&& deathComparator) {} + template + Dummy_chain_vine_swap([[maybe_unused]] const BirthComparatorFunction& birthComparator, + [[maybe_unused]] const DeathComparatorFunction& deathComparator) {} }; /** @@ -247,7 +247,6 @@ class Chain_vine_swap : public std::conditional bool. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if * the birth associated to the first position is strictly less than birth associated to * the second one with respect to some self defined order. It is used while swapping two unpaired or @@ -277,8 +276,7 @@ class Chain_vine_swap : public std::conditional inline typename Chain_vine_swap::index Chain_vine_swap::vine_swap_with_z_eq_1_case( index columnIndex1, index columnIndex2) { - if constexpr (Master_matrix::Option_list::has_column_pairings) { - assert(CP::are_adjacent(_matrix()->get_pivot(columnIndex1), _matrix()->get_pivot(columnIndex2)) && - "Columns to be swaped need to be adjacent in the 'real' matrix."); - } - const bool col1IsNeg = _is_negative_in_pair(columnIndex1); const bool col2IsNeg = _is_negative_in_pair(columnIndex2); @@ -585,7 +578,7 @@ inline typename Chain_vine_swap::index Chain_vine_swap bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -116,11 +117,11 @@ class Id_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Id_to_index_overlay(Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". * Constructs a new matrix from the given ranges of @ref Matrix::cell_rep_type. Each range corresponds to a column @@ -132,7 +133,8 @@ class Id_to_index_overlay * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref Matrix::pos_index, @ref Matrix::pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @tparam Boundary_type Range type for @ref Matrix::cell_rep_type ranges. * Assumed to have a begin(), end() and size() method. * @param orderedBoundaries Range of boundaries: @p orderedBoundaries is interpreted as a boundary matrix of a @@ -144,7 +146,7 @@ class Id_to_index_overlay * All dimensions up to the maximal dimension of interest have to be present. If only a higher dimension is of * interest and not everything should be stored, then use the @ref insert_boundary method instead * (after creating the matrix with the @ref Id_to_index_overlay(unsigned int, Field_operators*, Cell_constructor*, - * EventComparatorFunction&&, EventComparatorFunction&&) constructor preferably). + * const BirthComparatorFunction&, const DeathComparatorFunction&) constructor preferably). * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -156,12 +158,12 @@ class Id_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Id_to_index_overlay(const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". * Constructs a new empty matrix and reserves space for the given number of columns. @@ -171,7 +173,8 @@ class Id_to_index_overlay * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref Matrix::pos_index, @ref Matrix::pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param numberOfColumns Number of columns to reserve space for. * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. @@ -184,12 +187,12 @@ class Id_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Id_to_index_overlay(unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Copy constructor. If @p operators or @p cellConstructor is not a null pointer, its value is kept * instead of the one in the copied matrix. @@ -651,25 +654,25 @@ inline Id_to_index_overlay::Id_to_index_overlay } template -template +template inline Id_to_index_overlay::Id_to_index_overlay( Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(operators, cellConstructor, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0) { _initialize_map(0); } template -template +template inline Id_to_index_overlay::Id_to_index_overlay( const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(orderedBoundaries, operators, cellConstructor, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(orderedBoundaries.size()) @@ -683,13 +686,13 @@ inline Id_to_index_overlay::Id_to_index_overlay } template -template +template inline Id_to_index_overlay::Id_to_index_overlay( unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(numberOfColumns, operators, cellConstructor, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0) diff --git a/src/Persistence_matrix/include/gudhi/Persistence_matrix/overlay_posidx_to_matidx.h b/src/Persistence_matrix/include/gudhi/Persistence_matrix/overlay_posidx_to_matidx.h index 4a3085ea8c..e5e7578a68 100644 --- a/src/Persistence_matrix/include/gudhi/Persistence_matrix/overlay_posidx_to_matidx.h +++ b/src/Persistence_matrix/include/gudhi/Persistence_matrix/overlay_posidx_to_matidx.h @@ -108,7 +108,8 @@ class Position_to_index_overlay * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -120,11 +121,11 @@ class Position_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Position_to_index_overlay(Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". * Constructs a new matrix from the given ranges of @ref Matrix::cell_rep_type. Each range corresponds to a column @@ -136,7 +137,8 @@ class Position_to_index_overlay * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @tparam Boundary_type Range type for @ref Matrix::cell_rep_type ranges. * Assumed to have a begin(), end() and size() method. * @param orderedBoundaries Range of boundaries: @p orderedBoundaries is interpreted as a boundary matrix of a @@ -148,7 +150,7 @@ class Position_to_index_overlay * All dimensions up to the maximal dimension of interest have to be present. If only a higher dimension is of * interest and not everything should be stored, then use the @ref insert_boundary method instead * (after creating the matrix with the @ref Position_to_index_overlay(unsigned int, Field_operators*, - * Cell_constructor*, EventComparatorFunction&&, EventComparatorFunction&&) constructor preferably). + * Cell_constructor*, const BirthComparatorFunction&, const DeathComparatorFunction&) constructor preferably). * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. * @param birthComparator Method taking two @ref PosIdx indices as input and returning true if and only if @@ -160,12 +162,12 @@ class Position_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Position_to_index_overlay(const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". * Constructs a new empty matrix and reserves space for the given number of columns. @@ -175,7 +177,8 @@ class Position_to_index_overlay * @ref PersistenceMatrixOptions::has_column_pairings is also true, the comparators are ignored and * the current barcode is used to compare birth and deaths. Therefore it is useless to provide them in those cases. * - * @tparam EventComparatorFunction Method of the form: ( @ref pos_index, @ref pos_index ) -> bool. + * @tparam BirthComparatorFunction Type of the birth comparator: (@ref pos_index, @ref pos_index) -> bool + * @tparam DeathComparatorFunction Type of the death comparator: (@ref pos_index, @ref pos_index) -> bool * @param numberOfColumns Number of columns to reserve space for. * @param operators Pointer to the field operators. * @param cellConstructor Pointer to the cell factory. @@ -188,12 +191,12 @@ class Position_to_index_overlay * the second one with respect to some self defined order. It is used while swapping two positive but paired * columns. */ - template + template Position_to_index_overlay(unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator); /** * @brief Copy constructor. If @p operators or @p cellConstructor is not a null pointer, its value is kept * instead of the one in the copied matrix. @@ -555,23 +558,23 @@ inline Position_to_index_overlay::Position_to_i {} template -template +template inline Position_to_index_overlay::Position_to_index_overlay( Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(operators, cellConstructor, birthComparator, deathComparator), nextPosition_(0), nextIndex_(0) {} template -template +template inline Position_to_index_overlay::Position_to_index_overlay( const std::vector& orderedBoundaries, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(orderedBoundaries, operators, cellConstructor, birthComparator, deathComparator), positionToIndex_(orderedBoundaries.size()), nextPosition_(orderedBoundaries.size()), @@ -583,13 +586,13 @@ inline Position_to_index_overlay::Position_to_i } template -template +template inline Position_to_index_overlay::Position_to_index_overlay( unsigned int numberOfColumns, Field_operators* operators, Cell_constructor* cellConstructor, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) + const BirthComparatorFunction& birthComparator, + const DeathComparatorFunction& deathComparator) : matrix_(numberOfColumns, operators, cellConstructor, birthComparator, deathComparator), positionToIndex_(numberOfColumns), nextPosition_(0), diff --git a/src/Persistence_matrix/include/gudhi/matrix.h b/src/Persistence_matrix/include/gudhi/matrix.h index 8b15931de2..fe67806dd3 100644 --- a/src/Persistence_matrix/include/gudhi/matrix.h +++ b/src/Persistence_matrix/include/gudhi/matrix.h @@ -590,15 +590,13 @@ class Matrix { * information outside of the matrix about the barcode to provide a better suited comparator adapted to the situation * (as in the implementation of the Zigzag algorithm @cite zigzag for example.) * - * @tparam EventComparatorFunction Type of the birth or death comparator: (@ref pos_index, @ref pos_index) -> bool * @param birthComparator Method taking two @ref PosIdx indices as parameter and returns true if and only if the first * face is associated to a bar with strictly smaller birth than the bar associated to the second one. * @param deathComparator Method taking two @ref PosIdx indices as parameter and returns true if and only if the first * face is associated to a bar with strictly smaller death than the bar associated to the second one. */ - template - Matrix(EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator); + Matrix(const std::function& birthComparator, + const std::function& deathComparator); /** * @brief Constructs a new matrix from the given ranges with the given comparator functions. * Only available when those comparators are necessary. @@ -610,10 +608,9 @@ class Matrix { * * See description of @ref Matrix(const std::vector& columns, characteristic_type characteristic) * for more information about @p orderedBoundaries and - * @ref Matrix(EventComparatorFunction&& birthComparator, EventComparatorFunction&& deathComparator) + * @ref Matrix(const std::function&, const std::function&) * for more information about the comparators. * - * @tparam EventComparatorFunction Type of the birth or death comparator: (@ref pos_index, @ref pos_index) -> bool * @tparam Boundary_type Range type for @ref cell_rep_type ranges. Assumed to have a begin(), end() and size() method. * @param orderedBoundaries Vector of ordered boundaries in filtration order. Indexed continously starting at 0. * @param birthComparator Method taking two @ref PosIdx indices as parameter and returns true if and only if the first @@ -624,10 +621,10 @@ class Matrix { * @ref PersistenceMatrixOptions::is_z2 is false. Default value is 11. * Ignored if @ref PersistenceMatrixOptions::is_z2 is true. */ - template + template Matrix(const std::vector& orderedBoundaries, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator, + const std::function& birthComparator, + const std::function& deathComparator, characteristic_type characteristic = 11); /** * @brief Constructs a new empty matrix and reserves space for the given number of columns. @@ -639,10 +636,9 @@ class Matrix { * - @ref PersistenceMatrixOptions::has_column_pairings = false * * See description of - * @ref Matrix(EventComparatorFunction&& birthComparator, EventComparatorFunction&& deathComparator) + * @ref Matrix(const std::function&, const std::function&) * for more information about the comparators. * - * @tparam EventComparatorFunction Type of the birth or death comparator: (@ref pos_index, @ref pos_index) -> bool * @param numberOfColumns Number of columns to reserve space for. * @param birthComparator Method taking two @ref PosIdx indices as parameter and returns true if and only if the first * face is associated to a bar with strictly smaller birth than the bar associated to the second one. @@ -653,10 +649,9 @@ class Matrix { * @ref set_characteristic before calling for the first time a method needing it. * Ignored if @ref PersistenceMatrixOptions::is_z2 is true. */ - template Matrix(unsigned int numberOfColumns, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator, + const std::function& birthComparator, + const std::function& deathComparator, characteristic_type characteristic = 0); /** * @brief Copy constructor. @@ -1426,9 +1421,8 @@ inline Matrix::Matrix(int numberOfColumns, characteris } template -template -inline Matrix::Matrix(EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator) +inline Matrix::Matrix(const std::function& birthComparator, + const std::function& deathComparator) : operators_(new Field_operators()), cellPool_(new Cell_constructor()), matrix_(operators_, cellPool_, birthComparator, deathComparator) @@ -1441,10 +1435,10 @@ inline Matrix::Matrix(EventComparatorFunction&& birthC } template -template +template inline Matrix::Matrix(const std::vector& orderedBoundaries, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator, + const std::function& birthComparator, + const std::function& deathComparator, characteristic_type characteristic) : operators_(new Field_operators(characteristic)), cellPool_(new Cell_constructor()), @@ -1458,10 +1452,9 @@ inline Matrix::Matrix(const std::vector } template -template inline Matrix::Matrix(unsigned int numberOfColumns, - EventComparatorFunction&& birthComparator, - EventComparatorFunction&& deathComparator, + const std::function& birthComparator, + const std::function& deathComparator, characteristic_type characteristic) : operators_(new Field_operators(characteristic)), cellPool_(new Cell_constructor()), diff --git a/src/Persistence_matrix/include/gudhi/persistence_matrix_options.h b/src/Persistence_matrix/include/gudhi/persistence_matrix_options.h index bd7ae7d5b8..f5bdc3c79a 100644 --- a/src/Persistence_matrix/include/gudhi/persistence_matrix_options.h +++ b/src/Persistence_matrix/include/gudhi/persistence_matrix_options.h @@ -116,6 +116,7 @@ struct Zigzag_options : Default_options static const bool has_vine_update = true; static const bool is_of_boundary_type = false; static const bool has_map_column_container = true; + static const bool has_removable_columns = true; static const bool has_removable_rows = true; }; diff --git a/src/Persistence_matrix/test/Persistence_matrix_matrix_tests_z2_chain_vine.cpp b/src/Persistence_matrix/test/Persistence_matrix_matrix_tests_z2_chain_vine.cpp index 15ed8323a7..dba2e3594a 100644 --- a/src/Persistence_matrix/test/Persistence_matrix_matrix_tests_z2_chain_vine.cpp +++ b/src/Persistence_matrix/test/Persistence_matrix_matrix_tests_z2_chain_vine.cpp @@ -137,6 +137,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Chain_matrix_z2_vine_representative_cycles, Matrix bool birth_comparator(unsigned int columnIndex1, unsigned int columnIndex2) { if (columnIndex1 == 0) return false; if (columnIndex1 == 3) return true; + if (columnIndex1 == 1) return true; return false; }