Loading...
Searching...
No Matches
Id_to_index_overlay.h
Go to the documentation of this file.
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Hannah Schreiber
4 *
5 * Copyright (C) 2022 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
16
17#ifndef PM_ID_TO_POS_TRANSLATION_H
18#define PM_ID_TO_POS_TRANSLATION_H
19
20#include <vector>
21#include <cassert>
22#include <utility> //std::swap, std::move & std::exchange
23#include <algorithm> //std::transform
24#include <stdexcept> //std::invalid_argument
25
26namespace Gudhi {
27namespace persistence_matrix {
28
39template <class Underlying_matrix, class Master_matrix>
41{
42 public:
43 using Index = typename Master_matrix::Index;
44 using ID_index = typename Master_matrix::ID_index;
45 using Pos_index = typename Master_matrix::Pos_index;
46 using Dimension = typename Master_matrix::Dimension;
50 using Field_operators = typename Master_matrix::Field_operators;
51 using Field_element = typename Master_matrix::Element;
52 using Boundary = typename Master_matrix::Boundary;
53 using Column = typename Master_matrix::Column;
54 using Row = typename Master_matrix::Row;
56 using Bar = typename Master_matrix::Bar;
57 using Barcode = typename Master_matrix::Barcode;
58 using Cycle = typename Master_matrix::Cycle;
59 using Entry_constructor = typename Master_matrix::Entry_constructor;
60 using Column_settings = typename Master_matrix::Column_settings;
62
91 template <class Boundary_range = Boundary>
92 Id_to_index_overlay(const std::vector<Boundary_range>& orderedBoundaries, Column_settings* colSettings);
100 Id_to_index_overlay(unsigned int numberOfColumns, Column_settings* colSettings);
123 template <typename BirthComparatorFunction, typename DeathComparatorFunction>
125 const BirthComparatorFunction& birthComparator,
126 const DeathComparatorFunction& deathComparator);
163 template <typename BirthComparatorFunction, typename DeathComparatorFunction, class Boundary_range>
164 Id_to_index_overlay(const std::vector<Boundary_range>& orderedBoundaries,
165 Column_settings* colSettings,
166 const BirthComparatorFunction& birthComparator,
167 const DeathComparatorFunction& deathComparator);
191 template <typename BirthComparatorFunction, typename DeathComparatorFunction>
192 Id_to_index_overlay(unsigned int numberOfColumns,
193 Column_settings* colSettings,
194 const BirthComparatorFunction& birthComparator,
195 const DeathComparatorFunction& deathComparator);
205 Id_to_index_overlay(const Id_to_index_overlay& matrixToCopy, Column_settings* colSettings = nullptr);
216
244 template <class Boundary_range = Boundary>
245 void insert_boundary(const Boundary_range& boundary,
246 Dimension dim = Master_matrix::template get_null_value<Dimension>());
264 template <class Boundary_range = Boundary>
265 void insert_boundary(ID_index cellIndex,
266 const Boundary_range& boundary,
267 Dimension dim = Master_matrix::template get_null_value<Dimension>());
282 template <class Boundary_range = Boundary>
283 void insert_maximal_cell(Index columnIndex,
284 const Boundary_range& boundary,
285 Dimension dim = Master_matrix::template get_null_value<Dimension>());
303 template <class Boundary_range = Boundary>
304 void insert_maximal_cell(Index columnIndex,
305 ID_index cellIndex,
306 const Boundary_range& boundary,
307 Dimension dim = Master_matrix::template get_null_value<Dimension>());
316 Column& get_column(ID_index cellID);
331 Row& get_row(ID_index rowIndex);
356 void erase_empty_row(ID_index rowIndex);
377 void remove_maximal_cell(ID_index cellID);
401 void remove_maximal_cell(ID_index cellID, const std::vector<ID_index>& columnsToSwap);
416 void remove_last();
417
438
449 void add_to(ID_index sourceCellID, ID_index targetCellID);
462 void multiply_target_and_add_to(ID_index sourceCellID, const Field_element& coefficient, ID_index targetCellID);
475 void multiply_source_and_add_to(const Field_element& coefficient, ID_index sourceCellID, ID_index targetCellID);
476
487 void zero_entry(ID_index cellID, ID_index rowIndex);
497 void zero_column(ID_index cellID);
508 bool is_zero_entry(ID_index cellID, ID_index rowIndex) const;
521 bool is_zero_column(ID_index cellID);
522
534 ID_index get_column_with_pivot(ID_index cellIndex) const;
542
549 void reset(Column_settings* colSettings)
550 {
551 matrix_.reset(colSettings);
552 if constexpr (Master_matrix::Option_list::is_of_boundary_type)
553 if (idToIndex_ != nullptr) idToIndex_->clear();
554 nextIndex_ = 0;
555 }
556
565
569 friend void swap(Id_to_index_overlay& matrix1, Id_to_index_overlay& matrix2) noexcept
570 {
571 swap(matrix1.matrix_, matrix2.matrix_);
572 std::swap(matrix1.idToIndex_, matrix2.idToIndex_);
573 std::swap(matrix1.nextIndex_, matrix2.nextIndex_);
574 }
575
576 void print(); // for debug
577
578 // access to optional methods
579
593
603 void swap_columns(ID_index cellID1, ID_index cellID2);
613 void swap_rows(Index rowIndex1, Index rowIndex2);
641 ID_index vine_swap(ID_index cellID1, ID_index cellID2);
642
652 void update_all_representative_cycles(Dimension dim = Master_matrix::template get_null_value<Dimension>());
661 void update_representative_cycle(const Bar& bar);
668 const std::vector<Cycle>& get_all_representative_cycles() const;
676 const Cycle& get_representative_cycle(const Bar& bar) const;
677
678 private:
679 using Dictionary = typename Master_matrix::template Dictionary<Index>;
680
681 Underlying_matrix matrix_;
682 Dictionary* idToIndex_;
683 Index nextIndex_;
684
685 void _initialize_map(unsigned int size);
686 Index _id_to_index(ID_index id) const;
687 Index& _id_to_index(ID_index id);
688
689 template <bool dir>
690 void _move_column_in_RU(Pos_index start, Pos_index end);
691};
692
693template <class Underlying_matrix, class Master_matrix>
695 : matrix_(colSettings), idToIndex_(nullptr), nextIndex_(0)
696{
697 _initialize_map(0);
698}
699
700template <class Underlying_matrix, class Master_matrix>
701template <class Boundary_range>
703 const std::vector<Boundary_range>& orderedBoundaries,
704 Column_settings* colSettings)
705 : matrix_(orderedBoundaries, colSettings), idToIndex_(nullptr), nextIndex_(orderedBoundaries.size())
706{
707 _initialize_map(orderedBoundaries.size());
708 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
709 for (unsigned int i = 0; i < orderedBoundaries.size(); i++) {
710 _id_to_index(i) = i;
711 }
712 }
713}
714
715template <class Underlying_matrix, class Master_matrix>
717 Column_settings* colSettings)
718 : matrix_(numberOfColumns, colSettings), idToIndex_(nullptr), nextIndex_(0)
719{
720 _initialize_map(numberOfColumns);
721}
722
723template <class Underlying_matrix, class Master_matrix>
724template <typename BirthComparatorFunction, typename DeathComparatorFunction>
726 Column_settings* colSettings,
727 const BirthComparatorFunction& birthComparator,
728 const DeathComparatorFunction& deathComparator)
729 : matrix_(colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
730{
731 _initialize_map(0);
732}
733
734template <class Underlying_matrix, class Master_matrix>
735template <typename BirthComparatorFunction, typename DeathComparatorFunction, class Boundary_range>
737 const std::vector<Boundary_range>& orderedBoundaries,
738 Column_settings* colSettings,
739 const BirthComparatorFunction& birthComparator,
740 const DeathComparatorFunction& deathComparator)
741 : matrix_(orderedBoundaries, colSettings, birthComparator, deathComparator),
742 idToIndex_(nullptr),
743 nextIndex_(orderedBoundaries.size())
744{
745 _initialize_map(orderedBoundaries.size());
746 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
747 for (unsigned int i = 0; i < orderedBoundaries.size(); i++) {
748 _id_to_index(i) = i;
749 }
750 }
751}
752
753template <class Underlying_matrix, class Master_matrix>
754template <typename BirthComparatorFunction, typename DeathComparatorFunction>
756 unsigned int numberOfColumns,
757 Column_settings* colSettings,
758 const BirthComparatorFunction& birthComparator,
759 const DeathComparatorFunction& deathComparator)
760 : matrix_(numberOfColumns, colSettings, birthComparator, deathComparator), idToIndex_(nullptr), nextIndex_(0)
761{
762 _initialize_map(numberOfColumns);
763}
764
765template <class Underlying_matrix, class Master_matrix>
767 const Id_to_index_overlay& matrixToCopy,
768 Column_settings* colSettings)
769 : matrix_(matrixToCopy.matrix_, colSettings), idToIndex_(nullptr), nextIndex_(matrixToCopy.nextIndex_)
770{
771 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
772 idToIndex_ = new Dictionary(*matrixToCopy.idToIndex_);
773 } else {
774 idToIndex_ = &matrix_.pivotToColumnIndex_;
775 }
776}
777
778template <class Underlying_matrix, class Master_matrix>
780 : matrix_(std::move(other.matrix_)),
781 idToIndex_(std::exchange(other.idToIndex_, nullptr)),
782 nextIndex_(std::exchange(other.nextIndex_, 0))
783{
784}
785
786template <class Underlying_matrix, class Master_matrix>
788{
789 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
790 delete idToIndex_;
791 }
792}
793
794template <class Underlying_matrix, class Master_matrix>
795template <class Boundary_range>
797 Dimension dim)
798{
799 matrix_.insert_boundary(boundary, dim);
800 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
801 if constexpr (Master_matrix::Option_list::has_map_column_container) {
802 idToIndex_->emplace(nextIndex_, nextIndex_);
803 } else {
804 if (idToIndex_->size() == nextIndex_) {
805 idToIndex_->push_back(nextIndex_);
806 } else {
807 _id_to_index(nextIndex_) = nextIndex_;
808 }
809 }
810 ++nextIndex_;
811 }
812}
813
814template <class Underlying_matrix, class Master_matrix>
815template <class Boundary_range>
817 const Boundary_range& boundary,
818 Dimension dim)
819{
820 if constexpr (Master_matrix::Option_list::has_map_column_container) {
821 GUDHI_CHECK(idToIndex_->find(cellIndex) == idToIndex_->end(),
822 std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
823 } else {
824 GUDHI_CHECK(
825 (idToIndex_->size() <= cellIndex || _id_to_index(cellIndex) == Master_matrix::template get_null_value<Index>()),
826 std::invalid_argument("Id_to_index_overlay::insert_boundary - Index for simplex already chosen!"));
827 }
828 matrix_.insert_boundary(cellIndex, boundary, dim);
829 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
830 if constexpr (Master_matrix::Option_list::has_map_column_container) {
831 idToIndex_->emplace(cellIndex, nextIndex_);
832 } else {
833 if (idToIndex_->size() <= cellIndex) {
834 idToIndex_->resize(cellIndex + 1, Master_matrix::template get_null_value<Index>());
835 }
836 _id_to_index(cellIndex) = nextIndex_;
837 }
838 ++nextIndex_;
839 }
840}
841
842template <class Underlying_matrix, class Master_matrix>
843template <class Boundary_range>
845 const Boundary_range& boundary,
846 Dimension dim)
847{
848 GUDHI_CHECK(columnIndex >= 0, std::invalid_argument("Indices have to be positive."));
849
850 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
851 insert_boundary(boundary, dim);
852
853 if (get_number_of_columns() == 1) return;
854
855 // false = backward direction
856 _move_column_in_RU<false>(get_number_of_columns() - 1, columnIndex);
857 } else {
858 matrix_.insert_maximal_cell(columnIndex, boundary, dim);
859 }
860}
861
862template <class Underlying_matrix, class Master_matrix>
863template <class Boundary_range>
865 ID_index cellIndex,
866 const Boundary_range& boundary,
867 Dimension dim)
868{
869 GUDHI_CHECK(columnIndex >= 0, std::invalid_argument("Indices have to be positive."));
870
871 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
872 insert_boundary(cellIndex, boundary, dim);
873
874 if (get_number_of_columns() == 1) return;
875
876 // false = backward direction
877 _move_column_in_RU<false>(get_number_of_columns() - 1, columnIndex);
878 } else {
879 matrix_.insert_maximal_cell(columnIndex, cellIndex, boundary, dim);
880 }
881}
882
883template <class Underlying_matrix, class Master_matrix>
886{
887 return matrix_.get_column(_id_to_index(cellID));
888}
889
890template <class Underlying_matrix, class Master_matrix>
893{
894 return matrix_.get_row(rowIndex);
895}
896
897template <class Underlying_matrix, class Master_matrix>
899{
900 return matrix_.erase_empty_row(rowIndex);
901}
902
903template <class Underlying_matrix, class Master_matrix>
905{
906 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
907 // true = forward direction
908 _move_column_in_RU<true>(_id_to_index(cellID), nextIndex_ - 1);
909 // nextIndex_ is used in _move_column_in_RU, should not be decremented before
910 --nextIndex_;
911 matrix_.remove_last();
912 GUDHI_CHECK(_id_to_index(cellID) == nextIndex_,
913 std::logic_error("Id_to_index_overlay::remove_maximal_cell - Indexation problem."));
914
915 if constexpr (Master_matrix::Option_list::has_map_column_container) {
916 idToIndex_->erase(cellID);
917 } else {
918 _id_to_index(cellID) = Master_matrix::template get_null_value<Index>();
919 }
920 } else {
921 matrix_.remove_maximal_cell(cellID);
922 }
923}
924
925template <class Underlying_matrix, class Master_matrix>
927 ID_index cellID,
928 const std::vector<ID_index>& columnsToSwap)
929{
930 static_assert(!Master_matrix::Option_list::is_of_boundary_type,
931 "'remove_maximal_cell(ID_index,const std::vector<Index>&)' is not available for the chosen options.");
932 std::vector<Index> translatedIndices;
933 std::transform(columnsToSwap.cbegin(), columnsToSwap.cend(), std::back_inserter(translatedIndices), [&](ID_index id) {
934 return _id_to_index(id);
935 });
936 matrix_.remove_maximal_cell(cellID, translatedIndices);
937}
938
939template <class Underlying_matrix, class Master_matrix>
941{
942 if (idToIndex_->empty()) return; // empty matrix
943
944 matrix_.remove_last();
945
946 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
947 --nextIndex_;
948 if constexpr (Master_matrix::Option_list::has_map_column_container) {
949 auto it = idToIndex_->begin();
950 while (it->second != nextIndex_) ++it; // should never reach idToIndex_->end()
951 idToIndex_->erase(it);
952 } else {
953 Index id = idToIndex_->size() - 1;
954 // should always stop before reaching -1
955 while (_id_to_index(id) == Master_matrix::template get_null_value<Index>()) --id;
956 GUDHI_CHECK(_id_to_index(id) == nextIndex_,
957 std::logic_error("Id_to_index_overlay::remove_last - Indexation problem."));
958 _id_to_index(id) = Master_matrix::template get_null_value<Index>();
959 }
960 }
961}
962
963template <class Underlying_matrix, class Master_matrix>
966{
967 return matrix_.get_max_dimension();
968}
969
970template <class Underlying_matrix, class Master_matrix>
973{
974 return matrix_.get_number_of_columns();
975}
976
977template <class Underlying_matrix, class Master_matrix>
980{
981 return matrix_.get_column_dimension(_id_to_index(cellID));
982}
983
984template <class Underlying_matrix, class Master_matrix>
986{
987 return matrix_.add_to(_id_to_index(sourceCellID), _id_to_index(targetCellID));
988}
989
990template <class Underlying_matrix, class Master_matrix>
992 ID_index sourceCellID,
993 const Field_element& coefficient,
994 ID_index targetCellID)
995{
996 return matrix_.multiply_target_and_add_to(_id_to_index(sourceCellID), coefficient, _id_to_index(targetCellID));
997}
998
999template <class Underlying_matrix, class Master_matrix>
1001 const Field_element& coefficient,
1002 ID_index sourceCellID,
1003 ID_index targetCellID)
1004{
1005 return matrix_.multiply_source_and_add_to(coefficient, _id_to_index(sourceCellID), _id_to_index(targetCellID));
1006}
1007
1008template <class Underlying_matrix, class Master_matrix>
1010{
1011 return matrix_.zero_entry(_id_to_index(cellID), rowIndex);
1012}
1013
1014template <class Underlying_matrix, class Master_matrix>
1016{
1017 return matrix_.zero_column(_id_to_index(cellID));
1018}
1019
1020template <class Underlying_matrix, class Master_matrix>
1022 ID_index rowIndex) const
1023{
1024 return matrix_.is_zero_entry(_id_to_index(cellID), rowIndex);
1025}
1026
1027template <class Underlying_matrix, class Master_matrix>
1029{
1030 return matrix_.is_zero_column(_id_to_index(cellID));
1031}
1032
1033template <class Underlying_matrix, class Master_matrix>
1036{
1037 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1038 Index pos = matrix_.get_column_with_pivot(cellIndex);
1039 ID_index i = 0;
1040 while (_id_to_index(i) != pos) ++i;
1041 return i;
1042 } else {
1043 return cellIndex;
1044 }
1045}
1046
1047template <class Underlying_matrix, class Master_matrix>
1050{
1051 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1052 return matrix_.get_pivot(_id_to_index(cellID));
1053 } else {
1054 return cellID;
1055 }
1056}
1057
1058template <class Underlying_matrix, class Master_matrix>
1061{
1062 if (this == &other) return *this;
1063
1064 matrix_ = other.matrix_;
1065 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1066 delete idToIndex_;
1067 idToIndex_ = other.idToIndex_;
1068 } else {
1069 idToIndex_ = &matrix_.pivotToColumnIndex_;
1070 }
1071 nextIndex_ = other.nextIndex_;
1072
1073 return *this;
1074}
1075
1076template <class Underlying_matrix, class Master_matrix>
1079{
1080 if (this == &other) return *this;
1081
1082 matrix_ = std::move(other.matrix_);
1083 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1084 delete idToIndex_;
1085 }
1086 idToIndex_ = std::exchange(other.idToIndex_, nullptr);
1087 nextIndex_ = std::exchange(other.nextIndex_, 0);
1088
1089 return *this;
1090}
1091
1092template <class Underlying_matrix, class Master_matrix>
1093inline void Id_to_index_overlay<Underlying_matrix, Master_matrix>::print()
1094{
1095 return matrix_.print();
1096}
1097
1098template <class Underlying_matrix, class Master_matrix>
1101{
1102 return matrix_.get_current_barcode();
1103}
1104
1105template <class Underlying_matrix, class Master_matrix>
1107{
1108 matrix_.update_all_representative_cycles(dim);
1109}
1110
1111template <class Underlying_matrix, class Master_matrix>
1113{
1114 matrix_.update_representative_cycle(bar);
1115}
1116
1117template <class Underlying_matrix, class Master_matrix>
1118inline const std::vector<typename Id_to_index_overlay<Underlying_matrix, Master_matrix>::Cycle>&
1120{
1121 return matrix_.get_all_representative_cycles();
1122}
1123
1124template <class Underlying_matrix, class Master_matrix>
1127{
1128 return matrix_.get_representative_cycle(bar);
1129}
1130
1131template <class Underlying_matrix, class Master_matrix>
1133{
1134 matrix_.swap_columns(_id_to_index(cellID1), _id_to_index(cellID2));
1135 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1136}
1137
1138template <class Underlying_matrix, class Master_matrix>
1140{
1141 matrix_.swap_rows(rowIndex1, rowIndex2);
1142}
1143
1144template <class Underlying_matrix, class Master_matrix>
1147{
1148 Index first = _id_to_index(cellID1);
1149 Index second = _id_to_index(cellID2);
1150 if (first > second) std::swap(first, second);
1151
1152 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1153 GUDHI_CHECK(second - first == 1,
1154 std::invalid_argument(
1155 "Id_to_index_overlay::vine_swap_with_z_eq_1_case - The columns to swap are not contiguous."));
1156
1157 bool change = matrix_.vine_swap_with_z_eq_1_case(first);
1158
1159 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1160
1161 if (change) {
1162 return cellID1;
1163 }
1164 return cellID2;
1165 } else {
1166 return matrix_.vine_swap_with_z_eq_1_case(first, second);
1167 }
1168}
1169
1170template <class Underlying_matrix, class Master_matrix>
1173{
1174 Index first = _id_to_index(cellID1);
1175 Index second = _id_to_index(cellID2);
1176 if (first > second) std::swap(first, second);
1177
1178 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1179 GUDHI_CHECK(second - first == 1,
1180 std::invalid_argument("Id_to_index_overlay::vine_swap - The columns to swap are not contiguous."));
1181
1182 bool change = matrix_.vine_swap(first);
1183
1184 std::swap(idToIndex_->at(cellID1), idToIndex_->at(cellID2));
1185
1186 if (change) {
1187 return cellID1;
1188 }
1189 return cellID2;
1190 } else {
1191 return matrix_.vine_swap(first, second);
1192 }
1193}
1194
1195template <class Underlying_matrix, class Master_matrix>
1196inline void Id_to_index_overlay<Underlying_matrix, Master_matrix>::_initialize_map([[maybe_unused]] unsigned int size)
1197{
1198 if constexpr (Master_matrix::Option_list::is_of_boundary_type) {
1199 if constexpr (Master_matrix::Option_list::has_map_column_container) {
1200 idToIndex_ = new Dictionary(size);
1201 } else {
1202 idToIndex_ = new Dictionary(size, Master_matrix::template get_null_value<Index>());
1203 }
1204 } else {
1205 idToIndex_ = &matrix_.pivotToColumnIndex_;
1206 }
1207}
1208
1209template <class Underlying_matrix, class Master_matrix>
1211Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index id) const
1212{
1213 if constexpr (Master_matrix::Option_list::has_map_column_container) {
1214 return idToIndex_->at(id);
1215 } else {
1216 return idToIndex_->operator[](id);
1217 }
1218}
1219
1220template <class Underlying_matrix, class Master_matrix>
1222Id_to_index_overlay<Underlying_matrix, Master_matrix>::_id_to_index(ID_index id)
1223{
1224 return idToIndex_->operator[](id); // for maps, the entry is created if not existing as needed in the constructors
1225}
1226
1227template <class Underlying_matrix, class Master_matrix>
1228template <bool dir>
1229inline void Id_to_index_overlay<Underlying_matrix, Master_matrix>::_move_column_in_RU(Pos_index start, Pos_index end)
1230{
1231 // nextIndex_ would be overkill if start (dir == true) / end (dir == false) was different from end of matrix
1232 // but it is not used that way for now
1233 std::vector<ID_index> indexToID(nextIndex_);
1234 if constexpr (Master_matrix::Option_list::has_map_column_container) {
1235 for (auto& p : *idToIndex_) {
1236 indexToID[p.second] = p.first;
1237 }
1238 } else {
1239 for (ID_index i = 0; i < idToIndex_->size(); ++i) {
1240 if (_id_to_index(i) != Master_matrix::template get_null_value<Index>()) indexToID[_id_to_index(i)] = i;
1241 }
1242 }
1243 if constexpr (dir) {
1244 for (Index curr = start; curr < end; ++curr) {
1245 matrix_.vine_swap(curr);
1246 std::swap(idToIndex_->at(indexToID[curr]), idToIndex_->at(indexToID[curr + 1]));
1247 std::swap(indexToID[curr], indexToID[curr + 1]);
1248 }
1249 } else {
1250 for (Index curr = start; curr > end; --curr) {
1251 matrix_.vine_swap(curr - 1);
1252 std::swap(idToIndex_->at(indexToID[curr - 1]), idToIndex_->at(indexToID[curr]));
1253 std::swap(indexToID[curr - 1], indexToID[curr]);
1254 }
1255 }
1256}
1257
1258} // namespace persistence_matrix
1259} // namespace Gudhi
1260
1261#endif // PM_ID_TO_POS_TRANSLATION_H
Overlay for non-basic matrices replacing all input and output MatIdx indices of the original methods ...
Definition Id_to_index_overlay.h:41
Id_to_index_overlay(Column_settings *colSettings)
Constructs an empty matrix.
Definition Id_to_index_overlay.h:694
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:1106
bool is_zero_column(ID_index cellID)
Indicates if the column at given index has value zero.
Definition Id_to_index_overlay.h:1028
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:904
Id_to_index_overlay & operator=(const Id_to_index_overlay &other)
Assign operator.
Definition Id_to_index_overlay.h:1060
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:965
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:1126
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:985
ID_index get_pivot(ID_index cellID)
Returns the row index of the pivot of the given column.
Definition Id_to_index_overlay.h:1049
typename Master_matrix::Row Row
Definition Id_to_index_overlay.h:54
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Additionally,...
Definition Id_to_index_overlay.h:940
void update_representative_cycle(const Bar &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition Id_to_index_overlay.h:1112
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:991
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition Id_to_index_overlay.h:549
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:1015
typename Master_matrix::Index Index
Definition Id_to_index_overlay.h:43
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:1000
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:1100
typename Master_matrix::Column Column
Definition Id_to_index_overlay.h:53
typename Master_matrix::Bar Bar
Definition Id_to_index_overlay.h:56
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:1035
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:796
void erase_empty_row(ID_index rowIndex)
The effect varies depending on the matrices and the options:
Definition Id_to_index_overlay.h:898
void insert_maximal_cell(Index columnIndex, const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >())
Only available if PersistenceMatrixOptions::has_vine_update is true. Assumes that the cell will be ma...
Definition Id_to_index_overlay.h:844
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:885
typename Master_matrix::Boundary Boundary
Definition Id_to_index_overlay.h:52
friend void swap(Id_to_index_overlay &matrix1, Id_to_index_overlay &matrix2) noexcept
Swap operator.
Definition Id_to_index_overlay.h:569
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:892
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:1146
typename Master_matrix::Cycle Cycle
Definition Id_to_index_overlay.h:58
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:1021
typename Master_matrix::Barcode Barcode
Definition Id_to_index_overlay.h:57
typename Master_matrix::Entry_constructor Entry_constructor
Definition Id_to_index_overlay.h:59
typename Master_matrix::Dimension Dimension
Definition Id_to_index_overlay.h:46
~Id_to_index_overlay()
Destructor.
Definition Id_to_index_overlay.h:787
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:1132
typename Master_matrix::Field_operators Field_operators
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
Definition Id_to_index_overlay.h:50
typename Master_matrix::Column_settings Column_settings
Definition Id_to_index_overlay.h:60
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:1139
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:1172
typename Master_matrix::Pos_index Pos_index
Definition Id_to_index_overlay.h:45
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:1009
Index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition Id_to_index_overlay.h:972
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:979
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:1119
typename Master_matrix::ID_index ID_index
Definition Id_to_index_overlay.h:44
typename Master_matrix::Element Field_element
Definition Id_to_index_overlay.h:51
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14