17 #ifndef PM_ID_TO_POS_TRANSLATION_H
18 #define PM_ID_TO_POS_TRANSLATION_H
28 namespace persistence_matrix {
40 template <
class Matrix_type,
class Master_matrix_type>
44 using index =
typename Master_matrix_type::index;
45 using id_index =
typename Master_matrix_type::id_index;
54 using Row_type =
typename Master_matrix_type::Row_type;
56 using bar_type =
typename Master_matrix_type::Bar;
58 using cycle_type =
typename Master_matrix_type::cycle_type;
90 template <
class Boundary_type = boundary_type>
123 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
125 const BirthComparatorFunction& birthComparator,
126 const DeathComparatorFunction& deathComparator);
163 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_type>
166 const BirthComparatorFunction& birthComparator,
167 const DeathComparatorFunction& deathComparator);
191 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
194 const BirthComparatorFunction& birthComparator,
195 const DeathComparatorFunction& deathComparator);
244 template <
class Boundary_type = boundary_type>
262 template <
class Boundary_type = boundary_type>
503 matrix_.reset(colSettings);
517 swap(matrix1.matrix_, matrix2.matrix_);
518 if (Master_matrix_type::Option_list::is_of_boundary_type) std::swap(matrix1.idToIndex_, matrix2.idToIndex_);
519 std::swap(matrix1.nextIndex_, matrix2.nextIndex_);
614 using dictionnary_type =
typename Master_matrix_type::template dictionnary_type<index>;
617 dictionnary_type* idToIndex_;
620 void _initialize_map(
unsigned int size);
624 template <
class Matrix_type,
class Master_matrix_type>
626 : matrix_(colSettings), idToIndex_(nullptr), nextIndex_(0)
631 template <
class Matrix_type,
class Master_matrix_type>
632 template <
class Boundary_type>
634 const std::vector<Boundary_type>& orderedBoundaries,
Column_settings* colSettings)
635 : matrix_(orderedBoundaries, colSettings), idToIndex_(nullptr), nextIndex_(orderedBoundaries.size())
637 _initialize_map(orderedBoundaries.size());
638 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
639 for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
640 idToIndex_->operator[](i) = i;
645 template <
class Matrix_type,
class Master_matrix_type>
648 : matrix_(numberOfColumns, colSettings), idToIndex_(nullptr), nextIndex_(0)
650 _initialize_map(numberOfColumns);
653 template <
class Matrix_type,
class Master_matrix_type>
654 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
657 const BirthComparatorFunction& birthComparator,
658 const DeathComparatorFunction& deathComparator)
659 : matrix_(colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
664 template <
class Matrix_type,
class Master_matrix_type>
665 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_type>
667 const std::vector<Boundary_type>& orderedBoundaries,
669 const BirthComparatorFunction& birthComparator,
670 const DeathComparatorFunction& deathComparator)
671 : matrix_(orderedBoundaries, colSettings, birthComparator, deathComparator),
673 nextIndex_(orderedBoundaries.size())
675 _initialize_map(orderedBoundaries.size());
676 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
677 for (
unsigned int i = 0; i < orderedBoundaries.size(); i++) {
678 idToIndex_->operator[](i) = i;
683 template <
class Matrix_type,
class Master_matrix_type>
684 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
686 unsigned int numberOfColumns,
688 const BirthComparatorFunction& birthComparator,
689 const DeathComparatorFunction& deathComparator)
690 : matrix_(numberOfColumns, colSettings, birthComparator, deathComparator),
694 _initialize_map(numberOfColumns);
697 template <
class Matrix_type,
class Master_matrix_type>
700 : matrix_(matrixToCopy.matrix_, colSettings),
702 nextIndex_(matrixToCopy.nextIndex_)
704 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
705 idToIndex_ =
new dictionnary_type(*matrixToCopy.idToIndex_);
707 idToIndex_ = &matrix_.pivotToColumnIndex_;
711 template <
class Matrix_type,
class Master_matrix_type>
713 : matrix_(std::move(other.matrix_)),
714 idToIndex_(std::exchange(other.idToIndex_,
nullptr)),
715 nextIndex_(std::exchange(other.nextIndex_, 0))
718 template <
class Matrix_type,
class Master_matrix_type>
721 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
722 if (idToIndex_ !=
nullptr)
delete idToIndex_;
726 template <
class Matrix_type,
class Master_matrix_type>
727 template <
class Boundary_type>
731 matrix_.insert_boundary(boundary, dim);
732 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
733 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
734 idToIndex_->emplace(nextIndex_, nextIndex_);
736 if (idToIndex_->size() == nextIndex_) {
737 idToIndex_->push_back(nextIndex_);
739 idToIndex_->operator[](nextIndex_) = nextIndex_;
746 template <
class Matrix_type,
class Master_matrix_type>
747 template <
class Boundary_type>
749 const Boundary_type& boundary,
752 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
753 GUDHI_CHECK(idToIndex_->find(faceIndex) == idToIndex_->end(),
754 std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
756 GUDHI_CHECK((idToIndex_->size() <= faceIndex || idToIndex_[faceIndex] ==
static_cast<index>(-1)),
757 std::invalid_argument(
"Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
759 matrix_.insert_boundary(faceIndex, boundary, dim);
760 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
761 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
762 idToIndex_->emplace(faceIndex, nextIndex_);
764 if (idToIndex_->size() <= faceIndex) {
765 idToIndex_->resize(faceIndex + 1, -1);
767 idToIndex_->operator[](faceIndex) = nextIndex_;
773 template <
class Matrix_type,
class Master_matrix_type>
777 return matrix_.get_column(_id_to_index(faceID));
780 template <
class Matrix_type,
class Master_matrix_type>
784 return matrix_.get_row(rowIndex);
787 template <
class Matrix_type,
class Master_matrix_type>
790 return matrix_.erase_empty_row(rowIndex);
793 template <
class Matrix_type,
class Master_matrix_type>
796 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
797 std::vector<id_index> indexToID(nextIndex_);
798 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
799 for (
auto& p : *idToIndex_) {
800 indexToID[p.second] = p.first;
803 for (
id_index i = 0; i < idToIndex_->size(); ++i) {
804 if (idToIndex_->operator[](i) !=
static_cast<index>(-1)) indexToID[idToIndex_->operator[](i)] = i;
808 for (
index curr = _id_to_index(faceID); curr < nextIndex_; ++curr) {
809 matrix_.vine_swap(curr);
810 std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1]));
812 matrix_.remove_last();
813 GUDHI_CHECK(_id_to_index(faceID) == nextIndex_,
814 std::logic_error(
"Id_to_index_overlay::remove_maximal_face - Indexation problem."));
816 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
817 idToIndex_->erase(faceID);
819 idToIndex_->operator[](faceID) = -1;
822 matrix_.remove_maximal_face(faceID);
826 template <
class Matrix_type,
class Master_matrix_type>
828 id_index faceID,
const std::vector<id_index>& columnsToSwap)
830 static_assert(!Master_matrix_type::Option_list::is_of_boundary_type,
831 "'remove_maximal_face(id_index,const std::vector<index>&)' is not available for the chosen options.");
832 std::vector<index> translatedIndices;
833 std::transform(columnsToSwap.cbegin(), columnsToSwap.cend(), std::back_inserter(translatedIndices),
834 [&](
id_index id) { return _id_to_index(id); });
835 matrix_.remove_maximal_face(faceID, translatedIndices);
838 template <
class Matrix_type,
class Master_matrix_type>
841 if (idToIndex_->empty())
return;
843 matrix_.remove_last();
845 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
847 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
848 auto it = idToIndex_->begin();
849 while (it->second != nextIndex_) ++it;
850 idToIndex_->erase(it);
852 index id = idToIndex_->size() - 1;
853 while (idToIndex_->operator[](
id) ==
static_cast<index>(-1)) --id;
854 GUDHI_CHECK(idToIndex_->operator[](
id) == nextIndex_,
855 std::logic_error(
"Id_to_index_overlay::remove_last - Indexation problem."));
856 idToIndex_->operator[](id) = -1;
861 template <
class Matrix_type,
class Master_matrix_type>
865 return matrix_.get_max_dimension();
868 template <
class Matrix_type,
class Master_matrix_type>
872 return matrix_.get_number_of_columns();
875 template <
class Matrix_type,
class Master_matrix_type>
879 return matrix_.get_column_dimension(_id_to_index(faceID));
882 template <
class Matrix_type,
class Master_matrix_type>
885 return matrix_.add_to(_id_to_index(sourceFaceID), _id_to_index(targetFaceID));
888 template <
class Matrix_type,
class Master_matrix_type>
892 return matrix_.multiply_target_and_add_to(_id_to_index(sourceFaceID), coefficient, _id_to_index(targetFaceID));
895 template <
class Matrix_type,
class Master_matrix_type>
899 return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceFaceID), _id_to_index(targetFaceID));
902 template <
class Matrix_type,
class Master_matrix_type>
905 return matrix_.zero_cell(_id_to_index(faceID), rowIndex);
908 template <
class Matrix_type,
class Master_matrix_type>
911 return matrix_.zero_column(_id_to_index(faceID));
914 template <
class Matrix_type,
class Master_matrix_type>
918 return matrix_.is_zero_cell(_id_to_index(faceID), rowIndex);
921 template <
class Matrix_type,
class Master_matrix_type>
924 return matrix_.is_zero_column(_id_to_index(faceID));
927 template <
class Matrix_type,
class Master_matrix_type>
931 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
932 index pos = matrix_.get_column_with_pivot(simplexIndex);
934 while (_id_to_index(i) != pos) ++i;
941 template <
class Matrix_type,
class Master_matrix_type>
945 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
946 return matrix_.get_pivot(_id_to_index(faceID));
952 template <
class Matrix_type,
class Master_matrix_type>
956 matrix_ = other.matrix_;
957 if (Master_matrix_type::Option_list::is_of_boundary_type)
958 idToIndex_ = other.idToIndex_;
960 idToIndex_ = &matrix_.pivotToColumnIndex_;
961 nextIndex_ = other.nextIndex_;
966 template <
class Matrix_type,
class Master_matrix_type>
969 return matrix_.print();
972 template <
class Matrix_type,
class Master_matrix_type>
976 return matrix_.get_current_barcode();
979 template <
class Matrix_type,
class Master_matrix_type>
982 matrix_.update_representative_cycles();
985 template <
class Matrix_type,
class Master_matrix_type>
986 inline const std::vector<typename Id_to_index_overlay<Matrix_type, Master_matrix_type>::cycle_type>&
989 return matrix_.get_representative_cycles();
992 template <
class Matrix_type,
class Master_matrix_type>
996 return matrix_.get_representative_cycle(bar);
999 template <
class Matrix_type,
class Master_matrix_type>
1002 matrix_.swap_columns(_id_to_index(faceID1), _id_to_index(faceID2));
1003 std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2));
1006 template <
class Matrix_type,
class Master_matrix_type>
1009 matrix_.swap_rows(rowIndex1, rowIndex2);
1012 template <
class Matrix_type,
class Master_matrix_type>
1016 index first = _id_to_index(faceID1);
1017 index second = _id_to_index(faceID2);
1018 if (first > second) std::swap(first, second);
1020 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
1021 GUDHI_CHECK(second - first == 1,
1022 std::invalid_argument(
1023 "Id_to_index_overlay::vine_swap_with_z_eq_1_case - The columns to swap are not contiguous."));
1025 bool change = matrix_.vine_swap_with_z_eq_1_case(first);
1027 std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2));
1034 return matrix_.vine_swap_with_z_eq_1_case(first, second);
1038 template <
class Matrix_type,
class Master_matrix_type>
1042 index first = _id_to_index(faceID1);
1043 index second = _id_to_index(faceID2);
1044 if (first > second) std::swap(first, second);
1046 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
1047 GUDHI_CHECK(second - first == 1,
1048 std::invalid_argument(
"Id_to_index_overlay::vine_swap - The columns to swap are not contiguous."));
1050 bool change = matrix_.vine_swap(first);
1052 std::swap(idToIndex_->at(faceID1), idToIndex_->at(faceID2));
1059 return matrix_.vine_swap(first, second);
1063 template <
class Matrix_type,
class Master_matrix_type>
1066 if constexpr (Master_matrix_type::Option_list::is_of_boundary_type) {
1067 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
1068 idToIndex_ =
new dictionnary_type(size);
1070 idToIndex_ =
new dictionnary_type(size, -1);
1073 idToIndex_ = &matrix_.pivotToColumnIndex_;
1077 template <
class Matrix_type,
class Master_matrix_type>
1079 Id_to_index_overlay<Matrix_type, Master_matrix_type>::_id_to_index(id_index
id)
const
1081 if constexpr (Master_matrix_type::Option_list::has_map_column_container) {
1082 return idToIndex_->at(
id);
1084 return idToIndex_->operator[](id);
Overlay for non-basic matrices replacing all input and output MatIdx indices of the original methods ...
Definition: overlay_ididx_to_matidx.h:42
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition: overlay_ididx_to_matidx.h:502
Row_type & get_row(id_index rowIndex)
Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row ...
Definition: overlay_ididx_to_matidx.h:782
const barcode_type & get_current_barcode()
Returns the current barcode of the matrix. Available only if PersistenceMatrixOptions::has_column_pai...
Definition: overlay_ididx_to_matidx.h:974
void zero_cell(id_index faceID, id_index rowIndex)
Zeroes the cell at the given coordinates. Not available for chain matrices. In general,...
Definition: overlay_ididx_to_matidx.h:903
typename Master_matrix_type::index index
Definition: overlay_ididx_to_matidx.h:44
Id_to_index_overlay(Column_settings *colSettings)
Constructs an empty matrix.
Definition: overlay_ididx_to_matidx.h:625
id_index get_pivot(id_index faceID)
Returns the row index of the pivot of the given column.
Definition: overlay_ididx_to_matidx.h:943
typename Master_matrix_type::Bar bar_type
Definition: overlay_ididx_to_matidx.h:56
typename Master_matrix_type::Field_operators Field_operators
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
Definition: overlay_ididx_to_matidx.h:50
bool is_zero_column(id_index faceID)
Indicates if the column at given index has value zero.
Definition: overlay_ididx_to_matidx.h:922
friend void swap(Id_to_index_overlay &matrix1, Id_to_index_overlay &matrix2)
Swap operator.
Definition: overlay_ididx_to_matidx.h:516
typename Master_matrix_type::Row_type Row_type
Definition: overlay_ididx_to_matidx.h:55
bool is_zero_cell(id_index faceID, id_index rowIndex) const
Indicates if the cell at given coordinates has value zero.
Definition: overlay_ididx_to_matidx.h:915
typename Master_matrix_type::cycle_type cycle_type
Definition: overlay_ididx_to_matidx.h:58
void multiply_source_and_add_to(const Field_element_type &coefficient, id_index sourceFaceID, id_index targetFaceID)
Multiplies the source column with the coefficiant before adding it to the target column....
Definition: overlay_ididx_to_matidx.h:896
void update_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_ididx_to_matidx.h:980
id_index get_column_with_pivot(id_index faceIndex) const
Returns the IDIdx index of the column which has the given row index as pivot. Assumes that the pivot ...
Definition: overlay_ididx_to_matidx.h:929
Column_type & get_column(id_index faceID)
Returns the column at the given IDIdx index. For RU matrices, the returned column is from ....
Definition: overlay_ididx_to_matidx.h:775
index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition: overlay_ididx_to_matidx.h:870
dimension_type get_max_dimension() const
Returns the maximal dimension of a face stored in the matrix. Only available if PersistenceMatrixOpti...
Definition: overlay_ididx_to_matidx.h:863
void remove_maximal_face(id_index faceID)
Only available for RU and chain matrices and if PersistenceMatrixOptions::has_removable_columns and P...
Definition: overlay_ididx_to_matidx.h:794
typename Master_matrix_type::boundary_type boundary_type
Definition: overlay_ididx_to_matidx.h:52
const std::vector< cycle_type > & get_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_ididx_to_matidx.h:987
typename Master_matrix_type::element_type Field_element_type
Definition: overlay_ididx_to_matidx.h:51
typename Master_matrix_type::Column_type Column_type
Definition: overlay_ididx_to_matidx.h:53
void zero_column(id_index faceID)
Zeroes the column at the given index. Not available for chain matrices. In general,...
Definition: overlay_ididx_to_matidx.h:909
typename Master_matrix_type::id_index id_index
Definition: overlay_ididx_to_matidx.h:45
const cycle_type & get_representative_cycle(const bar_type &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_ididx_to_matidx.h:994
void add_to(id_index sourceFaceID, id_index targetFaceID)
Adds column corresponding to sourceFaceID onto the column corresponding to targetFaceID.
Definition: overlay_ididx_to_matidx.h:883
void swap_columns(id_index faceID1, id_index faceID2)
Only available for simple boundary matrices (only storing ) and if PersistenceMatrixOptions::has_colu...
Definition: overlay_ididx_to_matidx.h:1000
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Additionnaly,...
Definition: overlay_ididx_to_matidx.h:839
void erase_empty_row(id_index rowIndex)
The effect varies depending on the matrices and the options:
Definition: overlay_ididx_to_matidx.h:788
typename Master_matrix_type::barcode_type barcode_type
Definition: overlay_ididx_to_matidx.h:57
void swap_rows(index rowIndex1, index rowIndex2)
Only available for simple boundary matrices (only storing R) and if PersistenceMatrixOptions::has_col...
Definition: overlay_ididx_to_matidx.h:1007
void insert_boundary(const Boundary_type &boundary, dimension_type dim=-1)
Inserts at the end of the matrix a new ordered column corresponding to the given boundary....
Definition: overlay_ididx_to_matidx.h:728
Id_to_index_overlay & operator=(const Id_to_index_overlay &other)
Assign operator.
Definition: overlay_ididx_to_matidx.h:954
id_index vine_swap_with_z_eq_1_case(id_index faceID1, id_index faceID2)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does the same than vine_swap,...
Definition: overlay_ididx_to_matidx.h:1014
typename Master_matrix_type::Cell_constructor Cell_constructor
Definition: overlay_ididx_to_matidx.h:59
typename Master_matrix_type::Column_settings Column_settings
Definition: overlay_ididx_to_matidx.h:61
dimension_type get_column_dimension(id_index faceID) const
Returns the dimension of the given face. Only available for non-basic matrices.
Definition: overlay_ididx_to_matidx.h:877
typename Master_matrix_type::dimension_type dimension_type
Definition: overlay_ididx_to_matidx.h:46
~Id_to_index_overlay()
Destructor.
Definition: overlay_ididx_to_matidx.h:719
id_index vine_swap(id_index faceID1, id_index faceID2)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does a vine swap between two fac...
Definition: overlay_ididx_to_matidx.h:1040
void multiply_target_and_add_to(id_index sourceFaceID, const Field_element_type &coefficient, id_index targetFaceID)
Multiplies the target column with the coefficiant and then adds the source column to it....
Definition: overlay_ididx_to_matidx.h:889
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14