17 #ifndef PM_POS_TO_ID_TRANSLATION_H
18 #define PM_POS_TO_ID_TRANSLATION_H
25 namespace persistence_matrix {
38 template <
class Matrix_type,
class Master_matrix_type>
42 using index =
typename Master_matrix_type::index;
43 using id_index =
typename Master_matrix_type::id_index;
44 using pos_index =
typename Master_matrix_type::pos_index;
53 using Row_type =
typename Master_matrix_type::Row_type;
55 using bar_type =
typename Master_matrix_type::Bar;
57 using cycle_type =
typename Master_matrix_type::cycle_type;
90 template <
class Boundary_type = boundary_type>
124 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
126 const BirthComparatorFunction& birthComparator,
127 const DeathComparatorFunction& deathComparator);
164 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_type>
167 const BirthComparatorFunction& birthComparator,
168 const DeathComparatorFunction& deathComparator);
192 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
195 const BirthComparatorFunction& birthComparator,
196 const DeathComparatorFunction& deathComparator);
234 template <
class Boundary_type = boundary_type>
252 template <
class Boundary_type = boundary_type>
434 matrix_.reset(colSettings);
435 positionToIndex_.clear();
450 swap(matrix1.matrix_, matrix2.matrix_);
451 matrix1.positionToIndex_.swap(matrix2.positionToIndex_);
452 std::swap(matrix1.nextPosition_, matrix2.nextPosition_);
453 std::swap(matrix1.nextIndex_, matrix2.nextIndex_);
522 std::vector<index> positionToIndex_;
527 template <
class Matrix_type,
class Master_matrix_type>
530 : matrix_(colSettings), nextPosition_(0), nextIndex_(0)
533 template <
class Matrix_type,
class Master_matrix_type>
534 template <
class Boundary_type>
536 const std::vector<Boundary_type>& orderedBoundaries,
Column_settings* colSettings)
537 : matrix_(orderedBoundaries, colSettings),
538 positionToIndex_(orderedBoundaries.size()),
539 nextPosition_(orderedBoundaries.size()),
540 nextIndex_(orderedBoundaries.size())
542 for (
index i = 0; i < orderedBoundaries.size(); i++) {
543 positionToIndex_[i] = i;
547 template <
class Matrix_type,
class Master_matrix_type>
550 : matrix_(numberOfColumns, colSettings),
551 positionToIndex_(numberOfColumns),
556 template <
class Matrix_type,
class Master_matrix_type>
557 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
560 const BirthComparatorFunction& birthComparator,
561 const DeathComparatorFunction& deathComparator)
562 : matrix_(colSettings, birthComparator, deathComparator), nextPosition_(0), nextIndex_(0)
565 template <
class Matrix_type,
class Master_matrix_type>
566 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction,
class Boundary_type>
568 const std::vector<Boundary_type>& orderedBoundaries,
570 const BirthComparatorFunction& birthComparator,
571 const DeathComparatorFunction& deathComparator)
572 : matrix_(orderedBoundaries, colSettings, birthComparator, deathComparator),
573 positionToIndex_(orderedBoundaries.size()),
574 nextPosition_(orderedBoundaries.size()),
575 nextIndex_(orderedBoundaries.size())
577 for (
index i = 0; i < orderedBoundaries.size(); i++) {
578 positionToIndex_[i] = i;
582 template <
class Matrix_type,
class Master_matrix_type>
583 template <
typename BirthComparatorFunction,
typename DeathComparatorFunction>
585 unsigned int numberOfColumns,
587 const BirthComparatorFunction& birthComparator,
588 const DeathComparatorFunction& deathComparator)
589 : matrix_(numberOfColumns, colSettings, birthComparator, deathComparator),
590 positionToIndex_(numberOfColumns),
595 template <
class Matrix_type,
class Master_matrix_type>
598 : matrix_(matrixToCopy.matrix_, colSettings),
599 positionToIndex_(matrixToCopy.positionToIndex_),
600 nextPosition_(matrixToCopy.nextPosition_),
601 nextIndex_(matrixToCopy.nextIndex_)
604 template <
class Matrix_type,
class Master_matrix_type>
607 : matrix_(std::move(other.matrix_)),
608 positionToIndex_(std::move(other.positionToIndex_)),
609 nextPosition_(std::exchange(other.nextPosition_, 0)),
610 nextIndex_(std::exchange(other.nextIndex_, 0))
613 template <
class Matrix_type,
class Master_matrix_type>
614 template <
class Boundary_type>
618 if (positionToIndex_.size() <= nextPosition_) {
619 positionToIndex_.resize(nextPosition_ * 2 + 1);
622 positionToIndex_[nextPosition_++] = nextIndex_++;
624 matrix_.insert_boundary(boundary, dim);
627 template <
class Matrix_type,
class Master_matrix_type>
628 template <
class Boundary_type>
630 const Boundary_type& boundary,
633 if (positionToIndex_.size() <= nextPosition_) {
634 positionToIndex_.resize(nextPosition_ * 2 + 1);
637 positionToIndex_[nextPosition_++] = nextIndex_++;
639 matrix_.insert_boundary(faceIndex, boundary, dim);
642 template <
class Matrix_type,
class Master_matrix_type>
646 return matrix_.get_column(positionToIndex_[position]);
649 template <
class Matrix_type,
class Master_matrix_type>
653 return matrix_.get_column(positionToIndex_[position]);
656 template <
class Matrix_type,
class Master_matrix_type>
660 return matrix_.get_row(rowIndex);
663 template <
class Matrix_type,
class Master_matrix_type>
667 return matrix_.get_row(rowIndex);
670 template <
class Matrix_type,
class Master_matrix_type>
673 return matrix_.erase_empty_row(rowIndex);
676 template <
class Matrix_type,
class Master_matrix_type>
681 id_index pivot = matrix_.get_pivot(positionToIndex_[position]);
682 std::vector<index> columnsToSwap(nextPosition_ - position);
684 if (nextPosition_ != position) {
685 positionToIndex_[position] = positionToIndex_[position + 1];
686 for (
pos_index p = position + 1; p < nextPosition_; ++p) {
687 columnsToSwap[p - position - 1] = positionToIndex_[p];
688 positionToIndex_[p] = positionToIndex_[p + 1];
690 columnsToSwap.back() = positionToIndex_[nextPosition_];
693 matrix_.remove_maximal_face(pivot, columnsToSwap);
696 template <
class Matrix_type,
class Master_matrix_type>
700 if constexpr (Master_matrix_type::Option_list::has_vine_update) {
701 std::vector<index> columnsToSwap;
702 matrix_.remove_maximal_face(matrix_.get_pivot(positionToIndex_[nextPosition_]), columnsToSwap);
704 matrix_.remove_last();
708 template <
class Matrix_type,
class Master_matrix_type>
712 return matrix_.get_max_dimension();
715 template <
class Matrix_type,
class Master_matrix_type>
719 return matrix_.get_number_of_columns();
722 template <
class Matrix_type,
class Master_matrix_type>
726 return matrix_.get_column_dimension(positionToIndex_[position]);
729 template <
class Matrix_type,
class Master_matrix_type>
733 return matrix_.add_to(positionToIndex_[sourcePosition], positionToIndex_[targetPosition]);
736 template <
class Matrix_type,
class Master_matrix_type>
740 return matrix_.multiply_target_and_add_to(positionToIndex_[sourcePosition],
742 positionToIndex_[targetPosition]);
745 template <
class Matrix_type,
class Master_matrix_type>
749 return matrix_.multiply_source_and_add_to(coefficient,
750 positionToIndex_[sourcePosition],
751 positionToIndex_[targetPosition]);
754 template <
class Matrix_type,
class Master_matrix_type>
758 return matrix_.is_zero_cell(positionToIndex_[position], rowIndex);
761 template <
class Matrix_type,
class Master_matrix_type>
764 return matrix_.is_zero_column(positionToIndex_[position]);
767 template <
class Matrix_type,
class Master_matrix_type>
771 index id = matrix_.get_column_with_pivot(faceIndex);
773 while (positionToIndex_[i] !=
id) ++i;
777 template <
class Matrix_type,
class Master_matrix_type>
781 return matrix_.get_pivot(positionToIndex_[position]);
784 template <
class Matrix_type,
class Master_matrix_type>
788 matrix_ = other.matrix_;
789 positionToIndex_ = other.positionToIndex_;
790 nextPosition_ = other.nextPosition_;
791 nextIndex_ = other.nextIndex_;
796 template <
class Matrix_type,
class Master_matrix_type>
799 return matrix_.print();
802 template <
class Matrix_type,
class Master_matrix_type>
806 return matrix_.get_current_barcode();
809 template <
class Matrix_type,
class Master_matrix_type>
812 matrix_.update_representative_cycles();
815 template <
class Matrix_type,
class Master_matrix_type>
816 inline const std::vector<typename Position_to_index_overlay<Matrix_type, Master_matrix_type>::cycle_type>&
819 return matrix_.get_representative_cycles();
822 template <
class Matrix_type,
class Master_matrix_type>
826 return matrix_.get_representative_cycle(bar);
829 template <
class Matrix_type,
class Master_matrix_type>
832 index next = matrix_.vine_swap_with_z_eq_1_case(positionToIndex_[position], positionToIndex_[position + 1]);
833 if (next == positionToIndex_[position]) {
834 std::swap(positionToIndex_[position], positionToIndex_[position + 1]);
841 template <
class Matrix_type,
class Master_matrix_type>
844 index next = matrix_.vine_swap(positionToIndex_[position], positionToIndex_[position + 1]);
845 if (next == positionToIndex_[position]) {
846 std::swap(positionToIndex_[position], positionToIndex_[position + 1]);
Overlay for chain matrices replacing all input and output MatIdx indices of the original methods with...
Definition: overlay_posidx_to_matidx.h:40
typename Master_matrix_type::Bar bar_type
Definition: overlay_posidx_to_matidx.h:55
typename Master_matrix_type::cell_rep_type cell_rep_type
Definition: overlay_posidx_to_matidx.h:58
void multiply_target_and_add_to(pos_index sourcePosition, const Field_element_type &coefficient, pos_index targetPosition)
Multiplies the target column with the coefficiant and then adds the source column to it....
Definition: overlay_posidx_to_matidx.h:737
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_posidx_to_matidx.h:615
friend void swap(Position_to_index_overlay &matrix1, Position_to_index_overlay &matrix2)
Swap operator.
Definition: overlay_posidx_to_matidx.h:449
bool vine_swap(pos_index position)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does a vine swap between two fac...
Definition: overlay_posidx_to_matidx.h:842
typename Master_matrix_type::index index
Definition: overlay_posidx_to_matidx.h:42
typename Master_matrix_type::Cell_constructor Cell_constructor
Definition: overlay_posidx_to_matidx.h:59
bool vine_swap_with_z_eq_1_case(pos_index position)
Only available if PersistenceMatrixOptions::has_vine_update is true. Does the same than vine_swap,...
Definition: overlay_posidx_to_matidx.h:830
typename Master_matrix_type::boundary_type boundary_type
Definition: overlay_posidx_to_matidx.h:51
const std::vector< cycle_type > & get_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_posidx_to_matidx.h:817
dimension_type get_max_dimension() const
Returns the maximal dimension of a face stored in the matrix. Only available if PersistenceMatrixOpti...
Definition: overlay_posidx_to_matidx.h:710
void remove_maximal_face(pos_index position)
Only available if PersistenceMatrixOptions::has_removable_columns, PersistenceMatrixOptions::has_vine...
Definition: overlay_posidx_to_matidx.h:677
const barcode_type & get_current_barcode() const
Returns the current barcode of the matrix. Available only if PersistenceMatrixOptions::has_column_pai...
Definition: overlay_posidx_to_matidx.h:804
index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition: overlay_posidx_to_matidx.h:717
void multiply_source_and_add_to(const Field_element_type &coefficient, pos_index sourcePosition, pos_index targetPosition)
Multiplies the source column with the coefficiant before adding it to the target column....
Definition: overlay_posidx_to_matidx.h:746
typename Master_matrix_type::element_type Field_element_type
Definition: overlay_posidx_to_matidx.h:50
void update_representative_cycles()
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_posidx_to_matidx.h:810
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition: overlay_posidx_to_matidx.h:433
id_index get_pivot(pos_index position)
Returns the row index of the pivot of the given column.
Definition: overlay_posidx_to_matidx.h:779
Column_type & get_column(pos_index position)
Returns the column at the given PosIdx index. The type of the column depends on the choosen options,...
Definition: overlay_posidx_to_matidx.h:644
void erase_empty_row(id_index rowIndex)
Only available if PersistenceMatrixOptions::has_row_access and PersistenceMatrixOptions::has_removabl...
Definition: overlay_posidx_to_matidx.h:671
typename Master_matrix_type::Column_type Column_type
Definition: overlay_posidx_to_matidx.h:52
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true and, if PersistenceMatrixOp...
Definition: overlay_posidx_to_matidx.h:697
typename Master_matrix_type::id_index id_index
Definition: overlay_posidx_to_matidx.h:43
typename Master_matrix_type::dimension_type dimension_type
Definition: overlay_posidx_to_matidx.h:45
typename Master_matrix_type::Row_type Row_type
Definition: overlay_posidx_to_matidx.h:54
typename Master_matrix_type::barcode_type barcode_type
Definition: overlay_posidx_to_matidx.h:56
Position_to_index_overlay(Column_settings *colSettings)
Constructs an empty matrix.
Definition: overlay_posidx_to_matidx.h:528
typename Master_matrix_type::cycle_type cycle_type
Definition: overlay_posidx_to_matidx.h:57
typename Master_matrix_type::Column_settings Column_settings
Definition: overlay_posidx_to_matidx.h:61
bool is_zero_cell(pos_index position, id_index rowIndex) const
Indicates if the cell at given coordinates has value zero.
Definition: overlay_posidx_to_matidx.h:755
dimension_type get_column_dimension(pos_index position) const
Returns the dimension of the given face.
Definition: overlay_posidx_to_matidx.h:724
typename Master_matrix_type::Field_operators Field_operators
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
Definition: overlay_posidx_to_matidx.h:49
const cycle_type & get_representative_cycle(const bar_type &bar)
Only available if PersistenceMatrixOptions::can_retrieve_representative_cycles is true....
Definition: overlay_posidx_to_matidx.h:824
pos_index get_column_with_pivot(id_index faceIndex) const
Returns the PosIdx index of the column which has the given row index as pivot. Assumes that the pivot...
Definition: overlay_posidx_to_matidx.h:769
typename Master_matrix_type::pos_index pos_index
Definition: overlay_posidx_to_matidx.h:44
bool is_zero_column(pos_index position)
Indicates if the column at given index has value zero.
Definition: overlay_posidx_to_matidx.h:762
Position_to_index_overlay & operator=(const Position_to_index_overlay &other)
Assign operator.
Definition: overlay_posidx_to_matidx.h:786
void add_to(pos_index sourcePosition, pos_index targetPosition)
Adds column corresponding to sourcePosition onto the column corresponding to targetPosition.
Definition: overlay_posidx_to_matidx.h:730
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_posidx_to_matidx.h:658
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14