17#ifndef PM_ID_TO_POS_TRANSLATION_H 
   18#define PM_ID_TO_POS_TRANSLATION_H 
   28namespace persistence_matrix {
 
   40template <
class Underlying_matrix, 
class Master_matrix>
 
   44  using Index = 
typename Master_matrix::Index;                          
 
   45  using ID_index = 
typename Master_matrix::ID_index;                    
 
   46  using Pos_index = 
typename Master_matrix::Pos_index;                  
 
   47  using Dimension = 
typename Master_matrix::Dimension;                  
 
   53  using Boundary = 
typename Master_matrix::Boundary;                    
 
   54  using Column = 
typename Master_matrix::Column;                        
 
   55  using Row = 
typename Master_matrix::Row;                              
 
   57  using Bar = 
typename Master_matrix::Bar;                              
 
   58  using Barcode = 
typename Master_matrix::Barcode;                      
 
   59  using Cycle = 
typename Master_matrix::Cycle;                          
 
   92  template <
class Boundary_range = Boundary>
 
  125  template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction>
 
  127                      const BirthComparatorFunction& birthComparator,
 
  128                      const DeathComparatorFunction& deathComparator);
 
  165  template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction, 
class Boundary_range>
 
  168                      const BirthComparatorFunction& birthComparator,
 
  169                      const DeathComparatorFunction& deathComparator);
 
  193  template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction>
 
  196                      const BirthComparatorFunction& birthComparator,
 
  197                      const DeathComparatorFunction& deathComparator);
 
  247  template <
class Boundary_range = Boundary>
 
  249                       Dimension dim = Master_matrix::template get_null_value<Dimension>());
 
  267  template <
class Boundary_range = Boundary>
 
  269                       Dimension dim = Master_matrix::template get_null_value<Dimension>());
 
  511    matrix_.reset(colSettings);
 
  525    swap(matrix1.matrix_, matrix2.matrix_);
 
  526    if (Master_matrix::Option_list::is_of_boundary_type) std::swap(matrix1.idToIndex_, matrix2.idToIndex_);
 
  527    std::swap(matrix1.nextIndex_, matrix2.nextIndex_);
 
  567  void swap_rows(Index rowIndex1, Index rowIndex2);
 
  622  using Dictionary = 
typename Master_matrix::template Dictionary<Index>;
 
  624  Underlying_matrix matrix_;  
 
  625  Dictionary* idToIndex_;     
 
  628  void _initialize_map(
unsigned int size);
 
  629  Index _id_to_index(
ID_index id) 
const;
 
  633template <
class Underlying_matrix, 
class Master_matrix>
 
  635    : matrix_(colSettings), idToIndex_(nullptr), nextIndex_(0)
 
  640template <
class Underlying_matrix, 
class Master_matrix>
 
  641template <
class Boundary_range>
 
  643    const std::vector<Boundary_range>& orderedBoundaries, 
Column_settings* colSettings)
 
  644    : matrix_(orderedBoundaries, colSettings), idToIndex_(nullptr), nextIndex_(orderedBoundaries.size())
 
  646  _initialize_map(orderedBoundaries.size());
 
  647  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  648    for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
 
  654template <
class Underlying_matrix, 
class Master_matrix>
 
  657    : matrix_(numberOfColumns, colSettings), idToIndex_(nullptr), nextIndex_(0)
 
  659  _initialize_map(numberOfColumns);
 
  662template <
class Underlying_matrix, 
class Master_matrix>
 
  663template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction>
 
  666    const BirthComparatorFunction& birthComparator,
 
  667    const DeathComparatorFunction& deathComparator)
 
  668    : matrix_(colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
 
  673template <
class Underlying_matrix, 
class Master_matrix>
 
  674template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction, 
class Boundary_range>
 
  676    const std::vector<Boundary_range>& orderedBoundaries,
 
  678    const BirthComparatorFunction& birthComparator,
 
  679    const DeathComparatorFunction& deathComparator)
 
  680    : matrix_(orderedBoundaries, colSettings, birthComparator, deathComparator),
 
  682      nextIndex_(orderedBoundaries.size())
 
  684  _initialize_map(orderedBoundaries.size());
 
  685  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  686    for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
 
  692template <
class Underlying_matrix, 
class Master_matrix>
 
  693template <
typename BirthComparatorFunction, 
typename DeathComparatorFunction>
 
  695    unsigned int numberOfColumns,
 
  697    const BirthComparatorFunction& birthComparator,
 
  698    const DeathComparatorFunction& deathComparator)
 
  699    : matrix_(numberOfColumns, colSettings, birthComparator, deathComparator),
 
  703  _initialize_map(numberOfColumns);
 
  706template <
class Underlying_matrix, 
class Master_matrix>
 
  709    : matrix_(matrixToCopy.matrix_, colSettings),
 
  711      nextIndex_(matrixToCopy.nextIndex_)
 
  713  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  714    idToIndex_ = 
new Dictionary(*matrixToCopy.idToIndex_);
 
  716    idToIndex_ = &matrix_.pivotToColumnIndex_;
 
  720template <
class Underlying_matrix, 
class Master_matrix>
 
  722    : matrix_(std::move(other.matrix_)),
 
  723      idToIndex_(std::exchange(other.idToIndex_, 
nullptr)),
 
  724      nextIndex_(std::exchange(other.nextIndex_, 0))
 
  727template <
class Underlying_matrix, 
class Master_matrix>
 
  730  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  731    if (idToIndex_ != 
nullptr) 
delete idToIndex_;
 
  735template <
class Underlying_matrix, 
class Master_matrix>
 
  736template <
class Boundary_range>
 
  740  matrix_.insert_boundary(boundary, dim);
 
  741  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  742    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  743      idToIndex_->emplace(nextIndex_, nextIndex_);
 
  745      if (idToIndex_->size() == nextIndex_) {
 
  746        idToIndex_->push_back(nextIndex_);
 
  748        _id_to_index(nextIndex_) = nextIndex_;
 
  755template <
class Underlying_matrix, 
class Master_matrix>
 
  756template <
class Boundary_range>
 
  758                                                                                  const Boundary_range& boundary,
 
  761  if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  762    GUDHI_CHECK(idToIndex_->find(cellIndex) == idToIndex_->end(),
 
  763                std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
 
  766        (idToIndex_->size() <= cellIndex || _id_to_index(cellIndex) == Master_matrix::template get_null_value<Index>()),
 
  767        std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
 
  769  matrix_.insert_boundary(cellIndex, boundary, dim);
 
  770  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  771    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  772      idToIndex_->emplace(cellIndex, nextIndex_);
 
  774      if (idToIndex_->size() <= cellIndex) {
 
  775        idToIndex_->resize(cellIndex + 1, Master_matrix::template get_null_value<Index>());
 
  777      _id_to_index(cellIndex) = nextIndex_;
 
  783template <
class Underlying_matrix, 
class Master_matrix>
 
  787  return matrix_.get_column(_id_to_index(cellID));
 
  790template <
class Underlying_matrix, 
class Master_matrix>
 
  794  return matrix_.get_row(rowIndex);
 
  797template <
class Underlying_matrix, 
class Master_matrix>
 
  800  return matrix_.erase_empty_row(rowIndex);
 
  803template <
class Underlying_matrix, 
class Master_matrix>
 
  806  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  807    std::vector<ID_index> indexToID(nextIndex_);
 
  808    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  809      for (
auto& p : *idToIndex_) {
 
  810        indexToID[p.second] = p.first;
 
  813      for (
ID_index i = 0; i < idToIndex_->size(); ++i) {
 
  814        if (_id_to_index(i) != Master_matrix::template get_null_value<Index>()) indexToID[_id_to_index(i)] = i;
 
  818    for (
Index curr = _id_to_index(cellID); curr < nextIndex_; ++curr) {
 
  819      matrix_.vine_swap(curr);
 
  820      std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1]));
 
  822    matrix_.remove_last();
 
  823    GUDHI_CHECK(_id_to_index(cellID) == nextIndex_,
 
  824                std::logic_error(
"Id_to_index_overlay::remove_maximal_cell - Indexation problem."));
 
  826    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  827      idToIndex_->erase(cellID);
 
  829      _id_to_index(cellID) = Master_matrix::template get_null_value<Index>();
 
  832    matrix_.remove_maximal_cell(cellID);
 
  836template <
class Underlying_matrix, 
class Master_matrix>
 
  838    ID_index cellID, 
const std::vector<ID_index>& columnsToSwap)
 
  840  static_assert(!Master_matrix::Option_list::is_of_boundary_type,
 
  841                "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
 
  842  std::vector<Index> translatedIndices;
 
  843  std::transform(columnsToSwap.cbegin(), columnsToSwap.cend(), std::back_inserter(translatedIndices),
 
  844                 [&](
ID_index id) { return _id_to_index(id); });
 
  845  matrix_.remove_maximal_cell(cellID, translatedIndices);
 
  848template <
class Underlying_matrix, 
class Master_matrix>
 
  851  if (idToIndex_->empty()) 
return;  
 
  853  matrix_.remove_last();
 
  855  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  857    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
  858      auto it = idToIndex_->begin();
 
  859      while (it->second != nextIndex_) ++it;   
 
  860      idToIndex_->erase(it);
 
  862      Index id = idToIndex_->size() - 1;
 
  864      while (_id_to_index(
id) == Master_matrix::template get_null_value<Index>()) --
id;
 
  865      GUDHI_CHECK(_id_to_index(
id) == nextIndex_,
 
  866                  std::logic_error(
"Id_to_index_overlay::remove_last - Indexation problem."));
 
  867      _id_to_index(
id) = Master_matrix::template get_null_value<Index>();
 
  872template <
class Underlying_matrix, 
class Master_matrix>
 
  876  return matrix_.get_max_dimension();
 
  879template <
class Underlying_matrix, 
class Master_matrix>
 
  883  return matrix_.get_number_of_columns();
 
  886template <
class Underlying_matrix, 
class Master_matrix>
 
  890  return matrix_.get_column_dimension(_id_to_index(cellID));
 
  893template <
class Underlying_matrix, 
class Master_matrix>
 
  896  return matrix_.add_to(_id_to_index(sourceCellID), _id_to_index(targetCellID));
 
  899template <
class Underlying_matrix, 
class Master_matrix>
 
  903  return matrix_.multiply_target_and_add_to(_id_to_index(sourceCellID), coefficient, _id_to_index(targetCellID));
 
  906template <
class Underlying_matrix, 
class Master_matrix>
 
  910  return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceCellID), _id_to_index(targetCellID));
 
  913template <
class Underlying_matrix, 
class Master_matrix>
 
  916  return matrix_.zero_entry(_id_to_index(cellID), rowIndex);
 
  919template <
class Underlying_matrix, 
class Master_matrix>
 
  922  return matrix_.zero_column(_id_to_index(cellID));
 
  925template <
class Underlying_matrix, 
class Master_matrix>
 
  929  return matrix_.is_zero_entry(_id_to_index(cellID), rowIndex);
 
  932template <
class Underlying_matrix, 
class Master_matrix>
 
  935  return matrix_.is_zero_column(_id_to_index(cellID));
 
  938template <
class Underlying_matrix, 
class Master_matrix>
 
  942  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  943    Index pos = matrix_.get_column_with_pivot(simplexIndex);
 
  945    while (_id_to_index(i) != pos) ++i;
 
  952template <
class Underlying_matrix, 
class Master_matrix>
 
  956  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
  957    return matrix_.get_pivot(_id_to_index(cellID));
 
  963template <
class Underlying_matrix, 
class Master_matrix>
 
  967  matrix_ = other.matrix_;
 
  968  if (Master_matrix::Option_list::is_of_boundary_type)
 
  969    idToIndex_ = other.idToIndex_;
 
  971    idToIndex_ = &matrix_.pivotToColumnIndex_;
 
  972  nextIndex_ = other.nextIndex_;
 
  977template <
class Underlying_matrix, 
class Master_matrix>
 
  980  return matrix_.print();
 
  983template <
class Underlying_matrix, 
class Master_matrix>
 
  987  return matrix_.get_current_barcode();
 
  990template <
class Underlying_matrix, 
class Master_matrix>
 
  993  matrix_.update_representative_cycles();
 
  996template <
class Underlying_matrix, 
class Master_matrix>
 
  997inline const std::vector<typename Id_to_index_overlay<Underlying_matrix, Master_matrix>::Cycle>&
 
 1000  return matrix_.get_representative_cycles();
 
 1003template <
class Underlying_matrix, 
class Master_matrix>
 
 1007  return matrix_.get_representative_cycle(bar);
 
 1010template <
class Underlying_matrix, 
class Master_matrix>
 
 1013  matrix_.swap_columns(_id_to_index(cellID1), _id_to_index(cellID2));
 
 1014  std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
 
 1017template <
class Underlying_matrix, 
class Master_matrix>
 
 1020  matrix_.swap_rows(rowIndex1, rowIndex2);
 
 1023template <
class Underlying_matrix, 
class Master_matrix>
 
 1027  Index first = _id_to_index(cellID1);
 
 1028  Index second = _id_to_index(cellID2);
 
 1029  if (first > second) std::swap(first, second);
 
 1031  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
 1032    GUDHI_CHECK(second - first == 1,
 
 1033                std::invalid_argument(
 
 1034                    "Id_to_index_overlay::vine_swap_with_z_eq_1_case - The columns to swap are not contiguous."));
 
 1036    bool change = matrix_.vine_swap_with_z_eq_1_case(first);
 
 1038    std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
 
 1045    return matrix_.vine_swap_with_z_eq_1_case(first, second);
 
 1049template <
class Underlying_matrix, 
class Master_matrix>
 
 1053  Index first = _id_to_index(cellID1);
 
 1054  Index second = _id_to_index(cellID2);
 
 1055  if (first > second) std::swap(first, second);
 
 1057  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
 1058    GUDHI_CHECK(second - first == 1,
 
 1059                std::invalid_argument(
"Id_to_index_overlay::vine_swap - The columns to swap are not contiguous."));
 
 1061    bool change = matrix_.vine_swap(first);
 
 1063    std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
 
 1070    return matrix_.vine_swap(first, second);
 
 1074template <
class Underlying_matrix, 
class Master_matrix>
 
 1077  if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
 
 1078    if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
 1079      idToIndex_ = 
new Dictionary(size);
 
 1081      idToIndex_ = 
new Dictionary(size, Master_matrix::template get_null_value<Index>());
 
 1084    idToIndex_ = &matrix_.pivotToColumnIndex_;
 
 1088template <
class Underlying_matrix, 
class Master_matrix>
 
 1090Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index 
id)
 const 
 1092  if constexpr (Master_matrix::Option_list::has_map_column_container) {
 
 1093    return idToIndex_->at(
id);
 
 1095    return idToIndex_->operator[](id);
 
 1099template <
class Underlying_matrix, 
class Master_matrix>
 
 1101Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index 
id)
 
 1103  return idToIndex_->operator[](id);  
 
Overlay for non-basic matrices replacing all input and output MatIdx indices of the original methods ...
Definition: Id_to_index_overlay.h:42
 
Id_to_index_overlay(Column_settings *colSettings)
Constructs an empty matrix.
Definition: Id_to_index_overlay.h:634
 
bool is_zero_column(ID_index cellID)
Indicates if the column at given index has value zero.
Definition: Id_to_index_overlay.h:933
 
void update_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Id_to_index_overlay.h:991
 
void remove_maximal_cell(ID_index cellID)
Only available for RU and chain matrices and if PersistenceMatrixOptions::has_removable_columns and P...
Definition: Id_to_index_overlay.h:804
 
friend void swap(Id_to_index_overlay &matrix1, Id_to_index_overlay &matrix2)
Swap operator.
Definition: Id_to_index_overlay.h:524
 
Id_to_index_overlay & operator=(const Id_to_index_overlay &other)
Assign operator.
Definition: Id_to_index_overlay.h:965
 
Dimension get_max_dimension() const
Returns the maximal dimension of a cell stored in the matrix. Only available if PersistenceMatrixOpti...
Definition: Id_to_index_overlay.h:874
 
void add_to(ID_index sourceCellID, ID_index targetCellID)
Adds column corresponding to sourceCellID onto the column corresponding to targetCellID.
Definition: Id_to_index_overlay.h:894
 
ID_index get_pivot(ID_index cellID)
Returns the row index of the pivot of the given column.
Definition: Id_to_index_overlay.h:954
 
typename Master_matrix::Row Row
Definition: Id_to_index_overlay.h:56
 
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Additionally,...
Definition: Id_to_index_overlay.h:849
 
void multiply_target_and_add_to(ID_index sourceCellID, const Field_element &coefficient, ID_index targetCellID)
Multiplies the target column with the coefficient and then adds the source column to it....
Definition: Id_to_index_overlay.h:900
 
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition: Id_to_index_overlay.h:510
 
void zero_column(ID_index cellID)
Zeroes the column at the given index. Not available for chain matrices. In general,...
Definition: Id_to_index_overlay.h:920
 
typename Master_matrix::Index Index
Definition: Id_to_index_overlay.h:44
 
void multiply_source_and_add_to(const Field_element &coefficient, ID_index sourceCellID, ID_index targetCellID)
Multiplies the source column with the coefficient before adding it to the target column....
Definition: Id_to_index_overlay.h:907
 
const Barcode & get_current_barcode()
Returns the current barcode of the matrix. Available only if PersistenceMatrixOptions::has_column_pai...
Definition: Id_to_index_overlay.h:985
 
typename Master_matrix::Column Column
Definition: Id_to_index_overlay.h:54
 
typename Master_matrix::Bar Bar
Definition: Id_to_index_overlay.h:57
 
ID_index get_column_with_pivot(ID_index cellIndex) const
Returns the IDIdx index of the column which has the given row index as pivot. Assumes that the pivot ...
Definition: Id_to_index_overlay.h:940
 
void insert_boundary(const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >())
Inserts at the end of the matrix a new ordered column corresponding to the given boundary....
Definition: Id_to_index_overlay.h:737
 
void erase_empty_row(ID_index rowIndex)
The effect varies depending on the matrices and the options:
Definition: Id_to_index_overlay.h:798
 
Column & get_column(ID_index cellID)
Returns the column at the given IDIdx index. For RU matrices, the returned column is from ....
Definition: Id_to_index_overlay.h:785
 
typename Master_matrix::Boundary Boundary
Definition: Id_to_index_overlay.h:53
 
Row & get_row(ID_index rowIndex)
Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row ...
Definition: Id_to_index_overlay.h:792
 
ID_index vine_swap_with_z_eq_1_case(ID_index cellID1, ID_index cellID2)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does the same than vine_swap,...
Definition: Id_to_index_overlay.h:1025
 
const Cycle & get_representative_cycle(const Bar &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Id_to_index_overlay.h:1005
 
typename Master_matrix::Cycle Cycle
Definition: Id_to_index_overlay.h:59
 
bool is_zero_entry(ID_index cellID, ID_index rowIndex) const
Indicates if the entry at given coordinates has value zero.
Definition: Id_to_index_overlay.h:926
 
typename Master_matrix::Barcode Barcode
Definition: Id_to_index_overlay.h:58
 
typename Master_matrix::Entry_constructor Entry_constructor
Definition: Id_to_index_overlay.h:60
 
typename Master_matrix::Dimension Dimension
Definition: Id_to_index_overlay.h:47
 
~Id_to_index_overlay()
Destructor.
Definition: Id_to_index_overlay.h:728
 
void swap_columns(ID_index cellID1, ID_index cellID2)
Only available for simple boundary matrices (only storing ) and if PersistenceMatrixOptions::has_colu...
Definition: Id_to_index_overlay.h:1011
 
typename Master_matrix::Field_operators Field_operators
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
Definition: Id_to_index_overlay.h:51
 
typename Master_matrix::Column_settings Column_settings
Definition: Id_to_index_overlay.h:62
 
void swap_rows(Index rowIndex1, Index rowIndex2)
Only available for simple boundary matrices (only storing R) and if PersistenceMatrixOptions::has_col...
Definition: Id_to_index_overlay.h:1018
 
ID_index vine_swap(ID_index cellID1, ID_index cellID2)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does a vine swap between two cel...
Definition: Id_to_index_overlay.h:1051
 
typename Master_matrix::Pos_index Pos_index
Definition: Id_to_index_overlay.h:46
 
void zero_entry(ID_index cellID, ID_index rowIndex)
Zeroes the entry at the given coordinates. Not available for chain matrices. In general,...
Definition: Id_to_index_overlay.h:914
 
Index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition: Id_to_index_overlay.h:881
 
const std::vector< Cycle > & get_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: Id_to_index_overlay.h:998
 
Dimension get_column_dimension(ID_index cellID) const
Returns the dimension of the given cell. Only available for non-basic matrices.
Definition: Id_to_index_overlay.h:888
 
typename Master_matrix::ID_index ID_index
Definition: Id_to_index_overlay.h:45
 
typename Master_matrix::Element Field_element
Definition: Id_to_index_overlay.h:52
 
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14