17#ifndef PM_ID_TO_POS_TRANSLATION_H
18#define PM_ID_TO_POS_TRANSLATION_H
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>
124 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
126 const BirthComparatorFunction& birthComparator,
127 const DeathComparatorFunction& deathComparator);
164 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_range>
167 const BirthComparatorFunction& birthComparator,
168 const DeathComparatorFunction& deathComparator);
192 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
195 const BirthComparatorFunction& birthComparator,
196 const DeathComparatorFunction& deathComparator);
245 template <
class Boundary_range = Boundary>
247 Dimension dim = Master_matrix::template get_null_value<Dimension>());
265 template <
class Boundary_range = Boundary>
267 const Boundary_range& boundary,
268 Dimension dim = Master_matrix::template get_null_value<Dimension>());
511 matrix_.reset(colSettings);
512 if constexpr (Master_matrix::Option_list::is_of_boundary_type)
513 if (idToIndex_ !=
nullptr) idToIndex_->clear();
531 swap(matrix1.matrix_, matrix2.matrix_);
532 std::swap(matrix1.idToIndex_, matrix2.idToIndex_);
533 std::swap(matrix1.nextIndex_, matrix2.nextIndex_);
573 void swap_rows(Index rowIndex1, Index rowIndex2);
639 using Dictionary =
typename Master_matrix::template Dictionary<Index>;
641 Underlying_matrix matrix_;
642 Dictionary* idToIndex_;
645 void _initialize_map(
unsigned int size);
646 Index _id_to_index(
ID_index id)
const;
650template <
class Underlying_matrix,
class Master_matrix>
652 : matrix_(colSettings), idToIndex_(nullptr), nextIndex_(0)
657template <
class Underlying_matrix,
class Master_matrix>
658template <
class Boundary_range>
660 const std::vector<Boundary_range>& orderedBoundaries,
662 : matrix_(orderedBoundaries, colSettings), idToIndex_(nullptr), nextIndex_(orderedBoundaries.size())
664 _initialize_map(orderedBoundaries.size());
665 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
666 for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
672template <
class Underlying_matrix,
class Master_matrix>
675 : matrix_(numberOfColumns, colSettings), idToIndex_(nullptr), nextIndex_(0)
677 _initialize_map(numberOfColumns);
680template <
class Underlying_matrix,
class Master_matrix>
681template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
684 const BirthComparatorFunction& birthComparator,
685 const DeathComparatorFunction& deathComparator)
686 : matrix_(colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
691template <
class Underlying_matrix,
class Master_matrix>
692template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_range>
694 const std::vector<Boundary_range>& orderedBoundaries,
696 const BirthComparatorFunction& birthComparator,
697 const DeathComparatorFunction& deathComparator)
698 : matrix_(orderedBoundaries, colSettings, birthComparator, deathComparator),
700 nextIndex_(orderedBoundaries.size())
702 _initialize_map(orderedBoundaries.size());
703 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
704 for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
710template <
class Underlying_matrix,
class Master_matrix>
711template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
713 unsigned int numberOfColumns,
715 const BirthComparatorFunction& birthComparator,
716 const DeathComparatorFunction& deathComparator)
717 : matrix_(numberOfColumns, colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
719 _initialize_map(numberOfColumns);
722template <
class Underlying_matrix,
class Master_matrix>
726 : matrix_(matrixToCopy.matrix_, colSettings), idToIndex_(nullptr), nextIndex_(matrixToCopy.nextIndex_)
728 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
729 idToIndex_ =
new Dictionary(*matrixToCopy.idToIndex_);
731 idToIndex_ = &matrix_.pivotToColumnIndex_;
735template <
class Underlying_matrix,
class Master_matrix>
737 : matrix_(std::move(other.matrix_)),
738 idToIndex_(std::exchange(other.idToIndex_,
nullptr)),
739 nextIndex_(std::exchange(other.nextIndex_, 0))
743template <
class Underlying_matrix,
class Master_matrix>
746 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
751template <
class Underlying_matrix,
class Master_matrix>
752template <
class Boundary_range>
756 matrix_.insert_boundary(boundary, dim);
757 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
758 if constexpr (Master_matrix::Option_list::has_map_column_container) {
759 idToIndex_->emplace(nextIndex_, nextIndex_);
761 if (idToIndex_->size() == nextIndex_) {
762 idToIndex_->push_back(nextIndex_);
764 _id_to_index(nextIndex_) = nextIndex_;
771template <
class Underlying_matrix,
class Master_matrix>
772template <
class Boundary_range>
774 const Boundary_range& boundary,
777 if constexpr (Master_matrix::Option_list::has_map_column_container) {
778 GUDHI_CHECK(idToIndex_->find(cellIndex) == idToIndex_->end(),
779 std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
782 (idToIndex_->size() <= cellIndex || _id_to_index(cellIndex) == Master_matrix::template get_null_value<Index>()),
783 std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
785 matrix_.insert_boundary(cellIndex, boundary, dim);
786 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
787 if constexpr (Master_matrix::Option_list::has_map_column_container) {
788 idToIndex_->emplace(cellIndex, nextIndex_);
790 if (idToIndex_->size() <= cellIndex) {
791 idToIndex_->resize(cellIndex + 1, Master_matrix::template get_null_value<Index>());
793 _id_to_index(cellIndex) = nextIndex_;
799template <
class Underlying_matrix,
class Master_matrix>
803 return matrix_.get_column(_id_to_index(cellID));
806template <
class Underlying_matrix,
class Master_matrix>
810 return matrix_.get_row(rowIndex);
813template <
class Underlying_matrix,
class Master_matrix>
816 return matrix_.erase_empty_row(rowIndex);
819template <
class Underlying_matrix,
class Master_matrix>
822 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
823 std::vector<ID_index> indexToID(nextIndex_);
824 if constexpr (Master_matrix::Option_list::has_map_column_container) {
825 for (
auto& p : *idToIndex_) {
826 indexToID[p.second] = p.first;
829 for (
ID_index i = 0; i < idToIndex_->size(); ++i) {
830 if (_id_to_index(i) != Master_matrix::template get_null_value<Index>()) indexToID[_id_to_index(i)] = i;
834 for (
Index curr = _id_to_index(cellID); curr < nextIndex_; ++curr) {
835 matrix_.vine_swap(curr);
836 std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1]));
838 matrix_.remove_last();
839 GUDHI_CHECK(_id_to_index(cellID) == nextIndex_,
840 std::logic_error(
"Id_to_index_overlay::remove_maximal_cell - Indexation problem."));
842 if constexpr (Master_matrix::Option_list::has_map_column_container) {
843 idToIndex_->erase(cellID);
845 _id_to_index(cellID) = Master_matrix::template get_null_value<Index>();
848 matrix_.remove_maximal_cell(cellID);
852template <
class Underlying_matrix,
class Master_matrix>
855 const std::vector<ID_index>& columnsToSwap)
857 static_assert(!Master_matrix::Option_list::is_of_boundary_type,
858 "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
859 std::vector<Index> translatedIndices;
860 std::transform(columnsToSwap.cbegin(), columnsToSwap.cend(), std::back_inserter(translatedIndices), [&](
ID_index id) {
861 return _id_to_index(id);
863 matrix_.remove_maximal_cell(cellID, translatedIndices);
866template <
class Underlying_matrix,
class Master_matrix>
869 if (idToIndex_->empty())
return;
871 matrix_.remove_last();
873 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
875 if constexpr (Master_matrix::Option_list::has_map_column_container) {
876 auto it = idToIndex_->begin();
877 while (it->second != nextIndex_) ++it;
878 idToIndex_->erase(it);
880 Index id = idToIndex_->size() - 1;
882 while (_id_to_index(
id) == Master_matrix::template get_null_value<Index>()) --id;
883 GUDHI_CHECK(_id_to_index(
id) == nextIndex_,
884 std::logic_error(
"Id_to_index_overlay::remove_last - Indexation problem."));
885 _id_to_index(
id) = Master_matrix::template get_null_value<Index>();
890template <
class Underlying_matrix,
class Master_matrix>
894 return matrix_.get_max_dimension();
897template <
class Underlying_matrix,
class Master_matrix>
901 return matrix_.get_number_of_columns();
904template <
class Underlying_matrix,
class Master_matrix>
908 return matrix_.get_column_dimension(_id_to_index(cellID));
911template <
class Underlying_matrix,
class Master_matrix>
914 return matrix_.add_to(_id_to_index(sourceCellID), _id_to_index(targetCellID));
917template <
class Underlying_matrix,
class Master_matrix>
923 return matrix_.multiply_target_and_add_to(_id_to_index(sourceCellID), coefficient, _id_to_index(targetCellID));
926template <
class Underlying_matrix,
class Master_matrix>
932 return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceCellID), _id_to_index(targetCellID));
935template <
class Underlying_matrix,
class Master_matrix>
938 return matrix_.zero_entry(_id_to_index(cellID), rowIndex);
941template <
class Underlying_matrix,
class Master_matrix>
944 return matrix_.zero_column(_id_to_index(cellID));
947template <
class Underlying_matrix,
class Master_matrix>
951 return matrix_.is_zero_entry(_id_to_index(cellID), rowIndex);
954template <
class Underlying_matrix,
class Master_matrix>
957 return matrix_.is_zero_column(_id_to_index(cellID));
960template <
class Underlying_matrix,
class Master_matrix>
964 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
965 Index pos = matrix_.get_column_with_pivot(cellIndex);
967 while (_id_to_index(i) != pos) ++i;
974template <
class Underlying_matrix,
class Master_matrix>
978 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
979 return matrix_.get_pivot(_id_to_index(cellID));
985template <
class Underlying_matrix,
class Master_matrix>
989 if (
this == &other)
return *
this;
991 matrix_ = other.matrix_;
992 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
994 idToIndex_ = other.idToIndex_;
996 idToIndex_ = &matrix_.pivotToColumnIndex_;
998 nextIndex_ = other.nextIndex_;
1003template <
class Underlying_matrix,
class Master_matrix>
1007 if (
this == &other)
return *
this;
1009 matrix_ = std::move(other.matrix_);
1010 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1013 idToIndex_ = std::exchange(other.idToIndex_,
nullptr);
1014 nextIndex_ = std::exchange(other.nextIndex_, 0);
1019template <
class Underlying_matrix,
class Master_matrix>
1020inline void Id_to_index_overlay<Underlying_matrix, Master_matrix>::print()
1022 return matrix_.print();
1025template <
class Underlying_matrix,
class Master_matrix>
1029 return matrix_.get_current_barcode();
1032template <
class Underlying_matrix,
class Master_matrix>
1035 matrix_.update_all_representative_cycles(dim);
1038template <
class Underlying_matrix,
class Master_matrix>
1041 matrix_.update_representative_cycle(bar);
1044template <
class Underlying_matrix,
class Master_matrix>
1045inline const std::vector<typename Id_to_index_overlay<Underlying_matrix, Master_matrix>::Cycle>&
1048 return matrix_.get_all_representative_cycles();
1051template <
class Underlying_matrix,
class Master_matrix>
1055 return matrix_.get_representative_cycle(bar);
1058template <
class Underlying_matrix,
class Master_matrix>
1061 matrix_.swap_columns(_id_to_index(cellID1), _id_to_index(cellID2));
1062 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1065template <
class Underlying_matrix,
class Master_matrix>
1068 matrix_.swap_rows(rowIndex1, rowIndex2);
1071template <
class Underlying_matrix,
class Master_matrix>
1075 Index first = _id_to_index(cellID1);
1076 Index second = _id_to_index(cellID2);
1077 if (first > second) std::swap(first, second);
1079 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1080 GUDHI_CHECK(second - first == 1,
1081 std::invalid_argument(
1082 "Id_to_index_overlay::vine_swap_with_z_eq_1_case - The columns to swap are not contiguous."));
1084 bool change = matrix_.vine_swap_with_z_eq_1_case(first);
1086 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1093 return matrix_.vine_swap_with_z_eq_1_case(first, second);
1097template <
class Underlying_matrix,
class Master_matrix>
1101 Index first = _id_to_index(cellID1);
1102 Index second = _id_to_index(cellID2);
1103 if (first > second) std::swap(first, second);
1105 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1106 GUDHI_CHECK(second - first == 1,
1107 std::invalid_argument(
"Id_to_index_overlay::vine_swap - The columns to swap are not contiguous."));
1109 bool change = matrix_.vine_swap(first);
1111 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1118 return matrix_.vine_swap(first, second);
1122template <
class Underlying_matrix,
class Master_matrix>
1123inline void Id_to_index_overlay<Underlying_matrix, Master_matrix>::_initialize_map([[maybe_unused]]
unsigned int size)
1125 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1126 if constexpr (Master_matrix::Option_list::has_map_column_container) {
1127 idToIndex_ =
new Dictionary(size);
1129 idToIndex_ =
new Dictionary(size, Master_matrix::template get_null_value<Index>());
1132 idToIndex_ = &matrix_.pivotToColumnIndex_;
1136template <
class Underlying_matrix,
class Master_matrix>
1138Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index
id)
const
1140 if constexpr (Master_matrix::Option_list::has_map_column_container) {
1141 return idToIndex_->at(
id);
1143 return idToIndex_->operator[](id);
1147template <
class Underlying_matrix,
class Master_matrix>
1149Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index
id)
1151 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:651
void update_all_representative_cycles(Dimension dim=Master_matrix::template get_null_value< Dimension >())
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition Id_to_index_overlay.h:1033
bool is_zero_column(ID_index cellID)
Indicates if the column at given index has value zero.
Definition Id_to_index_overlay.h:955
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:820
Id_to_index_overlay & operator=(const Id_to_index_overlay &other)
Assign operator.
Definition Id_to_index_overlay.h:987
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:892
const Cycle & get_representative_cycle(const Bar &bar) const
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition Id_to_index_overlay.h:1053
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:912
ID_index get_pivot(ID_index cellID)
Returns the row index of the pivot of the given column.
Definition Id_to_index_overlay.h:976
typename Master_matrix::Row Row
Definition Id_to_index_overlay.h:55
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Additionally,...
Definition Id_to_index_overlay.h:867
void update_representative_cycle(const Bar &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition Id_to_index_overlay.h:1039
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:918
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition Id_to_index_overlay.h:509
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:942
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:927
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:1027
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:962
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:753
void erase_empty_row(ID_index rowIndex)
The effect varies depending on the matrices and the options:
Definition Id_to_index_overlay.h:814
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:801
typename Master_matrix::Boundary Boundary
Definition Id_to_index_overlay.h:53
friend void swap(Id_to_index_overlay &matrix1, Id_to_index_overlay &matrix2) noexcept
Swap operator.
Definition Id_to_index_overlay.h:529
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:808
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:1073
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:948
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:744
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:1059
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:61
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:1066
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:1099
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:936
Index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition Id_to_index_overlay.h:899
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:906
const std::vector< Cycle > & get_all_representative_cycles() const
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition Id_to_index_overlay.h:1046
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
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14