diff --git a/multipers/gudhi/gudhi/Matrix.h b/multipers/gudhi/gudhi/Matrix.h index 1c9b8fa..d917bdd 100644 --- a/multipers/gudhi/gudhi/Matrix.h +++ b/multipers/gudhi/gudhi/Matrix.h @@ -51,8 +51,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -109,7 +109,7 @@ namespace persistence_matrix { * always take the same type of index as input (for optimization purposes). So, to avoid confusion, we will name and * define here the different possibilities, such that we can directly refer to it in the descriptions of the methods. * Note that every column and row in a @ref boundarymatrix "boundary" or @ref chainmatrix "chain matrix" is always - * associated to a single simplex/face, so in order to avoid repeating formulations like "of the simplex associated to + * associated to a single simplex/cell, so in order to avoid repeating formulations like "of the simplex associated to * the column" all the time, we will amalgamate both notions together. * * Let @f$ c @f$ be a column. @@ -134,7 +134,7 @@ namespace persistence_matrix { * indexed by its ID, so it correspond to the @ref IDIdx indexing scheme. If the matrix is not a * @ref chainmatrix "chain matrix", @f$ r @f$ will originally also be indexed by the ID, but when a swap occurs, * the rows also swap IDs and the new ID has to be used to access @f$ r @f$. This means that when the default - * @ref IDIdx scheme is used (the faces are numerated in order of appearance in the filtration starting at 0), + * @ref IDIdx scheme is used (the cells are numerated in order of appearance in the filtration starting at 0), * the indexation of the rows correspond to @ref PosIdx. * * @tparam PersistenceMatrixOptions Structure encoding all the options of the matrix. @@ -168,7 +168,7 @@ class Matrix { */ using Bar = Persistence_interval; - //tags for boost to associate a row and a column to a same cell + //tags for boost to associate a row and a column to a same entry struct Matrix_row_tag; struct Matrix_column_tag; @@ -182,7 +182,7 @@ class Matrix { boost::intrusive::set_base_hook, boost::intrusive::link_mode >; - //Two dummies are necessary to avoid double inheritance as a cell can inherit both a row and a column hook. + //Two dummies are necessary to avoid double inheritance as an entry can inherit both a row and a column hook. struct Dummy_row_hook {}; struct Dummy_column_hook {}; @@ -200,69 +200,69 @@ class Matrix { >::type >::type; - //Option to store the column index within the cell (additionally to the row index). Necessary only with row access. - using Cell_column_index_option = + //Option to store the column index within the entry (additionally to the row index). Necessary only with row access. + using Entry_column_index_option = typename std::conditional, - Dummy_cell_column_index_mixin + Entry_column_index, + Dummy_entry_column_index_mixin >::type; - //Option to store the value of the cell. - //Unnecessary for values in Z_2 as there are always 1 (0-valued cells are never stored). - using Cell_field_element_option = + //Option to store the value of the entry. + //Unnecessary for values in Z_2 as there are always 1 (0-valued entries are never stored). + using Entry_field_element_option = typename std::conditional + Dummy_entry_field_element_mixin, + Entry_field_element >::type; /** - * @brief Type of a matrix cell. See @ref Cell for a more detailed description. + * @brief Type of a matrix entry. See @ref Entry for a more detailed description. */ - using Matrix_cell = Cell >; + using Matrix_entry = Entry >; /** - * @brief Default cell constructor/destructor, using classic new and delete. + * @brief Default entry constructor/destructor, using classic new and delete. * For now, only used as default value for columns constructed independently outside of the matrix by the user. * Could be used in the future when parallel options are implemented, as usual pools are not thread safe. */ - inline static New_cell_constructor defaultCellConstructor; + inline static New_entry_constructor defaultEntryConstructor; /** - * @brief Cell constructor/destructor used by the matrix. Uses a pool of cells to accelerate memory management, - * as cells are constructed and destroyed a lot during reduction, swaps or additions. + * @brief Entry constructor/destructor used by the matrix. Uses a pool of entries to accelerate memory management, + * as entries are constructed and destroyed a lot during reduction, swaps or additions. */ - using Cell_constructor = Pool_cell_constructor; + using Entry_constructor = Pool_entry_constructor; /** - * @brief Type used to identify a cell, for example when inserting a boundary. + * @brief Type used to identify an entry, for example when inserting a boundary. * If @ref PersistenceMatrixOptions::is_z2 is true, the type is an @ref IDIdx and corresponds to the row index of the - * cell (the cell value is assumed to be 1). If @ref PersistenceMatrixOptions::is_z2 is false, the type is a pair - * whose first element is the row index of the cell and the second element is the value of the cell (which again is + * entry (the entry value is assumed to be 1). If @ref PersistenceMatrixOptions::is_z2 is false, the type is a pair + * whose first element is the row index of the entry and the second element is the value of the entry (which again is * assumed to be non-zero). The column index of the row is always deduced from the context in which the type is used. */ - using Cell_representative = typename std::conditional >::type; /** - * @brief Compares two cells by their position in the row. They are assume to be in the same row. + * @brief Compares two entries by their position in the row. They are assume to be in the same row. */ - struct RowCellComp { - bool operator()(const Matrix_cell& c1, const Matrix_cell& c2) const { + struct RowEntryComp { + bool operator()(const Matrix_entry& c1, const Matrix_entry& c2) const { return c1.get_column_index() < c2.get_column_index(); } }; /** - * @brief Type of the rows stored in the matrix. Is either an intrusive list of @ref Matrix_cell (not ordered) if - * @ref PersistenceMatrixOptions::has_intrusive_rows is true, or a set of @ref Matrix_cell (ordered by + * @brief Type of the rows stored in the matrix. Is either an intrusive list of @ref Matrix_entry (not ordered) if + * @ref PersistenceMatrixOptions::has_intrusive_rows is true, or a set of @ref Matrix_entry (ordered by * column index) otherwise. */ using Row = typename std::conditional, boost::intrusive::base_hook >, - std::set + std::set >::type; using Row_container = @@ -355,43 +355,43 @@ class Matrix { >::type; struct Column_z2_settings{ - Column_z2_settings() : cellConstructor() {} - Column_z2_settings([[maybe_unused]] Characteristic characteristic) : cellConstructor() {} - Column_z2_settings(const Column_z2_settings& toCopy) : cellConstructor() {} + Column_z2_settings() : entryConstructor() {} + Column_z2_settings([[maybe_unused]] Characteristic characteristic) : entryConstructor() {} + Column_z2_settings(const Column_z2_settings& toCopy) : entryConstructor() {} - Cell_constructor cellConstructor; //will be replaced by more specific allocators depending on the column type. + Entry_constructor entryConstructor; //will be replaced by more specific allocators depending on the column type. }; struct Column_zp_settings { - Column_zp_settings() : operators(), cellConstructor() {} + Column_zp_settings() : operators(), entryConstructor() {} //purposely triggers operators() instead of operators(characteristic) as the "dummy" values for the different //operators can be different from -1. - Column_zp_settings(Characteristic characteristic) : operators(), cellConstructor() { + Column_zp_settings(Characteristic characteristic) : operators(), entryConstructor() { if (characteristic != static_cast(-1)) operators.set_characteristic(characteristic); } Column_zp_settings(const Column_zp_settings& toCopy) - : operators(toCopy.operators.get_characteristic()), cellConstructor() {} + : operators(toCopy.operators.get_characteristic()), entryConstructor() {} Field_operators operators; - Cell_constructor cellConstructor; //will be replaced by more specific allocators depending on the column type. + Entry_constructor entryConstructor; //will be replaced by more specific allocators depending on the column type. }; // struct Column_z2_with_rows_settings { - // Column_z2_with_rows_settings() : cellConstructor(), rows(nullptr) {} + // Column_z2_with_rows_settings() : entryConstructor(), rows(nullptr) {} // Column_z2_with_rows_settings([[maybe_unused]] Characteristic characteristic) - // : cellConstructor(), rows(nullptr) {} + // : entryConstructor(), rows(nullptr) {} - // Cell_constructor cellConstructor; + // Entry_constructor entryConstructor; // Row_container* rows; // }; // struct Column_zp_with_rows_settings { - // Column_zp_with_rows_settings() : operators(), cellConstructor(), rows(nullptr) {} + // Column_zp_with_rows_settings() : operators(), entryConstructor(), rows(nullptr) {} // Column_zp_with_rows_settings(Characteristic characteristic) - // : operators(characteristic), cellConstructor(), rows(nullptr) {} + // : operators(characteristic), entryConstructor(), rows(nullptr) {} // Field_operators operators; - // Cell_constructor cellConstructor; + // Entry_constructor entryConstructor; // Row_container* rows; // }; @@ -548,7 +548,7 @@ class Matrix { PersistenceMatrixOptions::column_indexation_type == Column_indexation_types::POSITION, void, - std::vector + std::vector >::type; /** @@ -556,14 +556,14 @@ class Matrix { */ Matrix(); /** - * @brief Constructs a new matrix from the given ranges of @ref Cell_representative. 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 IDs. If the - * columns are representing a boundary matrix, the IDs of the simplices are also assumed to be consecutive, ordered by - * filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Entry_representative. 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 + * IDs. If the columns are representing a boundary matrix, the IDs of the simplices are also assumed to be + * consecutive, ordered by filtration value, starting with 0. * * See @ref mp_matrices "matrix descriptions" for further details on how the given matrix is handled. * - * @tparam Container Range type for @ref Cell_representative ranges. Assumed to have a begin(), end() and size() + * @tparam Container Range type for @ref Entry_representative ranges. Assumed to have a begin(), end() and size() * method. * @param columns For a @ref basematrix "base matrix", the columns are copied as is. If options related to homology * are activated, @p columns is interpreted as a boundary matrix of a **simplicial** complex. In this case, @@ -609,9 +609,9 @@ class Matrix { * (as in the implementation of the Zigzag algorithm @cite zigzag for example.) * * @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. + * cell 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. + * cell is associated to a bar with strictly smaller death than the bar associated to the second one. */ Matrix(const std::function& birthComparator, const std::function& deathComparator); @@ -629,12 +629,13 @@ class Matrix { * @ref Matrix(const std::function&, const std::function&) * for more information about the comparators. * - * @tparam Boundary_range Range type for @ref Cell_representative ranges. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range type for @ref Entry_representative ranges. Assumed to have a begin(), end() and size() + * method. * @param orderedBoundaries Vector of ordered boundaries in filtration order. Indexed continuously starting at 0. * @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. + * cell 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. + * cell is associated to a bar with strictly smaller death than the bar associated to the second one. * @param characteristic Characteristic of the coefficient field. Has to be specified if * @ref PersistenceMatrixOptions::is_z2 is false. Default value is 11. * Ignored if @ref PersistenceMatrixOptions::is_z2 is true. @@ -659,9 +660,9 @@ class Matrix { * * @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. + * cell 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. + * cell is associated to a bar with strictly smaller death than the bar associated to the second one. * @param characteristic Characteristic of the coefficient field. If not specified and * @ref PersistenceMatrixOptions::is_z2 is false, the characteristic has to be set later with the use of * @ref set_characteristic before calling for the first time a method needing it. @@ -697,7 +698,7 @@ class Matrix { * Do not change the value of the characteristic once used. * * @warning The coefficient values stored in the matrix are stored after computing the corresponding modulo. - * Therefore, changing the characteristic after is very likely to invalidate all cell values. + * Therefore, changing the characteristic after is very likely to invalidate all entry values. * * @param characteristic The characteristic to set. */ @@ -706,25 +707,25 @@ class Matrix { // (TODO: if there is no row access and the column type corresponds to the internal column type of the matrix, // moving the column instead of copying it should be possible. Is it worth implementing it?) /** - * @brief Inserts a new ordered column at the end of the matrix by copying the given range of @ref Cell_representative. - * The content of the range is assumed to be sorted by increasing ID value. + * @brief Inserts a new ordered column at the end of the matrix by copying the given range of + * @ref Entry_representative. The content of the range is assumed to be sorted by increasing ID value. * * Only available for @ref basematrix "base matrices". * Otherwise use @ref insert_boundary which will deduce a new column from the boundary given. * - * @tparam Container Range of @ref Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Container Range of @ref Entry_representative. Assumed to have a begin(), end() and size() method. * @param column Column to be inserted. */ template void insert_column(const Container& column); /** - * @brief Inserts a new ordered column at the given index by copying the given range of @ref Cell_representative. + * @brief Inserts a new ordered column at the given index by copying the given range of @ref Entry_representative. * There should not be any other column inserted at that index which was not explicitly removed before. * The content of the range is assumed to be sorted by increasing ID value. * * Only available for @ref basematrix "base matrices" without column compression and without row access. * - * @tparam Container Range of @ref Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Container Range of @ref Entry_representative. Assumed to have a begin(), end() and size() method. * @param column Column to be inserted. * @param columnIndex @ref MatIdx index to which the column has to be inserted. */ @@ -735,13 +736,13 @@ class Matrix { /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other - * @ref insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" - * instead by indicating the face ID used in the boundaries when the face is inserted. + * @ref insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" + * instead by indicating the cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * The content of the new column will vary depending on the underlying @ref mp_matrices "type of the matrix": * - If it is a @ref basematrix "basic matrix" type, the boundary is copied as it is, i.e., the method is equivalent @@ -756,9 +757,9 @@ class Matrix { * older column IDIdxs`, where the combination is deduced while reducing the given boundary. If the barcode is stored, * it will also be updated. * - * @tparam Boundary_range Range of @ref Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range of @ref Entry_representative. Assumed to have a begin(), end() and size() method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return If it is a @ref chainmatrix "chain matrix", the method returns the @ref MatIdx indices of the unpaired * chains used to reduce the boundary. Otherwise, nothing. @@ -767,26 +768,26 @@ class Matrix { Insertion_return insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** * @brief Only available for @ref mp_matrices "non-basic matrices". - * It does the same as the other version, but allows the boundary faces to be identified without restrictions + * It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * for @ref mp_matrices "non-basic matrices", the faces are inserted by order of filtration), it is sufficient to - * indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * for @ref mp_matrices "non-basic matrices", the cells are inserted by order of filtration), it is sufficient to + * indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Cell_representative. Assumed to have a begin(), end() and size() method. - * @param faceIndex @ref IDIdx index to use to identify the new face. + * @tparam Boundary_range Range of @ref Entry_representative. Assumed to have a begin(), end() and size() method. + * @param cellIndex @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceIndex values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellIndex values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return If it is a @ref chainmatrix "chain matrix", the method returns the @ref MatIdx indices of the unpaired * chains used to reduce the boundary. Otherwise, nothing. */ template - Insertion_return insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim = -1); + Insertion_return insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim = -1); /** * @brief Returns the column at the given @ref MatIdx index. @@ -859,8 +860,8 @@ class Matrix { /** * @brief Only available for @ref basematrix "base matrices" without column compression and if * @ref PersistenceMatrixOptions::has_map_column_container is true. Otherwise, see @ref remove_last. Erases the given - * column from the matrix. If @ref PersistenceMatrixOptions::has_row_access is also true, the deleted column cells are - * also automatically removed from their respective rows. + * column from the matrix. If @ref PersistenceMatrixOptions::has_row_access is also true, the deleted column entries + * are also automatically removed from their respective rows. * * @param columnIndex @ref MatIdx index of the column to remove. */ @@ -879,11 +880,11 @@ class Matrix { * - @ref chainmatrix "chain matrix": only available if @ref PersistenceMatrixOptions::has_row_access and * @ref PersistenceMatrixOptions::has_removable_rows are true. Assumes that the row is empty and removes it. * - * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row cells are not + * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not * removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when - * the column cells are destroyed later. The row access is just meant as a "read only" access to the rows and the + * the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the * @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from - * dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can be quite + * dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be quite * frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row to remove. @@ -894,10 +895,10 @@ class Matrix { * @brief Only available for @ref boundarymatrix "RU" and @ref chainmatrix "chain matrices" and if * @ref PersistenceMatrixOptions::has_removable_columns and @ref PersistenceMatrixOptions::has_vine_update are true. * For @ref chainmatrix "chain matrices", @ref PersistenceMatrixOptions::has_map_column_container and - * @ref PersistenceMatrixOptions::has_column_pairings also need to be true. Assumes that the face is maximal in the + * @ref PersistenceMatrixOptions::has_column_pairings also need to be true. Assumes that the cell is maximal in the * current complex and removes it such that the matrix remains consistent (i.e., RU is still an upper triangular * decomposition of the boundary matrix and chain is still a compatible bases of the chain complex in the sense - * of @cite zigzag). The maximality of the face is not verified. Also updates the barcode if it was computed. + * of @cite zigzag). The maximality of the cell is not verified. Also updates the barcode if it was computed. * * For @ref chainmatrix "chain matrices", using the other version of the method could perform better depending on how * the data is maintained on the side of the user. Then, @ref PersistenceMatrixOptions::has_column_pairings also do @@ -905,56 +906,56 @@ class Matrix { * * See also @ref remove_last and @ref remove_column. * - * @param columnIndex If @ref boundarymatrix "boundary matrix", @ref MatIdx index of the face to remove, otherwise the + * @param columnIndex If @ref boundarymatrix "boundary matrix", @ref MatIdx index of the cell to remove, otherwise the * @ref IDIdx index. */ - void remove_maximal_face(Index columnIndex); + void remove_maximal_cell(Index columnIndex); //TODO: See if it would be better to use something more general than a vector for columnsToSwap, such that // the user do not have to construct the vector from scratch. Like passing iterators instead. But it would be nice, - // to still be able to do (face, {})... + // to still be able to do (cell, {})... /** * @brief Only available for @ref chainmatrix "chain matrices" and if * @ref PersistenceMatrixOptions::has_removable_columns, @ref PersistenceMatrixOptions::has_vine_update and - * @ref PersistenceMatrixOptions::has_map_column_container are true. Assumes that the face is maximal in the current + * @ref PersistenceMatrixOptions::has_map_column_container are true. Assumes that the cell is maximal in the current * complex and removes it such that the matrix remains consistent (i.e., it is still a compatible bases of the chain - * complex in the sense of @cite zigzag). The maximality of the face is not verified. Also updates the barcode if it + * complex in the sense of @cite zigzag). The maximality of the cell is not verified. Also updates the barcode if it * was computed. * - * To maintain the compatibility, vine swaps are done to move the face up to the end of the filtration. Once at the + * To maintain the compatibility, vine swaps are done to move the cell up to the end of the filtration. Once at the * end, the removal is trivial. But for @ref chainmatrix "chain matrices", swaps do not actually swap the position of - * the column every time, so the faces appearing after @p faceIndex in the filtration have to be searched first within - * the matrix. If the user has an easy access to the @ref IDIdx of the faces in the order of filtration, passing them + * the column every time, so the cells appearing after @p cellIndex in the filtration have to be searched first within + * the matrix. If the user has an easy access to the @ref IDIdx of the cells in the order of filtration, passing them * by argument with @p columnsToSwap allows to skip a linear search process. Typically, if the user knows that the - * face he wants to remove is already the last face of the filtration, calling - * @ref remove_maximal_face(ID_index faceIndex, const std::vector& columnsToSwap) - * "remove_maximal_face(faceID, {})" will be faster than @ref remove_last(). + * cell he wants to remove is already the last cell of the filtration, calling + * @ref remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap) + * "remove_maximal_cell(cellID, {})" will be faster than @ref remove_last(). * * See also @ref remove_last. * - * @param faceIndex @ref IDIdx index of the face to remove - * @param columnsToSwap Vector of @ref IDIdx indices of the faces coming after @p faceIndex in the filtration. + * @param cellIndex @ref IDIdx index of the cell to remove + * @param columnsToSwap Vector of @ref IDIdx indices of the cells coming after @p cellIndex in the filtration. */ - void remove_maximal_face(ID_index faceIndex, const std::vector& columnsToSwap); + void remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap); /** - * @brief Removes the last inserted column/face from the matrix. + * @brief Removes the last inserted column/cell from the matrix. * If the matrix is @ref mp_matrices "non basic", @ref PersistenceMatrixOptions::has_removable_columns has to be true * for the method to be available. Additionally, if the matrix is a @ref chainmatrix "chain matrix", either * @ref PersistenceMatrixOptions::has_map_column_container has to be true or * @ref PersistenceMatrixOptions::has_vine_update has to be false. And if the matrix is a * @ref basematrix "base matrix" it should be without column compression. * - * See also @ref remove_maximal_face and @ref remove_column. + * See also @ref remove_maximal_cell and @ref remove_column. * - * For @ref chainmatrix "chain matrices", if @ref PersistenceMatrixOptions::has_vine_update is true, the last face + * For @ref chainmatrix "chain matrices", if @ref PersistenceMatrixOptions::has_vine_update is true, the last cell * does not have to be at the end of the matrix and therefore has to be searched first. In this case, if the user - * already knows the @ref IDIdx of the last face, calling - * @ref remove_maximal_face(ID_index faceIndex, const std::vector& columnsToSwap) - * "remove_maximal_face(faceID, {})" instead allows to skip the search. + * already knows the @ref IDIdx of the last cell, calling + * @ref remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap) + * "remove_maximal_cell(cellID, {})" instead allows to skip the search. */ void remove_last(); /** - * @brief Returns the maximal dimension of a face stored in the matrix. Only available for + * @brief Returns the maximal dimension of a cell stored in the matrix. Only available for * @ref mp_matrices "non-basic matrices" and if @ref PersistenceMatrixOptions::has_matrix_maximal_dimension_access * is true. * @@ -968,10 +969,10 @@ class Matrix { */ Index get_number_of_columns() const; /** - * @brief Returns the dimension of the given face. Only available for @ref mp_matrices "non-basic matrices". + * @brief Returns the dimension of the given cell. Only available for @ref mp_matrices "non-basic matrices". * - * @param columnIndex @ref MatIdx index of the column representing the face. - * @return Dimension of the face. + * @param columnIndex @ref MatIdx index of the column representing the cell. + * @return Dimension of the cell. */ Dimension get_column_dimension(Index columnIndex) const; @@ -992,19 +993,19 @@ class Matrix { std::enable_if_t > add_to(Integer_index sourceColumnIndex, Integer_index targetColumnIndex); /** - * @brief Adds the given range of @ref Cell onto the column at @p targetColumnIndex in the matrix. Only available + * @brief Adds the given range of @ref Entry onto the column at @p targetColumnIndex in the matrix. Only available * for @ref basematrix "basic matrices". * * For @ref basematrix "basic matrices" with column compression, the range is summed onto the representative, which * means that all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range Range of @ref Cell. Needs a begin() and end() method. A column index does not need to be - * stored in the cells, even if @ref PersistenceMatrixOptions::has_row_access is true. - * @param sourceColumn Source @ref Cell range. + * @tparam Entry_range Range of @ref Entry. Needs a begin() and end() method. A column index does not need to be + * stored in the entries, even if @ref PersistenceMatrixOptions::has_row_access is true. + * @param sourceColumn Source @ref Entry range. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - std::enable_if_t > add_to(const Cell_range& sourceColumn, Index targetColumnIndex); + template + std::enable_if_t > add_to(const Entry_range& sourceColumn, Index targetColumnIndex); /** * @brief Multiplies the target column with the coefficient and then adds the source column to it. @@ -1027,21 +1028,21 @@ class Matrix { int coefficient, Integer_index targetColumnIndex); /** - * @brief Multiplies the target column with the coefficient and then adds the given range of @ref Cell to it. + * @brief Multiplies the target column with the coefficient and then adds the given range of @ref Entry to it. * That is: `targetColumn = (targetColumn * coefficient) + sourceColumn`. Only available for * @ref basematrix "basic matrices". * * For @ref basematrix "basic matrices" with column compression, the range is summed onto the representative, which * means that all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range Range of @ref Cell. Needs a begin() and end() method. A column index does not need to be - * stored in the cells, even if @ref PersistenceMatrixOptions::has_row_access is true. - * @param sourceColumn Source @ref Cell range. + * @tparam Entry_range Range of @ref Entry. Needs a begin() and end() method. A column index does not need to be + * stored in the entries, even if @ref PersistenceMatrixOptions::has_row_access is true. + * @param sourceColumn Source @ref Entry range. * @param coefficient Value to multiply. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - std::enable_if_t > multiply_target_and_add_to(const Cell_range& sourceColumn, + template + std::enable_if_t > multiply_target_and_add_to(const Entry_range& sourceColumn, int coefficient, Index targetColumnIndex); @@ -1073,40 +1074,40 @@ class Matrix { * For @ref basematrix "basic matrices" with column compression, the range is summed onto the representative, which * means that all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range Range of @ref Cell. Needs a begin() and end() method. A column index does not need to be - * stored in the cells, even if @ref PersistenceMatrixOptions::has_row_access is true. + * @tparam Entry_range Range of @ref Entry. Needs a begin() and end() method. A column index does not need to be + * stored in the entries, even if @ref PersistenceMatrixOptions::has_row_access is true. * @param coefficient Value to multiply. - * @param sourceColumn Source @ref Cell range. + * @param sourceColumn Source @ref Entry range. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - std::enable_if_t > multiply_source_and_add_to(int coefficient, - const Cell_range& sourceColumn, + template + std::enable_if_t > multiply_source_and_add_to(int coefficient, + const Entry_range& sourceColumn, Index targetColumnIndex); /** - * @brief Zeroes the cell at the given coordinates. Not available for @ref chainmatrix "chain matrices" and for + * @brief Zeroes the entry at the given coordinates. Not available for @ref chainmatrix "chain matrices" and for * @ref basematrix "base matrices" with column compression. In general, should be used with care with * @ref mp_matrices "non-basic matrices" to not destroy the validity of the persistence related properties of the * matrix. * * For @ref boundarymatrix "RU matrices", equivalent to - * @ref zero_cell(Index columnIndex, ID_index rowIndex, bool inR) "zero_cell(columnIndex, rowIndex, true)". + * @ref zero_entry(Index columnIndex, ID_index rowIndex, bool inR) "zero_entry(columnIndex, rowIndex, true)". * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. */ - void zero_cell(Index columnIndex, ID_index rowIndex); + void zero_entry(Index columnIndex, ID_index rowIndex); /** - * @brief Only available for @ref boundarymatrix "RU matrices". Zeroes the cell at the given coordinates in \f$ R \f$ + * @brief Only available for @ref boundarymatrix "RU matrices". Zeroes the entry at the given coordinates in \f$ R \f$ * if @p inR is true or in \f$ U \f$ if @p inR is false. Should be used with care to not destroy the validity of the * persistence related properties of the matrix. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. * @param inR Boolean indicating in which matrix to zero: if true in \f$ R \f$ and if false in \f$ U \f$. */ - void zero_cell(Index columnIndex, ID_index rowIndex, bool inR); + void zero_entry(Index columnIndex, ID_index rowIndex, bool inR); /** * @brief Zeroes the column at the given index. Not available for @ref chainmatrix "chain matrices" and for * @ref basematrix "base matrices" with column compression. In general, should be used with care with @@ -1129,29 +1130,29 @@ class Matrix { */ void zero_column(Index columnIndex, bool inR); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * * For @ref boundarymatrix "RU matrices", equivalent to - * @ref is_zero_cell(Index columnIndex, ID_index rowIndex, bool inR) const - * "is_zero_cell(columnIndex, rowIndex, true)". + * @ref is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const + * "is_zero_entry(columnIndex, rowIndex, true)". * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, ID_index rowIndex); + bool is_zero_entry(Index columnIndex, ID_index rowIndex); /** - * @brief Only available for @ref boundarymatrix "RU matrices". Indicates if the cell at given coordinates has value + * @brief Only available for @ref boundarymatrix "RU matrices". Indicates if the entry at given coordinates has value * zero in \f$ R \f$ if @p inR is true or in \f$ U \f$ if @p inR is false. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. * @param inR Boolean indicating in which matrix to look: if true in \f$ R \f$ and if false in \f$ U \f$. - * @return true If the cell has value zero. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, ID_index rowIndex, bool inR) const; + bool is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const; /** * @brief Indicates if the column at given index has value zero. * @@ -1188,10 +1189,10 @@ class Matrix { * indices and that the @ref rowindex "row indices" for a @ref boundarymatrix "RU matrix" correspond to the updated * @ref IDIdx indices which got potentially swapped by a vine swap. * - * @param faceIndex @ref rowindex "Row index" of the pivot. + * @param cellIndex @ref rowindex "Row index" of the pivot. * @return @ref MatIdx index of the column with the given pivot. */ - Index get_column_with_pivot(ID_index faceIndex) const; + Index get_column_with_pivot(ID_index cellIndex) const; /** * @brief Returns the @ref rowindex "row index" of the pivot of the given column. Only available for * @ref mp_matrices "non-basic matrices". @@ -1279,7 +1280,7 @@ class Matrix { * Does the same than @ref vine_swap, but assumes that the swap is non trivial and therefore skips a part of the case * study. * - * @param index @ref PosIdx index of the first face to swap. The second one has to be at `index + 1`. Recall that for + * @param index @ref PosIdx index of the first cell to swap. The second one has to be at `index + 1`. Recall that for * @ref boundarymatrix "boundary matrices", @ref PosIdx == @ref MatIdx. * @return true If the barcode changed from the swap. * @return false Otherwise. @@ -1291,8 +1292,8 @@ class Matrix { * @ref Column_indexation_types::IDENTIFIER. Does the same than @ref vine_swap, but assumes that the swap is * non-trivial and therefore skips a part of the case study. * - * @param columnIndex1 @ref MatIdx index of the first face. - * @param columnIndex2 @ref MatIdx index of the second face. It is assumed that the @ref PosIdx of both only differs + * @param columnIndex1 @ref MatIdx index of the first cell. + * @param columnIndex2 @ref MatIdx index of the second cell. It is assumed that the @ref PosIdx of both only differs * by one. * @return Let \f$ pos1 \f$ be the @ref PosIdx index of @p columnIndex1 and \f$ pos2 \f$ be the @ref PosIdx index of * @p columnIndex2. The method returns the @ref MatIdx of the column which has now, after the swap, the @ref PosIdx @@ -1302,14 +1303,14 @@ class Matrix { /** * @brief Only available if @ref PersistenceMatrixOptions::has_vine_update is true and if it is either a * @ref boundarymatrix "boundary matrix" or @ref PersistenceMatrixOptions::column_indexation_type is set to - * @ref Column_indexation_types::POSITION. Does a vine swap between two faces which are consecutive in the + * @ref Column_indexation_types::POSITION. Does a vine swap between two cells which are consecutive in the * filtration. Roughly, if \f$ F \f$ is the current filtration represented by the matrix, the method modifies the * matrix such that the new state corresponds to a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but - * with the two faces at position `index` and `index + 1` swapped. Of course, the two faces should not have a + * with the two cells at position `index` and `index + 1` swapped. Of course, the two cells should not have a * face/coface relation which each other ; \f$ F' \f$ has to be a valid filtration. * See @cite vineyards for more information about vine and vineyards. * - * @param index @ref PosIdx index of the first face to swap. The second one has to be at `index + 1`. Recall that for + * @param index @ref PosIdx index of the first cell to swap. The second one has to be at `index + 1`. Recall that for * @ref boundarymatrix "boundary matrices", @ref PosIdx == @ref MatIdx. * @return true If the barcode changed from the swap. * @return false Otherwise. @@ -1318,15 +1319,15 @@ class Matrix { /** * @brief Only available if @ref PersistenceMatrixOptions::has_vine_update is true and if it is either a * @ref chainmatrix "chain matrix" or @ref PersistenceMatrixOptions::column_indexation_type is set to - * @ref Column_indexation_types::IDENTIFIER. Does a vine swap between two faces which are consecutive in the + * @ref Column_indexation_types::IDENTIFIER. Does a vine swap between two cells which are consecutive in the * filtration. Roughly, if \f$ F \f$ is the current filtration represented by the matrix, the method modifies the * matrix such that the new state corresponds to a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but - * with the two given faces at swapped positions. Of course, the two faces should not have a face/coface relation + * with the two given cells at swapped positions. Of course, the two cells should not have a face/coface relation * which each other ; \f$ F' \f$ has to be a valid filtration. * See @cite vineyards for more information about vine and vineyards. * - * @param columnIndex1 @ref MatIdx index of the first face. - * @param columnIndex2 @ref MatIdx index of the second face. It is assumed that the @ref PosIdx of both only differs + * @param columnIndex1 @ref MatIdx index of the first cell. + * @param columnIndex2 @ref MatIdx index of the second cell. It is assumed that the @ref PosIdx of both only differs * by one. * @return Let \f$ pos1 \f$ be the @ref PosIdx index of @p columnIndex1 and \f$ pos2 \f$ be the @ref PosIdx index of * @p columnIndex2. The method returns the @ref MatIdx of the column which has now, after the swap, the @ref PosIdx @@ -1394,7 +1395,7 @@ class Matrix { >::type; // Field_operators* operators_; - // Cell_constructor* cellPool_; + // Entry_constructor* entryPool_; Column_settings* colSettings_; //pointer because the of swap operator on matrix_ which also stores the pointer Underlying_matrix matrix_; @@ -1530,7 +1531,7 @@ inline void Matrix::insert_column(const Container& col static_assert( !isNonBasic, - "'insert_column' not available for the chosen options. The input has to be in the form of a face boundary."); + "'insert_column' not available for the chosen options. The input has to be in the form of a cell boundary."); matrix_.insert_column(column); } @@ -1572,7 +1573,7 @@ Matrix::insert_boundary(const Boundary_range& boundary template template inline typename Matrix::Insertion_return -Matrix::insert_boundary(ID_index faceIndex, +Matrix::insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) { @@ -1585,9 +1586,9 @@ Matrix::insert_boundary(ID_index faceIndex, static_assert(isNonBasic, "Only enabled for non-basic matrices."); if constexpr (!PersistenceMatrixOptions::is_of_boundary_type && PersistenceMatrixOptions::column_indexation_type == Column_indexation_types::CONTAINER) - return matrix_.insert_boundary(faceIndex, boundary, dim); + return matrix_.insert_boundary(cellIndex, boundary, dim); else - matrix_.insert_boundary(faceIndex, boundary, dim); + matrix_.insert_boundary(cellIndex, boundary, dim); } template @@ -1672,31 +1673,31 @@ inline void Matrix::erase_empty_row(ID_index rowIndex) } template -inline void Matrix::remove_maximal_face(Index columnIndex) +inline void Matrix::remove_maximal_cell(Index columnIndex) { static_assert(PersistenceMatrixOptions::has_removable_columns, - "'remove_maximal_face(ID_index)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index)' is not available for the chosen options."); static_assert(isNonBasic && PersistenceMatrixOptions::has_vine_update, - "'remove_maximal_face(ID_index)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index)' is not available for the chosen options."); static_assert(PersistenceMatrixOptions::is_of_boundary_type || (PersistenceMatrixOptions::has_map_column_container && PersistenceMatrixOptions::has_column_pairings), - "'remove_maximal_face(ID_index)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index)' is not available for the chosen options."); - matrix_.remove_maximal_face(columnIndex); + matrix_.remove_maximal_cell(columnIndex); } template -inline void Matrix::remove_maximal_face(ID_index faceIndex, +inline void Matrix::remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap) { static_assert(PersistenceMatrixOptions::has_removable_columns, - "'remove_maximal_face(ID_index,const std::vector&)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index,const std::vector&)' is not available for the chosen options."); static_assert(isNonBasic && !PersistenceMatrixOptions::is_of_boundary_type, - "'remove_maximal_face(ID_index,const std::vector&)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index,const std::vector&)' is not available for the chosen options."); static_assert(PersistenceMatrixOptions::has_map_column_container && PersistenceMatrixOptions::has_vine_update, - "'remove_maximal_face(ID_index,const std::vector&)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index,const std::vector&)' is not available for the chosen options."); - matrix_.remove_maximal_face(faceIndex, columnsToSwap); + matrix_.remove_maximal_cell(cellIndex, columnsToSwap); } template @@ -1746,9 +1747,9 @@ inline std::enable_if_t > Matrix -template -inline std::enable_if_t > Matrix::add_to( - const Cell_range& sourceColumn, Index targetColumnIndex) +template +inline std::enable_if_t > Matrix::add_to( + const Entry_range& sourceColumn, Index targetColumnIndex) { static_assert(!isNonBasic, "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain " @@ -1771,9 +1772,9 @@ inline std::enable_if_t > Matrix -template -inline std::enable_if_t > Matrix::multiply_target_and_add_to( - const Cell_range& sourceColumn, int coefficient, Index targetColumnIndex) +template +inline std::enable_if_t > Matrix::multiply_target_and_add_to( + const Entry_range& sourceColumn, int coefficient, Index targetColumnIndex) { static_assert(!isNonBasic, "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain " @@ -1801,9 +1802,9 @@ inline std::enable_if_t > Matrix -template -inline std::enable_if_t > Matrix::multiply_source_and_add_to( - int coefficient, const Cell_range& sourceColumn, Index targetColumnIndex) +template +inline std::enable_if_t > Matrix::multiply_source_and_add_to( + int coefficient, const Entry_range& sourceColumn, Index targetColumnIndex) { static_assert(!isNonBasic, "For boundary or chain matrices, only additions with columns inside the matrix is allowed to maintain " @@ -1818,16 +1819,16 @@ inline std::enable_if_t > Matrix -inline void Matrix::zero_cell(Index columnIndex, ID_index rowIndex) +inline void Matrix::zero_entry(Index columnIndex, ID_index rowIndex) { static_assert(PersistenceMatrixOptions::is_of_boundary_type && !PersistenceMatrixOptions::has_column_compression, - "'zero_cell' is not available for the chosen options."); + "'zero_entry' is not available for the chosen options."); - return matrix_.zero_cell(columnIndex, rowIndex); + return matrix_.zero_entry(columnIndex, rowIndex); } template -inline void Matrix::zero_cell(Index columnIndex, ID_index rowIndex, bool inR) +inline void Matrix::zero_entry(Index columnIndex, ID_index rowIndex, bool inR) { // TODO: I don't think there is a particular reason why the indexation is forced, should be removed. static_assert( @@ -1836,7 +1837,7 @@ inline void Matrix::zero_cell(Index columnIndex, ID_in PersistenceMatrixOptions::column_indexation_type != Column_indexation_types::IDENTIFIER, "Only enabled for RU matrices."); - return matrix_.zero_cell(columnIndex, rowIndex, inR); + return matrix_.zero_entry(columnIndex, rowIndex, inR); } template @@ -1862,13 +1863,13 @@ inline void Matrix::zero_column(Index columnIndex, boo } template -inline bool Matrix::is_zero_cell(Index columnIndex, ID_index rowIndex) +inline bool Matrix::is_zero_entry(Index columnIndex, ID_index rowIndex) { - return matrix_.is_zero_cell(columnIndex, rowIndex); + return matrix_.is_zero_entry(columnIndex, rowIndex); } template -inline bool Matrix::is_zero_cell(Index columnIndex, ID_index rowIndex, bool inR) const +inline bool Matrix::is_zero_entry(Index columnIndex, ID_index rowIndex, bool inR) const { // TODO: I don't think there is a particular reason why the indexation is forced, should be removed. static_assert( @@ -1877,7 +1878,7 @@ inline bool Matrix::is_zero_cell(Index columnIndex, ID PersistenceMatrixOptions::column_indexation_type != Column_indexation_types::IDENTIFIER, "Only enabled for RU matrices."); - return matrix_.is_zero_cell(columnIndex, rowIndex, inR); + return matrix_.is_zero_entry(columnIndex, rowIndex, inR); } template @@ -1901,14 +1902,14 @@ inline bool Matrix::is_zero_column(Index columnIndex, template inline typename Matrix::Index Matrix::get_column_with_pivot( - ID_index faceIndex) const + ID_index cellIndex) const { static_assert(isNonBasic && (!PersistenceMatrixOptions::is_of_boundary_type || (PersistenceMatrixOptions::has_vine_update || PersistenceMatrixOptions::can_retrieve_representative_cycles)), "'get_column_with_pivot' is not available for the chosen options."); - return matrix_.get_column_with_pivot(faceIndex); + return matrix_.get_column_with_pivot(cellIndex); } template diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h b/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h index 9eff178..0630aab 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h @@ -29,7 +29,7 @@ namespace persistence_matrix { * @ingroup persistence_matrix * * @brief A @ref basematrix "basic matrix" structure allowing to easily manipulate and access entire columns and rows, - * but not individual cells. + * but not individual entries. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. */ @@ -44,14 +44,14 @@ class Base_matrix : public Master_matrix::template Base_swap_option void insert_column(const Container& column); /** - * @brief Inserts a new ordered column at the given index by copying the given range of @ref Matrix::Cell_representative. + * @brief Inserts a new ordered column at the given index by copying the given range of + * @ref Matrix::Entry_representative. * There should not be any other column inserted at that index which was not explicitly removed before. * The content of the range is assumed to be sorted by increasing ID value. * Not available when row access is enabled. * - * @tparam Container Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param column Range of @ref Matrix::Cell_representative from which the column has to be constructed. Assumed to be + * @tparam Container Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() method. + * @param column Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to be * ordered by increasing ID value. * @param columnIndex @ref MatIdx index to which the column has to be inserted. */ @@ -125,9 +126,10 @@ class Base_matrix : public Master_matrix::template Base_swap_option @@ -136,7 +138,7 @@ class Base_matrix : public Master_matrix::template Base_swap_option - void add_to(const Cell_range_or_column_index& sourceColumn, Index targetColumnIndex); + template + void add_to(const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex); /** * @brief Multiplies the target column with the coefficient and then adds the source column to it. * That is: `targetColumn = (targetColumn * coefficient) + sourceColumn`. * - * @tparam Cell_range_or_column_index Either a range of @ref Cell with a begin() and end() method, + * @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method, * or any integer type. - * @param sourceColumn Either a cell range or the @ref MatIdx index of the column to add. + * @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add. * @param coefficient Value to multiply. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - void multiply_target_and_add_to(const Cell_range_or_column_index& sourceColumn, + template + void multiply_target_and_add_to(const Entry_range_or_column_index& sourceColumn, const Field_element& coefficient, Index targetColumnIndex); /** * @brief Multiplies the source column with the coefficient before adding it to the target column. * That is: `targetColumn += (coefficient * sourceColumn)`. The source column will **not** be modified. * - * @tparam Cell_range_or_column_index Either a range of @ref Cell with a begin() and end() method, + * @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method, * or any integer type. * @param coefficient Value to multiply. - * @param sourceColumn Either a cell range or the @ref MatIdx index of the column to add. + * @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template + template void multiply_source_and_add_to(const Field_element& coefficient, - const Cell_range_or_column_index& sourceColumn, + const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex); /** - * @brief Zeroes the cell at the given coordinates. + * @brief Zeroes the entry at the given coordinates. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. */ - void zero_cell(Index columnIndex, Index rowIndex); + void zero_entry(Index columnIndex, Index rowIndex); /** * @brief Zeroes the column at the given index. * @@ -265,14 +267,14 @@ class Base_matrix : public Master_matrix::template Base_swap_option >; using RA_opt = typename Master_matrix::Matrix_row_access_option; using Column_container = typename Master_matrix::Column_container; - using Cell_representative = + using Entry_representative = typename std::conditional @@ -330,7 +332,7 @@ class Base_matrix : public Master_matrix::template Base_swap_option void _insert(const Container& column, Index columnIndex, Dimension dim); @@ -513,11 +515,11 @@ inline typename Base_matrix::Index Base_matrix::ge } template -template -inline void Base_matrix::add_to(const Cell_range_or_column_index& sourceColumn, +template +inline void Base_matrix::add_to(const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex) { - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { _get_column(targetColumnIndex) += _get_column(sourceColumn); } else { _get_column(targetColumnIndex) += sourceColumn; @@ -525,12 +527,12 @@ inline void Base_matrix::add_to(const Cell_range_or_column_index& } template -template -inline void Base_matrix::multiply_target_and_add_to(const Cell_range_or_column_index& sourceColumn, +template +inline void Base_matrix::multiply_target_and_add_to(const Entry_range_or_column_index& sourceColumn, const Field_element& coefficient, Index targetColumnIndex) { - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { _get_column(targetColumnIndex).multiply_target_and_add(coefficient, _get_column(sourceColumn)); } else { _get_column(targetColumnIndex).multiply_target_and_add(coefficient, sourceColumn); @@ -538,12 +540,12 @@ inline void Base_matrix::multiply_target_and_add_to(const Cell_ra } template -template +template inline void Base_matrix::multiply_source_and_add_to(const Field_element& coefficient, - const Cell_range_or_column_index& sourceColumn, + const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex) { - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { _get_column(targetColumnIndex).multiply_source_and_add(_get_column(sourceColumn), coefficient); } else { _get_column(targetColumnIndex).multiply_source_and_add(sourceColumn, coefficient); @@ -551,7 +553,7 @@ inline void Base_matrix::multiply_source_and_add_to(const Field_e } template -inline void Base_matrix::zero_cell(Index columnIndex, Index rowIndex) +inline void Base_matrix::zero_entry(Index columnIndex, Index rowIndex) { _get_column(columnIndex).clear(_get_real_row_index(rowIndex)); } @@ -562,7 +564,7 @@ inline void Base_matrix::zero_column(Index columnIndex) { } template -inline bool Base_matrix::is_zero_cell(Index columnIndex, Index rowIndex) const +inline bool Base_matrix::is_zero_entry(Index columnIndex, Index rowIndex) const { return !(_get_column(columnIndex).is_non_zero(_get_real_row_index(rowIndex))); } @@ -613,9 +615,9 @@ inline void Base_matrix::print() if constexpr (Master_matrix::Option_list::has_row_access) { std::cout << "Row Matrix:\n"; for (Index i = 0; i < nextInsertIndex_; ++i) { - const auto& row = RA_opt::rows_[i]; - for (const auto& cell : row) { - std::cout << cell.get_column_index() << " "; + const auto& row = (*RA_opt::rows_)[i]; + for (const auto& entry : row) { + std::cout << entry.get_column_index() << " "; } std::cout << "(" << i << ")\n"; } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h b/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h index 009e016..cdb3efb 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h @@ -45,18 +45,18 @@ template class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_access_option { public: - using Index = typename Master_matrix::Index; /**< Container index type. */ - using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ + using Index = typename Master_matrix::Index; /**< Container index type. */ + using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ /** * @brief Field operators class. Necessary only if @ref PersistenceMatrixOptions::is_z2 is false. */ using Field_operators = typename Master_matrix::Field_operators; - using Field_element = typename Master_matrix::Element; /**< Field element value type. */ - using Row = typename Master_matrix::Row; /**< Row type, - only necessary with row access option. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ - using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to - necessary external classes. */ + using Field_element = typename Master_matrix::Element; /**< Field element value type. */ + using Row = typename Master_matrix::Row; /**< Row type, + only necessary with row access option. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ + using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to + necessary external classes. */ /** * @brief Type for columns. Only one for each "column class" is explicitly constructed. @@ -119,9 +119,9 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ * If no identical column already existed, a copy of the column is stored. If an identical one existed, no new * column is constructed and the relationship between the two is registered in an union-find structure. * - * @tparam Container Range type for @ref Matrix::Cell_representative ranges. + * @tparam Container Range type for @ref Matrix::Entry_representative ranges. * Assumed to have a begin(), end() and size() method. - * @param columns A vector of @ref Matrix::Cell_representative ranges to construct the columns from. + * @param columns A vector of @ref Matrix::Entry_representative ranges to construct the columns from. * The content of the ranges are assumed to be sorted by increasing ID value. * @param colSettings Pointer to an existing setting structure for the columns. The structure should contain all * the necessary external classes specifically necessary for the choosen column type, such as custom allocators. @@ -162,10 +162,10 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ /** * @brief Inserts a new ordered column at the end of the matrix by copying the given range of - * @ref Matrix::Cell_representative. The content of the range is assumed to be sorted by increasing ID value. + * @ref Matrix::Entry_representative. The content of the range is assumed to be sorted by increasing ID value. * - * @tparam Container Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param column Range of @ref Matrix::Cell_representative from which the column has to be constructed. Assumed to be + * @tparam Container Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() method. + * @param column Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to be * ordered by increasing ID value. */ template @@ -173,9 +173,10 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ /** * @brief Same as @ref insert_column, only for interface purposes. The given dimension is ignored and not stored. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param boundary Range of @ref Matrix::Cell_representative from which the column has to be constructed. Assumed to be - * ordered by increasing ID value. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. + * @param boundary Range of @ref Matrix::Entry_representative from which the column has to be constructed. Assumed to + * be ordered by increasing ID value. * @param dim Ignored. */ template @@ -205,11 +206,11 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ * @brief If @ref PersistenceMatrixOptions::has_row_access and @ref PersistenceMatrixOptions::has_removable_rows * are true: assumes that the row is empty and removes it. Otherwise, does nothing. * - * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row cells are not + * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not * removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when - * the column cells are destroyed later. The row access is just meant as a "read only" access to the rows and the + * the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the * @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from - * dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can be + * dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be * quite frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row. @@ -229,13 +230,13 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ * The representatives of redundant columns are summed together, which means that * all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range_or_column_index Either a range of @ref Cell with a begin() and end() method, + * @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method, * or any integer type. - * @param sourceColumn Either a cell range or the @ref MatIdx index of the column to add. + * @param sourceColumn Either an entry range or the @ref MatIdx index of the column to add. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - void add_to(const Cell_range_or_column_index& sourceColumn, Index targetColumnIndex); + template + void add_to(const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex); /** * @brief Multiplies the target column with the coefficient and then adds the source column to it. * That is: `targetColumn = (targetColumn * coefficient) + sourceColumn`. @@ -243,14 +244,14 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ * The representatives of redundant columns are summed together, which means that * all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range_or_column_index Either a range of @ref Cell with a begin() and end() method, + * @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method, * or any integer type. - * @param sourceColumn Either a @ref Cell range or the @ref MatIdx index of the column to add. + * @param sourceColumn Either a @ref Entry range or the @ref MatIdx index of the column to add. * @param coefficient Value to multiply. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template - void multiply_target_and_add_to(const Cell_range_or_column_index& sourceColumn, + template + void multiply_target_and_add_to(const Entry_range_or_column_index& sourceColumn, const Field_element& coefficient, Index targetColumnIndex); /** @@ -260,26 +261,26 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ * The representatives of redundant columns are summed together, which means that * all column compressed together with the target column are affected by the change, not only the target. * - * @tparam Cell_range_or_column_index Either a range of @ref Cell with a begin() and end() method, + * @tparam Entry_range_or_column_index Either a range of @ref Entry with a begin() and end() method, * or any integer type. * @param coefficient Value to multiply. - * @param sourceColumn Either a @ref Cell range or the @ref MatIdx index of the column to add. + * @param sourceColumn Either a @ref Entry range or the @ref MatIdx index of the column to add. * @param targetColumnIndex @ref MatIdx index of the target column. */ - template + template void multiply_source_and_add_to(const Field_element& coefficient, - const Cell_range_or_column_index& sourceColumn, + const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, Index rowIndex); + bool is_zero_entry(Index columnIndex, Index rowIndex); /** * @brief Indicates if the column at given index has value zero. * @@ -292,7 +293,7 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ /** * @brief Resets the matrix to an empty matrix. * - * @param colSettings Pointer to the cell factory. + * @param colSettings Pointer to the entry factory. */ void reset(Column_settings* colSettings) { columnToRep_.clear_and_dispose(Delete_disposer(this)); @@ -346,7 +347,7 @@ class Base_matrix_with_column_compression : protected Master_matrix::Matrix_row_ std::vector repToColumn_; /**< Map from the representative index to the representative Column. */ Index nextColumnIndex_; /**< Next unused column index. */ - Column_settings* colSettings_; /**< Cell factory. */ + Column_settings* colSettings_; /**< Entry factory. */ /** * @brief Column factory. Has to be a pointer as Simple_object_pool is not swappable, so their addresses have to be * exchanged instead. @@ -519,15 +520,15 @@ Base_matrix_with_column_compression::get_number_of_columns() cons } template -template -inline void Base_matrix_with_column_compression::add_to(const Cell_range_or_column_index& sourceColumn, +template +inline void Base_matrix_with_column_compression::add_to(const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex) { // handle case where targetRep == sourceRep? Index targetRep = columnClasses_.find_set(targetColumnIndex); Column& target = *repToColumn_[targetRep]; columnToRep_.erase(target); - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { target += get_column(sourceColumn); } else { target += sourceColumn; @@ -536,15 +537,15 @@ inline void Base_matrix_with_column_compression::add_to(const Cel } template -template +template inline void Base_matrix_with_column_compression::multiply_target_and_add_to( - const Cell_range_or_column_index& sourceColumn, const Field_element& coefficient, Index targetColumnIndex) + const Entry_range_or_column_index& sourceColumn, const Field_element& coefficient, Index targetColumnIndex) { // handle case where targetRep == sourceRep? Index targetRep = columnClasses_.find_set(targetColumnIndex); Column& target = *repToColumn_[targetRep]; columnToRep_.erase(target); - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { target.multiply_target_and_add(coefficient, get_column(sourceColumn)); } else { target.multiply_target_and_add(coefficient, sourceColumn); @@ -553,15 +554,15 @@ inline void Base_matrix_with_column_compression::multiply_target_ } template -template +template inline void Base_matrix_with_column_compression::multiply_source_and_add_to( - const Field_element& coefficient, const Cell_range_or_column_index& sourceColumn, Index targetColumnIndex) + const Field_element& coefficient, const Entry_range_or_column_index& sourceColumn, Index targetColumnIndex) { // handle case where targetRep == sourceRep? Index targetRep = columnClasses_.find_set(targetColumnIndex); Column& target = *repToColumn_[targetRep]; columnToRep_.erase(target); - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { target.multiply_source_and_add(get_column(sourceColumn), coefficient); } else { target.multiply_source_and_add(sourceColumn, coefficient); @@ -570,7 +571,7 @@ inline void Base_matrix_with_column_compression::multiply_source_ } template -inline bool Base_matrix_with_column_compression::is_zero_cell(Index columnIndex, Index rowIndex) +inline bool Base_matrix_with_column_compression::is_zero_entry(Index columnIndex, Index rowIndex) { auto col = repToColumn_[columnClasses_.find_set(columnIndex)]; if (col == nullptr) return true; @@ -636,8 +637,8 @@ inline void Base_matrix_with_column_compression::print() std::cout << "Row Matrix:\n"; for (Index i = 0; i < RA_opt::rows_->size(); ++i) { const Row& row = RA_opt::rows_[i]; - for (const auto& cell : row) { - std::cout << cell.get_column_index() << " "; + for (const auto& entry : row) { + std::cout << entry.get_column_index() << " "; } std::cout << "(" << i << ")\n"; } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h b/multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h index e9f6b07..4ffb3fb 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h @@ -32,7 +32,7 @@ namespace persistence_matrix { * * @brief %Matrix structure to store the ordered @ref boundarymatrix "boundary matrix" \f$ R \f$ of a filtered complex * in order to compute its persistent homology. Provides an access to its columns and rows as well as the possibility - * to remove the last faces of the filtration while maintaining a valid barcode. + * to remove the last cells of the filtration while maintaining a valid barcode. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. */ @@ -50,14 +50,14 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, * @brief Field operators class. Necessary only if @ref PersistenceMatrixOptions::is_z2 is false. */ using Field_operators = typename Master_matrix::Field_operators; - using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ - using Column = typename Master_matrix::Column; /**< Column type. */ - using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ - using Row = typename Master_matrix::Row; /**< Row type, - only necessary with row access option. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ - using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to - necessary external classes. */ + using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ + using Column = typename Master_matrix::Column; /**< Column type. */ + using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ + using Row = typename Master_matrix::Row; /**< Row type, + only necessary with row access option. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ + using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to + necessary external classes. */ /** * @brief Constructs an empty matrix. @@ -67,11 +67,12 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, */ Boundary_matrix(Column_settings* colSettings); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. * - * @tparam Boundary_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -119,51 +120,53 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other - * @ref insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" - * instead by indicating the face ID used in the boundaries when the face is inserted. + * @ref insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" + * instead by indicating the cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * At the insertion, the boundary will be copied as is. The column will only be reduced later when the barcode * is requested in order to apply some optimizations with the additional knowledge. Hence, the barcode will also * not be updated, so call @ref Base_pairing::get_current_barcode "get_current_barcode" only when the matrix is * complete. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return The @ref MatIdx index of the inserted boundary. */ template Index insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** - * @brief It does the same as the other version, but allows the boundary faces to be identified without restrictions + * @brief It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * the faces are inserted by order of filtration), it is sufficient to indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param faceIndex @ref IDIdx index to use to identify the new face. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. + * @param cellIndex @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceIndex values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellIndex values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return The @ref MatIdx index of the inserted boundary. */ template - Index insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim = -1); + Index insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim = -1); /** * @brief Returns the column at the given @ref MatIdx index. * The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type. * - * Note that before returning the column, all column cells can eventually be reordered, if lazy swaps occurred. + * Note that before returning the column, all column entries can eventually be reordered, if lazy swaps occurred. * It is therefore recommended to avoid calling @ref get_column between column or row swaps, otherwise the benefits * of the the laziness is lost. * @@ -176,7 +179,7 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, * Returns the row at the given @ref rowindex "row index" of the matrix. * The type of the row depends on the choosen options, see @ref PersistenceMatrixOptions::has_intrusive_rows. * - * Note that before returning the row, all column cells can eventually be reordered, if lazy swaps occurred. + * Note that before returning the row, all column entries can eventually be reordered, if lazy swaps occurred. * It is therefore recommended to avoid calling @ref get_row between column or row swaps, otherwise the benefits * of the the laziness is lost. * @@ -186,9 +189,9 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, Row& get_row(Index rowIndex); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns is true. - * Removes the last face in the filtration from the matrix and updates the barcode if this one was already computed. + * Removes the last cell in the filtration from the matrix and updates the barcode if this one was already computed. * - * @return The pivot of the removed face. + * @return The pivot of the removed cell. */ Index remove_last(); /** @@ -197,11 +200,11 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, * and @ref PersistenceMatrixOptions::has_column_and_row_swaps are true: cleans up maps used for the lazy row swaps. * Otherwise, does nothing. * - * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row cells are not + * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not * removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when - * the column cells are destroyed later. The row access is just meant as a "read only" access to the rows and the + * the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the * @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from - * dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can be + * dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be * quite frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row. @@ -218,8 +221,8 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, /** * @brief Returns the dimension of the given column. * - * @param columnIndex @ref MatIdx index of the column representing the face. - * @return Dimension of the face. + * @param columnIndex @ref MatIdx index of the column representing the cell. + * @return Dimension of the cell. */ Dimension get_column_dimension(Index columnIndex) const; @@ -266,15 +269,15 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, Index targetColumnIndex); /** - * @brief Zeroes the cell at the given coordinates. + * @brief Zeroes the entry at the given coordinates. * * @warning They will be no verification to ensure that the zeroing makes sense for the validity of a * boundary matrix of a filtered complex. So should be used while knowing what one is doing. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. */ - void zero_cell(Index columnIndex, Index rowIndex); + void zero_entry(Index columnIndex, Index rowIndex); /** * @brief Zeroes the column at the given index. * @@ -285,14 +288,14 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, */ void zero_column(Index columnIndex); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, Index rowIndex) const; + bool is_zero_entry(Index columnIndex, Index rowIndex) const; /** * @brief Indicates if the column at given index has value zero. * @@ -358,9 +361,9 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option, friend Swap_opt; friend Pair_opt; - Column_container matrix_; /**< Column container. */ - Index nextInsertIndex_; /**< Next unused column index. */ - Column_settings* colSettings_; /**< Cell factory. */ + Column_container matrix_; /**< Column container. */ + Index nextInsertIndex_; /**< Next unused column index. */ + Column_settings* colSettings_; /**< Entry factory. */ static constexpr bool activeDimOption = Master_matrix::Option_list::has_matrix_maximal_dimension_access || Master_matrix::maxDimensionIsNeeded; @@ -466,7 +469,7 @@ inline typename Boundary_matrix::Index Boundary_matrix template inline typename Boundary_matrix::Index Boundary_matrix::insert_boundary( - ID_index faceIndex, const Boundary_range& boundary, Dimension dim) + ID_index cellIndex, const Boundary_range& boundary, Dimension dim) { if (dim == -1) dim = boundary.size() == 0 ? 0 : boundary.size() - 1; @@ -489,12 +492,12 @@ inline typename Boundary_matrix::Index Boundary_matrix::Index Boundary_matrix::multiply_source_and_add_to(const Fie } template -inline void Boundary_matrix::zero_cell(Index columnIndex, Index rowIndex) +inline void Boundary_matrix::zero_entry(Index columnIndex, Index rowIndex) { _get_column(columnIndex).clear(_get_real_row_index(rowIndex)); } @@ -662,7 +665,7 @@ inline void Boundary_matrix::zero_column(Index columnIndex) } template -inline bool Boundary_matrix::is_zero_cell(Index columnIndex, Index rowIndex) const +inline bool Boundary_matrix::is_zero_entry(Index columnIndex, Index rowIndex) const { return !(_get_column(columnIndex).is_non_zero(_get_real_row_index(rowIndex))); } @@ -726,9 +729,9 @@ inline void Boundary_matrix::print() if constexpr (Master_matrix::Option_list::has_row_access) { std::cout << "Row Matrix:\n"; for (ID_index i = 0; i < nextInsertIndex_; ++i) { - const auto& row = RA_opt::rows_[i]; - for (const auto& cell : row) { - std::cout << cell.get_column_index() << " "; + const auto& row = (*RA_opt::rows_)[i]; + for (const typename Column::Entry& entry : row) { + std::cout << entry.get_column_index() << " "; } std::cout << "(" << i << ")\n"; } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h b/multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h index c1f0af1..7611990 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h @@ -35,9 +35,9 @@ namespace persistence_matrix { * @ingroup persistence_matrix * * @brief %Matrix structure storing a compatible base of a filtered chain complex. See @cite zigzag. - * The base is constructed from the boundaries of the faces in the complex. Allows the persistent homology to be + * The base is constructed from the boundaries of the cells in the complex. Allows the persistent homology to be * computed, as well as representative cycles. Supports vineyards (see @cite vineyards) and the removal - * of maximal faces while maintaining a valid barcode. Provides an access to its columns and rows. + * of maximal cells while maintaining a valid barcode. Provides an access to its columns and rows. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. */ @@ -57,12 +57,12 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, using Column = typename Master_matrix::Column; /**< Column type. */ using Row = typename Master_matrix::Row; /**< Row type, only necessary with row access option. */ - using Cell = typename Master_matrix::Matrix_cell; /**< @ref Cell "Matrix cell" type. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ + using Entry = typename Master_matrix::Matrix_entry; /**< @ref Entry "Matrix entry" type. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to necessary external classes. */ using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ - using Cell_representative = typename Master_matrix::Cell_representative; /**< %Cell content representative. */ + using Entry_representative = typename Master_matrix::Entry_representative; /**< %Entry content representative. */ using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */ @@ -78,14 +78,14 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, */ Chain_matrix(Column_settings* colSettings); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. - * Only available if @ref PersistenceMatrixOptions::has_column_pairings is true or + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. Only available if @ref PersistenceMatrixOptions::has_column_pairings is true or * @ref PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death * comparators have to be provided. * - * @tparam Boundary_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -140,9 +140,10 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, const BirthComparatorFunction& birthComparator, const DeathComparatorFunction& deathComparator); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. * * @warning If @ref PersistenceMatrixOptions::has_vine_update is false, the comparators are not used. * And if @ref PersistenceMatrixOptions::has_vine_update is true, but @@ -151,7 +152,7 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * * @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_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -227,44 +228,48 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other - * @ref insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" - * instead by indicating the face ID used in the boundaries when the face is inserted. + * @ref insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) "insert_boundary" + * instead by indicating the cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * When inserted, the given boundary is reduced and from the reduction process, the column is deduced in the form of: * `IDIdx + linear combination of older column IDIdxs`. If the barcode is stored, it will be updated. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return The @ref MatIdx indices of the unpaired chains used to reduce the boundary. */ template - std::vector insert_boundary(const Boundary_range& boundary, Dimension dim = -1); + std::vector insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** - * @brief It does the same as the other version, but allows the boundary faces to be identified without restrictions + * @brief It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * the faces are inserted by order of filtration), it is sufficient to indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param faceID @ref IDIdx index to use to identify the new face. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. + * @param cellID @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceID values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellID values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. * @return The @ref MatIdx index of the inserted boundary. */ template - std::vector insert_boundary(ID_index faceID, const Boundary_range& boundary, Dimension dim = -1); + std::vector insert_boundary(ID_index cellID, + const Boundary_range& boundary, + Dimension dim = -1); /** * @brief Returns the column at the given @ref MatIdx index. * The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type. @@ -285,9 +290,9 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns and * @ref PersistenceMatrixOptions::has_vine_update are true, as well as, * @ref PersistenceMatrixOptions::has_map_column_container and @ref PersistenceMatrixOptions::has_column_pairings. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., the matrix is still a compatible bases of the chain complex in the sense of @cite zigzag). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it is stored. * * Note that using the other version of the method could perform better depending on how the data is @@ -295,46 +300,46 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, * * See also @ref remove_last. * - * @param faceID @ref IDIdx index of the face to remove + * @param cellID @ref IDIdx index of the cell to remove */ - void remove_maximal_face(ID_index faceID); + void remove_maximal_cell(ID_index cellID); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns, * @ref PersistenceMatrixOptions::has_vine_update and @ref PersistenceMatrixOptions::has_map_column_container * are true. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., it is still a compatible bases of the chain complex in the sense of @cite zigzag). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it is stored. * - * To maintain the compatibility, vine swaps are done to move the face up to the end of the filtration. Once at + * To maintain the compatibility, vine swaps are done to move the cell up to the end of the filtration. Once at * the end, the removal is trivial. But for @ref chainmatrix "chain matrices", swaps do not actually swap the position - * of the column every time, so the faces appearing after @p faceID in the filtration have to be searched first within - * the matrix. If the user has an easy access to the @ref IDIdx of the faces in the order of filtration, passing them + * of the column every time, so the cells appearing after @p cellID in the filtration have to be searched first within + * the matrix. If the user has an easy access to the @ref IDIdx of the cells in the order of filtration, passing them * by argument with @p columnsToSwap allows to skip a linear search process. Typically, if the user knows that the - * face he wants to remove is already the last face of the filtration, calling - * @ref remove_maximal_face(ID_index faceIndex, const std::vector& columnsToSwap) - * "remove_maximal_face(faceID, {})" will be faster than @ref remove_last(). + * cell he wants to remove is already the last cell of the filtration, calling + * @ref remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap) + * "remove_maximal_cell(cellID, {})" will be faster than @ref remove_last(). * * See also @ref remove_last. * - * @param faceID @ref IDIdx index of the face to remove - * @param columnsToSwap Vector of @ref IDIdx indices of the faces coming after @p faceID in the filtration. + * @param cellID @ref IDIdx index of the cell to remove + * @param columnsToSwap Vector of @ref IDIdx indices of the cells coming after @p cellID in the filtration. */ - void remove_maximal_face(ID_index faceID, const std::vector& columnsToSwap); + void remove_maximal_cell(ID_index cellID, const std::vector& columnsToSwap); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns is true and, * if @ref PersistenceMatrixOptions::has_map_column_container is true or * @ref PersistenceMatrixOptions::has_vine_update is false. - * Removes the last face in the filtration from the matrix and updates the barcode if it is stored. + * Removes the last cell in the filtration from the matrix and updates the barcode if it is stored. * - * See also @ref remove_maximal_face. + * See also @ref remove_maximal_cell. * - * @warning If @ref PersistenceMatrixOptions::has_vine_update is true, the last face does not have to + * @warning If @ref PersistenceMatrixOptions::has_vine_update is true, the last cell does not have to * be at the end of the matrix container and therefore has to be searched first. In this case, if the user - * already knows the @ref IDIdx of the last face, calling - * @ref remove_maximal_face(ID_index faceIndex, const std::vector& columnsToSwap) - * "remove_maximal_face(faceID, {})" instead allows to skip the search. + * already knows the @ref IDIdx of the last cell, calling + * @ref remove_maximal_cell(ID_index cellIndex, const std::vector& columnsToSwap) + * "remove_maximal_cell(cellID, {})" instead allows to skip the search. */ void remove_last(); @@ -348,8 +353,8 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, /** * @brief Returns the dimension of the given column. * - * @param columnIndex @ref MatIdx index of the column representing the face. - * @return Dimension of the face. + * @param columnIndex @ref MatIdx index of the column representing the cell. + * @return Dimension of the cell. */ Dimension get_column_dimension(Index columnIndex) const; @@ -396,14 +401,14 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, Index targetColumnIndex); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, ID_index rowIndex) const; + bool is_zero_entry(Index columnIndex, ID_index rowIndex) const; /** * @brief Indicates if the column at given index has value zero. Note that if the matrix is valid, this method * should always return false. @@ -417,10 +422,10 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, /** * @brief Returns the column with given @ref rowindex "row index" as pivot. Assumes that the pivot exists. * - * @param faceID @ref rowindex "Row index" of the pivot. + * @param cellID @ref rowindex "Row index" of the pivot. * @return @ref MatIdx index of the column with the given pivot. */ - Index get_column_with_pivot(ID_index faceID) const; + Index get_column_with_pivot(ID_index cellID) const; /** * @brief Returns the @ref rowindex "row index" of the pivot of the given column. * @@ -491,14 +496,14 @@ class Chain_matrix : public Master_matrix::Matrix_dimension_option, Column_container matrix_; /**< Column container. */ Dictionary pivotToColumnIndex_; /**< Map from @ref IDIdx to @ref MatIdx index. */ Index nextIndex_; /**< Next unused column index. */ - Column_settings* colSettings_; /**< Cell factory. */ + Column_settings* colSettings_; /**< Entry factory. */ template - std::vector _reduce_boundary(ID_index faceID, const Boundary_range& boundary, Dimension dim); - void _reduce_by_G(Tmp_column& column, std::vector& chainsInH, Index currentPivot); - void _reduce_by_F(Tmp_column& column, std::vector& chainsInF, Index currentPivot); - void _build_from_H(ID_index faceID, Tmp_column& column, std::vector& chainsInH); - void _update_largest_death_in_F(const std::vector& chainsInF); + std::vector _reduce_boundary(ID_index cellID, const Boundary_range& boundary, Dimension dim); + void _reduce_by_G(Tmp_column& column, std::vector& chainsInH, Index currentPivot); + void _reduce_by_F(Tmp_column& column, std::vector& chainsInF, Index currentPivot); + void _build_from_H(ID_index cellID, Tmp_column& column, std::vector& chainsInH); + void _update_largest_death_in_F(const std::vector& chainsInF); void _insert_chain(const Tmp_column& column, Dimension dimension); void _insert_chain(const Tmp_column& column, Dimension dimension, Index pair); void _add_to(const Column& column, Tmp_column& set, unsigned int coef); @@ -667,7 +672,7 @@ inline Chain_matrix::Chain_matrix(Chain_matrix&& other) noexcept template template -inline std::vector Chain_matrix::insert_boundary( +inline std::vector Chain_matrix::insert_boundary( const Boundary_range& boundary, Dimension dim) { return insert_boundary(nextIndex_, boundary, dim); @@ -675,22 +680,22 @@ inline std::vector Chain_matrix template -inline std::vector Chain_matrix::insert_boundary( - ID_index faceID, const Boundary_range& boundary, Dimension dim) +inline std::vector Chain_matrix::insert_boundary( + ID_index cellID, const Boundary_range& boundary, Dimension dim) { if constexpr (!Master_matrix::Option_list::has_map_column_container) { - if (pivotToColumnIndex_.size() <= faceID) { - pivotToColumnIndex_.resize(faceID * 2 + 1, -1); + if (pivotToColumnIndex_.size() <= cellID) { + pivotToColumnIndex_.resize(cellID * 2 + 1, -1); } } if constexpr (Master_matrix::Option_list::has_vine_update && Master_matrix::Option_list::has_column_pairings) { if constexpr (Master_matrix::Option_list::has_map_column_container) { - Swap_opt::CP::pivotToPosition_.try_emplace(faceID, _nextPosition()); + Swap_opt::CP::pivotToPosition_.try_emplace(cellID, _nextPosition()); } else { - if (Swap_opt::CP::pivotToPosition_.size() <= faceID) + if (Swap_opt::CP::pivotToPosition_.size() <= cellID) Swap_opt::CP::pivotToPosition_.resize(pivotToColumnIndex_.size(), -1); - Swap_opt::CP::pivotToPosition_[faceID] = _nextPosition(); + Swap_opt::CP::pivotToPosition_[cellID] = _nextPosition(); } } @@ -698,7 +703,7 @@ inline std::vector Chain_matrix(-1) ? (boundary.size() == 0 ? 0 : boundary.size() - 1) : dim); } - return _reduce_boundary(faceID, boundary, dim); + return _reduce_boundary(cellID, boundary, dim); } template @@ -723,22 +728,22 @@ inline const typename Chain_matrix::Column& Chain_matrix -inline void Chain_matrix::remove_maximal_face(ID_index faceID) +inline void Chain_matrix::remove_maximal_cell(ID_index cellID) { static_assert(Master_matrix::Option_list::has_removable_columns, - "'remove_maximal_face' is not implemented for the chosen options."); + "'remove_maximal_cell' is not implemented for the chosen options."); static_assert(Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_vine_update && Master_matrix::Option_list::has_column_pairings, - "'remove_maximal_face' is not implemented for the chosen options."); + "'remove_maximal_cell' is not implemented for the chosen options."); // TODO: find simple test to verify that col at columnIndex is maximal even without row access. const auto& pivotToPosition = Swap_opt::CP::pivotToPosition_; - auto it = pivotToPosition.find(faceID); - if (it == pivotToPosition.end()) return; // face does not exists. TODO: put an assert instead? + auto it = pivotToPosition.find(cellID); + if (it == pivotToPosition.end()) return; // cell does not exists. TODO: put an assert instead? Pos_index startPos = it->second; - Index startIndex = pivotToColumnIndex_.at(faceID); + Index startIndex = pivotToColumnIndex_.at(cellID); if (startPos != _nextPosition() - 1) { std::vector colToSwap; @@ -760,17 +765,17 @@ inline void Chain_matrix::remove_maximal_face(ID_index faceID) } template -inline void Chain_matrix::remove_maximal_face(ID_index faceID, +inline void Chain_matrix::remove_maximal_cell(ID_index cellID, const std::vector& columnsToSwap) { static_assert(Master_matrix::Option_list::has_removable_columns, - "'remove_maximal_face' is not implemented for the chosen options."); + "'remove_maximal_cell' is not implemented for the chosen options."); static_assert(Master_matrix::Option_list::has_map_column_container && Master_matrix::Option_list::has_vine_update, - "'remove_maximal_face' is not implemented for the chosen options."); + "'remove_maximal_cell' is not implemented for the chosen options."); // TODO: find simple test to verify that col at columnIndex is maximal even without row access. - Index startIndex = pivotToColumnIndex_.at(faceID); + Index startIndex = pivotToColumnIndex_.at(cellID); for (ID_index i : columnsToSwap) { startIndex = Swap_opt::vine_swap(startIndex, pivotToColumnIndex_.at(i)); @@ -792,7 +797,7 @@ inline void Chain_matrix::remove_last() if constexpr (Master_matrix::Option_list::has_vine_update) { // careful: linear because of the search of the last index. It is better to keep track of the @ref IDIdx index // of the last column while performing swaps (or the @ref MatIdx with the return values of `vine_swap` + get_pivot) - // and then call `remove_maximal_face` with it and an empty `columnsToSwap`. + // and then call `remove_maximal_cell` with it and an empty `columnsToSwap`. ID_index pivot = 0; Index colIndex = 0; @@ -851,7 +856,7 @@ inline void Chain_matrix::multiply_source_and_add_to(const Field_ } template -inline bool Chain_matrix::is_zero_cell(Index columnIndex, ID_index rowIndex) const +inline bool Chain_matrix::is_zero_entry(Index columnIndex, ID_index rowIndex) const { return !get_column(columnIndex).is_non_zero(rowIndex); } @@ -864,12 +869,12 @@ inline bool Chain_matrix::is_zero_column(Index columnIndex) template inline typename Chain_matrix::Index Chain_matrix::get_column_with_pivot( - ID_index faceID) const + ID_index cellID) const { if constexpr (Master_matrix::Option_list::has_map_column_container) { - return pivotToColumnIndex_.at(faceID); + return pivotToColumnIndex_.at(cellID); } else { - return pivotToColumnIndex_[faceID]; + return pivotToColumnIndex_[cellID]; } } @@ -911,8 +916,8 @@ inline void Chain_matrix::print() const for (ID_index i = 0; i < pivotToColumnIndex_.size() && pivotToColumnIndex_[i] != static_cast(-1); ++i) { Index pos = pivotToColumnIndex_[i]; const Column& col = matrix_[pos]; - for (const auto& cell : col) { - std::cout << cell.get_row_index() << " "; + for (const auto& entry : col) { + std::cout << entry.get_row_index() << " "; } std::cout << "(" << i << ", " << pos << ")\n"; } @@ -922,8 +927,8 @@ inline void Chain_matrix::print() const for (ID_index i = 0; i < pivotToColumnIndex_.size() && pivotToColumnIndex_[i] != static_cast(-1); ++i) { Index pos = pivotToColumnIndex_[i]; const Row& row = RA_opt::get_row(pos); - for (const auto& cell : row) { - std::cout << cell.get_column_index() << " "; + for (const auto& entry : row) { + std::cout << entry.get_column_index() << " "; } std::cout << "(" << i << ", " << pos << ")\n"; } @@ -931,8 +936,8 @@ inline void Chain_matrix::print() const } else { for (const auto& p : pivotToColumnIndex_) { const Column& col = matrix_.at(p.second); - for (const auto& cell : col) { - std::cout << cell.get_row_index() << " "; + for (const auto& entry : col) { + std::cout << entry.get_row_index() << " "; } std::cout << "(" << p.first << ", " << p.second << ")\n"; } @@ -941,8 +946,8 @@ inline void Chain_matrix::print() const std::cout << "Row Matrix:\n"; for (const auto& p : pivotToColumnIndex_) { const Row& row = RA_opt::get_row(p.first); - for (const auto& cell : row) { - std::cout << cell.get_column_index() << " "; + for (const auto& entry : row) { + std::cout << entry.get_column_index() << " "; } std::cout << "(" << p.first << ", " << p.second << ")\n"; } @@ -953,13 +958,13 @@ inline void Chain_matrix::print() const template template -inline std::vector Chain_matrix::_reduce_boundary( - ID_index faceID, const Boundary_range& boundary, Dimension dim) +inline std::vector Chain_matrix::_reduce_boundary( + ID_index cellID, const Boundary_range& boundary, Dimension dim) { Tmp_column column(boundary.begin(), boundary.end()); if (dim == static_cast(-1)) dim = boundary.begin() == boundary.end() ? 0 : boundary.size() - 1; - std::vector chainsInH; // for corresponding indices in H (paired columns) - std::vector chainsInF; // for corresponding indices in F (unpaired, essential columns) + std::vector chainsInH; // for corresponding indices in H (paired columns) + std::vector chainsInF; // for corresponding indices in F (unpaired, essential columns) auto get_last = [&column]() { if constexpr (Master_matrix::Option_list::is_z2) @@ -970,9 +975,9 @@ inline std::vector Chain_matrix Chain_matrix Chain_matrix Chain_matrix inline void Chain_matrix::_reduce_by_G(Tmp_column& column, - std::vector& chainsInH, + std::vector& chainsInH, Index currentIndex) { Column& col = get_column(currentIndex); @@ -1040,7 +1045,7 @@ inline void Chain_matrix::_reduce_by_G(Tmp_column& column, template inline void Chain_matrix::_reduce_by_F(Tmp_column& column, - std::vector& chainsInF, + std::vector& chainsInF, Index currentIndex) { Column& col = get_column(currentIndex); @@ -1059,17 +1064,17 @@ inline void Chain_matrix::_reduce_by_F(Tmp_column& column, } template -inline void Chain_matrix::_build_from_H(ID_index faceID, +inline void Chain_matrix::_build_from_H(ID_index cellID, Tmp_column& column, - std::vector& chainsInH) + std::vector& chainsInH) { if constexpr (Master_matrix::Option_list::is_z2) { - column.insert(faceID); + column.insert(cellID); for (Index idx_h : chainsInH) { _add_to(get_column(idx_h), column, 1u); } } else { - column.emplace(faceID, 1); + column.emplace(cellID, 1); for (std::pair& idx_h : chainsInH) { _add_to(get_column(idx_h.first), column, idx_h.second); } @@ -1077,7 +1082,7 @@ inline void Chain_matrix::_build_from_H(ID_index faceID, } template -inline void Chain_matrix::_update_largest_death_in_F(const std::vector& chainsInF) +inline void Chain_matrix::_update_largest_death_in_F(const std::vector& chainsInF) { if constexpr (Master_matrix::Option_list::is_z2) { Index toUpdate = chainsInF[0]; @@ -1131,20 +1136,20 @@ inline void Chain_matrix::_add_to(const Column& column, { if constexpr (Master_matrix::Option_list::is_z2) { std::pair::iterator, bool> res_insert; - for (const Cell& cell : column) { - res_insert = set.insert(cell.get_row_index()); + for (const Entry& entry : column) { + res_insert = set.insert(entry.get_row_index()); if (!res_insert.second) { set.erase(res_insert.first); } } } else { auto& operators = colSettings_->operators; - for (const Cell& cell : column) { - auto res = set.emplace(cell.get_row_index(), cell.get_element()); + for (const Entry& entry : column) { + auto res = set.emplace(entry.get_row_index(), entry.get_element()); if (res.second){ operators.multiply_inplace(res.first->second, coef); } else { - operators.multiply_and_add_inplace_back(cell.get_element(), coef, res.first->second); + operators.multiply_and_add_inplace_back(entry.get_element(), coef, res.first->second); if (res.first->second == Field_operators::get_additive_identity()) { set.erase(res.first); } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h b/multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h index b539308..be885d1 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h @@ -41,25 +41,25 @@ template class Id_to_index_overlay { public: - using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ - using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ - using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */ - using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ + using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ + using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ + using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */ + using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ /** * @brief Field operators class. Necessary only if @ref PersistenceMatrixOptions::is_z2 is false. */ using Field_operators = typename Master_matrix::Field_operators; - using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ - using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ - using Column = typename Master_matrix::Column; /**< Column type. */ - using Row = typename Master_matrix::Row; /**< Row type, - only necessary with row access option. */ - using Bar = typename Master_matrix::Bar; /**< Bar type. */ - using Barcode = typename Master_matrix::Barcode; /**< Barcode type. */ - using Cycle = typename Master_matrix::Cycle; /**< Cycle type. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ - using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to - necessary external classes. */ + using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ + using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ + using Column = typename Master_matrix::Column; /**< Column type. */ + using Row = typename Master_matrix::Row; /**< Row type, + only necessary with row access option. */ + using Bar = typename Master_matrix::Bar; /**< Bar type. */ + using Barcode = typename Master_matrix::Barcode; /**< Barcode type. */ + using Cycle = typename Master_matrix::Cycle; /**< Cycle type. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ + using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to + necessary external classes. */ /** * @brief Constructs an empty matrix. @@ -69,11 +69,12 @@ class Id_to_index_overlay */ Id_to_index_overlay(Column_settings* colSettings); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. * - * @tparam Boundary_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -127,9 +128,9 @@ class Id_to_index_overlay const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". - * Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 IDs. - * The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 + * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. * * @warning If @ref PersistenceMatrixOptions::has_vine_update is false, the comparators are not used. * And if @ref PersistenceMatrixOptions::has_vine_update is true, but @@ -138,7 +139,7 @@ class Id_to_index_overlay * * @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_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -195,7 +196,7 @@ class Id_to_index_overlay const BirthComparatorFunction& birthComparator, const DeathComparatorFunction& deathComparator); /** - * @brief Copy constructor. If @p operators or @p cellConstructor is not a null pointer, its value is kept + * @brief Copy constructor. If @p operators or @p entryConstructor is not a null pointer, its value is kept * instead of the one in the copied matrix. * * @param matrixToCopy Matrix to copy. @@ -219,13 +220,13 @@ class Id_to_index_overlay /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other * @ref insert_boundary(ID_index, const Boundary_range&, Dimension) "insert_boundary" instead by indicating the - * face ID used in the boundaries when the face is inserted. + * cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * The content of the new column will vary depending on the underlying @ref mp_matrices "type of the matrix": * - If it is a boundary type matrix and only \f$ R \f$ is stored, the boundary is just copied. The column will only @@ -237,47 +238,49 @@ class Id_to_index_overlay * `IDIdx + linear combination of older column IDIdxs`, where the combination is deduced while reducing the * given boundary. If the barcode is stored, it will also be updated. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template void insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** - * @brief It does the same as the other version, but allows the boundary faces to be identified without restrictions + * @brief It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * the faces are inserted by order of filtration), it is sufficient to indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param faceIndex @ref IDIdx index to use to identify the new face. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. + * @param cellIndex @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceIndex values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellIndex values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template - void insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim = -1); + void insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim = -1); /** * @brief Returns the column at the given @ref IDIdx index. * For @ref boundarymatrix "RU matrices", the returned column is from \f$ R \f$. * The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type. * - * @param faceID @ref IDIdx index of the column to return. + * @param cellID @ref IDIdx index of the column to return. * @return Reference to the column. */ - Column& get_column(ID_index faceID); + Column& get_column(ID_index cellID); /** * @brief Only available if @ref PersistenceMatrixOptions::has_row_access is true. * Returns the row at the given @ref rowindex "row index". * For @ref boundarymatrix "RU matrices", the returned row is from \f$ R \f$. * The type of the row depends on the choosen options, see @ref PersistenceMatrixOptions::has_intrusive_rows. * - * @warning The @ref Cell_column_index::get_column_index "get_column_index" method of the row cells returns the + * @warning The @ref Entry_column_index::get_column_index "get_column_index" method of the row entries returns the * original @ref PosIdx indices (before any swaps) for @ref boundarymatrix "boundary matrices" and * @ref MatIdx indices for @ref chainmatrix "chain matrices". * @@ -301,11 +304,11 @@ class Id_to_index_overlay * @ref PersistenceMatrixOptions::has_removable_rows are true. * Assumes that the row is empty and removes it. * - * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row cells are not + * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not * removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when - * the column cells are destroyed later. The row access is just meant as a "read only" access to the rows and the + * the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the * @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from - * dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can be + * dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be * quite frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row to remove. @@ -316,10 +319,10 @@ class Id_to_index_overlay * @ref PersistenceMatrixOptions::has_removable_columns and @ref PersistenceMatrixOptions::has_vine_update are true. * For @ref chainmatrix "chain matrices", @ref PersistenceMatrixOptions::has_map_column_container and * @ref PersistenceMatrixOptions::has_column_pairings also need to be true. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., RU is still an upper triangular decomposition of the @ref boundarymatrix "boundary matrix" and chain is * still a compatible bases of the chain complex in the sense of @cite zigzag). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it was computed. * * For @ref chainmatrix "chain matrices", using the other version of the method could perform better depending on @@ -328,51 +331,51 @@ class Id_to_index_overlay * * See also @ref remove_last. * - * @param faceID @ref IDIdx index of the face to remove. + * @param cellID @ref IDIdx index of the cell to remove. */ - void remove_maximal_face(ID_index faceID); + void remove_maximal_cell(ID_index cellID); /** * @brief Only available for @ref chainmatrix "chain matrices" and if * @ref PersistenceMatrixOptions::has_removable_columns, @ref PersistenceMatrixOptions::has_vine_update * and @ref PersistenceMatrixOptions::has_map_column_container are true. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., it is still a compatible bases of the chain complex in the sense of @cite zigzag). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it was computed. * - * To maintain the compatibility, vine swaps are done to move the face up to the end of the filtration. Once at + * To maintain the compatibility, vine swaps are done to move the cell up to the end of the filtration. Once at * the end, the removal is trivial. But for @ref chainmatrix "chain matrices", swaps do not actually swap the position - * of the column every time, so the faces appearing after @p faceIndex in the filtration have to be searched first - * within the matrix. If the user has an easy access to the @ref IDIdx of the faces in the order of filtration, + * of the column every time, so the cells appearing after @p cellIndex in the filtration have to be searched first + * within the matrix. If the user has an easy access to the @ref IDIdx of the cells in the order of filtration, * passing them by argument with @p columnsToSwap allows to skip a linear search process. Typically, if the user knows - * that the face he wants to remove is already the last face of the filtration, calling - * @ref remove_maximal_face(ID_index, const std::vector&) "remove_maximal_face(faceID, {})" + * that the cell he wants to remove is already the last cell of the filtration, calling + * @ref remove_maximal_cell(ID_index, const std::vector&) "remove_maximal_cell(cellID, {})" * will be faster than @ref remove_last(). * * See also @ref remove_last. * - * @param faceID @ref IDIdx index of the face to remove. - * @param columnsToSwap Vector of @ref IDIdx indices of the faces coming after @p faceID in the filtration. + * @param cellID @ref IDIdx index of the cell to remove. + * @param columnsToSwap Vector of @ref IDIdx indices of the cells coming after @p cellID in the filtration. */ - void remove_maximal_face(ID_index faceID, const std::vector& columnsToSwap); + void remove_maximal_cell(ID_index cellID, const std::vector& columnsToSwap); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns is true. Additionally, if the * matrix is a @ref chainmatrix "chain matrix", either @ref PersistenceMatrixOptions::has_map_column_container has to * be true or @ref PersistenceMatrixOptions::has_vine_update has to be false. - * Removes the last face in the filtration from the matrix and updates the barcode if it is stored. + * Removes the last cell in the filtration from the matrix and updates the barcode if it is stored. * - * See also @ref remove_maximal_face. + * See also @ref remove_maximal_cell. * - * For @ref chainmatrix "chain matrices", if @ref PersistenceMatrixOptions::has_vine_update is true, the last face + * For @ref chainmatrix "chain matrices", if @ref PersistenceMatrixOptions::has_vine_update is true, the last cell * does not have to be at the end of the matrix and therefore has to be searched first. In this case, if the user - * already knows the @ref IDIdx of the last face, calling - * @ref remove_maximal_face(ID_index, const std::vector&) "remove_maximal_face(faceID, {})" + * already knows the @ref IDIdx of the last cell, calling + * @ref remove_maximal_cell(ID_index, const std::vector&) "remove_maximal_cell(cellID, {})" * instead allows to skip the search. */ void remove_last(); /** - * @brief Returns the maximal dimension of a face stored in the matrix. Only available + * @brief Returns the maximal dimension of a cell stored in the matrix. Only available * if @ref PersistenceMatrixOptions::has_matrix_maximal_dimension_access is true. * * @return The maximal dimension. @@ -385,24 +388,24 @@ class Id_to_index_overlay */ Index get_number_of_columns() const; /** - * @brief Returns the dimension of the given face. Only available for @ref mp_matrices "non-basic matrices". + * @brief Returns the dimension of the given cell. Only available for @ref mp_matrices "non-basic matrices". * - * @param faceID @ref IDIdx index of the face. - * @return Dimension of the face. + * @param cellID @ref IDIdx index of the cell. + * @return Dimension of the cell. */ - Dimension get_column_dimension(ID_index faceID) const; + Dimension get_column_dimension(ID_index cellID) const; /** - * @brief Adds column corresponding to @p sourceFaceID onto the column corresponding to @p targetFaceID. + * @brief Adds column corresponding to @p sourceCellID onto the column corresponding to @p targetCellID. * * @warning They will be no verification to ensure that the addition makes sense for the validity of the matrix. * For example, a right-to-left addition could corrupt the computation of the barcode if done blindly. * So should be used with care. * - * @param sourceFaceID @ref IDIdx index of the source column. - * @param targetFaceID @ref IDIdx index of the target column. + * @param sourceCellID @ref IDIdx index of the source column. + * @param targetCellID @ref IDIdx index of the target column. */ - void add_to(ID_index sourceFaceID, ID_index targetFaceID); + void add_to(ID_index sourceCellID, ID_index targetCellID); /** * @brief Multiplies the target column with the coefficient and then adds the source column to it. * That is: `targetColumn = (targetColumn * coefficient) + sourceColumn`. @@ -411,11 +414,11 @@ class Id_to_index_overlay * For example, a right-to-left addition could corrupt the computation of the barcode if done blindly. * So should be used with care. * - * @param sourceFaceID @ref IDIdx index of the source column. + * @param sourceCellID @ref IDIdx index of the source column. * @param coefficient Value to multiply. - * @param targetFaceID @ref IDIdx index of the target column. + * @param targetCellID @ref IDIdx index of the target column. */ - void multiply_target_and_add_to(ID_index sourceFaceID, const Field_element& coefficient, ID_index targetFaceID); + void multiply_target_and_add_to(ID_index sourceCellID, const Field_element& coefficient, ID_index targetCellID); /** * @brief Multiplies the source column with the coefficient before adding it to the target column. * That is: `targetColumn += (coefficient * sourceColumn)`. The source column will **not** be modified. @@ -425,22 +428,22 @@ class Id_to_index_overlay * So should be used with care. * * @param coefficient Value to multiply. - * @param sourceFaceID @ref IDIdx index of the source column. - * @param targetFaceID @ref IDIdx index of the target column. + * @param sourceCellID @ref IDIdx index of the source column. + * @param targetCellID @ref IDIdx index of the target column. */ - void multiply_source_and_add_to(const Field_element& coefficient, ID_index sourceFaceID, ID_index targetFaceID); + void multiply_source_and_add_to(const Field_element& coefficient, ID_index sourceCellID, ID_index targetCellID); /** - * @brief Zeroes the cell at the given coordinates. Not available for @ref chainmatrix "chain matrices". + * @brief Zeroes the entry at the given coordinates. Not available for @ref chainmatrix "chain matrices". * In general, should be used with care to not destroy the validity * of the persistence related properties of the matrix. * - * For @ref boundarymatrix "RU matrices", zeros only the cell in \f$ R \f$. + * For @ref boundarymatrix "RU matrices", zeros only the entry in \f$ R \f$. * - * @param faceID @ref IDIdx index of the face corresponding to the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param cellID @ref IDIdx index of the cell corresponding to the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. */ - void zero_cell(ID_index faceID, ID_index rowIndex); + void zero_entry(ID_index cellID, ID_index rowIndex); /** * @brief Zeroes the column at the given index. Not available for @ref chainmatrix "chain matrices". * In general, should be used with care to not destroy the validity @@ -448,20 +451,20 @@ class Id_to_index_overlay * * For @ref boundarymatrix "RU matrices", zeros only the column in \f$ R \f$. * - * @param faceID @ref IDIdx index of the face corresponding to the column. + * @param cellID @ref IDIdx index of the cell corresponding to the column. */ - void zero_column(ID_index faceID); + void zero_column(ID_index cellID); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * * For @ref boundarymatrix "RU matrices", looks into \f$ R \f$. * - * @param faceID @ref IDIdx index of the face corresponding to the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param cellID @ref IDIdx index of the cell corresponding to the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(ID_index faceID, ID_index rowIndex) const; + bool is_zero_entry(ID_index cellID, ID_index rowIndex) const; /** * @brief Indicates if the column at given index has value zero. * @@ -470,11 +473,11 @@ class Id_to_index_overlay * Note that for @ref chainmatrix "chain matrices", this method should always return false, as a valid * @ref chainmatrix "chain matrix" never has empty columns. * - * @param faceID @ref IDIdx index of the face corresponding to the column. + * @param cellID @ref IDIdx index of the cell corresponding to the column. * @return true If the column has value zero. * @return false Otherwise. */ - bool is_zero_column(ID_index faceID); + bool is_zero_column(ID_index cellID); /** * @brief Returns the @ref IDIdx index of the column which has the given @ref rowindex "row index" as pivot. @@ -484,17 +487,17 @@ class Id_to_index_overlay * the row indices for a @ref boundarymatrix "RU matrix" correspond to the updated @ref IDIdx indices which got * potentially swapped by a vine swap. * - * @param faceIndex @ref rowindex "Row index" of the pivot. + * @param cellIndex @ref rowindex "Row index" of the pivot. * @return @ref IDIdx index of the column with the given pivot. */ - ID_index get_column_with_pivot(ID_index faceIndex) const; + ID_index get_column_with_pivot(ID_index cellIndex) const; /** * @brief Returns the @ref rowindex "row index" of the pivot of the given column. * - * @param faceID @ref IDIdx index of the face corresponding to the column. + * @param cellID @ref IDIdx index of the cell corresponding to the column. * @return The @ref rowindex "row index" of the pivot. */ - ID_index get_pivot(ID_index faceID); + ID_index get_pivot(ID_index cellID); /** * @brief Resets the matrix to an empty matrix. @@ -546,10 +549,10 @@ class Id_to_index_overlay * Swaps the two given columns. Note that it really just swaps two columns and do not updates * anything else, nor performs additions to maintain some properties on the matrix. * - * @param faceID1 First column @ref IDIdx index to swap. - * @param faceID2 Second column @ref IDIdx index to swap. + * @param cellID1 First column @ref IDIdx index to swap. + * @param cellID2 Second column @ref IDIdx index to swap. */ - void swap_columns(ID_index faceID1, ID_index faceID2); + void swap_columns(ID_index cellID1, ID_index cellID2); /** * @brief Only available for simple @ref boundarymatrix "boundary matrices" (only storing R) * and if @ref PersistenceMatrixOptions::has_column_and_row_swaps is true. @@ -565,29 +568,29 @@ class Id_to_index_overlay * Does the same than @ref vine_swap, but assumes that the swap is non trivial and * therefore skips a part of the case study. * - * @param faceID1 @ref IDIdx index of the first face. - * @param faceID2 @ref IDIdx index of the second face. It is assumed that the @ref PosIdx of both only differs by one. + * @param cellID1 @ref IDIdx index of the first cell. + * @param cellID2 @ref IDIdx index of the second cell. It is assumed that the @ref PosIdx of both only differs by one. * @return Let \f$ pos1 \f$ be the @ref PosIdx index of @p columnIndex1 and \f$ pos2 \f$ be the @ref PosIdx index of * @p columnIndex2. The method returns the @ref MatIdx of the column which has now, after the swap, the @ref PosIdx * \f$ max(pos1, pos2) \f$. */ - ID_index vine_swap_with_z_eq_1_case(ID_index faceID1, ID_index faceID2); + ID_index vine_swap_with_z_eq_1_case(ID_index cellID1, ID_index cellID2); /** * @brief Only available if @ref PersistenceMatrixOptions::has_vine_update is true. - * Does a vine swap between two faces which are consecutive in the filtration. Roughly, if \f$ F \f$ is + * Does a vine swap between two cells which are consecutive in the filtration. Roughly, if \f$ F \f$ is * the current filtration represented by the matrix, the method modifies the matrix such that the new state - * corresponds to a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but with the two given faces - * at swapped positions. Of course, the two faces should not have a face/coface relation which each other ; + * corresponds to a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but with the two given cells + * at swapped positions. Of course, the two cells should not have a face/coface relation which each other ; * \f$ F' \f$ has to be a valid filtration. * See @cite vineyards for more information about vine and vineyards. * - * @param faceID1 @ref IDIdx index of the first face. - * @param faceID2 @ref IDIdx index of the second face. It is assumed that the @ref PosIdx of both only differs by one. + * @param cellID1 @ref IDIdx index of the first cell. + * @param cellID2 @ref IDIdx index of the second cell. It is assumed that the @ref PosIdx of both only differs by one. * @return Let \f$ pos1 \f$ be the @ref PosIdx index of @p columnIndex1 and \f$ pos2 \f$ be the @ref PosIdx index of * @p columnIndex2. The method returns the @ref MatIdx of the column which has now, after the swap, the @ref PosIdx * \f$ max(pos1, pos2) \f$. */ - ID_index vine_swap(ID_index faceID1, ID_index faceID2); + ID_index vine_swap(ID_index cellID1, ID_index cellID2); /** * @brief Only available if @ref PersistenceMatrixOptions::can_retrieve_representative_cycles is true. Pre-computes @@ -749,26 +752,26 @@ inline void Id_to_index_overlay::insert_bounda template template -inline void Id_to_index_overlay::insert_boundary(ID_index faceIndex, +inline void Id_to_index_overlay::insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) { if constexpr (Master_matrix::Option_list::has_map_column_container) { - GUDHI_CHECK(idToIndex_->find(faceIndex) == idToIndex_->end(), + GUDHI_CHECK(idToIndex_->find(cellIndex) == idToIndex_->end(), std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!")); } else { - GUDHI_CHECK((idToIndex_->size() <= faceIndex || _id_to_index(faceIndex) == static_cast(-1)), + GUDHI_CHECK((idToIndex_->size() <= cellIndex || _id_to_index(cellIndex) == static_cast(-1)), std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!")); } - matrix_.insert_boundary(faceIndex, boundary, dim); + matrix_.insert_boundary(cellIndex, boundary, dim); if constexpr (Master_matrix::Option_list::is_of_boundary_type) { if constexpr (Master_matrix::Option_list::has_map_column_container) { - idToIndex_->emplace(faceIndex, nextIndex_); + idToIndex_->emplace(cellIndex, nextIndex_); } else { - if (idToIndex_->size() <= faceIndex) { - idToIndex_->resize(faceIndex + 1, -1); + if (idToIndex_->size() <= cellIndex) { + idToIndex_->resize(cellIndex + 1, -1); } - _id_to_index(faceIndex) = nextIndex_; + _id_to_index(cellIndex) = nextIndex_; } ++nextIndex_; } @@ -776,9 +779,9 @@ inline void Id_to_index_overlay::insert_bounda template inline typename Id_to_index_overlay::Column& -Id_to_index_overlay::get_column(ID_index faceID) +Id_to_index_overlay::get_column(ID_index cellID) { - return matrix_.get_column(_id_to_index(faceID)); + return matrix_.get_column(_id_to_index(cellID)); } template @@ -795,7 +798,7 @@ inline void Id_to_index_overlay::erase_empty_r } template -inline void Id_to_index_overlay::remove_maximal_face(ID_index faceID) +inline void Id_to_index_overlay::remove_maximal_cell(ID_index cellID) { if constexpr (Master_matrix::Option_list::is_of_boundary_type) { std::vector indexToID(nextIndex_); @@ -809,34 +812,34 @@ inline void Id_to_index_overlay::remove_maxima } } --nextIndex_; - for (Index curr = _id_to_index(faceID); curr < nextIndex_; ++curr) { + for (Index curr = _id_to_index(cellID); curr < nextIndex_; ++curr) { matrix_.vine_swap(curr); std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1])); } matrix_.remove_last(); - GUDHI_CHECK(_id_to_index(faceID) == nextIndex_, - std::logic_error("Id_to_index_overlay::remove_maximal_face - Indexation problem.")); + GUDHI_CHECK(_id_to_index(cellID) == nextIndex_, + std::logic_error("Id_to_index_overlay::remove_maximal_cell - Indexation problem.")); if constexpr (Master_matrix::Option_list::has_map_column_container) { - idToIndex_->erase(faceID); + idToIndex_->erase(cellID); } else { - _id_to_index(faceID) = -1; + _id_to_index(cellID) = -1; } } else { - matrix_.remove_maximal_face(faceID); + matrix_.remove_maximal_cell(cellID); } } template -inline void Id_to_index_overlay::remove_maximal_face( - ID_index faceID, const std::vector& columnsToSwap) +inline void Id_to_index_overlay::remove_maximal_cell( + ID_index cellID, const std::vector& columnsToSwap) { static_assert(!Master_matrix::Option_list::is_of_boundary_type, - "'remove_maximal_face(ID_index,const std::vector&)' is not available for the chosen options."); + "'remove_maximal_cell(ID_index,const std::vector&)' is not available for the chosen options."); std::vector translatedIndices; std::transform(columnsToSwap.cbegin(), columnsToSwap.cend(), std::back_inserter(translatedIndices), [&](ID_index id) { return _id_to_index(id); }); - matrix_.remove_maximal_face(faceID, translatedIndices); + matrix_.remove_maximal_cell(cellID, translatedIndices); } template @@ -878,54 +881,54 @@ Id_to_index_overlay::get_number_of_columns() c template inline typename Id_to_index_overlay::Dimension -Id_to_index_overlay::get_column_dimension(ID_index faceID) const +Id_to_index_overlay::get_column_dimension(ID_index cellID) const { - return matrix_.get_column_dimension(_id_to_index(faceID)); + return matrix_.get_column_dimension(_id_to_index(cellID)); } template -inline void Id_to_index_overlay::add_to(ID_index sourceFaceID, ID_index targetFaceID) +inline void Id_to_index_overlay::add_to(ID_index sourceCellID, ID_index targetCellID) { - return matrix_.add_to(_id_to_index(sourceFaceID), _id_to_index(targetFaceID)); + return matrix_.add_to(_id_to_index(sourceCellID), _id_to_index(targetCellID)); } template inline void Id_to_index_overlay::multiply_target_and_add_to( - ID_index sourceFaceID, const Field_element& coefficient, ID_index targetFaceID) + ID_index sourceCellID, const Field_element& coefficient, ID_index targetCellID) { - return matrix_.multiply_target_and_add_to(_id_to_index(sourceFaceID), coefficient, _id_to_index(targetFaceID)); + return matrix_.multiply_target_and_add_to(_id_to_index(sourceCellID), coefficient, _id_to_index(targetCellID)); } template inline void Id_to_index_overlay::multiply_source_and_add_to( - const Field_element& coefficient, ID_index sourceFaceID, ID_index targetFaceID) + const Field_element& coefficient, ID_index sourceCellID, ID_index targetCellID) { - return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceFaceID), _id_to_index(targetFaceID)); + return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceCellID), _id_to_index(targetCellID)); } template -inline void Id_to_index_overlay::zero_cell(ID_index faceID, ID_index rowIndex) +inline void Id_to_index_overlay::zero_entry(ID_index cellID, ID_index rowIndex) { - return matrix_.zero_cell(_id_to_index(faceID), rowIndex); + return matrix_.zero_entry(_id_to_index(cellID), rowIndex); } template -inline void Id_to_index_overlay::zero_column(ID_index faceID) +inline void Id_to_index_overlay::zero_column(ID_index cellID) { - return matrix_.zero_column(_id_to_index(faceID)); + return matrix_.zero_column(_id_to_index(cellID)); } template -inline bool Id_to_index_overlay::is_zero_cell(ID_index faceID, +inline bool Id_to_index_overlay::is_zero_entry(ID_index cellID, ID_index rowIndex) const { - return matrix_.is_zero_cell(_id_to_index(faceID), rowIndex); + return matrix_.is_zero_entry(_id_to_index(cellID), rowIndex); } template -inline bool Id_to_index_overlay::is_zero_column(ID_index faceID) +inline bool Id_to_index_overlay::is_zero_column(ID_index cellID) { - return matrix_.is_zero_column(_id_to_index(faceID)); + return matrix_.is_zero_column(_id_to_index(cellID)); } template @@ -944,12 +947,12 @@ Id_to_index_overlay::get_column_with_pivot(ID_ template inline typename Id_to_index_overlay::ID_index -Id_to_index_overlay::get_pivot(ID_index faceID) +Id_to_index_overlay::get_pivot(ID_index cellID) { if constexpr (Master_matrix::Option_list::is_of_boundary_type) { - return matrix_.get_pivot(_id_to_index(faceID)); + return matrix_.get_pivot(_id_to_index(cellID)); } else { - return faceID; + return cellID; } } @@ -1001,10 +1004,10 @@ Id_to_index_overlay::get_representative_cycle( } template -inline void Id_to_index_overlay::swap_columns(ID_index faceID1, ID_index faceID2) +inline void Id_to_index_overlay::swap_columns(ID_index cellID1, ID_index cellID2) { - matrix_.swap_columns(_id_to_index(faceID1), _id_to_index(faceID2)); - std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2)); + matrix_.swap_columns(_id_to_index(cellID1), _id_to_index(cellID2)); + std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2)); } template @@ -1015,10 +1018,10 @@ inline void Id_to_index_overlay::swap_rows(Ind template inline typename Id_to_index_overlay::ID_index -Id_to_index_overlay::vine_swap_with_z_eq_1_case(ID_index faceID1, ID_index faceID2) +Id_to_index_overlay::vine_swap_with_z_eq_1_case(ID_index cellID1, ID_index cellID2) { - Index first = _id_to_index(faceID1); - Index second = _id_to_index(faceID2); + Index first = _id_to_index(cellID1); + Index second = _id_to_index(cellID2); if (first > second) std::swap(first, second); if constexpr (Master_matrix::Option_list::is_of_boundary_type) { @@ -1028,12 +1031,12 @@ Id_to_index_overlay::vine_swap_with_z_eq_1_cas bool change = matrix_.vine_swap_with_z_eq_1_case(first); - std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2)); + std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2)); if (change) { - return faceID1; + return cellID1; } - return faceID2; + return cellID2; } else { return matrix_.vine_swap_with_z_eq_1_case(first, second); } @@ -1041,10 +1044,10 @@ Id_to_index_overlay::vine_swap_with_z_eq_1_cas template inline typename Id_to_index_overlay::ID_index -Id_to_index_overlay::vine_swap(ID_index faceID1, ID_index faceID2) +Id_to_index_overlay::vine_swap(ID_index cellID1, ID_index cellID2) { - Index first = _id_to_index(faceID1); - Index second = _id_to_index(faceID2); + Index first = _id_to_index(cellID1); + Index second = _id_to_index(cellID2); if (first > second) std::swap(first, second); if constexpr (Master_matrix::Option_list::is_of_boundary_type) { @@ -1053,12 +1056,12 @@ Id_to_index_overlay::vine_swap(ID_index faceID bool change = matrix_.vine_swap(first); - std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2)); + std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2)); if (change) { - return faceID1; + return cellID1; } - return faceID2; + return cellID2; } else { return matrix_.vine_swap(first, second); } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h b/multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h index d908675..4a19488 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h @@ -55,8 +55,8 @@ class Position_to_index_overlay using Bar = typename Master_matrix::Bar; /**< Bar type. */ using Barcode = typename Master_matrix::Barcode; /**< Barcode type. */ using Cycle = typename Master_matrix::Cycle; /**< Cycle type. */ - using Cell_representative = typename Master_matrix::Cell_representative; /**< %Cell content representative. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ + using Entry_representative = typename Master_matrix::Entry_representative; /**< %Entry content representative. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to necessary external classes. */ @@ -68,11 +68,12 @@ class Position_to_index_overlay */ Position_to_index_overlay(Column_settings* colSettings); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. * - * @tparam Boundary_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -127,9 +128,9 @@ class Position_to_index_overlay const DeathComparatorFunction& deathComparator); /** * @brief Only available for @ref chainmatrix "chain matrices". - * Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 IDs. - * The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 + * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. * * @warning If @ref PersistenceMatrixOptions::has_vine_update is false, the comparators are not used. * And if @ref PersistenceMatrixOptions::has_vine_update is true, but @@ -138,7 +139,7 @@ class Position_to_index_overlay * * @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_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -215,42 +216,44 @@ class Position_to_index_overlay /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other * @ref insert_boundary(ID_index, const Boundary_range&, Dimension) "insert_boundary" instead by indicating the - * face ID used in the boundaries when the face is inserted. + * cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * When inserted, the given boundary is reduced and from the reduction process, the column is deduced in the form of: * `IDIdx + linear combination of older column IDIdxs`. If the barcode is stored, it will be updated. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template void insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** - * @brief It does the same as the other version, but allows the boundary faces to be identified without restrictions + * @brief It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * the faces are inserted by order of filtration), it is sufficient to indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() method. - * @param faceIndex @ref IDIdx index to use to identify the new face. + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() + * method. + * @param cellIndex @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceID values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellID values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template - void insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim = -1); + void insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim = -1); /** * @brief Returns the column at the given @ref PosIdx index. * The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type. @@ -290,11 +293,11 @@ class Position_to_index_overlay * @ref PersistenceMatrixOptions::has_removable_rows are true. * Assumes that the row is empty and removes it. * - * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row cells are not + * @warning The removed rows are always assumed to be empty. If it is not the case, the deleted row entries are not * removed from their columns. And in the case of intrusive rows, this will generate a segmentation fault when - * the column cells are destroyed later. The row access is just meant as a "read only" access to the rows and the + * the column entries are destroyed later. The row access is just meant as a "read only" access to the rows and the * @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed from - * dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can be + * dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can be * quite frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row to remove. @@ -304,28 +307,28 @@ class Position_to_index_overlay * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns, * @ref PersistenceMatrixOptions::has_vine_update and @ref PersistenceMatrixOptions::has_map_column_container * are true. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., the matrix is still a compatible bases of the chain complex in the sense of @cite zigzag). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it was computed. * * See also @ref remove_last. * - * @param position @ref PosIdx index of the face to remove. + * @param position @ref PosIdx index of the cell to remove. */ - void remove_maximal_face(Pos_index position); + void remove_maximal_cell(Pos_index position); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns is true and, * if @ref PersistenceMatrixOptions::has_map_column_container is true or * @ref PersistenceMatrixOptions::has_vine_update is false. - * Removes the last face in the filtration from the matrix and updates the barcode if it is stored. + * Removes the last cell in the filtration from the matrix and updates the barcode if it is stored. * - * See also @ref remove_maximal_face. + * See also @ref remove_maximal_cell. */ void remove_last(); /** - * @brief Returns the maximal dimension of a face stored in the matrix. Only available + * @brief Returns the maximal dimension of a cell stored in the matrix. Only available * if @ref PersistenceMatrixOptions::has_matrix_maximal_dimension_access is true. * * @return The maximal dimension. @@ -338,10 +341,10 @@ class Position_to_index_overlay */ Index get_number_of_columns() const; /** - * @brief Returns the dimension of the given face. + * @brief Returns the dimension of the given cell. * - * @param position @ref PosIdx index of the face. - * @return Dimension of the face. + * @param position @ref PosIdx index of the cell. + * @return Dimension of the cell. */ Dimension get_column_dimension(Pos_index position) const; @@ -388,21 +391,21 @@ class Position_to_index_overlay Pos_index targetPosition); /** - * @brief Indicates if the cell at given coordinates has value zero. + * @brief Indicates if the entry at given coordinates has value zero. * - * @param position @ref PosIdx index of the face corresponding to the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. - * @return true If the cell has value zero. + * @param position @ref PosIdx index of the cell corresponding to the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Pos_index position, ID_index rowIndex) const; + bool is_zero_entry(Pos_index position, ID_index rowIndex) const; /** * @brief Indicates if the column at given index has value zero. * * Note that this method should always return false, as a valid @ref chainmatrix "chain matrix" never has * empty columns. * - * @param position @ref PosIdx index of the face corresponding to the column. + * @param position @ref PosIdx index of the cell corresponding to the column. * @return true If the column has value zero. * @return false Otherwise. */ @@ -412,14 +415,14 @@ class Position_to_index_overlay * @brief Returns the @ref PosIdx index of the column which has the given @ref rowindex "row index" as pivot. * Assumes that the pivot exists. * - * @param faceIndex @ref rowindex "Row index" of the pivot. + * @param cellIndex @ref rowindex "Row index" of the pivot. * @return @ref PosIdx index of the column with the given pivot. */ - Pos_index get_column_with_pivot(ID_index faceIndex) const; // assumes that pivot exists + Pos_index get_column_with_pivot(ID_index cellIndex) const; // assumes that pivot exists /** * @brief Returns the @ref rowindex "row index" of the pivot of the given column. * - * @param position @ref PosIdx index of the face corresponding to the column. + * @param position @ref PosIdx index of the cell corresponding to the column. * @return The @ref rowindex "row index" of the pivot. */ ID_index get_pivot(Pos_index position); @@ -497,21 +500,21 @@ class Position_to_index_overlay * Does the same than @ref vine_swap, but assumes that the swap is non trivial and * therefore skips a part of the case study. * - * @param position @ref PosIdx index of the first face to swap. The second one has to be at `position + 1`. + * @param position @ref PosIdx index of the first cell to swap. The second one has to be at `position + 1`. * @return true If the barcode changed from the swap. * @return false Otherwise. */ bool vine_swap_with_z_eq_1_case(Pos_index position); /** * @brief Only available if @ref PersistenceMatrixOptions::has_vine_update is true. - * Does a vine swap between two faces which are consecutive in the filtration. Roughly, if \f$ F \f$ is the current + * Does a vine swap between two cells which are consecutive in the filtration. Roughly, if \f$ F \f$ is the current * filtration represented by the matrix, the method modifies the matrix such that the new state corresponds to - * a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but with the two faces at position `position` - * and `position + 1` swapped. Of course, the two faces should not have a face/coface relation which each other ; + * a valid state for the filtration \f$ F' \f$ equal to \f$ F \f$ but with the two cells at position `position` + * and `position + 1` swapped. Of course, the two cells should not have a face/coface relation which each other ; * \f$ F' \f$ has to be a valid filtration. * See @cite vineyards for more information about vine and vineyards. * - * @param position @ref PosIdx index of the first face to swap. The second one has to be at `position + 1`. + * @param position @ref PosIdx index of the first cell to swap. The second one has to be at `position + 1`. * @return true If the barcode changed from the swap. * @return false Otherwise. */ @@ -626,7 +629,7 @@ inline void Position_to_index_overlay::insert_ template template -inline void Position_to_index_overlay::insert_boundary(ID_index faceIndex, +inline void Position_to_index_overlay::insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) { @@ -636,7 +639,7 @@ inline void Position_to_index_overlay::insert_ positionToIndex_[nextPosition_++] = nextIndex_++; - matrix_.insert_boundary(faceIndex, boundary, dim); + matrix_.insert_boundary(cellIndex, boundary, dim); } template @@ -674,7 +677,7 @@ inline void Position_to_index_overlay::erase_e } template -inline void Position_to_index_overlay::remove_maximal_face(Pos_index position) +inline void Position_to_index_overlay::remove_maximal_cell(Pos_index position) { --nextPosition_; @@ -690,7 +693,7 @@ inline void Position_to_index_overlay::remove_ columnsToSwap.back() = positionToIndex_[nextPosition_]; } - matrix_.remove_maximal_face(pivot, columnsToSwap); + matrix_.remove_maximal_cell(pivot, columnsToSwap); } template @@ -699,9 +702,9 @@ inline void Position_to_index_overlay::remove_ --nextPosition_; if constexpr (Master_matrix::Option_list::has_vine_update) { std::vector columnsToSwap; - matrix_.remove_maximal_face(matrix_.get_pivot(positionToIndex_[nextPosition_]), columnsToSwap); + matrix_.remove_maximal_cell(matrix_.get_pivot(positionToIndex_[nextPosition_]), columnsToSwap); } else { - matrix_.remove_last(); // linear with vine updates, so it is better to use remove_maximal_face + matrix_.remove_last(); // linear with vine updates, so it is better to use remove_maximal_cell } } @@ -752,10 +755,10 @@ inline void Position_to_index_overlay::multipl } template -inline bool Position_to_index_overlay::is_zero_cell(Pos_index position, +inline bool Position_to_index_overlay::is_zero_entry(Pos_index position, ID_index rowIndex) const { - return matrix_.is_zero_cell(positionToIndex_[position], rowIndex); + return matrix_.is_zero_entry(positionToIndex_[position], rowIndex); } template @@ -766,9 +769,9 @@ inline bool Position_to_index_overlay::is_zero template inline typename Position_to_index_overlay::Pos_index -Position_to_index_overlay::get_column_with_pivot(ID_index faceIndex) const +Position_to_index_overlay::get_column_with_pivot(ID_index cellIndex) const { - Index id = matrix_.get_column_with_pivot(faceIndex); + Index id = matrix_.get_column_with_pivot(cellIndex); Pos_index i = 0; while (positionToIndex_[i] != id) ++i; return i; diff --git a/multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h b/multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h index 28b7a14..38ceae6 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h @@ -30,7 +30,7 @@ namespace persistence_matrix { * * @brief %Matrix structure to store the ordered @ref boundarymatrix "boundary matrix" \f$ R \cdot U \f$ of a filtered * complex in order to compute its persistent homology, as well as representative cycles. - * Supports vineyards (see @cite vineyards) and the removal of maximal faces while maintaining + * Supports vineyards (see @cite vineyards) and the removal of maximal cells while maintaining * a valid barcode. Provides an access to its columns and rows. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. @@ -45,18 +45,18 @@ class RU_matrix : public Master_matrix::RU_pairing_option, * @brief Field operators class. Necessary only if @ref PersistenceMatrixOptions::is_z2 is false. */ using Field_operators = typename Master_matrix::Field_operators; - using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ - using Column = typename Master_matrix::Column; /**< Column type. */ - using Row = typename Master_matrix::Row; /**< Row type, - only necessary with row access option. */ - using Cell_constructor = typename Master_matrix::Cell_constructor; /**< Factory of @ref Cell classes. */ - using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to - necessary external classes. */ - using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ - using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ - using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ - using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */ - using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ + using Field_element = typename Master_matrix::Element; /**< Type of an field element. */ + using Column = typename Master_matrix::Column; /**< Column type. */ + using Row = typename Master_matrix::Row; /**< Row type, + only necessary with row access option. */ + using Entry_constructor = typename Master_matrix::Entry_constructor; /**< Factory of @ref Entry classes. */ + using Column_settings = typename Master_matrix::Column_settings; /**< Structure giving access to the columns to + necessary external classes. */ + using Boundary = typename Master_matrix::Boundary; /**< Type of an input column. */ + using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ + using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ + using Pos_index = typename Master_matrix::Pos_index; /**< @ref PosIdx index type. */ + using Dimension = typename Master_matrix::Dimension; /**< Dimension value type. */ /** * @brief Constructs an empty matrix. @@ -66,11 +66,12 @@ class RU_matrix : public Master_matrix::RU_pairing_option, */ RU_matrix(Column_settings* colSettings); /** - * @brief Constructs a new matrix from the given ranges of @ref Matrix::Cell_representative. 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 - * IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. + * @brief Constructs a new matrix from the given ranges of @ref Matrix::Entry_representative. 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 IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting + * with 0. * - * @tparam Boundary_range Range type for @ref Matrix::Cell_representative ranges. + * @tparam Boundary_range Range type for @ref Matrix::Entry_representative 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 * filtered **simplicial** complex, whose boundaries are ordered by filtration order. @@ -114,49 +115,49 @@ class RU_matrix : public Master_matrix::RU_pairing_option, /** * @brief Inserts at the end of the matrix a new ordered column corresponding to the given boundary. * This means that it is assumed that this method is called on boundaries in the order of the filtration. - * It also assumes that the faces in the given boundary are identified by their relative position in the filtration, + * It also assumes that the cells in the given boundary are identified by their relative position in the filtration, * starting at 0. If it is not the case, use the other * @ref insert_boundary(ID_index, const Boundary_range&, Dimension) "insert_boundary" instead by indicating the - * face ID used in the boundaries when the face is inserted. + * cell ID used in the boundaries when the cell is inserted. * * Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from - * a more general cell complex. This includes cubical complexes or Morse complexes for example. + * a more general entry complex. This includes cubical complexes or Morse complexes for example. * * At the insertion, the boundary is stored in its reduced form and the barcode, if enabled, is updated. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() * method. * @param boundary Boundary generating the new column. The content should be ordered by ID. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template void insert_boundary(const Boundary_range& boundary, Dimension dim = -1); /** - * @brief It does the same as the other version, but allows the boundary faces to be identified without restrictions + * @brief It does the same as the other version, but allows the boundary cells to be identified without restrictions * except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then * to use the other insertion method to avoid overwriting IDs. * - * As a face has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that - * the faces are inserted by order of filtration), it is sufficient to indicate the ID of the face being inserted. + * As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that + * the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted. * - * @tparam Boundary_range Range of @ref Matrix::Cell_representative. Assumed to have a begin(), end() and size() + * @tparam Boundary_range Range of @ref Matrix::Entry_representative. Assumed to have a begin(), end() and size() * method. - * @param faceIndex @ref IDIdx index to use to identify the new face. + * @param cellIndex @ref IDIdx index to use to identify the new cell. * @param boundary Boundary generating the new column. The indices of the boundary have to correspond to the - * @p faceIndex values of precedent calls of the method for the corresponding faces and should be ordered in + * @p cellIndex values of precedent calls of the method for the corresponding cells and should be ordered in * increasing order. - * @param dim Dimension of the face whose boundary is given. If the complex is simplicial, + * @param dim Dimension of the cell whose boundary is given. If the complex is simplicial, * this parameter can be omitted as it can be deduced from the size of the boundary. */ template - void insert_boundary(ID_index faceIndex, const Boundary_range& boundary, Dimension dim = -1); + void insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim = -1); /** * @brief Returns the column at the given @ref MatIdx index in \f$ R \f$ if @p inR is true and * in \f$ U \f$ if @p inR is false. * The type of the column depends on the choosen options, see @ref PersistenceMatrixOptions::column_type. * - * Note that before returning the column, all column cells can eventually be reordered, if lazy swaps occurred. + * Note that before returning the column, all column entries can eventually be reordered, if lazy swaps occurred. * It is therefore recommended to avoid calling @ref get_column between vine swaps, otherwise the benefits * of the the laziness is lost. * @@ -171,7 +172,7 @@ class RU_matrix : public Master_matrix::RU_pairing_option, * in \f$ U \f$ if @p inR is false. * The type of the row depends on the choosen options, see @ref PersistenceMatrixOptions::has_intrusive_rows. * - * Note that before returning the row, all column cells can eventually be reordered, if lazy swaps occurred. + * Note that before returning the row, all column entries can eventually be reordered, if lazy swaps occurred. * It is therefore recommended to avoid calling @ref get_row between vine swaps, otherwise the benefits * of the the laziness is lost. * @@ -190,10 +191,10 @@ class RU_matrix : public Master_matrix::RU_pairing_option, * Otherwise, does nothing. * * @warning The removed rows are always assumed to be empty in \f$ R \f$. If it is not the case, the deleted row - * cells are not removed from their columns. And in the case of intrusive rows, this will generate a segmentation - * fault when the column cells are destroyed later. The row access is just meant as a "read only" access to the + * entries are not removed from their columns. And in the case of intrusive rows, this will generate a segmentation + * fault when the column entries are destroyed later. The row access is just meant as a "read only" access to the * rows and the @ref erase_empty_row method just as a way to specify that a row is empty and can therefore be removed - * from dictionaries. This allows to avoid testing the emptiness of a row at each column cell removal, what can + * from dictionaries. This allows to avoid testing the emptiness of a row at each column entry removal, what can * be quite frequent. * * @param rowIndex @ref rowindex "Row index" of the empty row. @@ -202,26 +203,26 @@ class RU_matrix : public Master_matrix::RU_pairing_option, /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns and * @ref PersistenceMatrixOptions::has_vine_update are true. - * Assumes that the face is maximal in the current complex and removes it such that the matrix remains consistent + * Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent * (i.e., RU is still an upper triangular decomposition of the @ref boundarymatrix "boundary matrix"). - * The maximality of the face is not verified. + * The maximality of the cell is not verified. * Also updates the barcode if it is stored. * * See also @ref remove_last. * - * @param columnIndex @ref MatIdx index of the face to remove. + * @param columnIndex @ref MatIdx index of the cell to remove. */ - void remove_maximal_face(Index columnIndex); + void remove_maximal_cell(Index columnIndex); /** * @brief Only available if @ref PersistenceMatrixOptions::has_removable_columns is true. - * Removes the last face in the filtration from the matrix and updates the barcode if it is stored. + * Removes the last cell in the filtration from the matrix and updates the barcode if it is stored. * - * See also @ref remove_maximal_face. + * See also @ref remove_maximal_cell. */ void remove_last(); /** - * @brief Returns the maximal dimension of a face stored in the matrix. + * @brief Returns the maximal dimension of a cell stored in the matrix. * Only available if @ref PersistenceMatrixOptions::has_matrix_maximal_dimension_access is true. * * @return The maximal dimension. @@ -236,8 +237,8 @@ class RU_matrix : public Master_matrix::RU_pairing_option, /** * @brief Returns the dimension of the given column. * - * @param columnIndex @ref MatIdx index of the column representing the face. - * @return Dimension of the face. + * @param columnIndex @ref MatIdx index of the column representing the cell. + * @return Dimension of the cell. */ Dimension get_column_dimension(Index columnIndex) const; @@ -280,16 +281,16 @@ class RU_matrix : public Master_matrix::RU_pairing_option, void multiply_source_and_add_to(const Field_element& coefficient, Index sourceColumnIndex, Index targetColumnIndex); /** - * @brief Zeroes the cell at the given coordinates in \f$ R \f$ if @p inR is true or in + * @brief Zeroes the entry at the given coordinates in \f$ R \f$ if @p inR is true or in * \f$ U \f$ if @p inR is false. Should be used with care to not destroy the validity of the persistence * related properties of the matrix. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. * @param inR Boolean indicating in which matrix to zero: if true in \f$ R \f$ and if false in \f$ U \f$. * Default value: true. */ - void zero_cell(Index columnIndex, Index rowIndex, bool inR = true); + void zero_entry(Index columnIndex, Index rowIndex, bool inR = true); /** * @brief Zeroes the column at the given index in \f$ R \f$ if @p inR is true or in * \f$ U \f$ if @p inR is false. Should be used with care to not destroy the validity of the persistence @@ -301,17 +302,17 @@ class RU_matrix : public Master_matrix::RU_pairing_option, */ void zero_column(Index columnIndex, bool inR = true); /** - * @brief Indicates if the cell at given coordinates has value zero in \f$ R \f$ + * @brief Indicates if the entry at given coordinates has value zero in \f$ R \f$ * if @p inR is true or in \f$ U \f$ if @p inR is false. * - * @param columnIndex @ref MatIdx index of the column of the cell. - * @param rowIndex @ref rowindex "Row index" of the row of the cell. + * @param columnIndex @ref MatIdx index of the column of the entry. + * @param rowIndex @ref rowindex "Row index" of the row of the entry. * @param inR Boolean indicating in which matrix to look: if true in \f$ R \f$ and if false in \f$ U \f$. * Default value: true. - * @return true If the cell has value zero. + * @return true If the entry has value zero. * @return false Otherwise. */ - bool is_zero_cell(Index columnIndex, Index rowIndex, bool inR = true) const; + bool is_zero_entry(Index columnIndex, Index rowIndex, bool inR = true) const; /** * @brief Indicates if the column at given index has value zero in \f$ R \f$ * if @p inR is true or in \f$ U \f$ if @p inR is false. @@ -330,10 +331,10 @@ class RU_matrix : public Master_matrix::RU_pairing_option, * @brief Returns the @ref MatIdx index of the column which has the given @ref rowindex "row index" as pivot in * \f$ R \f$. Assumes that the pivot exists. * - * @param faceIndex @ref rowindex "Row index" of the pivot. + * @param cellIndex @ref rowindex "Row index" of the pivot. * @return @ref MatIdx index of the column in \f$ R \f$ with the given pivot. */ - Index get_column_with_pivot(Index faceIndex) const; + Index get_column_with_pivot(Index cellIndex) const; /** * @brief Returns the @ref rowindex "row index" of the pivot of the given column in \f$ R \f$. * @@ -521,28 +522,28 @@ inline void RU_matrix::insert_boundary(const Boundary_range& boun template template -inline void RU_matrix::insert_boundary(ID_index faceIndex, +inline void RU_matrix::insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim) { // maps for possible shifting between column content and position indices used for birth events if constexpr (Master_matrix::Option_list::has_column_pairings && !Master_matrix::Option_list::has_vine_update) { - if (faceIndex != nextEventIndex_) { - Pair_opt::idToPosition_.emplace(faceIndex, nextEventIndex_); + if (cellIndex != nextEventIndex_) { + Pair_opt::idToPosition_.emplace(cellIndex, nextEventIndex_); if constexpr (Master_matrix::Option_list::has_removable_columns) { - Pair_opt::PIDM::map_.emplace(nextEventIndex_, faceIndex); + Pair_opt::PIDM::map_.emplace(nextEventIndex_, cellIndex); } } } if constexpr (Master_matrix::Option_list::has_vine_update) { - if (faceIndex != nextEventIndex_) { - Swap_opt::_positionToRowIdx().emplace(nextEventIndex_, faceIndex); + if (cellIndex != nextEventIndex_) { + Swap_opt::_positionToRowIdx().emplace(nextEventIndex_, cellIndex); if (Master_matrix::Option_list::has_column_pairings) { - Swap_opt::template RU_pairing::idToPosition_.emplace(faceIndex, nextEventIndex_); + Swap_opt::template RU_pairing::idToPosition_.emplace(cellIndex, nextEventIndex_); } } } - _insert_boundary(reducedMatrixR_.insert_boundary(faceIndex, boundary, dim)); + _insert_boundary(reducedMatrixR_.insert_boundary(cellIndex, boundary, dim)); } template @@ -572,10 +573,10 @@ inline void RU_matrix::erase_empty_row(Index rowIndex) } template -inline void RU_matrix::remove_maximal_face(Index columnIndex) +inline void RU_matrix::remove_maximal_cell(Index columnIndex) { static_assert(Master_matrix::Option_list::has_removable_columns && Master_matrix::Option_list::has_vine_update, - "'remove_maximal_face' is not implemented for the chosen options."); + "'remove_maximal_cell' is not implemented for the chosen options."); // TODO: is there an easy test to verify maximality even without row access? @@ -637,7 +638,7 @@ inline void RU_matrix::add_to(Index sourceColumnIndex, Index targ { reducedMatrixR_.add_to(sourceColumnIndex, targetColumnIndex); // U transposed to avoid row operations - if constexpr (Master_matrix::Option_list::has_vine_update) + if constexpr (Master_matrix::Option_list::is_z2) mirrorMatrixU_.add_to(targetColumnIndex, sourceColumnIndex); else mirrorMatrixU_.add_to(sourceColumnIndex, targetColumnIndex); @@ -648,6 +649,8 @@ inline void RU_matrix::multiply_target_and_add_to(Index sourceCol const Field_element& coefficient, Index targetColumnIndex) { + static_assert(!Master_matrix::Option_list::is_z2, + "Multiplication with something else than the identity is not allowed with Z2 coefficients."); reducedMatrixR_.multiply_target_and_add_to(sourceColumnIndex, coefficient, targetColumnIndex); mirrorMatrixU_.multiply_target_and_add_to(sourceColumnIndex, coefficient, targetColumnIndex); } @@ -657,17 +660,19 @@ inline void RU_matrix::multiply_source_and_add_to(const Field_ele Index sourceColumnIndex, Index targetColumnIndex) { + static_assert(!Master_matrix::Option_list::is_z2, + "Multiplication with something else than the identity is not allowed with Z2 coefficients."); reducedMatrixR_.multiply_source_and_add_to(coefficient, sourceColumnIndex, targetColumnIndex); mirrorMatrixU_.multiply_source_and_add_to(coefficient, sourceColumnIndex, targetColumnIndex); } template -inline void RU_matrix::zero_cell(Index columnIndex, Index rowIndex, bool inR) +inline void RU_matrix::zero_entry(Index columnIndex, Index rowIndex, bool inR) { if (inR) { - return reducedMatrixR_.zero_cell(columnIndex, rowIndex); + return reducedMatrixR_.zero_entry(columnIndex, rowIndex); } - return mirrorMatrixU_.zero_cell(columnIndex, rowIndex); + return mirrorMatrixU_.zero_entry(columnIndex, rowIndex); } template @@ -680,12 +685,12 @@ inline void RU_matrix::zero_column(Index columnIndex, bool inR) } template -inline bool RU_matrix::is_zero_cell(Index columnIndex, Index rowIndex, bool inR) const +inline bool RU_matrix::is_zero_entry(Index columnIndex, Index rowIndex, bool inR) const { if (inR) { - return reducedMatrixR_.is_zero_cell(columnIndex, rowIndex); + return reducedMatrixR_.is_zero_entry(columnIndex, rowIndex); } - return mirrorMatrixU_.is_zero_cell(columnIndex, rowIndex); + return mirrorMatrixU_.is_zero_entry(columnIndex, rowIndex); } template @@ -698,12 +703,12 @@ inline bool RU_matrix::is_zero_column(Index columnIndex, bool inR } template -inline typename RU_matrix::Index RU_matrix::get_column_with_pivot(Index faceIndex) const +inline typename RU_matrix::Index RU_matrix::get_column_with_pivot(Index cellIndex) const { if constexpr (Master_matrix::Option_list::has_map_column_container) { - return pivotToColumnIndex_.at(faceIndex); + return pivotToColumnIndex_.at(cellIndex); } else { - return pivotToColumnIndex_[faceIndex]; + return pivotToColumnIndex_[cellIndex]; } } @@ -843,10 +848,7 @@ inline void RU_matrix::_reduce_column_by(Index target, Index sour curr += reducedMatrixR_.get_column(source); // to avoid having to do line operations during vineyards, U is transposed // TODO: explain this somewhere in the documentation... - if constexpr (Master_matrix::Option_list::has_vine_update) - mirrorMatrixU_.get_column(source) += mirrorMatrixU_.get_column(target); - else - mirrorMatrixU_.get_column(target) += mirrorMatrixU_.get_column(source); + mirrorMatrixU_.get_column(source).push_back(*mirrorMatrixU_.get_column(target).begin()); } else { Column& toadd = reducedMatrixR_.get_column(source); Field_element coef = toadd.get_pivot_value(); @@ -854,8 +856,9 @@ inline void RU_matrix::_reduce_column_by(Index target, Index sour operators_->multiply_inplace(coef, operators_->get_characteristic() - curr.get_pivot_value()); curr.multiply_source_and_add(toadd, coef); + // but no transposition for Zp, careful if there will be vineyard or rep cycles in Zp one day + // TODO: explain this somewhere in the documentation... mirrorMatrixU_.multiply_source_and_add_to(coef, source, target); - // mirrorMatrixU_.get_column(target).multiply_source_and_add(mirrorMatrixU_.get_column(source), coef); } } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h b/multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h new file mode 100644 index 0000000..8485477 --- /dev/null +++ b/multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h @@ -0,0 +1,139 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Hannah Schreiber + * + * Copyright (C) 2024 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +/** + * @file entry_constructors.h + * @author Hannah Schreiber + * @brief Contains different versions of @ref Gudhi::persistence_matrix::Entry factories. + */ + +#ifndef PM_COLUMN_ENTRY_CONSTRUCTORS_H +#define PM_COLUMN_ENTRY_CONSTRUCTORS_H + +#include //std::swap + +#include + +namespace Gudhi { +namespace persistence_matrix { + +/** + * @private + * @ingroup persistence_matrix + * + * @brief @ref Entry factory. Constructs and destroys entry pointers with new and delete. + * + * @tparam Entry @ref Entry with the right templates. + */ +template +struct New_entry_constructor +{ + /** + * @brief Default constructor. + */ + New_entry_constructor() {} + + /** + * @brief Constructs an entry with the given entry arguments. + * + * @param u Arguments forwarded to the @ref Entry constructor. + * @return @ref Entry pointer. + */ + template + Entry* construct(U&&... u) const { + return new Entry(std::forward(u)...); + } + + /** + * @brief Destroys the given entry. + * + * @param entry @ref Entry pointer. + */ + void destroy(Entry* entry) const { delete entry; } + + /** + * @brief Swap operator. + */ + friend void swap(New_entry_constructor& col1, New_entry_constructor& col2) {} +}; + +/** + * @private + * @ingroup persistence_matrix + * + * @brief @ref Entry factory. Uses @ref Gudhi::Simple_object_pool, which is based on boost::object_pool, + * to construct and destroy entry pointer. + * + * @tparam Entry @ref Entry with the right templates. + */ +template +struct Pool_entry_constructor +{ + public: + /** + * @brief Default constructor. + * + */ + Pool_entry_constructor() : entryPool_() {} + //TODO: what does happen when the pool is copied? + /** + * @brief Copy constructor. + * + * @param col Factory to copy. + */ + Pool_entry_constructor(const Pool_entry_constructor& col) : entryPool_(col.entryPool_) {} + /** + * @brief Move constructor. + * + * @param col Factory to move. + */ + Pool_entry_constructor(Pool_entry_constructor&& col) : entryPool_(std::move(col.entryPool_)) {} + + /** + * @brief Constructs an entry with the given entry arguments. + * + * @param u Arguments forwarded to the @ref Entry constructor. + * @return @ref Entry pointer. + */ + template + Entry* construct(U&&... u) { + return entryPool_.construct(std::forward(u)...); + } + + /** + * @brief Destroys the given entry. + * + * @param entry @ref Entry pointer. + */ + void destroy(Entry* entry) { entryPool_.destroy(entry); } + + //TODO: Again, what does it mean to copy the pool? + /** + * @brief Assign operator. + */ + Pool_entry_constructor& operator=(const Pool_entry_constructor& other) { + entryPool_ = other.entryPool_; + return *this; + } + /** + * @brief Swap operator. + */ + friend void swap(Pool_entry_constructor& col1, Pool_entry_constructor& col2) { + std::swap(col1.entryPool_, col2.entryPool_); + } + + private: + Simple_object_pool entryPool_; /**< Entry pool. */ +}; + +} // namespace persistence_matrix +} // namespace Gudhi + +#endif // PM_COLUMN_ENTRY_CONSTRUCTORS_H diff --git a/multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h b/multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h index ac883ff..8ce95ce 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h @@ -23,7 +23,7 @@ #include #include -#include "boundary_face_position_to_id_mapper.h" +#include "boundary_cell_position_to_id_mapper.h" namespace Gudhi { namespace persistence_matrix { @@ -50,7 +50,7 @@ struct Dummy_base_pairing { template class Base_pairing : public std::conditional< Master_matrix::Option_list::has_removable_columns, - Face_position_to_ID_mapper, + Cell_position_to_ID_mapper, Dummy_pos_mapper >::type { @@ -82,8 +82,8 @@ class Base_pairing : public std::conditional< */ friend void swap(Base_pairing& pairing1, Base_pairing& pairing2) { if constexpr (Master_matrix::Option_list::has_removable_columns) { - swap(static_cast&>(pairing1), - static_cast&>(pairing2)); + swap(static_cast&>(pairing1), + static_cast&>(pairing2)); } pairing1.barcode_.swap(pairing2.barcode_); pairing1.deathToBar_.swap(pairing2.deathToBar_); @@ -98,14 +98,14 @@ class Base_pairing : public std::conditional< using Base_matrix = typename Master_matrix::Master_boundary_matrix; //PIDM = Position to ID Map using PIDM = typename std::conditional, + Cell_position_to_ID_mapper, Dummy_pos_mapper >::type; Barcode barcode_; /**< Bar container. */ Dictionary deathToBar_; /**< Map from death index to bar index. */ /** - * @brief Map from face ID to face position. Only stores a pair if ID != position. + * @brief Map from cell ID to cell position. Only stores a pair if ID != position. */ std::unordered_map idToPosition_; //TODO: test other map types bool isReduced_; /**< True if `_reduce()` was called. */ diff --git a/multipers/gudhi/gudhi/Persistence_matrix/base_swap.h b/multipers/gudhi/gudhi/Persistence_matrix/base_swap.h index e8f9bf4..db6af1c 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/base_swap.h @@ -77,7 +77,7 @@ class Base_swap { /** * @brief Swaps the two columns at given indices in the column container. Does not updates the column index value, - * potentially stored in the cells. This will be done when calling `_orderRows()`. + * potentially stored in the entries. This will be done when calling `_orderRows()`. * * @param columnIndex1 First @ref MatIdx column index. * @param columnIndex2 Second @ref MatIdx column index. @@ -145,7 +145,7 @@ template inline void Base_swap::swap_columns(Index columnIndex1, Index columnIndex2) { swap(_matrix()->matrix_.at(columnIndex1), _matrix()->matrix_.at(columnIndex2)); - if constexpr (Master_matrix::Option_list::has_row_access) rowSwapped_ = true; //to update column index in cells. + if constexpr (Master_matrix::Option_list::has_row_access) rowSwapped_ = true; //to update column index in entries. } template diff --git a/multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h b/multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h new file mode 100644 index 0000000..1b85b07 --- /dev/null +++ b/multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h @@ -0,0 +1,60 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Hannah Schreiber + * + * Copyright (C) 2022-24 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +/** + * @file boundary_cell_position_to_id_mapper.h + * @author Hannah Schreiber + * @brief Contains the @ref Gudhi::persistence_matrix::Cell_position_to_ID_mapper class and + * @ref Gudhi::persistence_matrix::Dummy_pos_mapper structure. + */ + +#ifndef PM_ID_POS_MAPPER_H +#define PM_ID_POS_MAPPER_H + +#include + +namespace Gudhi { +namespace persistence_matrix { + +/** + * @private + * @ingroup persistence_matrix + * + * @brief Empty structure. + * Inherited instead of @ref Cell_position_to_ID_mapper. + */ +struct Dummy_pos_mapper { + friend void swap([[maybe_unused]] Dummy_pos_mapper& d1, [[maybe_unused]] Dummy_pos_mapper& d2) {} +}; + +/** + * @private + * @ingroup persistence_matrix + * + * @brief Map from cell position to cell ID. Only stores a pair if ID != position and has_removable_column is true. + * + * @tparam ID_index @ref IDIdx index type + * @tparam Pos_index @ref PosIdx index type + */ +template +struct Cell_position_to_ID_mapper { + using Index_map = std::unordered_map; //TODO: test other map types + + Index_map map_; + + friend void swap(Cell_position_to_ID_mapper& mapper1, Cell_position_to_ID_mapper& mapper2) { + mapper1.map_.swap(mapper2.map_); + } +}; + +} // namespace persistence_matrix +} // namespace Gudhi + +#endif // PM_ID_POS_MAPPER_H diff --git a/multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h b/multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h index 2956ba0..3168b54 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h @@ -281,23 +281,23 @@ class Chain_vine_swap : public std::conditional::Index Chain_vine_swapis_zero_cell(columnIndex2, _matrix()->get_pivot(columnIndex1))) { + if (_matrix()->is_zero_entry(columnIndex2, _matrix()->get_pivot(columnIndex1))) { if constexpr (Master_matrix::Option_list::has_column_pairings) { ID_index pivot1 = _matrix()->get_pivot(columnIndex1); ID_index pivot2 = _matrix()->get_pivot(columnIndex2); @@ -415,7 +415,7 @@ inline typename Chain_vine_swap::Index Chain_vine_swapis_zero_cell(columnIndex2, _matrix()->get_pivot(columnIndex1))) { + if (_matrix()->is_zero_entry(columnIndex2, _matrix()->get_pivot(columnIndex1))) { if constexpr (Master_matrix::Option_list::has_column_pairings) { ID_index pivot1 = _matrix()->get_pivot(columnIndex1); ID_index pivot2 = _matrix()->get_pivot(columnIndex2); @@ -429,7 +429,7 @@ inline typename Chain_vine_swap::Index Chain_vine_swapis_zero_cell(columnIndex2, _matrix()->get_pivot(columnIndex1))) { + if (_matrix()->is_zero_entry(columnIndex2, _matrix()->get_pivot(columnIndex1))) { if constexpr (Master_matrix::Option_list::has_column_pairings) { ID_index pivot1 = _matrix()->get_pivot(columnIndex1); ID_index pivot2 = _matrix()->get_pivot(columnIndex2); @@ -442,7 +442,7 @@ inline typename Chain_vine_swap::Index Chain_vine_swapis_zero_cell(columnIndex2, _matrix()->get_pivot(columnIndex1))) { + if (_matrix()->is_zero_entry(columnIndex2, _matrix()->get_pivot(columnIndex1))) { if constexpr (Master_matrix::Option_list::has_column_pairings) { ID_index pivot1 = _matrix()->get_pivot(columnIndex1); ID_index pivot2 = _matrix()->get_pivot(columnIndex2); diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h index aca3982..5fb6d6a 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h @@ -66,14 +66,14 @@ class Chain_column_extra_properties /** * @brief Constructor setting the pivot at the given value and the pair to -1 (i.e. not paired). * - * @param pivot @ref rowindex "Row index" of the pivot. Corresponds to the @ref IDIdx index of the face represented + * @param pivot @ref rowindex "Row index" of the pivot. Corresponds to the @ref IDIdx index of the cell represented * by the column. */ Chain_column_extra_properties(ID_index pivot) : pivot_(pivot), pairedColumn_(-1) {} /** * @brief Constructor setting the pivot and the pair at the given values. * - * @param pivot @ref rowindex "Row index" of the pivot. Corresponds to the @ref IDIdx index of the face represented + * @param pivot @ref rowindex "Row index" of the pivot. Corresponds to the @ref IDIdx index of the cell represented * by the column. * @param pair @ref MatIdx index of the pair of the column. */ diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h index 360ac37..bb7670c 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h @@ -25,11 +25,11 @@ namespace Gudhi { namespace persistence_matrix { -template -Cell* _get_cell(const Cell_iterator& itTarget) +template +Entry* _get_entry(const Entry_iterator& itTarget) { - if constexpr (Cell::Master::Option_list::column_type == Column_types::INTRUSIVE_LIST || - Cell::Master::Option_list::column_type == Column_types::INTRUSIVE_SET) { + if constexpr (Entry::Master::Option_list::column_type == Column_types::INTRUSIVE_LIST || + Entry::Master::Option_list::column_type == Column_types::INTRUSIVE_SET) { return &*itTarget; } else { return *itTarget; @@ -37,41 +37,41 @@ Cell* _get_cell(const Cell_iterator& itTarget) } // works only for ordered columns -template -void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, - typename Column::Column_support::iterator& itTarget, - F1&& process_target, - F2&& process_source, - F3&& update_target1, - F4&& update_target2, - bool& pivotIsZeroed) +template +void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, + typename Column::Column_support::iterator& itTarget, + F1&& process_target, + F2&& process_source, + F3&& update_target1, + F4&& update_target2, + bool& pivotIsZeroed) { - typename Column::Cell* targetCell = _get_cell(itTarget); + typename Column::Entry* targetEntry = _get_entry(itTarget); - if (targetCell->get_row_index() < itSource->get_row_index()) { - process_target(targetCell); + if (targetEntry->get_row_index() < itSource->get_row_index()) { + process_target(targetEntry); ++itTarget; - } else if (targetCell->get_row_index() > itSource->get_row_index()) { + } else if (targetEntry->get_row_index() > itSource->get_row_index()) { process_source(itSource, itTarget); ++itSource; } else { if constexpr (Column::Master::Option_list::is_z2) { //_multiply_*_and_add never enters here so not treated if constexpr (Column::Master::isNonBasic && !Column::Master::Option_list::is_of_boundary_type) { - if (targetCell->get_row_index() == targetColumn.get_pivot()) pivotIsZeroed = true; + if (targetEntry->get_row_index() == targetColumn.get_pivot()) pivotIsZeroed = true; } - targetColumn._delete_cell(itTarget); + targetColumn._delete_entry(itTarget); } else { - update_target1(targetCell->get_element(), itSource); - if (targetCell->get_element() == Column::Field_operators::get_additive_identity()) { + update_target1(targetEntry->get_element(), itSource); + if (targetEntry->get_element() == Column::Field_operators::get_additive_identity()) { if constexpr (Column::Master::isNonBasic && !Column::Master::Option_list::is_of_boundary_type) { - if (targetCell->get_row_index() == targetColumn.get_pivot()) pivotIsZeroed = true; + if (targetEntry->get_row_index() == targetColumn.get_pivot()) pivotIsZeroed = true; } - targetColumn._delete_cell(itTarget); + targetColumn._delete_entry(itTarget); } else { - update_target2(targetCell); - if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_cell(*targetCell); + update_target2(targetEntry); + if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_entry(*targetEntry); ++itTarget; } } @@ -80,8 +80,8 @@ void _generic_merge_cell_to_column(Column& targetColumn, } // works only for ordered columns -template -bool _generic_add_to_column(const Cell_range& source, +template +bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, @@ -95,9 +95,9 @@ bool _generic_add_to_column(const Cell_range& source, auto itTarget = target.begin(); auto itSource = source.begin(); while (itTarget != target.end() && itSource != source.end()) { - _generic_merge_cell_to_column(targetColumn, itSource, itTarget, - process_target, process_source, update_target1, update_target2, - pivotIsZeroed); + _generic_merge_entry_to_column(targetColumn, itSource, itTarget, + process_target, process_source, update_target1, update_target2, + pivotIsZeroed); } finish_target(itTarget); @@ -110,32 +110,32 @@ bool _generic_add_to_column(const Cell_range& source, return pivotIsZeroed; } -template -bool _add_to_column(const Cell_range& source, Column& targetColumn) +template +bool _add_to_column(const Entry_range& source, Column& targetColumn) { return _generic_add_to_column( source, targetColumn, - [&]([[maybe_unused]] typename Column::Cell* cellTarget) {}, - [&](typename Cell_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { + [&]([[maybe_unused]] typename Column::Entry* entryTarget) {}, + [&](typename Entry_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { if constexpr (Column::Master::Option_list::is_z2) { - targetColumn._insert_cell(itSource->get_row_index(), itTarget); + targetColumn._insert_entry(itSource->get_row_index(), itTarget); } else { - targetColumn._insert_cell(itSource->get_element(), itSource->get_row_index(), itTarget); + targetColumn._insert_entry(itSource->get_element(), itSource->get_row_index(), itTarget); } }, - [&](typename Column::Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](typename Column::Field_element& targetElement, typename Entry_range::const_iterator& itSource) { if constexpr (!Column::Master::Option_list::is_z2) targetColumn.operators_->add_inplace(targetElement, itSource->get_element()); }, - [&]([[maybe_unused]] typename Column::Cell* cellTarget) {}, + [&]([[maybe_unused]] typename Column::Entry* entryTarget) {}, [&]([[maybe_unused]] typename Column::Column_support::iterator& itTarget) {} ); } -template +template bool _multiply_target_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn) { if (val == 0u) { @@ -150,33 +150,33 @@ bool _multiply_target_and_add_to_column(const typename Column::Field_element& va return _generic_add_to_column( source, targetColumn, - [&](typename Column::Cell* cellTarget) { - targetColumn.operators_->multiply_inplace(cellTarget->get_element(), val); - // targetColumn.RA_opt::update_cell(*itTarget) produces an internal compiler error + [&](typename Column::Entry* entryTarget) { + targetColumn.operators_->multiply_inplace(entryTarget->get_element(), val); + // targetColumn.RA_opt::update_entry(*itTarget) produces an internal compiler error // even though it works in _generic_add_to_column... Probably because of the lambda. - if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_cell(*cellTarget); + if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_entry(*entryTarget); }, - [&](typename Cell_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { - targetColumn._insert_cell(itSource->get_element(), itSource->get_row_index(), itTarget); + [&](typename Entry_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { + targetColumn._insert_entry(itSource->get_element(), itSource->get_row_index(), itTarget); }, - [&](typename Column::Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](typename Column::Field_element& targetElement, typename Entry_range::const_iterator& itSource) { targetColumn.operators_->multiply_and_add_inplace_front(targetElement, val, itSource->get_element()); }, - [&]([[maybe_unused]] typename Column::Cell* cellTarget) {}, + [&]([[maybe_unused]] typename Column::Entry* entryTarget) {}, [&](typename Column::Column_support::iterator& itTarget) { while (itTarget != targetColumn.column_.end()) { - typename Column::Cell* targetCell = _get_cell(itTarget); - targetColumn.operators_->multiply_inplace(targetCell->get_element(), val); - if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_cell(*targetCell); + typename Column::Entry* targetEntry = _get_entry(itTarget); + targetColumn.operators_->multiply_inplace(targetEntry->get_element(), val); + if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_entry(*targetEntry); itTarget++; } } ); } -template +template bool _multiply_source_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn) { if (val == 0u) { @@ -186,17 +186,17 @@ bool _multiply_source_and_add_to_column(const typename Column::Field_element& va return _generic_add_to_column( source, targetColumn, - []([[maybe_unused]] typename Column::Cell* cellTarget) {}, - [&](typename Cell_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { - typename Column::Cell* cell = - targetColumn._insert_cell(itSource->get_element(), itSource->get_row_index(), itTarget); - targetColumn.operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_cell(*cell); + []([[maybe_unused]] typename Column::Entry* entryTarget) {}, + [&](typename Entry_range::const_iterator& itSource, const typename Column::Column_support::iterator& itTarget) { + typename Column::Entry* entry = + targetColumn._insert_entry(itSource->get_element(), itSource->get_row_index(), itTarget); + targetColumn.operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Column::Master::Option_list::has_row_access) targetColumn.update_entry(*entry); }, - [&](typename Column::Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](typename Column::Field_element& targetElement, typename Entry_range::const_iterator& itSource) { targetColumn.operators_->multiply_and_add_inplace_back(itSource->get_element(), val, targetElement); }, - [&]([[maybe_unused]] typename Column::Cell* cellTarget) {}, + [&]([[maybe_unused]] typename Column::Entry* entryTarget) {}, []([[maybe_unused]] typename Column::Column_support::iterator& itTarget) {}); } @@ -206,8 +206,8 @@ template std::size_t hash_column(const Column& column) { std::size_t seed = 0; - for (auto& cell : column) { - seed ^= std::hash()(cell.get_row_index() * static_cast(cell.get_element())) + + for (auto& entry : column) { + seed ^= std::hash()(entry.get_row_index() * static_cast(entry.get_element())) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h new file mode 100644 index 0000000..81083d3 --- /dev/null +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h @@ -0,0 +1,327 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Hannah Schreiber + * + * Copyright (C) 2022-24 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +/** + * @file entry_types.h + * @author Hannah Schreiber + * @brief Contains the @ref Gudhi::persistence_matrix::Entry, @ref Gudhi::persistence_matrix::Entry_column_index and + * @ref Gudhi::persistence_matrix::Entry_field_element classes, as well as the + * @ref Gudhi::persistence_matrix::Dummy_entry_column_index_mixin and + * @ref Gudhi::persistence_matrix::Dummy_entry_field_element_mixin structures. + * Also defines the std::hash method for @ref Gudhi::persistence_matrix::Entry. + */ + +#ifndef PM_MATRIX_ENTRY_H +#define PM_MATRIX_ENTRY_H + +#include //std::swap, std::exchange & std::move +#include //std::hash + +namespace Gudhi { +namespace persistence_matrix { + +/** + * @ingroup persistence_matrix + * + * @brief Empty structure. + * Inherited instead of @ref Entry_column_index, when the row access is disabled. + */ +struct Dummy_entry_column_index_mixin +{ + Dummy_entry_column_index_mixin() {} + template + Dummy_entry_column_index_mixin([[maybe_unused]] Index columnIndex) {} +}; + +/** + * @ingroup persistence_matrix + * + * @brief Empty structure. + * Inherited instead of @ref Entry_field_element, when @ref PersistenceMatrixOptions::is_z2 is true. + */ +struct Dummy_entry_field_element_mixin +{ + Dummy_entry_field_element_mixin() {} + template + Dummy_entry_field_element_mixin([[maybe_unused]] Field_element t) {} +}; + +/** + * @ingroup persistence_matrix + * + * @brief Class managing the column index access of an entry. + * + * @tparam Index @ref MatIdx index type. + */ +template +class Entry_column_index +{ + public: + /** + * @brief Default constructor. Sets to the column index to -1. + */ + Entry_column_index() : columnIndex_(-1){}; + /** + * @brief Stores the given column index. + * + * @param columnIndex Column index of the entry. + */ + Entry_column_index(Index columnIndex) : columnIndex_(columnIndex){}; + /** + * @brief Copy constructor. + * + * @param entry Entry to copy. + */ + Entry_column_index(const Entry_column_index& entry) : columnIndex_(entry.columnIndex_){}; + /** + * @brief Move constructor. + * + * @param entry Entry to move. + */ + Entry_column_index(Entry_column_index&& entry) noexcept : columnIndex_(std::exchange(entry.columnIndex_, 0)){}; + + /** + * @brief Returns the @ref MatIdx column index stored in the entry. + * + * @return Column index of the entry. + */ + Index get_column_index() const { return columnIndex_; }; + /** + * @brief Sets the column index to the given value. + * + * @param columnIndex Column index of the entry. + */ + void set_column_index(Index columnIndex) { columnIndex_ = columnIndex; } + + /** + * @brief Assign operator. + */ + Entry_column_index& operator=(Entry_column_index other) { + std::swap(columnIndex_, other.columnIndex_); + return *this; + }; + + private: + Index columnIndex_; /**< Column index. */ +}; + +/** + * @ingroup persistence_matrix + * + * @brief Class managing the value access of an entry. + * + * @tparam Field_element Type of an entry value. + */ +template +class Entry_field_element +{ + public: + /** + * @brief Default constructor. Sets to the element to 0. + */ + Entry_field_element() : element_(0){}; + /** + * @brief Stores the given element. + * + * @param element Value to store. + */ + Entry_field_element(Field_element element) : element_(element){}; + /** + * @brief Copy constructor. + * + * @param entry Entry to copy. + */ + Entry_field_element(const Entry_field_element& entry) : element_(entry.element_){}; + /** + * @brief Move constructor. + * + * @param entry Entry to move. + */ + Entry_field_element(Entry_field_element&& entry) noexcept : element_(std::move(entry.element_)){}; + + /** + * @brief Returns the value stored in the entry. + * + * @return Reference to the value of the entry. + */ + Field_element& get_element() { return element_; }; + /** + * @brief Returns the value stored in the entry. + * + * @return Const reference to the value of the entry. + */ + const Field_element& get_element() const { return element_; }; + /** + * @brief Sets the value. + * + * @param element Value to store. + */ + void set_element(const Field_element& element) { element_ = element; } + + /** + * @brief Assign operator. + */ + Entry_field_element& operator=(Entry_field_element other) { + std::swap(element_, other.element_); + return *this; + }; + + private: + Field_element element_; /**< Value of the entry. */ +}; + +/** + * @class Entry entry_types.h gudhi/Persistence_matrix/columns/entry_types.h + * @ingroup persistence_matrix + * + * @brief %Matrix entry class. Stores by default only the row index it belongs to, but can also store its + * column index when the row access is enabled, as well as its value when they are different from only 0 and 1. + * Zero-valued entries are never made explicit in the matrix. + * + * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. + */ +template +class Entry : public Master_matrix::Entry_column_index_option, + public Master_matrix::Entry_field_element_option, + public Master_matrix::Row_hook, + public Master_matrix::Column_hook +{ + private: + using col_opt = typename Master_matrix::Entry_column_index_option; + using field_opt = typename Master_matrix::Entry_field_element_option; + + public: + using Master = Master_matrix; /**< Access to options from outside. */ + using Index = typename Master_matrix::Index; /**< Column index type. */ + using ID_index = typename Master_matrix::ID_index; /**< Row index type. */ + using Field_element = typename Master_matrix::Element; /**< Value type. */ + + /** + * @brief Constructs an entry with all attributes at default values. + */ + Entry(){}; + /** + * @brief Constructs an entry with given row index. Other possible attributes are set at default values. + * + * @param rowIndex @ref rowindex "Row index" of the entry. + */ + Entry(ID_index rowIndex) : col_opt(), field_opt(), rowIndex_(rowIndex){}; + /** + * @brief Constructs an entry with given row and column index. Other possible attributes are set at default values. + * + * @param columnIndex Column index of the entry. + * @param rowIndex @ref rowindex "Row index" of the entry. + */ + Entry(Index columnIndex, ID_index rowIndex) : col_opt(columnIndex), field_opt(), rowIndex_(rowIndex){}; + /** + * @brief Copy constructor. + * + * @param entry Entry to copy. + */ + Entry(const Entry& entry) + : col_opt(static_cast(entry)), + field_opt(static_cast(entry)), + rowIndex_(entry.rowIndex_){}; + /** + * @brief Move constructor. + * + * @param entry Entry to move. + */ + Entry(Entry&& entry) noexcept + : col_opt(std::move(static_cast(entry))), + field_opt(std::move(static_cast(entry))), + rowIndex_(std::exchange(entry.rowIndex_, 0)){}; + + /** + * @brief Returns the row index stored in the entry. + * + * @return @ref rowindex "Row index" of the entry. + */ + ID_index get_row_index() const { return rowIndex_; }; + /** + * @brief Sets the row index stored in the entry. + * + * @param rowIndex @ref rowindex "Row index" of the entry. + */ + void set_row_index(ID_index rowIndex) { rowIndex_ = rowIndex; }; + + /** + * @brief Assign operator. + */ + Entry& operator=(Entry other) { + col_opt::operator=(other); + field_opt::operator=(other); + std::swap(rowIndex_, other.rowIndex_); + return *this; + }; + + /** + * @brief Strictly smaller than comparator. + * + * @param c1 First entry to compare. + * @param c2 Second entry to compare. + * @return true If the row index of the first entry is strictly smaller than the row index of the second entry. + * @return false Otherwise. + */ + friend bool operator<(const Entry& c1, const Entry& c2) { return c1.get_row_index() < c2.get_row_index(); } + /** + * @brief Equality comparator. + * + * @param c1 First entry to compare. + * @param c2 Second entry to compare. + * @return true If the row index of the first entry is equal to the row index of the second entry. + * @return false Otherwise. + */ + friend bool operator==(const Entry& c1, const Entry& c2) { return c1.get_row_index() == c2.get_row_index(); } + + /** + * @brief Converts the entry into a row index. + * + * @return The row index of the entry. + */ + operator ID_index() const { return rowIndex_; } + /** + * @brief Converts the entry into a pair of row index and entry value. + * + * @return A std::pair with first element the row index and second element the value. + */ + operator std::pair() const { + if constexpr (Master_matrix::Option_list::is_z2) { + return {rowIndex_, 1}; + } else { + return {rowIndex_, field_opt::element_}; + } + } + + private: + ID_index rowIndex_; /**< Row index of the entry. */ +}; + +} // namespace persistence_matrix +} // namespace Gudhi + +/** + * @ingroup persistence_matrix + * + * @brief Hash method for @ref Gudhi::persistence_matrix::Entry. + * + * The entries are differentiated by their row indices only. For example, two entries with the same row index + * but different column indices have the same hash value. + * + * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Entry. + */ +template +struct std::hash > { + std::size_t operator()(const Gudhi::persistence_matrix::Entry& entry) const { + return std::hash()(entry.get_row_index()); + } +}; + +#endif // PM_MATRIX_ENTRY_H diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h index 33e8558..c7b0fa8 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h @@ -26,7 +26,7 @@ #include -#include +#include namespace Gudhi { namespace persistence_matrix { @@ -38,13 +38,13 @@ namespace persistence_matrix { * @brief Column class following the @ref PersistenceMatrixColumn concept. Not compatible with row access. * * Column based on a heap structure. The heap is represented as a vector sorted as a heap. The top of the heap is - * the cell with the biggest row index. The sum of two columns is lazy: the content of the source is simply inserted - * into the heap of the target. Therefore the underlying vector can contain several cells with the same row index. - * The real value of a cell at a row index corresponds to the sum in the coefficient field of all values with same - * row index. Additionally, the given cell range added into the heap does not need to be somehow ordered. + * the entry with the biggest row index. The sum of two columns is lazy: the content of the source is simply inserted + * into the heap of the target. Therefore the underlying vector can contain several entries with the same row index. + * The real value of an entry at a row index corresponds to the sum in the coefficient field of all values with same + * row index. Additionally, the given entry range added into the heap does not need to be somehow ordered. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Heap_column : public Master_matrix::Column_dimension_option, public Master_matrix::Chain_column_option @@ -55,13 +55,13 @@ class Heap_column : public Master_matrix::Column_dimension_option, public Master using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - using Column_support = std::vector; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Column_support = std::vector; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = boost::indirect_iterator; @@ -119,54 +119,56 @@ class Heap_column : public Master_matrix::Column_dimension_option, public Master reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Heap_column& operator+=(const Cell_range& column); + template + Heap_column& operator+=(const Entry_range& column); Heap_column& operator+=(Heap_column& column); Heap_column& operator*=(unsigned int v); // this = v * this + column - template - Heap_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Heap_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Heap_column& multiply_target_and_add(const Field_element& val, Heap_column& column); // this = this + column * v - template - Heap_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Heap_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Heap_column& multiply_source_and_add(Heap_column& column, const Field_element& val); + void push_back(const Entry& entry); + std::size_t compute_hash_value(); friend bool operator==(const Heap_column& c1, const Heap_column& c2) { if (&c1 == &c2) return true; Heap_column cc1(c1), cc2(c2); - Cell* p1 = cc1._pop_pivot(); - Cell* p2 = cc2._pop_pivot(); + Entry* p1 = cc1._pop_pivot(); + Entry* p2 = cc2._pop_pivot(); while (p1 != nullptr && p2 != nullptr) { if (p1->get_row_index() != p2->get_row_index()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return false; } if constexpr (!Master_matrix::Option_list::is_z2) { if (p1->get_element() != p2->get_element()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return false; } } - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); p1 = cc1._pop_pivot(); p2 = cc2._pop_pivot(); } if (p1 == nullptr && p2 == nullptr) return true; if (p1 != nullptr) { - c1.cellPool_->destroy(p1); + c1.entryPool_->destroy(p1); return false; } - c2.cellPool_->destroy(p2); + c2.entryPool_->destroy(p2); return false; } friend bool operator<(const Heap_column& c1, const Heap_column& c2) { @@ -174,42 +176,42 @@ class Heap_column : public Master_matrix::Column_dimension_option, public Master // lexicographical order but starting from last value and not first Heap_column cc1(c1), cc2(c2); - Cell* p1 = cc1._pop_pivot(); - Cell* p2 = cc2._pop_pivot(); + Entry* p1 = cc1._pop_pivot(); + Entry* p2 = cc2._pop_pivot(); while (p1 != nullptr && p2 != nullptr) { if (p1->get_row_index() > p2->get_row_index()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return false; } if (p1->get_row_index() < p2->get_row_index()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return true; } if constexpr (!Master_matrix::Option_list::is_z2) { if (p1->get_element() > p2->get_element()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return false; } if (p1->get_element() < p2->get_element()) { - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); return true; } } - c1.cellPool_->destroy(p1); - c2.cellPool_->destroy(p2); + c1.entryPool_->destroy(p1); + c2.entryPool_->destroy(p2); p1 = cc1._pop_pivot(); p2 = cc2._pop_pivot(); } if (p2 == nullptr) { - c1.cellPool_->destroy(p1); + c1.entryPool_->destroy(p1); return false; } - c2.cellPool_->destroy(p2); + c2.entryPool_->destroy(p2); return true; } @@ -224,30 +226,30 @@ class Heap_column : public Master_matrix::Column_dimension_option, public Master col1.column_.swap(col2.column_); std::swap(col1.insertsSinceLastPrune_, col2.insertsSinceLastPrune_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: using Dim_opt = typename Master_matrix::Column_dimension_option; using Chain_opt = typename Master_matrix::Chain_column_option; - struct CellPointerComp { - bool operator()(const Cell* c1, const Cell* c2) const { return *c1 < *c2; } - } cellPointerComp_; + struct EntryPointerComp { + bool operator()(const Entry* c1, const Entry* c2) const { return *c1 < *c2; } + } entryPointerComp_; Column_support column_; unsigned int insertsSinceLastPrune_; Field_operators* operators_; - Cell_constructor* cellPool_; + Entry_constructor* entryPool_; void _prune(); - Cell* _pop_pivot(); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + Entry* _pop_pivot(); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -256,7 +258,7 @@ inline Heap_column::Heap_column(Column_settings* colSettings) Chain_opt(), insertsSinceLastPrune_(0), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { if (colSettings == nullptr) return; // to allow default constructor which gives a dummy column @@ -273,7 +275,7 @@ inline Heap_column::Heap_column(const Container& nonZeroRowIndice column_(nonZeroRowIndices.size(), nullptr), insertsSinceLastPrune_(0), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -285,15 +287,15 @@ inline Heap_column::Heap_column(const Container& nonZeroRowIndice Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - column_[i++] = cellPool_->construct(id); + column_[i++] = entryPool_->construct(id); } } else { for (const auto& p : nonZeroRowIndices) { - column_[i] = cellPool_->construct(p.first); + column_[i] = entryPool_->construct(p.first); column_[i++]->set_element(operators_->get_value(p.second)); } } - std::make_heap(column_.begin(), column_.end(), cellPointerComp_); + std::make_heap(column_.begin(), column_.end(), entryPointerComp_); } template @@ -312,21 +314,21 @@ inline Heap_column::Heap_column(const Container& nonZeroRowIndice column_(nonZeroRowIndices.size(), nullptr), insertsSinceLastPrune_(0), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - column_[i++] = cellPool_->construct(id); + column_[i++] = entryPool_->construct(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - column_[i] = cellPool_->construct(p.first); + column_[i] = entryPool_->construct(p.first); column_[i++]->set_element(operators_->get_value(p.second)); } } - std::make_heap(column_.begin(), column_.end(), cellPointerComp_); + std::make_heap(column_.begin(), column_.end(), entryPointerComp_); } template @@ -336,7 +338,7 @@ inline Heap_column::Heap_column(const Heap_column& column, Column column_(column.column_.size(), nullptr), insertsSinceLastPrune_(0), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -347,12 +349,12 @@ inline Heap_column::Heap_column(const Heap_column& column, Column } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - column_[i++] = cellPool_->construct(cell->get_row_index()); + column_[i++] = entryPool_->construct(entry->get_row_index()); } else { - column_[i] = cellPool_->construct(cell->get_row_index()); - column_[i++]->set_element(cell->get_element()); + column_[i] = entryPool_->construct(entry->get_row_index()); + column_[i++]->set_element(entry->get_element()); } } // column.column_ already ordered as a heap, so no need of make_heap. @@ -365,7 +367,7 @@ inline Heap_column::Heap_column(Heap_column&& column) noexcept column_(std::move(column.column_)), insertsSinceLastPrune_(std::exchange(column.insertsSinceLastPrune_, 0)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template @@ -385,7 +387,7 @@ inline Heap_column::Heap_column(Index columnIndex, column_(nonZeroRowIndices.size(), nullptr), insertsSinceLastPrune_(0), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -393,16 +395,16 @@ inline Heap_column::Heap_column(Index columnIndex, Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - column_[i++] = cellPool_->construct(id); + column_[i++] = entryPool_->construct(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - column_[i] = cellPool_->construct(p.first); + column_[i] = entryPool_->construct(p.first); column_[i++]->set_element(operators_->get_value(p.second)); } } - std::make_heap(column_.begin(), column_.end(), cellPointerComp_); + std::make_heap(column_.begin(), column_.end(), entryPointerComp_); } template @@ -423,21 +425,21 @@ inline Heap_column::Heap_column(Index columnIndex, column_(nonZeroRowIndices.size(), nullptr), insertsSinceLastPrune_(0), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - column_[i++] = cellPool_->construct(id); + column_[i++] = entryPool_->construct(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - column_[i] = cellPool_->construct(p.first); + column_[i] = entryPool_->construct(p.first); column_[i++]->set_element(operators_->get_value(p.second)); } } - std::make_heap(column_.begin(), column_.end(), cellPointerComp_); + std::make_heap(column_.begin(), column_.end(), entryPointerComp_); } template @@ -451,19 +453,19 @@ inline Heap_column::Heap_column(const Heap_column& column, column_(column.column_.size(), nullptr), insertsSinceLastPrune_(0), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - column_[i++] = cellPool_->construct(cell->get_row_index()); + column_[i++] = entryPool_->construct(entry->get_row_index()); } else { - column_[i] = cellPool_->construct(cell->get_row_index()); - column_[i++]->set_element(cell->get_element()); + column_[i] = entryPool_->construct(entry->get_row_index()); + column_[i++]->set_element(entry->get_element()); } } // column.column_ already ordered as a heap, so no need of make_heap. @@ -472,8 +474,8 @@ inline Heap_column::Heap_column(const Heap_column& column, template inline Heap_column::~Heap_column() { - for (auto* cell : column_) { - cellPool_->destroy(cell); + for (auto* entry : column_) { + entryPool_->destroy(entry); } } @@ -509,12 +511,12 @@ template inline bool Heap_column::is_non_zero(ID_index rowIndex) const { Field_element c(0); - for (const Cell* cell : column_) { - if (cell->get_row_index() == rowIndex) { + for (const Entry* entry : column_) { + if (entry->get_row_index() == rowIndex) { if constexpr (Master_matrix::Option_list::is_z2) c = !c; else - operators_->add_inplace(c, cell->get_element()); + operators_->add_inplace(c, entry->get_element()); } } return c != Field_operators::get_additive_identity(); @@ -523,10 +525,10 @@ inline bool Heap_column::is_non_zero(ID_index rowIndex) const template inline bool Heap_column::is_empty() { - Cell* pivot = _pop_pivot(); + Entry* pivot = _pop_pivot(); if (pivot != nullptr) { column_.push_back(pivot); - std::push_heap(column_.begin(), column_.end(), cellPointerComp_); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); return false; } return true; @@ -546,14 +548,14 @@ inline void Heap_column::reorder(const Row_index_map& valueMap, [ "Method not available for chain columns."); Column_support tempCol; - Cell* pivot = _pop_pivot(); + Entry* pivot = _pop_pivot(); while (pivot != nullptr) { pivot->set_row_index(valueMap.at(pivot->get_row_index())); tempCol.push_back(pivot); pivot = _pop_pivot(); } column_.swap(tempCol); - std::make_heap(column_.begin(), column_.end(), cellPointerComp_); + std::make_heap(column_.begin(), column_.end(), entryPointerComp_); insertsSinceLastPrune_ = 0; } @@ -564,8 +566,8 @@ inline void Heap_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - cellPool_->destroy(cell); + for (auto* entry : column_) { + entryPool_->destroy(entry); } column_.clear(); @@ -579,12 +581,12 @@ inline void Heap_column::clear(ID_index rowIndex) "Method not available for chain columns."); Column_support tempCol; - Cell* pivot = _pop_pivot(); + Entry* pivot = _pop_pivot(); while (pivot != nullptr) { if (pivot->get_row_index() != rowIndex) { tempCol.push_back(pivot); } else { - cellPool_->destroy(pivot); + entryPool_->destroy(pivot); } pivot = _pop_pivot(); } @@ -600,10 +602,10 @@ inline typename Heap_column::ID_index Heap_column: "Method not available for base columns."); // could technically be, but is the notion useful then? if constexpr (Master_matrix::Option_list::is_of_boundary_type) { - Cell* pivot = _pop_pivot(); + Entry* pivot = _pop_pivot(); if (pivot != nullptr) { column_.push_back(pivot); - std::push_heap(column_.begin(), column_.end(), cellPointerComp_); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); return pivot->get_row_index(); } return -1; @@ -622,18 +624,18 @@ inline typename Heap_column::Field_element Heap_columnget_element(); } return 0; } else { Field_element sum(0); if (Chain_opt::get_pivot() == static_cast(-1)) return sum; - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(sum, cell->get_element()); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(sum, entry->get_element()); } return sum; // should not be 0 if properly used. } @@ -689,10 +691,10 @@ inline typename Heap_column::const_reverse_iterator Heap_column -template -inline Heap_column& Heap_column::operator+=(const Cell_range& column) +template +inline Heap_column& Heap_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -744,8 +746,8 @@ inline Heap_column& Heap_column::operator*=(unsign if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); } } @@ -753,11 +755,11 @@ inline Heap_column& Heap_column::operator*=(unsign } template -template +template inline Heap_column& Heap_column::multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -815,11 +817,11 @@ inline Heap_column& Heap_column::multiply_target_a } template -template -inline Heap_column& Heap_column::multiply_source_and_add(const Cell_range& column, +template +inline Heap_column& Heap_column::multiply_source_and_add(const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -868,6 +870,19 @@ inline Heap_column& Heap_column::multiply_source_a return *this; } +template +inline void Heap_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + Entry* newEntry = entryPool_->construct(entry.get_row_index()); + if constexpr (!Master_matrix::Option_list::is_z2) { + newEntry->set_element(operators_->get_value(entry.get_element())); + } + column_.push_back(newEntry); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); +} + template inline Heap_column& Heap_column::operator=(const Heap_column& other) { @@ -877,25 +892,25 @@ inline Heap_column& Heap_column::operator=(const H Chain_opt::operator=(other); while (column_.size() > other.column_.size()) { - if (column_.back() != nullptr) cellPool_->destroy(column_.back()); + if (column_.back() != nullptr) entryPool_->destroy(column_.back()); column_.pop_back(); } column_.resize(other.column_.size(), nullptr); Index i = 0; - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if (column_[i] != nullptr) { - cellPool_->destroy(column_[i]); + entryPool_->destroy(column_[i]); } - column_[i] = other.cellPool_->construct(cell->get_row_index()); + column_[i] = other.entryPool_->construct(entry->get_row_index()); if constexpr (!Master_matrix::Option_list::is_z2) { - column_[i]->set_element(cell->get_element()); + column_[i]->set_element(entry->get_element()); } ++i; } insertsSinceLastPrune_ = other.insertsSinceLastPrune_; operators_ = other.operators_; - cellPool_ = other.cellPool_; + entryPool_ = other.entryPool_; return *this; } @@ -913,7 +928,7 @@ inline void Heap_column::_prune() if (insertsSinceLastPrune_ == 0) return; Column_support tempCol; - Cell* pivot = _pop_pivot(); + Entry* pivot = _pop_pivot(); while (pivot != nullptr) { tempCol.push_back(pivot); pivot = _pop_pivot(); @@ -924,39 +939,39 @@ inline void Heap_column::_prune() } template -inline typename Heap_column::Cell* Heap_column::_pop_pivot() +inline typename Heap_column::Entry* Heap_column::_pop_pivot() { if (column_.empty()) { return nullptr; } - Cell* pivot = column_.front(); - std::pop_heap(column_.begin(), column_.end(), cellPointerComp_); + Entry* pivot = column_.front(); + std::pop_heap(column_.begin(), column_.end(), entryPointerComp_); column_.pop_back(); if constexpr (Master_matrix::Option_list::is_z2) { while (!column_.empty() && column_.front()->get_row_index() == pivot->get_row_index()) { - std::pop_heap(column_.begin(), column_.end(), cellPointerComp_); - cellPool_->destroy(column_.back()); + std::pop_heap(column_.begin(), column_.end(), entryPointerComp_); + entryPool_->destroy(column_.back()); column_.pop_back(); - cellPool_->destroy(pivot); + entryPool_->destroy(pivot); if (column_.empty()) { return nullptr; } pivot = column_.front(); - std::pop_heap(column_.begin(), column_.end(), cellPointerComp_); + std::pop_heap(column_.begin(), column_.end(), entryPointerComp_); column_.pop_back(); } } else { while (!column_.empty() && column_.front()->get_row_index() == pivot->get_row_index()) { operators_->add_inplace(pivot->get_element(), column_.front()->get_element()); - std::pop_heap(column_.begin(), column_.end(), cellPointerComp_); - cellPool_->destroy(column_.back()); + std::pop_heap(column_.begin(), column_.end(), entryPointerComp_); + entryPool_->destroy(column_.back()); column_.pop_back(); } if (pivot->get_element() == Field_operators::get_additive_identity()) { - cellPool_->destroy(pivot); + entryPool_->destroy(pivot); return _pop_pivot(); } } @@ -965,17 +980,17 @@ inline typename Heap_column::Cell* Heap_column::_p } template -template -inline bool Heap_column::_add(const Cell_range& column) +template +inline bool Heap_column::_add(const Entry_range& column) { if (column.begin() == column.end()) return false; if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { - column_[i] = cellPool_->construct(cell.get_row_index()); + for (const Entry& entry : column) { + column_[i] = entryPool_->construct(entry.get_row_index()); if constexpr (!Master_matrix::Option_list::is_z2) { - column_[i]->set_element(cell.get_element()); + column_[i]->set_element(entry.get_element()); } ++i; } @@ -988,21 +1003,21 @@ inline bool Heap_column::_add(const Cell_range& column) if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) pivotVal = get_pivot_value(); - for (const Cell& cell : column) { + for (const Entry& entry : column) { ++insertsSinceLastPrune_; if constexpr (Master_matrix::Option_list::is_z2) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell.get_row_index() == Chain_opt::get_pivot()) pivotVal = !pivotVal; + if (entry.get_row_index() == Chain_opt::get_pivot()) pivotVal = !pivotVal; } - column_.push_back(cellPool_->construct(cell.get_row_index())); + column_.push_back(entryPool_->construct(entry.get_row_index())); } else { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell.get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, cell.get_element()); + if (entry.get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, entry.get_element()); } - column_.push_back(cellPool_->construct(cell.get_row_index())); - column_.back()->set_element(cell.get_element()); + column_.push_back(entryPool_->construct(entry.get_row_index())); + column_.back()->set_element(entry.get_element()); } - std::push_heap(column_.begin(), column_.end(), cellPointerComp_); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); } if (2 * insertsSinceLastPrune_ > column_.size()) _prune(); @@ -1014,8 +1029,8 @@ inline bool Heap_column::_add(const Cell_range& column) } template -template -inline bool Heap_column::_multiply_target_and_add(const Field_element& val, const Cell_range& column) +template +inline bool Heap_column::_multiply_target_and_add(const Field_element& val, const Entry_range& column) { if (val == 0u) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { @@ -1028,9 +1043,9 @@ inline bool Heap_column::_multiply_target_and_add(const Field_ele if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { - column_[i] = cellPool_->construct(cell.get_row_index()); - column_[i++]->set_element(cell.get_element()); + for (const Entry& entry : column) { + column_[i] = entryPool_->construct(entry.get_row_index()); + column_[i++]->set_element(entry.get_element()); } insertsSinceLastPrune_ = column_.size(); return true; @@ -1038,21 +1053,21 @@ inline bool Heap_column::_multiply_target_and_add(const Field_ele Field_element pivotVal(0); - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell->get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, cell->get_element()); + if (entry->get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, entry->get_element()); } } - for (const Cell& cell : column) { + for (const Entry& entry : column) { ++insertsSinceLastPrune_; if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell.get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, cell.get_element()); + if (entry.get_row_index() == Chain_opt::get_pivot()) operators_->add_inplace(pivotVal, entry.get_element()); } - column_.push_back(cellPool_->construct(cell.get_row_index())); - column_.back()->set_element(cell.get_element()); - std::push_heap(column_.begin(), column_.end(), cellPointerComp_); + column_.push_back(entryPool_->construct(entry.get_row_index())); + column_.back()->set_element(entry.get_element()); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); } if (2 * insertsSinceLastPrune_ > column_.size()) _prune(); @@ -1064,8 +1079,8 @@ inline bool Heap_column::_multiply_target_and_add(const Field_ele } template -template -inline bool Heap_column::_multiply_source_and_add(const Cell_range& column, const Field_element& val) +template +inline bool Heap_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { if (val == 0u || column.begin() == column.end()) { return false; @@ -1073,9 +1088,9 @@ inline bool Heap_column::_multiply_source_and_add(const Cell_rang if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { - column_[i] = cellPool_->construct(cell.get_row_index()); - column_[i++]->set_element(cell.get_element()); + for (const Entry& entry : column) { + column_[i] = entryPool_->construct(entry.get_row_index()); + column_[i++]->set_element(entry.get_element()); } insertsSinceLastPrune_ = column_.size(); return true; @@ -1086,17 +1101,17 @@ inline bool Heap_column::_multiply_source_and_add(const Cell_rang if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) pivotVal = get_pivot_value(); - for (const Cell& cell : column) { + for (const Entry& entry : column) { ++insertsSinceLastPrune_; - column_.push_back(cellPool_->construct(cell.get_row_index())); - column_.back()->set_element(cell.get_element()); + column_.push_back(entryPool_->construct(entry.get_row_index())); + column_.back()->set_element(entry.get_element()); operators_->multiply_inplace(column_.back()->get_element(), val); if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell.get_row_index() == Chain_opt::get_pivot()) { + if (entry.get_row_index() == Chain_opt::get_pivot()) { operators_->add_inplace(pivotVal, column_.back()->get_element()); } } - std::push_heap(column_.begin(), column_.end(), cellPointerComp_); + std::push_heap(column_.begin(), column_.end(), entryPointerComp_); } if (2 * insertsSinceLastPrune_ > column_.size()) _prune(); @@ -1113,7 +1128,7 @@ inline bool Heap_column::_multiply_source_and_add(const Cell_rang * @brief Hash method for @ref Gudhi::persistence_matrix::Heap_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Heap_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Heap_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Heap_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h index 01c6791..7730580 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h @@ -25,7 +25,7 @@ #include -#include +#include #include namespace Gudhi { @@ -37,11 +37,11 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a intrusive list structure. The cells are always ordered by row index and only non-zero values + * Column based on a intrusive list structure. The entries are always ordered by row index and only non-zero values * are stored uniquely in the underlying container. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Intrusive_list_column : public Master_matrix::Row_access_option, @@ -54,15 +54,15 @@ class Intrusive_list_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; using Column_support = - boost::intrusive::list, + boost::intrusive::list, boost::intrusive::base_hook >; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = typename Column_support::iterator; @@ -117,21 +117,23 @@ class Intrusive_list_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Intrusive_list_column& operator+=(const Cell_range& column); + template + Intrusive_list_column& operator+=(const Entry_range& column); Intrusive_list_column& operator+=(Intrusive_list_column& column); Intrusive_list_column& operator*=(const Field_element& val); // this = v * this + column - template - Intrusive_list_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Intrusive_list_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Intrusive_list_column& multiply_target_and_add(const Field_element& val, Intrusive_list_column& column); // this = this + column * v - template - Intrusive_list_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Intrusive_list_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Intrusive_list_column& multiply_source_and_add(Intrusive_list_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const Intrusive_list_column& c1, const Intrusive_list_column& c2) { if (&c1 == &c2) return true; @@ -179,7 +181,7 @@ class Intrusive_list_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -189,11 +191,11 @@ class Intrusive_list_column : public Master_matrix::Row_access_option, // Cloner object function for boost intrusive container struct New_cloner { - New_cloner(Cell_constructor* cellPool) : cellPool_(cellPool) {}; + New_cloner(Entry_constructor* entryPool) : entryPool_(entryPool) {}; - Cell* operator()(const Cell& clone_this) { return cellPool_->construct(clone_this); } + Entry* operator()(const Entry& clone_this) { return entryPool_->construct(clone_this); } - Cell_constructor* cellPool_; + Entry_constructor* entryPool_; }; // The disposer object function for boost intrusive container @@ -201,55 +203,55 @@ class Intrusive_list_column : public Master_matrix::Row_access_option, Delete_disposer() {}; Delete_disposer(Intrusive_list_column* col) : col_(col) {}; - void operator()(Cell* delete_this) { + void operator()(Entry* delete_this) { if constexpr (Master_matrix::Option_list::has_row_access) col_->unlink(delete_this); - col_->cellPool_->destroy(delete_this); + col_->entryPool_->destroy(delete_this); } Intrusive_list_column* col_; }; Field_operators* operators_; - Cell_constructor* cellPool_; + Entry_constructor* entryPool_; Column_support column_; - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, typename Column::Column_support::iterator& itTarget, F1&& process_target, F2&& process_source, F3&& update_target1, F4&& update_target2, bool& pivotIsZeroed); - template - friend bool _generic_add_to_column(const Cell_range& source, + template + friend bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, F3&& update_target1, F4&& update_target2, F5&& finish_target); - template - friend bool _add_to_column(const Cell_range& source, Column& targetColumn); - template + template + friend bool _add_to_column(const Entry_range& source, Column& targetColumn); + template friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - template + template friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - void _delete_cell(iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, const iterator& position); - void _insert_cell(ID_index rowIndex, const iterator& position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + void _delete_entry(iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const iterator& position); + void _insert_entry(ID_index rowIndex, const iterator& position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -258,7 +260,7 @@ inline Intrusive_list_column::Intrusive_list_column(Column_settin Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)), + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)), column_() { if (colSettings == nullptr) return; // to allow default constructor which gives a dummy column @@ -275,7 +277,7 @@ inline Intrusive_list_column::Intrusive_list_column(const Contain Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1), Chain_opt(), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)), + entryPool_(&(colSettings->entryConstructor)), column_() { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, @@ -283,12 +285,12 @@ inline Intrusive_list_column::Intrusive_list_column(const Contain if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -309,7 +311,7 @@ inline Intrusive_list_column::Intrusive_list_column(Index columnI } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)), + entryPool_(&(colSettings->entryConstructor)), column_() { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, @@ -317,12 +319,12 @@ inline Intrusive_list_column::Intrusive_list_column(Index columnI if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -342,17 +344,17 @@ inline Intrusive_list_column::Intrusive_list_column(const Contain } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)), + entryPool_(&(colSettings->entryConstructor)), column_() { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -374,17 +376,17 @@ inline Intrusive_list_column::Intrusive_list_column(Index columnI } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)), + entryPool_(&(colSettings->entryConstructor)), column_() { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -396,7 +398,7 @@ inline Intrusive_list_column::Intrusive_list_column(const Intrusi Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)), + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)), column_() { static_assert(!Master_matrix::Option_list::has_row_access, @@ -406,7 +408,7 @@ inline Intrusive_list_column::Intrusive_list_column(const Intrusi if (colSettings != nullptr) operators_ = &(colSettings->operators); } - column_.clone_from(column.column_, New_cloner(cellPool_), Delete_disposer(this)); + column_.clone_from(column.column_, New_cloner(entryPool_), Delete_disposer(this)); } template @@ -419,18 +421,18 @@ inline Intrusive_list_column::Intrusive_list_column(const Intrusi Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)), + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)), column_() { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell& cell : column.column_) { + for (const Entry& entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell.get_row_index(), column_.end()); + _insert_entry(entry.get_row_index(), column_.end()); } else { - _insert_cell(cell.get_element(), cell.get_row_index(), column_.end()); + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); } } } @@ -441,7 +443,7 @@ inline Intrusive_list_column::Intrusive_list_column(Intrusive_lis Dim_opt(std::move(static_cast(column))), Chain_opt(std::move(static_cast(column))), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)), + entryPool_(std::exchange(column.entryPool_, nullptr)), column_(std::move(column.column_)) {} @@ -478,8 +480,8 @@ inline bool Intrusive_list_column::is_non_zero(ID_index rowIndex) // could be changed to dichotomic search as column is ordered by row index, // but I am not sure if it is really worth it as there is no random access // and the columns should not be that long anyway. - for (const Cell& cell : column_) - if (cell.get_row_index() == rowIndex) return true; + for (const Entry& entry : column_) + if (entry.get_row_index() == rowIndex) return true; return false; } @@ -505,21 +507,21 @@ inline void Intrusive_list_column::reorder(const Row_index_map& v "Method not available for chain columns."); for (auto it = column_.begin(); it != column_.end(); ++it) { - Cell* cell = &(*it); + Entry* entry = &(*it); if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); + entry->set_row_index(valueMap.at(entry->get_row_index())); if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // all cells have to be deleted first, to avoid problem with insertion when row is a set + // all entries have to be deleted first, to avoid problem with insertion when row is a set if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) { for (auto it = column_.begin(); it != column_.end(); ++it) { - Cell* cell = &(*it); - RA_opt::insert_cell(cell->get_row_index(), cell); + Entry* entry = &(*it); + RA_opt::insert_entry(entry->get_row_index(), entry); } } @@ -543,7 +545,7 @@ inline void Intrusive_list_column::clear(ID_index rowIndex) auto it = column_.begin(); while (it != column_.end() && it->get_row_index() != rowIndex) it++; - if (it != column_.end()) _delete_cell(it); + if (it != column_.end()) _delete_entry(it); } template @@ -575,8 +577,8 @@ Intrusive_list_column::get_pivot_value() const return column_.back().get_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell& cell : column_) { - if (cell.get_row_index() == Chain_opt::get_pivot()) return cell.get_element(); + for (const Entry& entry : column_) { + if (entry.get_row_index() == Chain_opt::get_pivot()) return entry.get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -638,11 +640,11 @@ Intrusive_list_column::rend() const noexcept } template -template +template inline Intrusive_list_column& Intrusive_list_column::operator+=( - const Cell_range& column) + const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -696,9 +698,9 @@ inline Intrusive_list_column& Intrusive_list_columnmultiply_inplace(cell.get_element(), realVal); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(cell); + for (Entry& entry : column_) { + operators_->multiply_inplace(entry.get_element(), realVal); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(entry); } } @@ -706,11 +708,11 @@ inline Intrusive_list_column& Intrusive_list_column -template +template inline Intrusive_list_column& Intrusive_list_column::multiply_target_and_add( - const Field_element& val, const Cell_range& column) + const Field_element& val, const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -768,11 +770,11 @@ inline Intrusive_list_column& Intrusive_list_column -template +template inline Intrusive_list_column& Intrusive_list_column::multiply_source_and_add( - const Cell_range& column, const Field_element& val) + const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -821,6 +823,18 @@ inline Intrusive_list_column& Intrusive_list_column +inline void Intrusive_list_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_.end()); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); + } +} + template inline Intrusive_list_column& Intrusive_list_column::operator=( const Intrusive_list_column& other) @@ -833,67 +847,67 @@ inline Intrusive_list_column& Intrusive_list_column -inline void Intrusive_list_column::_delete_cell(iterator& it) +inline void Intrusive_list_column::_delete_entry(iterator& it) { it = column_.erase_and_dispose(it, Delete_disposer(this)); } template -inline typename Intrusive_list_column::Cell* Intrusive_list_column::_insert_cell( +inline typename Intrusive_list_column::Entry* Intrusive_list_column::_insert_entry( const Field_element& value, ID_index rowIndex, const iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_.insert(position, *newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_.insert(position, *newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column_.insert(position, *newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column_.insert(position, *newEntry); + return newEntry; } } template -inline void Intrusive_list_column::_insert_cell(ID_index rowIndex, const iterator& position) +inline void Intrusive_list_column::_insert_entry(ID_index rowIndex, const iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_.insert(position, *newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_.insert(position, *newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column_.insert(position, *newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column_.insert(position, *newEntry); } } template -template -inline bool Intrusive_list_column::_add(const Cell_range& column) +template +inline bool Intrusive_list_column::_add(const Entry_range& column) { return _add_to_column(column, *this); } template -template +template inline bool Intrusive_list_column::_multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { return _multiply_target_and_add_to_column(val, column, *this); } template -template -inline bool Intrusive_list_column::_multiply_source_and_add(const Cell_range& column, +template +inline bool Intrusive_list_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { return _multiply_source_and_add_to_column(val, column, *this); @@ -908,7 +922,7 @@ inline bool Intrusive_list_column::_multiply_source_and_add(const * @brief Hash method for @ref Gudhi::persistence_matrix::Intrusive_list_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Intrusive_list_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_list_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_list_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h index 983e425..17cb7d8 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include namespace Gudhi { @@ -38,11 +38,11 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a intrusive set structure. The cells are ordered by row index and only non-zero values + * Column based on a intrusive set structure. The entries are ordered by row index and only non-zero values * are stored uniquely in the underlying container. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Intrusive_set_column : public Master_matrix::Row_access_option, @@ -55,15 +55,15 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; using Column_support = - boost::intrusive::set, + boost::intrusive::set, boost::intrusive::base_hook >; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = typename Column_support::iterator; @@ -118,21 +118,23 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Intrusive_set_column& operator+=(const Cell_range& column); + template + Intrusive_set_column& operator+=(const Entry_range& column); Intrusive_set_column& operator+=(Intrusive_set_column& column); Intrusive_set_column& operator*=(unsigned int v); // this = v * this + column - template - Intrusive_set_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Intrusive_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Intrusive_set_column& multiply_target_and_add(const Field_element& val, Intrusive_set_column& column); // this = this + column * v - template - Intrusive_set_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Intrusive_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Intrusive_set_column& multiply_source_and_add(Intrusive_set_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const Intrusive_set_column& c1, const Intrusive_set_column& c2) { if (&c1 == &c2) return true; @@ -180,7 +182,7 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -190,11 +192,11 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, // Cloner object function for boost intrusive container struct New_cloner { - New_cloner(Cell_constructor* cellPool) : cellPool_(cellPool) {}; + New_cloner(Entry_constructor* entryPool) : entryPool_(entryPool) {}; - Cell* operator()(const Cell& clone_this) { return cellPool_->construct(clone_this); } + Entry* operator()(const Entry& clone_this) { return entryPool_->construct(clone_this); } - Cell_constructor* cellPool_; + Entry_constructor* entryPool_; }; // The disposer object function for boost intrusive container @@ -202,9 +204,9 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, Delete_disposer() {}; Delete_disposer(Intrusive_set_column* col) : col_(col) {}; - void operator()(Cell* delete_this) { + void operator()(Entry* delete_this) { if constexpr (Master_matrix::Option_list::has_row_access) col_->unlink(delete_this); - col_->cellPool_->destroy(delete_this); + col_->entryPool_->destroy(delete_this); } Intrusive_set_column* col_; @@ -212,45 +214,45 @@ class Intrusive_set_column : public Master_matrix::Row_access_option, Column_support column_; Field_operators* operators_; - Cell_constructor* cellPool_; - - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, - typename Column::Column_support::iterator& itTarget, - F1&& process_target, - F2&& process_source, - F3&& update_target1, - F4&& update_target2, - bool& pivotIsZeroed); - template - friend bool _generic_add_to_column(const Cell_range& source, + Entry_constructor* entryPool_; + + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, + typename Column::Column_support::iterator& itTarget, + F1&& process_target, + F2&& process_source, + F3&& update_target1, + F4&& update_target2, + bool& pivotIsZeroed); + template + friend bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, F3&& update_target1, F4&& update_target2, F5&& finish_target); - template - friend bool _add_to_column(const Cell_range& source, Column& targetColumn); - template + template + friend bool _add_to_column(const Entry_range& source, Column& targetColumn); + template friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - template + template friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - void _delete_cell(iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, const iterator& position); - void _insert_cell(ID_index rowIndex, const iterator& position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + void _delete_entry(iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const iterator& position); + void _insert_entry(ID_index rowIndex, const iterator& position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -259,9 +261,9 @@ inline Intrusive_set_column::Intrusive_set_column(Column_settings Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -275,19 +277,19 @@ inline Intrusive_set_column::Intrusive_set_column(const Container Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1), Chain_opt(), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -308,19 +310,19 @@ inline Intrusive_set_column::Intrusive_set_column(Index columnInd } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -340,16 +342,16 @@ inline Intrusive_set_column::Intrusive_set_column(const Container } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -371,16 +373,16 @@ inline Intrusive_set_column::Intrusive_set_column(Index columnInd } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -392,7 +394,7 @@ inline Intrusive_set_column::Intrusive_set_column(const Intrusive Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -402,7 +404,7 @@ inline Intrusive_set_column::Intrusive_set_column(const Intrusive if (colSettings != nullptr) operators_ = &(colSettings->operators); } - column_.clone_from(column.column_, New_cloner(cellPool_), Delete_disposer(this)); + column_.clone_from(column.column_, New_cloner(entryPool_), Delete_disposer(this)); } template @@ -415,17 +417,17 @@ inline Intrusive_set_column::Intrusive_set_column(const Intrusive Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell& cell : column.column_) { + for (const Entry& entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell.get_row_index(), column_.end()); + _insert_entry(entry.get_row_index(), column_.end()); } else { - _insert_cell(cell.get_element(), cell.get_row_index(), column_.end()); + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); } } } @@ -437,7 +439,7 @@ inline Intrusive_set_column::Intrusive_set_column(Intrusive_set_c Chain_opt(std::move(static_cast(column))), column_(std::move(column.column_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template @@ -470,7 +472,7 @@ Intrusive_set_column::get_content(int columnLength) const template inline bool Intrusive_set_column::is_non_zero(ID_index rowIndex) const { - return column_.find(Cell(rowIndex)) != column_.end(); + return column_.find(Entry(rowIndex)) != column_.end(); } template @@ -496,31 +498,31 @@ inline void Intrusive_set_column::reorder(const Row_index_map& va if constexpr (Master_matrix::Option_list::has_row_access) { for (auto it = column_.begin(); it != column_.end();) { - Cell* newCell = cellPool_->construct(columnIndex == static_cast(-1) ? RA_opt::columnIndex_ : columnIndex, - valueMap.at(it->get_row_index())); + Entry* newEntry = entryPool_->construct( + columnIndex == static_cast(-1) ? RA_opt::columnIndex_ : columnIndex, valueMap.at(it->get_row_index())); if constexpr (!Master_matrix::Option_list::is_z2) { - newCell->set_element(it->get_element()); + newEntry->set_element(it->get_element()); } - newSet.insert(newSet.end(), *newCell); - _delete_cell(it); // increases it + newSet.insert(newSet.end(), *newEntry); + _delete_entry(it); // increases it if constexpr (Master_matrix::Option_list::has_intrusive_rows) // intrusive list - RA_opt::insert_cell(newCell->get_row_index(), newCell); + RA_opt::insert_entry(newEntry->get_row_index(), newEntry); } - // when row is a set, all cells have to be deleted first, to avoid colliding when inserting + // when row is a set, all entries have to be deleted first, to avoid colliding when inserting if constexpr (!Master_matrix::Option_list::has_intrusive_rows) { // set - for (Cell& cell : newSet) { - RA_opt::insert_cell(cell.get_row_index(), &cell); + for (Entry& entry : newSet) { + RA_opt::insert_entry(entry.get_row_index(), &entry); } } } else { for (auto it = column_.begin(); it != column_.end();) { - Cell* newCell = cellPool_->construct(valueMap.at(it->get_row_index())); + Entry* newEntry = entryPool_->construct(valueMap.at(it->get_row_index())); if constexpr (!Master_matrix::Option_list::is_z2) { - newCell->set_element(it->get_element()); + newEntry->set_element(it->get_element()); } - newSet.insert(newSet.end(), *newCell); - _delete_cell(it); // increases it + newSet.insert(newSet.end(), *newEntry); + _delete_entry(it); // increases it } } @@ -542,9 +544,9 @@ inline void Intrusive_set_column::clear(ID_index rowIndex) static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns."); - auto it = column_.find(Cell(rowIndex)); + auto it = column_.find(Entry(rowIndex)); if (it != column_.end()) { - _delete_cell(it); + _delete_entry(it); } } @@ -577,7 +579,7 @@ Intrusive_set_column::get_pivot_value() const return column_.rbegin()->get_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return 0; - auto it = column_.find(Cell(Chain_opt::get_pivot())); + auto it = column_.find(Entry(Chain_opt::get_pivot())); GUDHI_CHECK(it != column_.end(), "Intrusive_set_column::get_pivot_value - Pivot not found only if the column was misused."); return it->get_element(); @@ -640,10 +642,10 @@ inline typename Intrusive_set_column::const_reverse_iterator Intr } template -template -inline Intrusive_set_column& Intrusive_set_column::operator+=(const Cell_range& column) +template +inline Intrusive_set_column& Intrusive_set_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -696,9 +698,9 @@ inline Intrusive_set_column& Intrusive_set_column: if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell& cell : column_) { - operators_->multiply_inplace(cell.get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(cell); + for (Entry& entry : column_) { + operators_->multiply_inplace(entry.get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(entry); } } @@ -706,11 +708,11 @@ inline Intrusive_set_column& Intrusive_set_column: } template -template +template inline Intrusive_set_column& Intrusive_set_column::multiply_target_and_add( - const Field_element& val, const Cell_range& column) + const Field_element& val, const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -768,11 +770,11 @@ inline Intrusive_set_column& Intrusive_set_column: } template -template +template inline Intrusive_set_column& Intrusive_set_column::multiply_source_and_add( - const Cell_range& column, const Field_element& val) + const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -821,6 +823,18 @@ inline Intrusive_set_column& Intrusive_set_column: return *this; } +template +inline void Intrusive_set_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_.end()); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); + } +} + template inline Intrusive_set_column& Intrusive_set_column::operator=( const Intrusive_set_column& other) @@ -833,67 +847,67 @@ inline Intrusive_set_column& Intrusive_set_column: // order is important column_.clear_and_dispose(Delete_disposer(this)); operators_ = other.operators_; - cellPool_ = other.cellPool_; - column_.clone_from(other.column_, New_cloner(cellPool_), Delete_disposer(this)); + entryPool_ = other.entryPool_; + column_.clone_from(other.column_, New_cloner(entryPool_), Delete_disposer(this)); return *this; } template -inline void Intrusive_set_column::_delete_cell(iterator& it) +inline void Intrusive_set_column::_delete_entry(iterator& it) { it = column_.erase_and_dispose(it, Delete_disposer(this)); } template -inline typename Intrusive_set_column::Cell* Intrusive_set_column::_insert_cell( +inline typename Intrusive_set_column::Entry* Intrusive_set_column::_insert_entry( const Field_element& value, ID_index rowIndex, const iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_.insert(position, *newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_.insert(position, *newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column_.insert(position, *newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column_.insert(position, *newEntry); + return newEntry; } } template -inline void Intrusive_set_column::_insert_cell(ID_index rowIndex, const iterator& position) +inline void Intrusive_set_column::_insert_entry(ID_index rowIndex, const iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_.insert(position, *newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_.insert(position, *newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column_.insert(position, *newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column_.insert(position, *newEntry); } } template -template -inline bool Intrusive_set_column::_add(const Cell_range& column) +template +inline bool Intrusive_set_column::_add(const Entry_range& column) { return _add_to_column(column, *this); } template -template +template inline bool Intrusive_set_column::_multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { return _multiply_target_and_add_to_column(val, column, *this); } template -template -inline bool Intrusive_set_column::_multiply_source_and_add(const Cell_range& column, +template +inline bool Intrusive_set_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { return _multiply_source_and_add_to_column(val, column, *this); @@ -908,7 +922,7 @@ inline bool Intrusive_set_column::_multiply_source_and_add(const * @brief Hash method for @ref Gudhi::persistence_matrix::Intrusive_set_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Intrusive_set_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h index f795d87..5793d52 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h @@ -26,7 +26,7 @@ #include -#include +#include #include namespace Gudhi { @@ -38,11 +38,11 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a list structure. The cells are always ordered by row index and only non-zero values + * Column based on a list structure. The entries are always ordered by row index and only non-zero values * are stored uniquely in the underlying container. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class List_column : public Master_matrix::Row_access_option, @@ -55,13 +55,13 @@ class List_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - using Column_support = std::list; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Column_support = std::list; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = boost::indirect_iterator; @@ -116,21 +116,23 @@ class List_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - List_column& operator+=(const Cell_range& column); + template + List_column& operator+=(const Entry_range& column); List_column& operator+=(List_column& column); List_column& operator*=(unsigned int v); // this = v * this + column - template - List_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + List_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); List_column& multiply_target_and_add(const Field_element& val, List_column& column); // this = this + column * v - template - List_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + List_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); List_column& multiply_source_and_add(List_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const List_column& c1, const List_column& c2) { if (&c1 == &c2) return true; @@ -177,7 +179,7 @@ class List_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -187,47 +189,47 @@ class List_column : public Master_matrix::Row_access_option, Column_support column_; Field_operators* operators_; - Cell_constructor* cellPool_; - - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, - typename Column::Column_support::iterator& itTarget, - F1&& process_target, - F2&& process_source, - F3&& update_target1, - F4&& update_target2, - bool& pivotIsZeroed); - template - friend bool _generic_add_to_column(const Cell_range& source, + Entry_constructor* entryPool_; + + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, + typename Column::Column_support::iterator& itTarget, + F1&& process_target, + F2&& process_source, + F3&& update_target1, + F4&& update_target2, + bool& pivotIsZeroed); + template + friend bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, F3&& update_target1, F4&& update_target2, F5&& finish_target); - template - friend bool _add_to_column(const Cell_range& source, Column& targetColumn); - template + template + friend bool _add_to_column(const Entry_range& source, Column& targetColumn); + template friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - template + template friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - void _delete_cell(typename Column_support::iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); - void _insert_cell(ID_index rowIndex, const typename Column_support::iterator& position); - void _update_cell(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); - void _update_cell(ID_index rowIndex, const typename Column_support::iterator& position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + void _delete_entry(typename Column_support::iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); + void _insert_entry(ID_index rowIndex, const typename Column_support::iterator& position); + void _update_entry(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); + void _update_entry(ID_index rowIndex, const typename Column_support::iterator& position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -236,9 +238,9 @@ inline List_column::List_column(Column_settings* colSettings) Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -252,7 +254,7 @@ inline List_column::List_column(const Container& nonZeroRowIndice Chain_opt(), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -260,12 +262,12 @@ inline List_column::List_column(const Container& nonZeroRowIndice auto it = column_.begin(); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, it++); + _update_entry(id, it++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, it++); + _update_entry(operators_->get_value(p.second), p.first, it++); } } } @@ -287,7 +289,7 @@ inline List_column::List_column(Index columnIndex, }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -295,12 +297,12 @@ inline List_column::List_column(Index columnIndex, auto it = column_.begin(); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, it++); + _update_entry(id, it++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, it++); + _update_entry(operators_->get_value(p.second), p.first, it++); } } } @@ -321,17 +323,17 @@ inline List_column::List_column(const Container& nonZeroRowIndice }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { auto it = column_.begin(); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, it++); + _update_entry(id, it++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, it++); + _update_entry(operators_->get_value(p.second), p.first, it++); } } } @@ -354,17 +356,17 @@ inline List_column::List_column(Index columnIndex, }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { auto it = column_.begin(); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, it++); + _update_entry(id, it++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, it++); + _update_entry(operators_->get_value(p.second), p.first, it++); } } } @@ -376,7 +378,7 @@ inline List_column::List_column(const List_column& column, Column Chain_opt(static_cast(column)), column_(column.column_.size()), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -387,11 +389,11 @@ inline List_column::List_column(const List_column& column, Column } auto it = column_.begin(); - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), it++); + _update_entry(entry->get_row_index(), it++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), it++); + _update_entry(entry->get_element(), entry->get_row_index(), it++); } } } @@ -407,18 +409,18 @@ inline List_column::List_column(const List_column& column, Chain_opt(static_cast(column)), column_(column.column_.size()), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } auto it = column_.begin(); - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), it++); + _update_entry(entry->get_row_index(), it++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), it++); + _update_entry(entry->get_element(), entry->get_row_index(), it++); } } } @@ -430,14 +432,14 @@ inline List_column::List_column(List_column&& column) noexcept Chain_opt(std::move(static_cast(column))), column_(std::move(column.column_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template inline List_column::~List_column() { - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } } @@ -468,8 +470,8 @@ inline bool List_column::is_non_zero(ID_index rowIndex) const // could be changed to dichotomic search as column is ordered by row index, // but I am not sure if it is really worth it as there is no random access // and the columns should not be that long anyway. - for (const Cell* cell : column_) - if (cell->get_row_index() == rowIndex) return true; + for (const Entry* entry : column_) + if (entry->get_row_index() == rowIndex) return true; return false; } @@ -494,25 +496,25 @@ inline void List_column::reorder(const Row_index_map& valueMap, [ "Method not available for chain columns."); for (auto it = column_.begin(); it != column_.end(); ++it) { - Cell* cell = *it; + Entry* entry = *it; if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); + entry->set_row_index(valueMap.at(entry->get_row_index())); if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // all cells have to be deleted first, to avoid problem with insertion when row is a set + // all entries have to be deleted first, to avoid problem with insertion when row is a set if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) { for (auto it = column_.begin(); it != column_.end(); ++it) { - Cell* cell = *it; - RA_opt::insert_cell(cell->get_row_index(), cell); + Entry* entry = *it; + RA_opt::insert_entry(entry->get_row_index(), entry); } } - column_.sort([](const Cell* c1, const Cell* c2) { return *c1 < *c2; }); + column_.sort([](const Entry* c1, const Entry* c2) { return *c1 < *c2; }); } template @@ -521,9 +523,9 @@ inline void List_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); @@ -537,7 +539,7 @@ inline void List_column::clear(ID_index rowIndex) auto it = column_.begin(); while (it != column_.end() && (*it)->get_row_index() != rowIndex) it++; - if (it != column_.end()) _delete_cell(it); + if (it != column_.end()) _delete_entry(it); } template @@ -568,8 +570,8 @@ inline typename List_column::Field_element List_columnget_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) return cell->get_element(); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -625,10 +627,10 @@ inline typename List_column::const_reverse_iterator List_column -template -inline List_column& List_column::operator+=(const Cell_range& column) +template +inline List_column& List_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -680,9 +682,9 @@ inline List_column& List_column::operator*=(unsign if (val == 1u) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cell); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry); } } @@ -690,11 +692,11 @@ inline List_column& List_column::operator*=(unsign } template -template +template inline List_column& List_column::multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -752,11 +754,11 @@ inline List_column& List_column::multiply_target_a } template -template -inline List_column& List_column::multiply_source_and_add(const Cell_range& column, +template +inline List_column& List_column::multiply_source_and_add(const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -805,6 +807,18 @@ inline List_column& List_column::multiply_source_a return *this; } +template +inline void List_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_.end()); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); + } +} + template inline List_column& List_column::operator=(const List_column& other) { @@ -813,8 +827,8 @@ inline List_column& List_column::operator=(const L Dim_opt::operator=(other); Chain_opt::operator=(other); - auto tmpPool = cellPool_; - cellPool_ = other.cellPool_; + auto tmpPool = entryPool_; + entryPool_ = other.entryPool_; while (column_.size() > other.column_.size()) { if (column_.back() != nullptr) { @@ -826,15 +840,15 @@ inline List_column& List_column::operator=(const L column_.resize(other.column_.size(), nullptr); auto it = column_.begin(); - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if (*it != nullptr) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it); tmpPool->destroy(*it); } if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), it++); + _update_entry(entry->get_row_index(), it++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), it++); + _update_entry(entry->get_element(), entry->get_row_index(), it++); } } @@ -844,85 +858,85 @@ inline List_column& List_column::operator=(const L } template -inline void List_column::_delete_cell(typename Column_support::iterator& it) +inline void List_column::_delete_entry(typename Column_support::iterator& it) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it); - cellPool_->destroy(*it); + entryPool_->destroy(*it); it = column_.erase(it); } template -inline typename List_column::Cell* List_column::_insert_cell( +inline typename List_column::Entry* List_column::_insert_entry( const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_.insert(position, newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_.insert(position, newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column_.insert(position, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column_.insert(position, newEntry); + return newEntry; } } template -inline void List_column::_insert_cell(ID_index rowIndex, - const typename Column_support::iterator& position) +inline void List_column::_insert_entry(ID_index rowIndex, + const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_.insert(position, newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_.insert(position, newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column_.insert(position, newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column_.insert(position, newEntry); } } template -inline void List_column::_update_cell(const Field_element& value, - ID_index rowIndex, - const typename Column_support::iterator& position) +inline void List_column::_update_entry(const Field_element& value, + ID_index rowIndex, + const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - *position = cellPool_->construct(RA_opt::columnIndex_, rowIndex); + *position = entryPool_->construct(RA_opt::columnIndex_, rowIndex); (*position)->set_element(value); - RA_opt::insert_cell(rowIndex, *position); + RA_opt::insert_entry(rowIndex, *position); } else { - *position = cellPool_->construct(rowIndex); + *position = entryPool_->construct(rowIndex); (*position)->set_element(value); } } template -inline void List_column::_update_cell(ID_index rowIndex, - const typename Column_support::iterator& position) +inline void List_column::_update_entry(ID_index rowIndex, + const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - *position = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - RA_opt::insert_cell(rowIndex, *position); + *position = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + RA_opt::insert_entry(rowIndex, *position); } else { - *position = cellPool_->construct(rowIndex); + *position = entryPool_->construct(rowIndex); } } template -template -inline bool List_column::_add(const Cell_range& column) +template +inline bool List_column::_add(const Entry_range& column) { if (column.begin() == column.end()) return false; if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); auto it = column_.begin(); - for (const Cell& cell : column) { + for (const Entry& entry : column) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell.get_row_index(), it++); + _update_entry(entry.get_row_index(), it++); } else { - _update_cell(cell.get_element(), cell.get_row_index(), it++); + _update_entry(entry.get_element(), entry.get_row_index(), it++); } } return true; @@ -932,15 +946,15 @@ inline bool List_column::_add(const Cell_range& column) } template -template -inline bool List_column::_multiply_target_and_add(const Field_element& val, const Cell_range& column) +template +inline bool List_column::_multiply_target_and_add(const Field_element& val, const Entry_range& column) { return _multiply_target_and_add_to_column(val, column, *this); } template -template -inline bool List_column::_multiply_source_and_add(const Cell_range& column, const Field_element& val) +template +inline bool List_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { return _multiply_source_and_add_to_column(val, column, *this); } @@ -954,7 +968,7 @@ inline bool List_column::_multiply_source_and_add(const Cell_rang * @brief Hash method for @ref Gudhi::persistence_matrix::List_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::List_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::List_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::List_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h index 9a7bb6b..21809f1 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h @@ -26,7 +26,7 @@ #include -#include +#include #include namespace Gudhi { @@ -38,11 +38,11 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a vector structure. The cells are always ordered by row index and only non-zero values + * Column based on a vector structure. The entries are always ordered by row index and only non-zero values * are stored uniquely in the underlying container. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Naive_vector_column : public Master_matrix::Row_access_option, @@ -55,13 +55,13 @@ class Naive_vector_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - using Column_support = std::vector; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Column_support = std::vector; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = boost::indirect_iterator; @@ -116,21 +116,23 @@ class Naive_vector_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Naive_vector_column& operator+=(const Cell_range& column); + template + Naive_vector_column& operator+=(const Entry_range& column); Naive_vector_column& operator+=(Naive_vector_column& column); Naive_vector_column& operator*=(unsigned int v); // this = v * this + column - template - Naive_vector_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Naive_vector_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Naive_vector_column& multiply_target_and_add(const Field_element& val, Naive_vector_column& column); // this = this + column * v - template - Naive_vector_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Naive_vector_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Naive_vector_column& multiply_source_and_add(Naive_vector_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const Naive_vector_column& c1, const Naive_vector_column& c2) { if (&c1 == &c2) return true; if (c1.column_.size() != c2.column_.size()) return false; @@ -177,7 +179,7 @@ class Naive_vector_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -187,19 +189,19 @@ class Naive_vector_column : public Master_matrix::Row_access_option, Column_support column_; Field_operators* operators_; - Cell_constructor* cellPool_; - - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, - typename Column::Column_support::iterator& itTarget, - F1&& process_target, - F2&& process_source, - F3&& update_target1, - F4&& update_target2, - bool& pivotIsZeroed); - template - friend bool _generic_add_to_column(const Cell_range& source, + Entry_constructor* entryPool_; + + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, + typename Column::Column_support::iterator& itTarget, + F1&& process_target, + F2&& process_source, + F3&& update_target1, + F4&& update_target2, + bool& pivotIsZeroed); + template + friend bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, @@ -207,18 +209,18 @@ class Naive_vector_column : public Master_matrix::Row_access_option, F4&& update_target2, F5&& finish_target); - void _delete_cell(Cell* cell); - void _delete_cell(typename Column_support::iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, Column_support& column); - void _insert_cell(ID_index rowIndex, Column_support& column); - void _update_cell(const Field_element& value, ID_index rowIndex, Index position); - void _update_cell(ID_index rowIndex, Index position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + void _delete_entry(Entry* entry); + void _delete_entry(typename Column_support::iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, Column_support& column); + void _insert_entry(ID_index rowIndex, Column_support& column); + void _update_entry(const Field_element& value, ID_index rowIndex, Index position); + void _update_entry(ID_index rowIndex, Index position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -227,9 +229,9 @@ inline Naive_vector_column::Naive_vector_column(Column_settings* Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -244,7 +246,7 @@ inline Naive_vector_column::Naive_vector_column(const Container& Chain_opt(), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -252,12 +254,12 @@ inline Naive_vector_column::Naive_vector_column(const Container& Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -279,7 +281,7 @@ inline Naive_vector_column::Naive_vector_column(Index columnIndex }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -287,12 +289,12 @@ inline Naive_vector_column::Naive_vector_column(Index columnIndex Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -313,17 +315,17 @@ inline Naive_vector_column::Naive_vector_column(const Container& }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -346,17 +348,17 @@ inline Naive_vector_column::Naive_vector_column(Index columnIndex }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -369,7 +371,7 @@ inline Naive_vector_column::Naive_vector_column(const Naive_vecto Chain_opt(static_cast(column)), column_(column.column_.size(), nullptr), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -380,11 +382,11 @@ inline Naive_vector_column::Naive_vector_column(const Naive_vecto } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } } @@ -400,18 +402,18 @@ inline Naive_vector_column::Naive_vector_column(const Naive_vecto Chain_opt(static_cast(column)), column_(column.column_.size(), nullptr), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } } @@ -423,14 +425,14 @@ inline Naive_vector_column::Naive_vector_column(Naive_vector_colu Chain_opt(std::move(static_cast(column))), column_(std::move(column.column_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template inline Naive_vector_column::~Naive_vector_column() { - for (auto* cell : column_) { - _delete_cell(cell); + for (auto* entry : column_) { + _delete_entry(entry); } } @@ -458,9 +460,9 @@ Naive_vector_column::get_content(int columnLength) const template inline bool Naive_vector_column::is_non_zero(ID_index rowIndex) const { - Cell cell(rowIndex); - return std::binary_search(column_.begin(), column_.end(), &cell, - [](const Cell* a, const Cell* b) { return a->get_row_index() < b->get_row_index(); }); + Entry entry(rowIndex); + return std::binary_search(column_.begin(), column_.end(), &entry, + [](const Entry* a, const Entry* b) { return a->get_row_index() < b->get_row_index(); }); } template @@ -483,24 +485,24 @@ inline void Naive_vector_column::reorder(const Row_index_map& val static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns."); - for (Cell* cell : column_) { + for (Entry* entry : column_) { if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); + entry->set_row_index(valueMap.at(entry->get_row_index())); if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // all cells have to be deleted first, to avoid problem with insertion when row is a set + // all entries have to be deleted first, to avoid problem with insertion when row is a set if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) { - for (Cell* cell : column_) { - RA_opt::insert_cell(cell->get_row_index(), cell); + for (Entry* entry : column_) { + RA_opt::insert_entry(entry->get_row_index(), entry); } } - std::sort(column_.begin(), column_.end(), [](const Cell* c1, const Cell* c2) { return *c1 < *c2; }); + std::sort(column_.begin(), column_.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; }); } template @@ -509,9 +511,9 @@ inline void Naive_vector_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); @@ -526,7 +528,7 @@ inline void Naive_vector_column::clear(ID_index rowIndex) auto it = column_.begin(); while (it != column_.end() && (*it)->get_row_index() != rowIndex) ++it; if (it != column_.end()) { - _delete_cell(*it); + _delete_entry(*it); column_.erase(it); } } @@ -558,8 +560,8 @@ inline typename Naive_vector_column::Field_element Naive_vector_c return column_.empty() ? Field_element() : column_.back()->get_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) return cell->get_element(); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -621,10 +623,10 @@ inline typename Naive_vector_column::const_reverse_iterator Naive } template -template -inline Naive_vector_column& Naive_vector_column::operator+=(const Cell_range& column) +template +inline Naive_vector_column& Naive_vector_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -676,9 +678,9 @@ inline Naive_vector_column& Naive_vector_column::o if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cell); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry); } } @@ -686,11 +688,11 @@ inline Naive_vector_column& Naive_vector_column::o } template -template +template inline Naive_vector_column& Naive_vector_column::multiply_target_and_add( - const Field_element& val, const Cell_range& column) + const Field_element& val, const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -748,11 +750,11 @@ inline Naive_vector_column& Naive_vector_column::m } template -template +template inline Naive_vector_column& Naive_vector_column::multiply_source_and_add( - const Cell_range& column, const Field_element& val) + const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -801,6 +803,18 @@ inline Naive_vector_column& Naive_vector_column::m return *this; } +template +inline void Naive_vector_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_); + } +} + template inline Naive_vector_column& Naive_vector_column::operator=( const Naive_vector_column& other) @@ -810,8 +824,8 @@ inline Naive_vector_column& Naive_vector_column::o Dim_opt::operator=(other); Chain_opt::operator=(other); - auto tmpPool = cellPool_; - cellPool_ = other.cellPool_; + auto tmpPool = entryPool_; + entryPool_ = other.entryPool_; while (column_.size() > other.column_.size()) { if (column_.back() == nullptr) { @@ -823,15 +837,15 @@ inline Naive_vector_column& Naive_vector_column::o column_.resize(other.column_.size(), nullptr); Index i = 0; - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if (column_[i] != nullptr) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_[i]); tmpPool->destroy(column_[i]); } if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } @@ -841,90 +855,90 @@ inline Naive_vector_column& Naive_vector_column::o } template -inline void Naive_vector_column::_delete_cell(Cell* cell) +inline void Naive_vector_column::_delete_entry(Entry* entry) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } template -inline void Naive_vector_column::_delete_cell(typename Column_support::iterator& it) +inline void Naive_vector_column::_delete_entry(typename Column_support::iterator& it) { - _delete_cell(*it); + _delete_entry(*it); ++it; } template -inline typename Naive_vector_column::Cell* Naive_vector_column::_insert_cell( +inline typename Naive_vector_column::Entry* Naive_vector_column::_insert_entry( const Field_element& value, ID_index rowIndex, Column_support& column) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column.push_back(newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column.push_back(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - column.push_back(newCell); - newCell->set_element(value); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + column.push_back(newEntry); + newEntry->set_element(value); + return newEntry; } } template -inline void Naive_vector_column::_insert_cell(ID_index rowIndex, Column_support& column) +inline void Naive_vector_column::_insert_entry(ID_index rowIndex, Column_support& column) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column.push_back(newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column.push_back(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - column.push_back(cellPool_->construct(rowIndex)); + column.push_back(entryPool_->construct(rowIndex)); } } template -inline void Naive_vector_column::_update_cell(const Field_element& value, +inline void Naive_vector_column::_update_entry(const Field_element& value, ID_index rowIndex, Index position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_[position] = newCell; - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_[position] = newEntry; + RA_opt::insert_entry(rowIndex, newEntry); } else { - column_[position] = cellPool_->construct(rowIndex); + column_[position] = entryPool_->construct(rowIndex); column_[position]->set_element(value); } } template -inline void Naive_vector_column::_update_cell(ID_index rowIndex, Index position) +inline void Naive_vector_column::_update_entry(ID_index rowIndex, Index position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_[position] = newCell; - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_[position] = newEntry; + RA_opt::insert_entry(rowIndex, newEntry); } else { - column_[position] = cellPool_->construct(rowIndex); + column_[position] = entryPool_->construct(rowIndex); } } template -template -inline bool Naive_vector_column::_add(const Cell_range& column) +template +inline bool Naive_vector_column::_add(const Entry_range& column) { if (column.begin() == column.end()) return false; if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { + for (const Entry& entry : column) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell.get_row_index(), i++); + _update_entry(entry.get_row_index(), i++); } else { - _update_cell(cell.get_element(), cell.get_row_index(), i++); + _update_entry(entry.get_element(), entry.get_row_index(), i++); } } return true; @@ -936,20 +950,20 @@ inline bool Naive_vector_column::_add(const Cell_range& column) auto pivotIsZeroed = _generic_add_to_column( column, *this, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, - [&](typename Cell_range::const_iterator& itSource, + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, + [&](typename Entry_range::const_iterator& itSource, [[maybe_unused]] const typename Column_support::iterator& itTarget) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(itSource->get_row_index(), newColumn); + _insert_entry(itSource->get_row_index(), newColumn); } else { - _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); + _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); } }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { if constexpr (!Master_matrix::Option_list::is_z2) operators_->add_inplace(targetElement, itSource->get_element()); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, [&](typename Column_support::iterator& itTarget) { while (itTarget != column_.end()) { newColumn.push_back(*itTarget); @@ -963,9 +977,9 @@ inline bool Naive_vector_column::_add(const Cell_range& column) } template -template +template inline bool Naive_vector_column::_multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { if (val == 0u) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { @@ -978,11 +992,11 @@ inline bool Naive_vector_column::_multiply_target_and_add(const F if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { + for (const Entry& entry : column) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell.get_row_index(), i++); + _update_entry(entry.get_row_index(), i++); } else { - _update_cell(cell.get_element(), cell.get_row_index(), i++); + _update_entry(entry.get_element(), entry.get_row_index(), i++); } } return true; @@ -994,22 +1008,22 @@ inline bool Naive_vector_column::_multiply_target_and_add(const F auto pivotIsZeroed = _generic_add_to_column( column, *this, - [&](Cell* cellTarget) { - operators_->multiply_inplace(cellTarget->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cellTarget); - newColumn.push_back(cellTarget); + [&](Entry* entryTarget) { + operators_->multiply_inplace(entryTarget->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entryTarget); + newColumn.push_back(entryTarget); }, - [&](typename Cell_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { - _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); + [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { + _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { operators_->multiply_and_add_inplace_front(targetElement, val, itSource->get_element()); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, [&](typename Column_support::iterator& itTarget) { while (itTarget != column_.end()) { operators_->multiply_inplace((*itTarget)->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(**itTarget); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(**itTarget); newColumn.push_back(*itTarget); itTarget++; } @@ -1021,8 +1035,8 @@ inline bool Naive_vector_column::_multiply_target_and_add(const F } template -template -inline bool Naive_vector_column::_multiply_source_and_add(const Cell_range& column, +template +inline bool Naive_vector_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { if (val == 0u || column.begin() == column.end()) { @@ -1035,16 +1049,16 @@ inline bool Naive_vector_column::_multiply_source_and_add(const C auto pivotIsZeroed = _generic_add_to_column( column, *this, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, - [&](typename Cell_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { - Cell* newCell = _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); - operators_->multiply_inplace(newCell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*newCell); + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, + [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { + Entry* newEntry = _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); + operators_->multiply_inplace(newEntry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*newEntry); }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { operators_->multiply_and_add_inplace_back(itSource->get_element(), val, targetElement); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, [&](typename Column_support::iterator& itTarget) { while (itTarget != column_.end()) { newColumn.push_back(*itTarget); @@ -1066,7 +1080,7 @@ inline bool Naive_vector_column::_multiply_source_and_add(const C * @brief Hash method for @ref Gudhi::persistence_matrix::Naive_vector_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Naive_vector_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Naive_vector_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Naive_vector_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h index d170c49..035ad0e 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h @@ -52,7 +52,7 @@ class Row_access public: using Index = typename Master_matrix::Index; /**< @ref MatIdx index type. */ using ID_index = typename Master_matrix::ID_index; /**< @ref IDIdx index type. */ - using Matrix_cell = typename Master_matrix::Matrix_cell; /**< @ref Cell. */ + using Matrix_entry = typename Master_matrix::Matrix_entry; /**< @ref Entry. */ using Row_container = typename Master_matrix::Row_container; /**< Type of the row container. */ /** @@ -75,28 +75,28 @@ class Row_access Row_access(Row_access&& other) noexcept; /** - * @brief Inserts the given cell at the given row index. + * @brief Inserts the given entry at the given row index. * - * @param rowIndex @ref rowindex "Row index" of the cell. - * @param cell Pointer to the cell to insert. + * @param rowIndex @ref rowindex "Row index" of the entry. + * @param entry Pointer to the entry to insert. */ - void insert_cell(ID_index rowIndex, Matrix_cell* cell); + void insert_entry(ID_index rowIndex, Matrix_entry* entry); /** - * @brief Removes the given cell from its row. + * @brief Removes the given entry from its row. * - * @param cell Pointer to the cell to remove. + * @param entry Pointer to the entry to remove. */ - void unlink(Matrix_cell* cell); + void unlink(Matrix_entry* entry); /** - * @brief If @ref PersistenceMatrixOptions::has_intrusive_rows is false, updates the copy of the cell in its row. + * @brief If @ref PersistenceMatrixOptions::has_intrusive_rows is false, updates the copy of the entry in its row. * Otherwise does nothing. * - * If the rows are intrusive, only a pointer of the cell is stored and therefore any update on the cell (value + * If the rows are intrusive, only a pointer of the entry is stored and therefore any update on the entry (value * or column index) is automatically forwarded. But for non intrusive rows, any update has to be pushed explicitly. * - * @param cell Cell to update. + * @param entry Entry to update. */ - void update_cell(const Matrix_cell& cell); + void update_entry(const Matrix_entry& entry); /** * @brief Returns the @ref MatIdx column index. * @@ -135,7 +135,7 @@ inline Row_access::Row_access(Row_access&& other) noexcept {} template -inline void Row_access::insert_cell(ID_index rowIndex, Matrix_cell* cell) +inline void Row_access::insert_entry(ID_index rowIndex, Matrix_entry* entry) { if (rows_ == nullptr) return; @@ -145,38 +145,38 @@ inline void Row_access::insert_cell(ID_index rowIndex, Matrix_cel // if has_removable_rows should op[] create non existing entry? If not, use try_emplace() if constexpr (Master_matrix::Option_list::has_intrusive_rows) { - rows_->operator[](rowIndex).push_back(*cell); + rows_->operator[](rowIndex).push_back(*entry); } else { - rows_->operator[](rowIndex).insert(*cell); + rows_->operator[](rowIndex).insert(*entry); } } template -inline void Row_access::unlink(Matrix_cell* cell) +inline void Row_access::unlink(Matrix_entry* entry) { if (rows_ == nullptr) return; if constexpr (Master_matrix::Option_list::has_intrusive_rows) { - cell->Base_hook_matrix_row::unlink(); + entry->Base_hook_matrix_row::unlink(); } else { if constexpr (Master_matrix::Option_list::has_removable_rows) { - auto it = rows_->find(cell->get_row_index()); - it->second.erase(*cell); + auto it = rows_->find(entry->get_row_index()); + it->second.erase(*entry); } else { - rows_->operator[](cell->get_row_index()).erase(*cell); + rows_->operator[](entry->get_row_index()).erase(*entry); } } } template -inline void Row_access::update_cell(const Matrix_cell& cell) +inline void Row_access::update_entry(const Matrix_entry& entry) { if constexpr (!Master_matrix::Option_list::has_intrusive_rows) { if (rows_ == nullptr) return; - auto& row = rows_->at(cell.get_row_index()); - auto it = row.find(cell); + auto& row = rows_->at(entry.get_row_index()); + auto it = row.find(entry); it = row.erase(it); - row.insert(it, cell); + row.insert(it, entry); } } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h index d7c84e1..c2efb18 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h @@ -26,7 +26,7 @@ #include -#include +#include #include namespace Gudhi { @@ -38,11 +38,11 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a set structure. The cells are always ordered by row index and only non-zero values + * Column based on a set structure. The entries are always ordered by row index and only non-zero values * are stored uniquely in the underlying container. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Set_column : public Master_matrix::Row_access_option, @@ -55,18 +55,18 @@ class Set_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - struct CellPointerComp { - bool operator()(const Cell* c1, const Cell* c2) const { return *c1 < *c2; } + struct EntryPointerComp { + bool operator()(const Entry* c1, const Entry* c2) const { return *c1 < *c2; } }; - using Column_support = std::set; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Column_support = std::set; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = boost::indirect_iterator; @@ -121,21 +121,23 @@ class Set_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Set_column& operator+=(const Cell_range& column); + template + Set_column& operator+=(const Entry_range& column); Set_column& operator+=(Set_column& column); Set_column& operator*=(unsigned int v); // this = v * this + column - template - Set_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Set_column& multiply_target_and_add(const Field_element& val, Set_column& column); // this = this + column * v - template - Set_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Set_column& multiply_source_and_add(Set_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const Set_column& c1, const Set_column& c2) { if (&c1 == &c2) return true; @@ -182,7 +184,7 @@ class Set_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -192,45 +194,45 @@ class Set_column : public Master_matrix::Row_access_option, Column_support column_; Field_operators* operators_; - Cell_constructor* cellPool_; - - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, - typename Column::Column_support::iterator& itTarget, - F1&& process_target, - F2&& process_source, - F3&& update_target1, - F4&& update_target2, - bool& pivotIsZeroed); - template - friend bool _generic_add_to_column(const Cell_range& source, + Entry_constructor* entryPool_; + + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, + typename Column::Column_support::iterator& itTarget, + F1&& process_target, + F2&& process_source, + F3&& update_target1, + F4&& update_target2, + bool& pivotIsZeroed); + template + friend bool _generic_add_to_column(const Entry_range& source, Column& targetColumn, F1&& process_target, F2&& process_source, F3&& update_target1, F4&& update_target2, F5&& finish_target); - template - friend bool _add_to_column(const Cell_range& source, Column& targetColumn); - template + template + friend bool _add_to_column(const Entry_range& source, Column& targetColumn); + template friend bool _multiply_target_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - template + template friend bool _multiply_source_and_add_to_column(const typename Column::Field_element& val, - const Cell_range& source, + const Entry_range& source, Column& targetColumn); - void _delete_cell(typename Column_support::iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); - void _insert_cell(ID_index rowIndex, const typename Column_support::iterator& position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); + void _delete_entry(typename Column_support::iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position); + void _insert_entry(ID_index rowIndex, const typename Column_support::iterator& position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); }; template @@ -239,9 +241,9 @@ inline Set_column::Set_column(Column_settings* colSettings) Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -254,19 +256,19 @@ inline Set_column::Set_column(const Container& nonZeroRowIndices, Dim_opt(nonZeroRowIndices.size() == 0 ? 0 : nonZeroRowIndices.size() - 1), Chain_opt(), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -287,19 +289,19 @@ inline Set_column::Set_column(Index columnIndex, } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -319,16 +321,16 @@ inline Set_column::Set_column(const Container& nonZeroRowIndices, } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -350,16 +352,16 @@ inline Set_column::Set_column(Index columnIndex, } }()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id, column_.end()); + _insert_entry(id, column_.end()); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first, column_.end()); + _insert_entry(operators_->get_value(p.second), p.first, column_.end()); } } } @@ -370,7 +372,7 @@ inline Set_column::Set_column(const Set_column& column, Column_se Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -380,11 +382,11 @@ inline Set_column::Set_column(const Set_column& column, Column_se if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index(), column_.end()); + _insert_entry(entry->get_row_index(), column_.end()); } else { - _insert_cell(cell->get_element(), cell->get_row_index(), column_.end()); + _insert_entry(entry->get_element(), entry->get_row_index(), column_.end()); } } } @@ -399,17 +401,17 @@ inline Set_column::Set_column(const Set_column& column, Dim_opt(static_cast(column)), Chain_opt(static_cast(column)), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index(), column_.end()); + _insert_entry(entry->get_row_index(), column_.end()); } else { - _insert_cell(cell->get_element(), cell->get_row_index(), column_.end()); + _insert_entry(entry->get_element(), entry->get_row_index(), column_.end()); } } } @@ -421,15 +423,15 @@ inline Set_column::Set_column(Set_column&& column) noexcept Chain_opt(std::move(static_cast(column))), column_(std::move(column.column_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template inline Set_column::~Set_column() { - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } } @@ -457,8 +459,8 @@ inline std::vector::Field_element> Set_column template inline bool Set_column::is_non_zero(ID_index rowIndex) const { - Cell cell(rowIndex); - return column_.find(&cell) != column_.end(); + Entry entry(rowIndex); + return column_.find(&entry) != column_.end(); } template @@ -482,22 +484,22 @@ inline void Set_column::reorder(const Row_index_map& valueMap, [[ Column_support newSet; - for (Cell* cell : column_) { + for (Entry* entry : column_) { if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); - newSet.insert(cell); + entry->set_row_index(valueMap.at(entry->get_row_index())); + newSet.insert(entry); if constexpr (Master_matrix::Option_list::has_row_access && Master_matrix::Option_list::has_intrusive_rows) // intrusive list - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // when row is a set, all cells have to be deleted first, to avoid colliding when inserting + // when row is a set, all entries have to be deleted first, to avoid colliding when inserting if constexpr (Master_matrix::Option_list::has_row_access && !Master_matrix::Option_list::has_intrusive_rows) { // set - for (Cell* cell : newSet) { - RA_opt::insert_cell(cell->get_row_index(), cell); + for (Entry* entry : newSet) { + RA_opt::insert_entry(entry->get_row_index(), entry); } } @@ -510,9 +512,9 @@ inline void Set_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); @@ -524,12 +526,12 @@ inline void Set_column::clear(ID_index rowIndex) static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns."); - auto cell = cellPool_->construct(rowIndex); - auto it = column_.find(cell); + auto entry = entryPool_->construct(rowIndex); + auto it = column_.find(entry); if (it != column_.end()) { - _delete_cell(it); + _delete_entry(it); } - cellPool_->destroy(cell); + entryPool_->destroy(entry); } template @@ -560,8 +562,8 @@ inline typename Set_column::Field_element Set_columnget_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) return cell->get_element(); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -617,10 +619,10 @@ inline typename Set_column::const_reverse_iterator Set_column -template -inline Set_column& Set_column::operator+=(const Cell_range& column) +template +inline Set_column& Set_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -672,9 +674,9 @@ inline Set_column& Set_column::operator*=(unsigned if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cell); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry); } } @@ -682,11 +684,11 @@ inline Set_column& Set_column::operator*=(unsigned } template -template +template inline Set_column& Set_column::multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -744,11 +746,11 @@ inline Set_column& Set_column::multiply_target_and } template -template -inline Set_column& Set_column::multiply_source_and_add(const Cell_range& column, +template +inline Set_column& Set_column::multiply_source_and_add(const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -797,6 +799,18 @@ inline Set_column& Set_column::multiply_source_and return *this; } +template +inline void Set_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_.end()); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_.end()); + } +} + template inline Set_column& Set_column::operator=(const Set_column& other) { @@ -805,20 +819,20 @@ inline Set_column& Set_column::operator=(const Set Dim_opt::operator=(other); Chain_opt::operator=(other); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); - cellPool_ = other.cellPool_; + entryPool_ = other.entryPool_; operators_ = other.operators_; - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index(), column_.end()); + _insert_entry(entry->get_row_index(), column_.end()); } else { - _insert_cell(cell->get_element(), cell->get_row_index(), column_.end()); + _insert_entry(entry->get_element(), entry->get_row_index(), column_.end()); } } @@ -826,62 +840,62 @@ inline Set_column& Set_column::operator=(const Set } template -inline void Set_column::_delete_cell(typename Column_support::iterator& it) +inline void Set_column::_delete_entry(typename Column_support::iterator& it) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it); - cellPool_->destroy(*it); + entryPool_->destroy(*it); it = column_.erase(it); } template -inline typename Set_column::Cell* Set_column::_insert_cell( +inline typename Set_column::Entry* Set_column::_insert_entry( const Field_element& value, ID_index rowIndex, const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_.insert(position, newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_.insert(position, newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column_.insert(position, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column_.insert(position, newEntry); + return newEntry; } } template -inline void Set_column::_insert_cell(ID_index rowIndex, +inline void Set_column::_insert_entry(ID_index rowIndex, const typename Column_support::iterator& position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_.insert(position, newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_.insert(position, newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column_.insert(position, newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column_.insert(position, newEntry); } } template -template -inline bool Set_column::_add(const Cell_range& column) +template +inline bool Set_column::_add(const Entry_range& column) { return _add_to_column(column, *this); } template -template -inline bool Set_column::_multiply_target_and_add(const Field_element& val, const Cell_range& column) +template +inline bool Set_column::_multiply_target_and_add(const Field_element& val, const Entry_range& column) { return _multiply_target_and_add_to_column(val, column, *this); } template -template -inline bool Set_column::_multiply_source_and_add(const Cell_range& column, const Field_element& val) +template +inline bool Set_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { return _multiply_source_and_add_to_column(val, column, *this); } @@ -895,7 +909,7 @@ inline bool Set_column::_multiply_source_and_add(const Cell_range * @brief Hash method for @ref Gudhi::persistence_matrix::Set_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Set_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Set_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Set_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h index 0e4dc12..9513a20 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h @@ -31,22 +31,22 @@ #include #endif -#include +#include namespace Gudhi { namespace persistence_matrix { // For unordered_set container. Outside of Unordered_set_column because of a msvc bug who can't compile properly // unordered_flat_set if the hash method is nested. -template -struct CellPointerHash +template +struct EntryPointerHash { - size_t operator()(const Cell* c) const { return std::hash()(*c); } + size_t operator()(const Entry* c) const { return std::hash()(*c); } }; -template -struct CellPointerEq +template +struct EntryPointerEq { - bool operator()(const Cell* c1, const Cell* c2) const { return *c1 == *c2; } + bool operator()(const Entry* c1, const Entry* c2) const { return *c1 == *c2; } }; /** @@ -55,12 +55,12 @@ struct CellPointerEq * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on an unordered set structure. The cells are not ordered, but only non-zero values - * are stored uniquely in the underlying container. When adding a cell range into it, the given cell range + * Column based on an unordered set structure. The entries are not ordered, but only non-zero values + * are stored uniquely in the underlying container. When adding an entry range into it, the given entry range * also does not need to be ordered (contrary to most other column types). * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Unordered_set_column : public Master_matrix::Row_access_option, @@ -73,21 +73,21 @@ class Unordered_set_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Entry_constructor = typename Master_matrix::Entry_constructor; - struct CellPointerComp { - bool operator()(const Cell* c1, const Cell* c2) const { return *c1 < *c2; } + struct EntryPointerComp { + bool operator()(const Entry* c1, const Entry* c2) const { return *c1 < *c2; } }; #if BOOST_VERSION >= 108100 - using Column_support = boost::unordered_flat_set, CellPointerEq>; + using Column_support = boost::unordered_flat_set, EntryPointerEq>; #else - using Column_support = std::unordered_set, CellPointerEq>; + using Column_support = std::unordered_set, EntryPointerEq>; #endif public: @@ -137,30 +137,32 @@ class Unordered_set_column : public Master_matrix::Row_access_option, iterator end() noexcept; const_iterator end() const noexcept; - template - Unordered_set_column& operator+=(const Cell_range& column); + template + Unordered_set_column& operator+=(const Entry_range& column); Unordered_set_column& operator+=(Unordered_set_column& column); Unordered_set_column& operator*=(unsigned int v); // this = v * this + column - template - Unordered_set_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Unordered_set_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Unordered_set_column& multiply_target_and_add(const Field_element& val, Unordered_set_column& column); // this = this + column * v - template - Unordered_set_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Unordered_set_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Unordered_set_column& multiply_source_and_add(Unordered_set_column& column, const Field_element& val); + void push_back(const Entry& entry); + friend bool operator==(const Unordered_set_column& c1, const Unordered_set_column& c2) { if (&c1 == &c2) return true; if (c1.column_.size() != c2.column_.size()) return false; - for (Cell* cell : c1.column_) { - auto it = c2.column_.find(cell); + for (Entry* entry : c1.column_) { + auto it = c2.column_.find(entry); if (it == c2.column_.end()) return false; if constexpr (!Master_matrix::Option_list::is_z2) - if ((*it)->get_element() != cell->get_element()) return false; + if ((*it)->get_element() != entry->get_element()) return false; } return true; } @@ -168,7 +170,7 @@ class Unordered_set_column : public Master_matrix::Row_access_option, if (&c1 == &c2) return false; using ID_index = Unordered_set_column::ID_index; - using Cell_rep = + using Entry_rep = typename std::conditional @@ -176,35 +178,35 @@ class Unordered_set_column : public Master_matrix::Row_access_option, auto it1 = c1.column_.begin(); auto it2 = c2.column_.begin(); - std::set cells1, cells2; + std::set entries1, entries2; while (it1 != c1.column_.end() && it2 != c2.column_.end()) { if constexpr (Master_matrix::Option_list::is_z2) { - cells1.insert((*it1)->get_row_index()); - cells2.insert((*it2)->get_row_index()); + entries1.insert((*it1)->get_row_index()); + entries2.insert((*it2)->get_row_index()); } else { - cells1.emplace((*it1)->get_row_index(), (*it1)->get_element()); - cells2.emplace((*it2)->get_row_index(), (*it2)->get_element()); + entries1.emplace((*it1)->get_row_index(), (*it1)->get_element()); + entries2.emplace((*it2)->get_row_index(), (*it2)->get_element()); } ++it1; ++it2; } while (it1 != c1.column_.end()) { if constexpr (Master_matrix::Option_list::is_z2) { - cells1.insert((*it1)->get_row_index()); + entries1.insert((*it1)->get_row_index()); } else { - cells1.emplace((*it1)->get_row_index(), (*it1)->get_element()); + entries1.emplace((*it1)->get_row_index(), (*it1)->get_element()); } ++it1; } while (it2 != c2.column_.end()) { if constexpr (Master_matrix::Option_list::is_z2) { - cells2.insert((*it2)->get_row_index()); + entries2.insert((*it2)->get_row_index()); } else { - cells2.emplace((*it2)->get_row_index(), (*it2)->get_element()); + entries2.emplace((*it2)->get_row_index(), (*it2)->get_element()); } ++it2; } - return cells1 < cells2; + return entries1 < entries2; } // Disabled with row access. @@ -219,7 +221,7 @@ class Unordered_set_column : public Master_matrix::Row_access_option, static_cast(col2)); col1.column_.swap(col2.column_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -229,19 +231,19 @@ class Unordered_set_column : public Master_matrix::Row_access_option, Column_support column_; Field_operators* operators_; - Cell_constructor* cellPool_; - - void _delete_cell(typename Column_support::iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex); - void _insert_cell(ID_index rowIndex); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); - template - bool _generic_add(const Cell_range& source, F1&& process_source, F2&& update_target); + Entry_constructor* entryPool_; + + void _delete_entry(typename Column_support::iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex); + void _insert_entry(ID_index rowIndex); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); + template + bool _generic_add(const Entry_range& source, F1&& process_source, F2&& update_target); }; template @@ -250,9 +252,9 @@ inline Unordered_set_column::Unordered_set_column(Column_settings Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -267,19 +269,19 @@ inline Unordered_set_column::Unordered_set_column(const Container Chain_opt(), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id); + _insert_entry(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first); + _insert_entry(operators_->get_value(p.second), p.first); } } } @@ -301,19 +303,19 @@ inline Unordered_set_column::Unordered_set_column(Index columnInd }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id); + _insert_entry(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first); + _insert_entry(operators_->get_value(p.second), p.first); } } } @@ -334,16 +336,16 @@ inline Unordered_set_column::Unordered_set_column(const Container }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id); + _insert_entry(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first); + _insert_entry(operators_->get_value(p.second), p.first); } } } @@ -366,16 +368,16 @@ inline Unordered_set_column::Unordered_set_column(Index columnInd }()), column_(nonZeroRowIndices.size()), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _insert_cell(id); + _insert_entry(id); } } else { operators_ = &(colSettings->operators); for (const auto& p : nonZeroRowIndices) { - _insert_cell(operators_->get_value(p.second), p.first); + _insert_entry(operators_->get_value(p.second), p.first); } } } @@ -388,7 +390,7 @@ inline Unordered_set_column::Unordered_set_column(const Unordered Chain_opt(static_cast(column)), column_(column.column_.bucket_count()), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -398,11 +400,11 @@ inline Unordered_set_column::Unordered_set_column(const Unordered if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index()); + _insert_entry(entry->get_row_index()); } else { - _insert_cell(cell->get_element(), cell->get_row_index()); + _insert_entry(entry->get_element(), entry->get_row_index()); } } } @@ -418,17 +420,17 @@ inline Unordered_set_column::Unordered_set_column(const Unordered Chain_opt(static_cast(column)), column_(column.column_.bucket_count()), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index()); + _insert_entry(entry->get_row_index()); } else { - _insert_cell(cell->get_element(), cell->get_row_index()); + _insert_entry(entry->get_element(), entry->get_row_index()); } } } @@ -440,15 +442,15 @@ inline Unordered_set_column::Unordered_set_column(Unordered_set_c Chain_opt(std::move(static_cast(column))), column_(std::move(column.column_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template inline Unordered_set_column::~Unordered_set_column() { - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } } @@ -457,7 +459,7 @@ inline std::vector::Field_element> Unordered_set_column::get_content(int columnLength) const { if (columnLength < 0 && column_.size() > 0) - columnLength = (*std::max_element(column_.begin(), column_.end(), CellPointerComp()))->get_row_index() + 1; + columnLength = (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index() + 1; else if (columnLength < 0) return std::vector(); @@ -477,8 +479,8 @@ Unordered_set_column::get_content(int columnLength) const template inline bool Unordered_set_column::is_non_zero(ID_index rowIndex) const { - Cell cell(rowIndex); - return column_.find(&cell) != column_.end(); + Entry entry(rowIndex); + return column_.find(&entry) != column_.end(); } template @@ -503,22 +505,22 @@ inline void Unordered_set_column::reorder(const Row_index_map& va Column_support newSet; - for (Cell* cell : column_) { + for (Entry* entry : column_) { if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); - newSet.insert(cell); + entry->set_row_index(valueMap.at(entry->get_row_index())); + newSet.insert(entry); if constexpr (Master_matrix::Option_list::has_row_access && Master_matrix::Option_list::has_intrusive_rows) // intrusive list - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // when row is a set, all cells have to be deleted first, to avoid colliding when inserting + // when row is a set, all entries have to be deleted first, to avoid colliding when inserting if constexpr (Master_matrix::Option_list::has_row_access && !Master_matrix::Option_list::has_intrusive_rows) { // set - for (Cell* cell : newSet) { - RA_opt::insert_cell(cell->get_row_index(), cell); + for (Entry* entry : newSet) { + RA_opt::insert_entry(entry->get_row_index(), entry); } } @@ -531,9 +533,9 @@ inline void Unordered_set_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); @@ -545,12 +547,12 @@ inline void Unordered_set_column::clear(ID_index rowIndex) static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns."); - auto cell = cellPool_->construct(rowIndex); - auto it = column_.find(cell); + auto entry = entryPool_->construct(rowIndex); + auto it = column_.find(entry); if (it != column_.end()) { - _delete_cell(it); + _delete_entry(it); } - cellPool_->destroy(cell); + entryPool_->destroy(entry); } template @@ -563,7 +565,7 @@ inline typename Unordered_set_column::ID_index Unordered_set_colu if (column_.empty()) return -1; // linear search could be avoided with storing the pivot. But even then, some modifications of the column requires // the max, so not clear how much it is worth it. - return (*std::max_element(column_.begin(), column_.end(), CellPointerComp()))->get_row_index(); + return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_row_index(); } else { return Chain_opt::get_pivot(); } @@ -581,11 +583,11 @@ Unordered_set_column::get_pivot_value() const } else { if constexpr (Master_matrix::Option_list::is_of_boundary_type) { if (column_.empty()) return 0; - return (*std::max_element(column_.begin(), column_.end(), CellPointerComp()))->get_element(); + return (*std::max_element(column_.begin(), column_.end(), EntryPointerComp()))->get_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) return cell->get_element(); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -619,10 +621,10 @@ inline typename Unordered_set_column::const_iterator Unordered_se } template -template -inline Unordered_set_column& Unordered_set_column::operator+=(const Cell_range& column) +template +inline Unordered_set_column& Unordered_set_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -675,9 +677,9 @@ inline Unordered_set_column& Unordered_set_column: if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cell); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry); } } @@ -685,11 +687,11 @@ inline Unordered_set_column& Unordered_set_column: } template -template +template inline Unordered_set_column& Unordered_set_column::multiply_target_and_add( - const Field_element& val, const Cell_range& column) + const Field_element& val, const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -747,11 +749,11 @@ inline Unordered_set_column& Unordered_set_column: } template -template +template inline Unordered_set_column& Unordered_set_column::multiply_source_and_add( - const Cell_range& column, const Field_element& val) + const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -800,6 +802,18 @@ inline Unordered_set_column& Unordered_set_column: return *this; } +template +inline void Unordered_set_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index()); + } else { + _insert_entry(entry.get_element(), entry.get_row_index()); + } +} + template inline Unordered_set_column& Unordered_set_column::operator=( const Unordered_set_column& other) @@ -809,20 +823,20 @@ inline Unordered_set_column& Unordered_set_column: Dim_opt::operator=(other); Chain_opt::operator=(other); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); operators_ = other.operators_; - cellPool_ = other.cellPool_; + entryPool_ = other.entryPool_; - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(cell->get_row_index()); + _insert_entry(entry->get_row_index()); } else { - _insert_cell(cell->get_element(), cell->get_row_index()); + _insert_entry(entry->get_element(), entry->get_row_index()); } } @@ -830,65 +844,65 @@ inline Unordered_set_column& Unordered_set_column: } template -inline void Unordered_set_column::_delete_cell(typename Column_support::iterator& it) +inline void Unordered_set_column::_delete_entry(typename Column_support::iterator& it) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(*it); - cellPool_->destroy(*it); + entryPool_->destroy(*it); auto tmp = it++; // it = column_.erase(it); column_.erase(tmp); } template -inline typename Unordered_set_column::Cell* Unordered_set_column::_insert_cell( +inline typename Unordered_set_column::Entry* Unordered_set_column::_insert_entry( const Field_element& value, ID_index rowIndex) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_.insert(newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_.insert(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column_.insert(newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column_.insert(newEntry); + return newEntry; } } template -inline void Unordered_set_column::_insert_cell(ID_index rowIndex) +inline void Unordered_set_column::_insert_entry(ID_index rowIndex) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_.insert(newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_.insert(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column_.insert(newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column_.insert(newEntry); } } template -template -inline bool Unordered_set_column::_add(const Cell_range& column) +template +inline bool Unordered_set_column::_add(const Entry_range& column) { return _generic_add( column, - [&](const Cell& oldCell, Cell* newCell) { - if constexpr (!Master_matrix::Option_list::is_z2) newCell->set_element(oldCell.get_element()); + [&](const Entry& oldEntry, Entry* newEntry) { + if constexpr (!Master_matrix::Option_list::is_z2) newEntry->set_element(oldEntry.get_element()); }, - [&](Cell* targetCell, const Cell& sourceCell) { + [&](Entry* targetEntry, const Entry& sourceEntry) { if constexpr (!Master_matrix::Option_list::is_z2) - operators_->add_inplace(targetCell->get_element(), sourceCell.get_element()); + operators_->add_inplace(targetEntry->get_element(), sourceEntry.get_element()); }); } template -template +template inline bool Unordered_set_column::_multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { if (val == 0u) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { @@ -896,22 +910,22 @@ inline bool Unordered_set_column::_multiply_target_and_add(const // this would not only mess up the base, but also the pivots stored. } else { clear(); - for (const Cell& v : column) { - _insert_cell(v.get_element(), v.get_row_index()); + for (const Entry& v : column) { + _insert_entry(v.get_element(), v.get_row_index()); } return true; } } // because the column is unordered, I don't see a way to do both operations in one go - // without guarantees on the cell range... + // without guarantees on the entry range... operator*=(val); return _add(column); } template -template -inline bool Unordered_set_column::_multiply_source_and_add(const Cell_range& column, +template +inline bool Unordered_set_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { if (val == 0u) { @@ -920,50 +934,50 @@ inline bool Unordered_set_column::_multiply_source_and_add(const return _generic_add( column, - [&](const Cell& oldCell, Cell* newCell) { - newCell->set_element(oldCell.get_element()); - operators_->multiply_inplace(newCell->get_element(), val); + [&](const Entry& oldEntry, Entry* newEntry) { + newEntry->set_element(oldEntry.get_element()); + operators_->multiply_inplace(newEntry->get_element(), val); }, - [&](Cell* targetCell, const Cell& sourceCell) { - operators_->multiply_and_add_inplace_back(sourceCell.get_element(), val, targetCell->get_element()); + [&](Entry* targetEntry, const Entry& sourceEntry) { + operators_->multiply_and_add_inplace_back(sourceEntry.get_element(), val, targetEntry->get_element()); }); } template -template -inline bool Unordered_set_column::_generic_add(const Cell_range& source, +template +inline bool Unordered_set_column::_generic_add(const Entry_range& source, F1&& process_source, F2&& update_target) { bool pivotIsZeroed = false; - for (const Cell& cell : source) { - Cell* newCell; + for (const Entry& entry : source) { + Entry* newEntry; if constexpr (Master_matrix::Option_list::has_row_access) { - newCell = cellPool_->construct(RA_opt::columnIndex_, cell.get_row_index()); + newEntry = entryPool_->construct(RA_opt::columnIndex_, entry.get_row_index()); } else { - newCell = cellPool_->construct(cell.get_row_index()); + newEntry = entryPool_->construct(entry.get_row_index()); } - auto res = column_.insert(newCell); + auto res = column_.insert(newEntry); if (res.second) { - process_source(cell, newCell); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::insert_cell(cell.get_row_index(), newCell); + process_source(entry, newEntry); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::insert_entry(entry.get_row_index(), newEntry); } else { - cellPool_->destroy(newCell); + entryPool_->destroy(newEntry); if constexpr (Master_matrix::Option_list::is_z2) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { - if (cell.get_row_index() == Chain_opt::get_pivot()) pivotIsZeroed = true; + if (entry.get_row_index() == Chain_opt::get_pivot()) pivotIsZeroed = true; } - _delete_cell(res.first); + _delete_entry(res.first); } else { - update_target(*res.first, cell); + update_target(*res.first, entry); if ((*res.first)->get_element() == Field_operators::get_additive_identity()) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { if ((*res.first)->get_row_index() == Chain_opt::get_pivot()) pivotIsZeroed = true; } - _delete_cell(res.first); + _delete_entry(res.first); } else { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(**res.first); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(**res.first); } } } @@ -981,15 +995,15 @@ inline bool Unordered_set_column::_generic_add(const Cell_range& * @brief Hash method for @ref Gudhi::persistence_matrix::Unordered_set_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Unordered_set_column. */ template struct std::hash> { std::size_t operator()(const Gudhi::persistence_matrix::Unordered_set_column& column) const { // can't use Gudhi::persistence_matrix::hash_column because unordered std::size_t seed = 0; - for (const auto& cell : column) { - seed ^= std::hash()(cell.get_row_index() * static_cast(cell.get_element())); + for (const auto& entry : column) { + seed ^= std::hash()(entry.get_row_index() * static_cast(entry.get_element())); } return seed; } diff --git a/multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h b/multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h index 135d610..0721d86 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h @@ -38,13 +38,13 @@ namespace persistence_matrix { * * @brief Column class following the @ref PersistenceMatrixColumn concept. * - * Column based on a vector structure. The cells are always ordered by row index, but cells are removed by + * Column based on a vector structure. The entries are always ordered by row index, but entries are removed by * @ref PersistenceMatrixColumn::clear(PersistenceMatrixOptions::Index rowIndex) "clear(Index)" in a lazy way, * so erased values can still be in the underlying container. - * On the other hand, two cells will never have the same row index. + * On the other hand, two entries will never have the same row index. * * @tparam Master_matrix An instantiation of @ref Matrix from which all types and options are deduced. - * @tparam Cell_constructor Factory of @ref Cell classes. + * @tparam Entry_constructor Factory of @ref Entry classes. */ template class Vector_column : public Master_matrix::Row_access_option, @@ -57,13 +57,13 @@ class Vector_column : public Master_matrix::Row_access_option, using ID_index = typename Master_matrix::ID_index; using Dimension = typename Master_matrix::Dimension; using Field_element = typename Master_matrix::Element; - using Cell = typename Master_matrix::Matrix_cell; + using Entry = typename Master_matrix::Matrix_entry; using Column_settings = typename Master_matrix::Column_settings; private: using Field_operators = typename Master_matrix::Field_operators; - using Column_support = std::vector; - using Cell_constructor = typename Master_matrix::Cell_constructor; + using Column_support = std::vector; + using Entry_constructor = typename Master_matrix::Entry_constructor; public: using iterator = boost::indirect_iterator; @@ -104,7 +104,7 @@ class Vector_column : public Master_matrix::Row_access_option, template void reorder(const Row_index_map& valueMap, [[maybe_unused]] Index columnIndex = -1); void clear(); - // do not clear a cell to 0 if the cell was already 0, otherwise size/is_empty will be wrong. + // do not clear an entry to 0 if the entry was already 0, otherwise size/is_empty will be wrong. void clear(ID_index rowIndex); ID_index get_pivot(); @@ -119,21 +119,23 @@ class Vector_column : public Master_matrix::Row_access_option, reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; - template - Vector_column& operator+=(const Cell_range& column); + template + Vector_column& operator+=(const Entry_range& column); Vector_column& operator+=(Vector_column& column); Vector_column& operator*=(unsigned int v); // this = v * this + column - template - Vector_column& multiply_target_and_add(const Field_element& val, const Cell_range& column); + template + Vector_column& multiply_target_and_add(const Field_element& val, const Entry_range& column); Vector_column& multiply_target_and_add(const Field_element& val, Vector_column& column); // this = this + column * v - template - Vector_column& multiply_source_and_add(const Cell_range& column, const Field_element& val); + template + Vector_column& multiply_source_and_add(const Entry_range& column, const Field_element& val); Vector_column& multiply_source_and_add(Vector_column& column, const Field_element& val); + void push_back(const Entry& entry); + std::size_t compute_hash_value(); friend bool operator==(const Vector_column& c1, const Vector_column& c2) { @@ -209,7 +211,7 @@ class Vector_column : public Master_matrix::Row_access_option, col1.column_.swap(col2.column_); col1.erasedValues_.swap(col2.erasedValues_); std::swap(col1.operators_, col2.operators_); - std::swap(col1.cellPool_, col2.cellPool_); + std::swap(col1.entryPool_, col2.entryPool_); } private: @@ -221,11 +223,11 @@ class Vector_column : public Master_matrix::Row_access_option, std::unordered_set erasedValues_; // TODO: test other containers? Useless when clear(Index) is never // called, how much is it worth it? Field_operators* operators_; - Cell_constructor* cellPool_; + Entry_constructor* entryPool_; - template - friend void _generic_merge_cell_to_column(Column& targetColumn, - Cell_iterator& itSource, + template + friend void _generic_merge_entry_to_column(Column& targetColumn, + Entry_iterator& itSource, typename Column::Column_support::iterator& itTarget, F1&& process_target, F2&& process_source, @@ -233,20 +235,20 @@ class Vector_column : public Master_matrix::Row_access_option, F4&& update_target2, bool& pivotIsZeroed); - void _delete_cell(Cell* cell); - void _delete_cell(typename Column_support::iterator& it); - Cell* _insert_cell(const Field_element& value, ID_index rowIndex, Column_support& column); - void _insert_cell(ID_index rowIndex, Column_support& column); - void _update_cell(const Field_element& value, ID_index rowIndex, Index position); - void _update_cell(ID_index rowIndex, Index position); - template - bool _add(const Cell_range& column); - template - bool _multiply_target_and_add(const Field_element& val, const Cell_range& column); - template - bool _multiply_source_and_add(const Cell_range& column, const Field_element& val); - template - bool _generic_add(const Cell_range& source, + void _delete_entry(Entry* entry); + void _delete_entry(typename Column_support::iterator& it); + Entry* _insert_entry(const Field_element& value, ID_index rowIndex, Column_support& column); + void _insert_entry(ID_index rowIndex, Column_support& column); + void _update_entry(const Field_element& value, ID_index rowIndex, Index position); + void _update_entry(ID_index rowIndex, Index position); + template + bool _add(const Entry_range& column); + template + bool _multiply_target_and_add(const Field_element& val, const Entry_range& column); + template + bool _multiply_source_and_add(const Entry_range& column, const Field_element& val); + template + bool _generic_add(const Entry_range& source, F1&& process_target, F2&& process_source, F3&& update_target1, @@ -259,9 +261,9 @@ inline Vector_column::Vector_column(Column_settings* colSettings) Dim_opt(), Chain_opt(), operators_(nullptr), - cellPool_(colSettings == nullptr ? nullptr : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? nullptr : &(colSettings->entryConstructor)) { - if (operators_ == nullptr && cellPool_ == nullptr) return; // to allow default constructor which gives a dummy column + if (operators_ == nullptr && entryPool_ == nullptr) return; // to allow default constructor which gives a dummy column if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); } @@ -275,7 +277,7 @@ inline Vector_column::Vector_column(const Container& nonZeroRowIn Chain_opt(), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -287,11 +289,11 @@ inline Vector_column::Vector_column(const Container& nonZeroRowIn Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -313,7 +315,7 @@ inline Vector_column::Vector_column(Index columnIndex, }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Constructor not available for chain columns, please specify the dimension of the chain."); @@ -325,11 +327,11 @@ inline Vector_column::Vector_column(Index columnIndex, Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -350,7 +352,7 @@ inline Vector_column::Vector_column(const Container& nonZeroRowIn }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); @@ -359,11 +361,11 @@ inline Vector_column::Vector_column(const Container& nonZeroRowIn Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -386,7 +388,7 @@ inline Vector_column::Vector_column(Index columnIndex, }()), column_(nonZeroRowIndices.size(), nullptr), operators_(nullptr), - cellPool_(&(colSettings->cellConstructor)) + entryPool_(&(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { operators_ = &(colSettings->operators); @@ -395,11 +397,11 @@ inline Vector_column::Vector_column(Index columnIndex, Index i = 0; if constexpr (Master_matrix::Option_list::is_z2) { for (ID_index id : nonZeroRowIndices) { - _update_cell(id, i++); + _update_entry(id, i++); } } else { for (const auto& p : nonZeroRowIndices) { - _update_cell(operators_->get_value(p.second), p.first, i++); + _update_entry(operators_->get_value(p.second), p.first, i++); } } } @@ -412,7 +414,7 @@ inline Vector_column::Vector_column(const Vector_column& column, column_(column.column_.size(), nullptr), erasedValues_(column.erasedValues_), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { static_assert(!Master_matrix::Option_list::has_row_access, "Simple copy constructor not available when row access option enabled. Please specify the new column " @@ -423,11 +425,11 @@ inline Vector_column::Vector_column(const Vector_column& column, } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } } @@ -444,18 +446,18 @@ inline Vector_column::Vector_column(const Vector_column& column, column_(column.column_.size(), nullptr), erasedValues_(column.erasedValues_), operators_(colSettings == nullptr ? column.operators_ : nullptr), - cellPool_(colSettings == nullptr ? column.cellPool_ : &(colSettings->cellConstructor)) + entryPool_(colSettings == nullptr ? column.entryPool_ : &(colSettings->entryConstructor)) { if constexpr (!Master_matrix::Option_list::is_z2) { if (colSettings != nullptr) operators_ = &(colSettings->operators); } Index i = 0; - for (const Cell* cell : column.column_) { + for (const Entry* entry : column.column_) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } } @@ -468,14 +470,14 @@ inline Vector_column::Vector_column(Vector_column&& column) noexc column_(std::move(column.column_)), erasedValues_(std::move(column.erasedValues_)), operators_(std::exchange(column.operators_, nullptr)), - cellPool_(std::exchange(column.cellPool_, nullptr)) + entryPool_(std::exchange(column.entryPool_, nullptr)) {} template inline Vector_column::~Vector_column() { - for (auto* cell : column_) { - _delete_cell(cell); + for (auto* entry : column_) { + _delete_entry(entry); } } @@ -509,9 +511,9 @@ inline bool Vector_column::is_non_zero(ID_index rowIndex) const if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) if (erasedValues_.find(rowIndex) != erasedValues_.end()) return false; - Cell cell(rowIndex); - return std::binary_search(column_.begin(), column_.end(), &cell, - [](const Cell* a, const Cell* b) { return a->get_row_index() < b->get_row_index(); }); + Entry entry(rowIndex); + return std::binary_search(column_.begin(), column_.end(), &entry, + [](const Entry* a, const Entry* b) { return a->get_row_index() < b->get_row_index(); }); } template @@ -544,47 +546,47 @@ inline void Vector_column::reorder(const Row_index_map& valueMap, "Method not available for chain columns."); if (erasedValues_.empty()) { // to avoid useless push_backs. - for (Cell* cell : column_) { + for (Entry* entry : column_) { if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); + entry->set_row_index(valueMap.at(entry->get_row_index())); if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } - // all cells have to be deleted first, to avoid problem with insertion when row is a set + // all entries have to be deleted first, to avoid problem with insertion when row is a set if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) { - for (Cell* cell : column_) { - RA_opt::insert_cell(cell->get_row_index(), cell); + for (Entry* entry : column_) { + RA_opt::insert_entry(entry->get_row_index(), entry); } } - std::sort(column_.begin(), column_.end(), [](const Cell* c1, const Cell* c2) { return *c1 < *c2; }); + std::sort(column_.begin(), column_.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; }); } else { Column_support newColumn; - for (Cell* cell : column_) { - if (erasedValues_.find(cell->get_row_index()) == erasedValues_.end()) { + for (Entry* entry : column_) { + if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) { if constexpr (Master_matrix::Option_list::has_row_access) { - RA_opt::unlink(cell); - if (columnIndex != static_cast(-1)) cell->set_column_index(columnIndex); + RA_opt::unlink(entry); + if (columnIndex != static_cast(-1)) entry->set_column_index(columnIndex); } - cell->set_row_index(valueMap.at(cell->get_row_index())); - newColumn.push_back(cell); + entry->set_row_index(valueMap.at(entry->get_row_index())); + newColumn.push_back(entry); if constexpr (Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) - RA_opt::insert_cell(cell->get_row_index(), cell); + RA_opt::insert_entry(entry->get_row_index(), entry); } else { - _delete_cell(cell); + _delete_entry(entry); } } - // all cells have to be deleted first, to avoid problem with insertion when row is a set + // all entries have to be deleted first, to avoid problem with insertion when row is a set if constexpr (!Master_matrix::Option_list::has_intrusive_rows && Master_matrix::Option_list::has_row_access) { - for (Cell* cell : column_) { - RA_opt::insert_cell(cell->get_row_index(), cell); + for (Entry* entry : column_) { + RA_opt::insert_entry(entry->get_row_index(), entry); } } - std::sort(newColumn.begin(), newColumn.end(), [](const Cell* c1, const Cell* c2) { return *c1 < *c2; }); + std::sort(newColumn.begin(), newColumn.end(), [](const Entry* c1, const Entry* c2) { return *c1 < *c2; }); erasedValues_.clear(); column_.swap(newColumn); } @@ -596,9 +598,9 @@ inline void Vector_column::clear() static_assert(!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type, "Method not available for chain columns as a base element should not be empty."); - for (auto* cell : column_) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + for (auto* entry : column_) { + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } column_.clear(); @@ -627,7 +629,7 @@ inline typename Vector_column::ID_index Vector_columnget_row_index()); while (!column_.empty() && it != erasedValues_.end()) { erasedValues_.erase(it); - _delete_cell(column_.back()); + _delete_entry(column_.back()); column_.pop_back(); if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index()); } @@ -655,7 +657,7 @@ inline typename Vector_column::Field_element Vector_columnget_row_index()); while (!column_.empty() && it != erasedValues_.end()) { erasedValues_.erase(it); - _delete_cell(column_.back()); + _delete_entry(column_.back()); column_.pop_back(); if (!column_.empty()) it = erasedValues_.find(column_.back()->get_row_index()); } @@ -664,8 +666,8 @@ inline typename Vector_column::Field_element Vector_columnget_element(); } else { if (Chain_opt::get_pivot() == static_cast(-1)) return Field_element(); - for (const Cell* cell : column_) { - if (cell->get_row_index() == Chain_opt::get_pivot()) return cell->get_element(); + for (const Entry* entry : column_) { + if (entry->get_row_index() == Chain_opt::get_pivot()) return entry->get_element(); } return Field_element(); // should never happen if chain column is used properly } @@ -723,10 +725,10 @@ inline typename Vector_column::const_reverse_iterator Vector_colu } template -template -inline Vector_column& Vector_column::operator+=(const Cell_range& column) +template +inline Vector_column& Vector_column::operator+=(const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -778,9 +780,9 @@ inline Vector_column& Vector_column::operator*=(un if (val == Field_operators::get_multiplicative_identity()) return *this; - for (Cell* cell : column_) { - operators_->multiply_inplace(cell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cell); + for (Entry* entry : column_) { + operators_->multiply_inplace(entry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entry); } } @@ -788,11 +790,11 @@ inline Vector_column& Vector_column::operator*=(un } template -template +template inline Vector_column& Vector_column::multiply_target_and_add(const Field_element& val, - const Cell_range& column) + const Entry_range& column) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -850,11 +852,11 @@ inline Vector_column& Vector_column::multiply_targ } template -template -inline Vector_column& Vector_column::multiply_source_and_add(const Cell_range& column, +template +inline Vector_column& Vector_column::multiply_source_and_add(const Entry_range& column, const Field_element& val) { - static_assert((!Master_matrix::isNonBasic || std::is_same_v), + static_assert((!Master_matrix::isNonBasic || std::is_same_v), "For boundary columns, the range has to be a column of same type to help ensure the validity of the " "base element."); // could be removed, if we give the responsibility to the user. static_assert((!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type), @@ -903,6 +905,18 @@ inline Vector_column& Vector_column::multiply_sour return *this; } +template +inline void Vector_column::push_back(const Entry& entry) +{ + static_assert(Master_matrix::Option_list::is_of_boundary_type, "`push_back` is not available for Chain matrices."); + + if constexpr (Master_matrix::Option_list::is_z2) { + _insert_entry(entry.get_row_index(), column_); + } else { + _insert_entry(entry.get_element(), entry.get_row_index(), column_); + } +} + template inline Vector_column& Vector_column::operator=(const Vector_column& other) { @@ -911,8 +925,8 @@ inline Vector_column& Vector_column::operator=(con Dim_opt::operator=(other); Chain_opt::operator=(other); - auto tmpPool = cellPool_; - cellPool_ = other.cellPool_; + auto tmpPool = entryPool_; + entryPool_ = other.entryPool_; while (column_.size() > other.column_.size()) { if (column_.back() != nullptr) { @@ -924,15 +938,15 @@ inline Vector_column& Vector_column::operator=(con column_.resize(other.column_.size(), nullptr); Index i = 0; - for (const Cell* cell : other.column_) { + for (const Entry* entry : other.column_) { if (column_[i] != nullptr) { if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(column_[i]); tmpPool->destroy(column_[i]); } if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell->get_row_index(), i++); + _update_entry(entry->get_row_index(), i++); } else { - _update_cell(cell->get_element(), cell->get_row_index(), i++); + _update_entry(entry->get_element(), entry->get_row_index(), i++); } } erasedValues_ = other.erasedValues_; @@ -945,9 +959,9 @@ template inline std::size_t Vector_column::compute_hash_value() { std::size_t seed = 0; - for (Cell* cell : column_) { - if (erasedValues_.find(cell->get_row_index()) == erasedValues_.end()) { - seed ^= std::hash()(cell->get_row_index() * static_cast(cell->get_element())) + + for (Entry* entry : column_) { + if (erasedValues_.find(entry->get_row_index()) == erasedValues_.end()) { + seed ^= std::hash()(entry->get_row_index() * static_cast(entry->get_element())) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } } @@ -955,89 +969,89 @@ inline std::size_t Vector_column::compute_hash_value() } template -inline void Vector_column::_delete_cell(Cell* cell) +inline void Vector_column::_delete_entry(Entry* entry) { - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(cell); - cellPool_->destroy(cell); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::unlink(entry); + entryPool_->destroy(entry); } template -inline void Vector_column::_delete_cell(typename Column_support::iterator& it) +inline void Vector_column::_delete_entry(typename Column_support::iterator& it) { - _delete_cell(*it); + _delete_entry(*it); ++it; } template -inline typename Vector_column::Cell* Vector_column::_insert_cell( +inline typename Vector_column::Entry* Vector_column::_insert_entry( const Field_element& value, ID_index rowIndex, Column_support& column) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column.push_back(newCell); - RA_opt::insert_cell(rowIndex, newCell); - return newCell; + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column.push_back(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); + return newEntry; } else { - Cell* newCell = cellPool_->construct(rowIndex); - newCell->set_element(value); - column.push_back(newCell); - return newCell; + Entry* newEntry = entryPool_->construct(rowIndex); + newEntry->set_element(value); + column.push_back(newEntry); + return newEntry; } } template -inline void Vector_column::_insert_cell(ID_index rowIndex, Column_support& column) +inline void Vector_column::_insert_entry(ID_index rowIndex, Column_support& column) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column.push_back(newCell); - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column.push_back(newEntry); + RA_opt::insert_entry(rowIndex, newEntry); } else { - Cell* newCell = cellPool_->construct(rowIndex); - column.push_back(newCell); + Entry* newEntry = entryPool_->construct(rowIndex); + column.push_back(newEntry); } } template -inline void Vector_column::_update_cell(const Field_element& value, ID_index rowIndex, Index position) +inline void Vector_column::_update_entry(const Field_element& value, ID_index rowIndex, Index position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - newCell->set_element(value); - column_[position] = newCell; - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + newEntry->set_element(value); + column_[position] = newEntry; + RA_opt::insert_entry(rowIndex, newEntry); } else { - column_[position] = cellPool_->construct(rowIndex); + column_[position] = entryPool_->construct(rowIndex); column_[position]->set_element(value); } } template -inline void Vector_column::_update_cell(ID_index rowIndex, Index position) +inline void Vector_column::_update_entry(ID_index rowIndex, Index position) { if constexpr (Master_matrix::Option_list::has_row_access) { - Cell* newCell = cellPool_->construct(RA_opt::columnIndex_, rowIndex); - column_[position] = newCell; - RA_opt::insert_cell(rowIndex, newCell); + Entry* newEntry = entryPool_->construct(RA_opt::columnIndex_, rowIndex); + column_[position] = newEntry; + RA_opt::insert_entry(rowIndex, newEntry); } else { - column_[position] = cellPool_->construct(rowIndex); + column_[position] = entryPool_->construct(rowIndex); } } template -template -inline bool Vector_column::_add(const Cell_range& column) +template +inline bool Vector_column::_add(const Entry_range& column) { if (column.begin() == column.end()) return false; if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { + for (const Entry& entry : column) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell.get_row_index(), i++); + _update_entry(entry.get_row_index(), i++); } else { - _update_cell(cell.get_element(), cell.get_row_index(), i++); + _update_entry(entry.get_element(), entry.get_row_index(), i++); } } return true; @@ -1048,20 +1062,20 @@ inline bool Vector_column::_add(const Cell_range& column) auto pivotIsZeroed = _generic_add( column, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, - [&](typename Cell_range::const_iterator& itSource, + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, + [&](typename Entry_range::const_iterator& itSource, [[maybe_unused]] const typename Column_support::iterator& itTarget) { if constexpr (Master_matrix::Option_list::is_z2) { - _insert_cell(itSource->get_row_index(), newColumn); + _insert_entry(itSource->get_row_index(), newColumn); } else { - _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); + _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); } }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { if constexpr (!Master_matrix::Option_list::is_z2) operators_->add_inplace(targetElement, itSource->get_element()); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); } + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); } ); column_.swap(newColumn); @@ -1070,8 +1084,8 @@ inline bool Vector_column::_add(const Cell_range& column) } template -template -inline bool Vector_column::_multiply_target_and_add(const Field_element& val, const Cell_range& column) +template +inline bool Vector_column::_multiply_target_and_add(const Field_element& val, const Entry_range& column) { if (val == 0u) { if constexpr (Master_matrix::isNonBasic && !Master_matrix::Option_list::is_of_boundary_type) { @@ -1084,14 +1098,14 @@ inline bool Vector_column::_multiply_target_and_add(const Field_e if (column_.empty()) { // chain should never enter here. column_.resize(column.size()); Index i = 0; - for (const Cell& cell : column) { + for (const Entry& entry : column) { if constexpr (Master_matrix::Option_list::is_z2) { - _update_cell(cell.get_row_index(), i++); + _update_entry(entry.get_row_index(), i++); } else { - _update_cell(cell.get_element(), cell.get_row_index(), i++); + _update_entry(entry.get_element(), entry.get_row_index(), i++); } } - if constexpr (std::is_same_v >) erasedValues_ = column.erasedValues_; + if constexpr (std::is_same_v >) erasedValues_ = column.erasedValues_; return true; } @@ -1100,18 +1114,18 @@ inline bool Vector_column::_multiply_target_and_add(const Field_e auto pivotIsZeroed = _generic_add( column, - [&](Cell* cellTarget) { - operators_->multiply_inplace(cellTarget->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*cellTarget); - newColumn.push_back(cellTarget); + [&](Entry* entryTarget) { + operators_->multiply_inplace(entryTarget->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*entryTarget); + newColumn.push_back(entryTarget); }, - [&](typename Cell_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { - _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); + [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { + _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { operators_->multiply_and_add_inplace_front(targetElement, val, itSource->get_element()); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); } + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); } ); column_.swap(newColumn); @@ -1120,8 +1134,8 @@ inline bool Vector_column::_multiply_target_and_add(const Field_e } template -template -inline bool Vector_column::_multiply_source_and_add(const Cell_range& column, const Field_element& val) +template +inline bool Vector_column::_multiply_source_and_add(const Entry_range& column, const Field_element& val) { if (val == 0u || column.begin() == column.end()) { return false; @@ -1132,16 +1146,16 @@ inline bool Vector_column::_multiply_source_and_add(const Cell_ra auto pivotIsZeroed = _generic_add( column, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); }, - [&](typename Cell_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { - Cell* newCell = _insert_cell(itSource->get_element(), itSource->get_row_index(), newColumn); - operators_->multiply_inplace(newCell->get_element(), val); - if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_cell(*newCell); + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); }, + [&](typename Entry_range::const_iterator& itSource, const typename Column_support::iterator& itTarget) { + Entry* newEntry = _insert_entry(itSource->get_element(), itSource->get_row_index(), newColumn); + operators_->multiply_inplace(newEntry->get_element(), val); + if constexpr (Master_matrix::Option_list::has_row_access) RA_opt::update_entry(*newEntry); }, - [&](Field_element& targetElement, typename Cell_range::const_iterator& itSource) { + [&](Field_element& targetElement, typename Entry_range::const_iterator& itSource) { operators_->multiply_and_add_inplace_back(itSource->get_element(), val, targetElement); }, - [&](Cell* cellTarget) { newColumn.push_back(cellTarget); } + [&](Entry* entryTarget) { newColumn.push_back(entryTarget); } ); column_.swap(newColumn); @@ -1150,8 +1164,8 @@ inline bool Vector_column::_multiply_source_and_add(const Cell_ra } template -template -inline bool Vector_column::_generic_add(const Cell_range& column, +template +inline bool Vector_column::_generic_add(const Entry_range& column, F1&& process_target, F2&& process_source, F3&& update_target1, @@ -1160,13 +1174,13 @@ inline bool Vector_column::_generic_add(const Cell_range& column, auto updateTargetIterator = [&](typename Column_support::iterator& itTarget) { if constexpr (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type) { while (itTarget != column_.end() && erasedValues_.find((*itTarget)->get_row_index()) != erasedValues_.end()) { - _delete_cell(*itTarget); + _delete_entry(*itTarget); ++itTarget; } } }; - auto updateSourceIterator = [&](typename Cell_range::const_iterator& itSource) { - if constexpr (std::is_same_v > && + auto updateSourceIterator = [&](typename Entry_range::const_iterator& itSource) { + if constexpr (std::is_same_v > && (!Master_matrix::isNonBasic || Master_matrix::Option_list::is_of_boundary_type)) { while (itSource != column.end() && column.erasedValues_.find(itSource->get_row_index()) != column.erasedValues_.end()) @@ -1183,9 +1197,9 @@ inline bool Vector_column::_generic_add(const Cell_range& column, updateSourceIterator(itSource); if (itTarget == column_.end() || itSource == column.end()) break; - _generic_merge_cell_to_column(*this, itSource, itTarget, - process_target, process_source, update_target1, update_target2, - pivotIsZeroed); + _generic_merge_entry_to_column(*this, itSource, itTarget, + process_target, process_source, update_target1, update_target2, + pivotIsZeroed); } while (itSource != column.end()) { @@ -1218,7 +1232,7 @@ inline bool Vector_column::_generic_add(const Cell_range& column, * @brief Hash method for @ref Gudhi::persistence_matrix::Vector_column. * * @tparam Master_matrix Template parameter of @ref Gudhi::persistence_matrix::Vector_column. - * @tparam Cell_constructor Template parameter of @ref Gudhi::persistence_matrix::Vector_column. + * @tparam Entry_constructor Template parameter of @ref Gudhi::persistence_matrix::Vector_column. */ template struct std::hash > { diff --git a/multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h b/multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h index e743f98..30ce121 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h @@ -44,8 +44,8 @@ struct Dummy_matrix_dimension_holder /** * @ingroup persistence_matrix * - * @brief Class managing the maximal dimension of a face represented in the inheriting matrix, when the option of - * face removal is not enabled. + * @brief Class managing the maximal dimension of a cell represented in the inheriting matrix, when the option of + * cell removal is not enabled. * * @tparam Dimension Dimension value type. Has to be an integer type. * If unsigned, the maximal value of the type should not be attained during a run. @@ -75,7 +75,7 @@ class Matrix_max_dimension_holder : maxDim_(std::exchange(other.maxDim_, -1)){}; /** - * @brief Returns the maximal dimension of a face represented in the matrix. + * @brief Returns the maximal dimension of a cell represented in the matrix. * * @return The maximal dimension. */ @@ -106,8 +106,8 @@ class Matrix_max_dimension_holder /** * @ingroup persistence_matrix * - * @brief Class managing the maximal dimension of a face represented in the inheriting matrix, when the option of - * face removal is enabled. + * @brief Class managing the maximal dimension of a cell represented in the inheriting matrix, when the option of + * cell removal is enabled. * * @tparam Dimension Dimension value type. Has to be an integer type. * If unsigned, the maximal value of the type should not be attained during a run. @@ -141,7 +141,7 @@ class Matrix_all_dimension_holder : dimensions_(std::move(other.dimensions_)), maxDim_(std::exchange(other.maxDim_, -1)){}; /** - * @brief Returns the maximal dimension of a face represented in the matrix. + * @brief Returns the maximal dimension of a cell represented in the matrix. * * @return The maximal dimension. */ @@ -164,8 +164,8 @@ class Matrix_all_dimension_holder } protected: - std::vector dimensions_; /**< Number of faces by dimension. */ - Dimension maxDim_; /**< Current maximal dimension. */ + std::vector dimensions_; /**< Number of cells by dimension. */ + Dimension maxDim_; /**< Current maximal dimension. */ void update_up(unsigned int dimension) { if (dimensions_.size() <= dimension) dimensions_.resize(dimension + 1, 0); diff --git a/multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h b/multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h index cb1f92b..925f573 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h @@ -42,8 +42,8 @@ struct Dummy_matrix_row_access * * @brief Class managing the row access for the inheriting matrix. * - * @tparam Row Either boost::intrusive::list if @ref PersistenceMatrixOptions::has_intrusive_rows - * is true, or std::set otherwise. + * @tparam Row Either boost::intrusive::list if @ref PersistenceMatrixOptions::has_intrusive_rows + * is true, or std::set otherwise. * @tparam Row_container Either std::map if @ref PersistenceMatrixOptions::has_removable_rows is * true, or std::vector otherwise. * @tparam has_removable_rows Value of @ref PersistenceMatrixOptions::has_removable_rows. diff --git a/multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h b/multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h index f44e518..e6afe9f 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h @@ -20,7 +20,7 @@ #include -#include "boundary_face_position_to_id_mapper.h" +#include "boundary_cell_position_to_id_mapper.h" namespace Gudhi { namespace persistence_matrix { @@ -48,7 +48,7 @@ struct Dummy_ru_pairing template class RU_pairing : public std::conditional< Master_matrix::Option_list::has_removable_columns, - Face_position_to_ID_mapper, + Cell_position_to_ID_mapper, Dummy_pos_mapper >::type { @@ -57,9 +57,9 @@ class RU_pairing : public std::conditional< using ID_index = typename Master_matrix::ID_index; //PIDM = Position to ID Map using PIDM = typename std::conditional, - Dummy_pos_mapper - >::type; + Cell_position_to_ID_mapper, + Dummy_pos_mapper + >::type; public: using Barcode = typename Master_matrix::Barcode; /**< Barcode type. */ @@ -93,7 +93,7 @@ class RU_pairing : public std::conditional< Barcode barcode_; /**< Bar container. */ Dictionary indexToBar_; /**< Map from @ref MatIdx index to bar index. */ /** - * @brief Map from face ID to face position. Only stores a pair if ID != position. + * @brief Map from cell ID to cell position. Only stores a pair if ID != position. */ std::unordered_map idToPosition_; //TODO: test other map types diff --git a/multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h b/multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h index 330eec4..fb2e0c0 100644 --- a/multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +++ b/multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h @@ -135,7 +135,7 @@ inline RU_representative_cycles::RU_representative_cycles( template inline void RU_representative_cycles::update_representative_cycles() { - if constexpr (Master_matrix::Option_list::has_vine_update) { + if constexpr (Master_matrix::Option_list::is_z2) { birthToCycle_.clear(); birthToCycle_.resize(_matrix()->reducedMatrixR_.get_number_of_columns(), -1); Index c = 0; @@ -148,8 +148,8 @@ inline void RU_representative_cycles::update_representative_cycle representativeCycles_.clear(); representativeCycles_.resize(c); for (Index i = 0; i < _matrix()->mirrorMatrixU_.get_number_of_columns(); i++) { - for (const auto& cell : _matrix()->mirrorMatrixU_.get_column(i)) { - auto idx = birthToCycle_[cell.get_row_index()]; + for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) { + auto idx = birthToCycle_[entry.get_row_index()]; if (idx != static_cast(-1)) { representativeCycles_[idx].push_back(i); } @@ -161,8 +161,8 @@ inline void RU_representative_cycles::update_representative_cycle for (Index i = 0; i < _matrix()->reducedMatrixR_.get_number_of_columns(); i++) { if (_matrix()->reducedMatrixR_.is_zero_column(i)) { representativeCycles_.push_back(Cycle()); - for (const auto& cell : _matrix()->mirrorMatrixU_.get_column(i)) { - representativeCycles_.back().push_back(cell.get_row_index()); + for (const auto& entry : _matrix()->mirrorMatrixU_.get_column(i)) { + representativeCycles_.back().push_back(entry.get_row_index()); } if constexpr (std::is_same_v || std::is_same_v //std::invalid_argument #include "ru_pairing.h" -#include "boundary_face_position_to_id_mapper.h" +#include "boundary_cell_position_to_id_mapper.h" namespace Gudhi { namespace persistence_matrix { @@ -68,7 +68,7 @@ class RU_vine_swap : public std::conditional >::type { @@ -98,20 +98,20 @@ class RU_vine_swap : public std::conditional&>(swap1), static_cast&>(swap2)); } if (!Master_matrix::Option_list::has_column_pairings || !Master_matrix::Option_list::has_removable_columns) { - swap(static_cast&>(swap1), - static_cast&>(swap2)); + swap(static_cast&>(swap1), + static_cast&>(swap2)); } } @@ -144,7 +144,7 @@ class RU_vine_swap : public std::conditional + Cell_position_to_ID_mapper >::type; constexpr auto& _positionToRowIdx(); @@ -201,7 +201,7 @@ inline bool RU_vine_swap::vine_swap_with_z_eq_1_case(Pos_index in bool iiIsPositive = _matrix()->reducedMatrixR_.is_zero_column(index + 1); if (iIsPositive && iiIsPositive) { - _matrix()->mirrorMatrixU_.zero_cell(index, _get_row_id_from_position(index + 1)); + _matrix()->mirrorMatrixU_.zero_entry(index, _get_row_id_from_position(index + 1)); return _positive_vine_swap(index); } else if (!iIsPositive && !iiIsPositive) { return _negative_vine_swap(index); @@ -228,14 +228,14 @@ inline bool RU_vine_swap::vine_swap(Pos_index index) _swap_at_index(index); return true; } - if (!_matrix()->mirrorMatrixU_.is_zero_cell(index, _get_row_id_from_position(index + 1))) { - _matrix()->mirrorMatrixU_.zero_cell(index, _get_row_id_from_position(index + 1)); + if (!_matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) { + _matrix()->mirrorMatrixU_.zero_entry(index, _get_row_id_from_position(index + 1)); } return _positive_vine_swap(index); } else if (!iIsPositive && !iiIsPositive) { if (_matrix()->reducedMatrixR_.get_column_dimension(index) != _matrix()->reducedMatrixR_.get_column_dimension(index + 1) || - _matrix()->mirrorMatrixU_.is_zero_cell(index, _get_row_id_from_position(index + 1))) { + _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) { _negative_transpose(index); _swap_at_index(index); return true; @@ -244,7 +244,7 @@ inline bool RU_vine_swap::vine_swap(Pos_index index) } else if (iIsPositive && !iiIsPositive) { if (_matrix()->reducedMatrixR_.get_column_dimension(index) != _matrix()->reducedMatrixR_.get_column_dimension(index + 1) || - _matrix()->mirrorMatrixU_.is_zero_cell(index, _get_row_id_from_position(index + 1))) { + _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) { _positive_negative_transpose(index); _swap_at_index(index); return true; @@ -253,7 +253,7 @@ inline bool RU_vine_swap::vine_swap(Pos_index index) } else { if (_matrix()->reducedMatrixR_.get_column_dimension(index) != _matrix()->reducedMatrixR_.get_column_dimension(index + 1) || - _matrix()->mirrorMatrixU_.is_zero_cell(index, _get_row_id_from_position(index + 1))) { + _matrix()->mirrorMatrixU_.is_zero_entry(index, _get_row_id_from_position(index + 1))) { _negative_positive_transpose(index); _swap_at_index(index); return true; @@ -392,7 +392,7 @@ inline bool RU_vine_swap::_positive_vine_swap(Index columnIndex) const Pos_index iiDeath = _get_death(columnIndex + 1); if (iDeath != static_cast(-1) && iiDeath != static_cast(-1) && - !(_matrix()->reducedMatrixR_.is_zero_cell(iiDeath, _get_row_id_from_position(columnIndex)))) { + !(_matrix()->reducedMatrixR_.is_zero_entry(iiDeath, _get_row_id_from_position(columnIndex)))) { if (iDeath < iiDeath) { _swap_at_index(columnIndex); _add_to(iDeath, iiDeath); @@ -408,7 +408,7 @@ inline bool RU_vine_swap::_positive_vine_swap(Index columnIndex) _swap_at_index(columnIndex); if (iDeath != static_cast(-1) || iiDeath == static_cast(-1) || - _matrix()->reducedMatrixR_.is_zero_cell(iiDeath, _get_row_id_from_position(columnIndex + 1))) { + _matrix()->reducedMatrixR_.is_zero_entry(iiDeath, _get_row_id_from_position(columnIndex + 1))) { _positive_transpose(columnIndex); return true; } @@ -437,7 +437,7 @@ inline bool RU_vine_swap::_negative_vine_swap(Index columnIndex) template inline bool RU_vine_swap::_positive_negative_vine_swap(Index columnIndex) { - _matrix()->mirrorMatrixU_.zero_cell(columnIndex, _get_row_id_from_position(columnIndex + 1)); + _matrix()->mirrorMatrixU_.zero_entry(columnIndex, _get_row_id_from_position(columnIndex + 1)); _swap_at_index(columnIndex); _positive_negative_transpose(columnIndex); diff --git a/multipers/gudhi/gudhi/persistence_matrix_options.h b/multipers/gudhi/gudhi/persistence_matrix_options.h index 276dad7..58f7bc1 100644 --- a/multipers/gudhi/gudhi/persistence_matrix_options.h +++ b/multipers/gudhi/gudhi/persistence_matrix_options.h @@ -28,16 +28,16 @@ namespace persistence_matrix { * @brief List of column types. */ enum class Column_types { - LIST, /**< @ref List_column "": Underlying container is a std::list<@ref Cell*>. */ - SET, /**< @ref Set_column "": Underlying container is a std::set<@ref Cell*>. */ - HEAP, /**< @ref Heap_column "": Underlying container is a std::vector<@ref Cell*> ordered as a heap. + LIST, /**< @ref List_column "": Underlying container is a std::list<@ref Entry*>. */ + SET, /**< @ref Set_column "": Underlying container is a std::set<@ref Entry*>. */ + HEAP, /**< @ref Heap_column "": Underlying container is a std::vector<@ref Entry*> ordered as a heap. Is not compatible with row access and column compression. */ - VECTOR, /**< @ref Vector_column "": Underlying container is a std::vector<@ref Cell*> + VECTOR, /**< @ref Vector_column "": Underlying container is a std::vector<@ref Entry*> with a lazy removal method. */ - NAIVE_VECTOR, /**< @ref Naive_vector_column "": Underlying container is a std::vector<@ref Cell*>. */ - UNORDERED_SET, /**< @ref Unordered_set_column "": Underlying container is a std::unordered_set<@ref Cell*>. */ - INTRUSIVE_LIST, /**< @ref Intrusive_list_column "": Underlying container is a boost::intrusive::list<@ref Cell>. */ - INTRUSIVE_SET /**< @ref Intrusive_set_column "": Underlying container is a boost::intrusive::set<@ref Cell>. */ + NAIVE_VECTOR, /**< @ref Naive_vector_column "": Underlying container is a std::vector<@ref Entry*>. */ + UNORDERED_SET, /**< @ref Unordered_set_column "": Underlying container is a std::unordered_set<@ref Entry*>. */ + INTRUSIVE_LIST, /**< @ref Intrusive_list_column "": Underlying container is a boost::intrusive::list<@ref Entry>. */ + INTRUSIVE_SET /**< @ref Intrusive_set_column "": Underlying container is a boost::intrusive::set<@ref Entry>. */ }; /**