Loading...
Searching...
No Matches
RU_matrix.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 * - 2025/11 Jānis Lazovskis: Added insert_maximal_cell method
9 * - YYYY/MM Author: Description of the modification
10 */
11
17
18#ifndef PM_RU_MATRIX_H
19#define PM_RU_MATRIX_H
20
21#include <utility> //std::swap, std::move & std::exchange
22#include <iostream> //print() only
23#include <vector>
24#include <unordered_map>
25
26namespace Gudhi {
27namespace persistence_matrix {
28
29template <class Master_matrix>
30class RU_pairing;
31
43template <class Master_matrix>
44class RU_matrix : public Master_matrix::RU_pairing_option,
45 public Master_matrix::RU_vine_swap_option,
46 public Master_matrix::RU_representative_cycles_option
47{
48 private:
49 using Pair_opt = typename Master_matrix::RU_pairing_option;
50 using Swap_opt = typename Master_matrix::RU_vine_swap_option;
51 using Rep_opt = typename Master_matrix::RU_representative_cycles_option;
52
53 public:
57 using Field_operators = typename Master_matrix::Field_operators;
58 using Field_element = typename Master_matrix::Element;
59 using Column = typename Master_matrix::Column;
60 using Row = typename Master_matrix::Row;
62 using Entry_constructor = typename Master_matrix::Entry_constructor;
63 using Column_settings = typename Master_matrix::Column_settings;
65 using Boundary = typename Master_matrix::Boundary;
66 using Index = typename Master_matrix::Index;
67 using ID_index = typename Master_matrix::ID_index;
68 using Pos_index = typename Master_matrix::Pos_index;
69 using Dimension = typename Master_matrix::Dimension;
70
98 template <class Boundary_range = Boundary>
99 RU_matrix(const std::vector<Boundary_range>& orderedBoundaries, Column_settings* colSettings);
107 RU_matrix(unsigned int numberOfColumns, Column_settings* colSettings);
117 RU_matrix(const RU_matrix& matrixToCopy, Column_settings* colSettings = nullptr);
123 RU_matrix(RU_matrix&& other) noexcept;
124
125 ~RU_matrix() = default;
126
146 template <class Boundary_range = Boundary>
147 void insert_boundary(const Boundary_range& boundary,
148 Dimension dim = Master_matrix::template get_null_value<Dimension>());
166 template <class Boundary_range = Boundary>
167 void insert_boundary(ID_index cellIndex, const Boundary_range& boundary,
168 Dimension dim = Master_matrix::template get_null_value<Dimension>());
188 template <class Boundary_range = Boundary>
189 void insert_maximal_cell(Index columnIndex, const Boundary_range& boundary,
190 Dimension dim = Master_matrix::template get_null_value<Dimension>());
205 Column& get_column(Index columnIndex, bool inR = true);
220 Row& get_row(Index rowIndex, bool inR = true);
238 void erase_empty_row(Index rowIndex);
251 void remove_maximal_cell(Index columnIndex);
259
280
291 void add_to(Index sourceColumnIndex, Index targetColumnIndex);
304 void multiply_target_and_add_to(Index sourceColumnIndex, const Field_element& coefficient, Index targetColumnIndex);
317 void multiply_source_and_add_to(const Field_element& coefficient, Index sourceColumnIndex, Index targetColumnIndex);
318
329 void zero_entry(Index columnIndex, Index rowIndex, bool inR = true);
339 void zero_column(Index columnIndex, bool inR = true);
351 bool is_zero_entry(Index columnIndex, Index rowIndex, bool inR = true) const;
364 bool is_zero_column(Index columnIndex, bool inR = true);
365
380 Index get_pivot(Index columnIndex);
381
388 void reset(Column_settings* colSettings)
389 {
390 if constexpr (Master_matrix::Option_list::has_column_pairings) Pair_opt::_reset();
391 if constexpr (Master_matrix::Option_list::can_retrieve_representative_cycles) Rep_opt::_reset();
392 reducedMatrixR_.reset(colSettings);
393 mirrorMatrixU_.reset(colSettings);
394 pivotToColumnIndex_.clear();
395 nextEventIndex_ = 0;
396 positionToID_.clear();
397 operators_ = Master_matrix::get_operator_ptr(colSettings);
398 }
399
407 RU_matrix& operator=(RU_matrix&& other) noexcept;
408
412 friend void swap(RU_matrix& matrix1, RU_matrix& matrix2) noexcept
413 {
414 swap(static_cast<Pair_opt&>(matrix1), static_cast<Pair_opt&>(matrix2));
415 swap(static_cast<Swap_opt&>(matrix1), static_cast<Swap_opt&>(matrix2));
416 swap(static_cast<Rep_opt&>(matrix1), static_cast<Rep_opt&>(matrix2));
417 swap(matrix1.reducedMatrixR_, matrix2.reducedMatrixR_);
418 swap(matrix1.mirrorMatrixU_, matrix2.mirrorMatrixU_);
419 matrix1.pivotToColumnIndex_.swap(matrix2.pivotToColumnIndex_);
420 std::swap(matrix1.nextEventIndex_, matrix2.nextEventIndex_);
421 matrix1.positionToID_.swap(matrix2.positionToID_);
422 std::swap(matrix1.operators_, matrix2.operators_);
423 }
424
425 void print(); // for debug
426
427 private:
428 using Pivot_dictionary = typename Master_matrix::template Dictionary<Index>;
429 using Position_dictionary = std::unordered_map<Pos_index, ID_index>; // TODO: try other type of maps?
430 using Barcode = typename Master_matrix::Barcode;
431 using Bar_dictionary = typename Master_matrix::Bar_dictionary;
432 using R_matrix = typename Master_matrix::Master_boundary_matrix;
433 using U_matrix = typename Master_matrix::Master_base_matrix;
434
435 friend Rep_opt; // direct access to the two matrices
436 friend Swap_opt; // direct access to the two matrices, pivotToColumnIndex_
437 friend RU_pairing<Master_matrix>; // direct access to positionToID_
438
439 R_matrix reducedMatrixR_;
440 // TODO: make U not accessible by default and add option to enable access? Inaccessible, it
441 // needs less options and we could avoid some ifs.
442 U_matrix mirrorMatrixU_;
443 Pivot_dictionary pivotToColumnIndex_;
444 Pos_index nextEventIndex_;
445 Position_dictionary positionToID_;
446 Field_operators const* operators_;
448
449 void _insert_boundary(Index currentIndex);
450 void _initialize_U();
451 void _reduce();
452 void _reduce_last_column(Index lastIndex);
453 void _reduce_column(Index target, Index eventIndex);
454 void _reduce_column_by(Index target, Index source);
455 Index _get_column_with_pivot(ID_index pivot) const;
456 void _update_barcode(ID_index birthPivot, Pos_index death);
457 void _add_bar(Dimension dim, Pos_index birth);
458 void _remove_last_in_barcode(Pos_index eventIndex);
459};
460
461template <class Master_matrix>
463 : Pair_opt(),
464 Swap_opt(),
465 Rep_opt(),
466 reducedMatrixR_(colSettings),
467 mirrorMatrixU_(colSettings),
468 nextEventIndex_(0),
469 operators_(Master_matrix::get_operator_ptr(colSettings))
470{}
471
472template <class Master_matrix>
473template <class Boundary_range>
474inline RU_matrix<Master_matrix>::RU_matrix(const std::vector<Boundary_range>& orderedBoundaries,
475 Column_settings* colSettings)
476 : Pair_opt(),
477 Swap_opt(),
478 Rep_opt(),
479 reducedMatrixR_(orderedBoundaries, colSettings),
480 mirrorMatrixU_(orderedBoundaries.size(), colSettings),
481 nextEventIndex_(orderedBoundaries.size()),
482 operators_(Master_matrix::get_operator_ptr(colSettings))
483{
484 if constexpr (Master_matrix::Option_list::has_map_column_container) {
485 pivotToColumnIndex_.reserve(orderedBoundaries.size());
486 } else {
487 pivotToColumnIndex_.resize(orderedBoundaries.size(), Master_matrix::template get_null_value<Index>());
488 }
489
490 _initialize_U();
491 _reduce();
492}
493
494template <class Master_matrix>
495inline RU_matrix<Master_matrix>::RU_matrix(unsigned int numberOfColumns, Column_settings* colSettings)
496 : Pair_opt(),
497 Swap_opt(),
498 Rep_opt(),
499 reducedMatrixR_(numberOfColumns, colSettings),
500 mirrorMatrixU_(numberOfColumns, colSettings),
501 nextEventIndex_(0),
502 positionToID_(numberOfColumns),
503 operators_(Master_matrix::get_operator_ptr(colSettings))
504{
505 if constexpr (Master_matrix::Option_list::has_map_column_container) {
506 pivotToColumnIndex_.reserve(numberOfColumns);
507 } else {
508 pivotToColumnIndex_.resize(numberOfColumns, Master_matrix::template get_null_value<Index>());
509 }
510 if constexpr (Master_matrix::Option_list::has_column_pairings) {
511 Pair_opt::_reserve(numberOfColumns);
512 }
513}
514
515template <class Master_matrix>
516inline RU_matrix<Master_matrix>::RU_matrix(const RU_matrix& matrixToCopy, Column_settings* colSettings)
517 : Pair_opt(static_cast<const Pair_opt&>(matrixToCopy)),
518 Swap_opt(static_cast<const Swap_opt&>(matrixToCopy)),
519 Rep_opt(static_cast<const Rep_opt&>(matrixToCopy)),
520 reducedMatrixR_(matrixToCopy.reducedMatrixR_, colSettings),
521 mirrorMatrixU_(matrixToCopy.mirrorMatrixU_, colSettings),
522 pivotToColumnIndex_(matrixToCopy.pivotToColumnIndex_),
523 nextEventIndex_(matrixToCopy.nextEventIndex_),
524 positionToID_(matrixToCopy.positionToID_),
525 operators_(colSettings == nullptr ? matrixToCopy.operators_ : Master_matrix::get_operator_ptr(colSettings))
526{}
527
528template <class Master_matrix>
530 : Pair_opt(std::move(static_cast<Pair_opt&>(other))),
531 Swap_opt(std::move(static_cast<Swap_opt&>(other))),
532 Rep_opt(std::move(static_cast<Rep_opt&>(other))),
533 reducedMatrixR_(std::move(other.reducedMatrixR_)),
534 mirrorMatrixU_(std::move(other.mirrorMatrixU_)),
535 pivotToColumnIndex_(std::move(other.pivotToColumnIndex_)),
536 nextEventIndex_(std::exchange(other.nextEventIndex_, 0)),
537 positionToID_(std::move(other.positionToID_)),
538 operators_(std::exchange(other.operators_, nullptr))
539{}
540
541template <class Master_matrix>
542template <class Boundary_range>
543inline void RU_matrix<Master_matrix>::insert_boundary(const Boundary_range& boundary, Dimension dim)
544{
545 _insert_boundary(reducedMatrixR_.insert_boundary(boundary, dim));
546}
547
548template <class Master_matrix>
549template <class Boundary_range>
550inline void RU_matrix<Master_matrix>::insert_boundary(ID_index cellIndex, const Boundary_range& boundary, Dimension dim)
551{
552 // maps for possible shifting between column content and position indices used for birth events
553 if (cellIndex != nextEventIndex_) {
554 positionToID_.emplace(nextEventIndex_, cellIndex);
555 if constexpr (Master_matrix::Option_list::has_column_pairings) {
556 Pair_opt::_insert_id_position(cellIndex, nextEventIndex_);
557 }
558 }
559
560 _insert_boundary(reducedMatrixR_.insert_boundary(cellIndex, boundary, dim));
561}
562
563template <class Master_matrix>
564template <class Boundary_range>
565inline void RU_matrix<Master_matrix>::insert_maximal_cell(Index columnIndex, const Boundary_range& boundary,
566 Dimension dim) {
567 static_assert(Master_matrix::Option_list::has_vine_update,
568 "'insert_maximal_cell' is not implemented for the chosen options.");
569
570 insert_boundary(boundary, dim);
571
572 // If started with 0 columns, no swaps are needed
573 if (get_number_of_columns() == 1) return;
574
575 for (Index curr = get_number_of_columns() - 1; curr > columnIndex; --curr) {
576 Swap_opt::vine_swap(curr - 1);
577 }
578}
579
580template <class Master_matrix>
582{
583 if (inR) {
584 return reducedMatrixR_.get_column(columnIndex);
585 }
586 return mirrorMatrixU_.get_column(columnIndex);
587}
588
589template <class Master_matrix>
591{
592 static_assert(Master_matrix::Option_list::has_row_access, "'get_row' is not implemented for the chosen options.");
593
594 if (inR) {
595 return reducedMatrixR_.get_row(rowIndex);
596 }
597 return mirrorMatrixU_.get_row(rowIndex);
598}
599
600template <class Master_matrix>
602{
603 reducedMatrixR_.erase_empty_row(rowIndex);
604}
605
606template <class Master_matrix>
608{
609 static_assert(Master_matrix::Option_list::has_removable_columns && Master_matrix::Option_list::has_vine_update,
610 "'remove_maximal_cell' is not implemented for the chosen options.");
611
612 // TODO: is there an easy test to verify maximality even without row access?
613
614 for (Index curr = columnIndex; curr < nextEventIndex_ - 1; ++curr) {
615 Swap_opt::vine_swap(curr);
616 }
617
618 remove_last();
619}
620
621template <class Master_matrix>
623{
624 static_assert(Master_matrix::Option_list::has_removable_columns,
625 "'remove_last' is not implemented for the chosen options.");
626
627 if (nextEventIndex_ == 0) return; // empty matrix
628 --nextEventIndex_;
629
630 // assumes PosIdx == MatIdx for boundary matrices.
631 _remove_last_in_barcode(nextEventIndex_);
632
633 mirrorMatrixU_.remove_last();
634 if constexpr (Master_matrix::Option_list::has_map_column_container) {
635 pivotToColumnIndex_.erase(reducedMatrixR_.remove_last());
636 } else {
637 ID_index lastPivot = reducedMatrixR_.remove_last();
638 if (lastPivot != Master_matrix::template get_null_value<ID_index>())
639 pivotToColumnIndex_[lastPivot] = Master_matrix::template get_null_value<Index>();
640 }
641
642 // if has_column_pairings is true, then the element is already removed in _remove_last_in_barcode
643 // to avoid a second "find"
644 if constexpr (!Master_matrix::Option_list::has_column_pairings) {
645 positionToID_.erase(nextEventIndex_);
646 }
647}
648
649template <class Master_matrix>
651{
652 return reducedMatrixR_.get_max_dimension();
653}
654
655template <class Master_matrix>
657{
658 return reducedMatrixR_.get_number_of_columns();
659}
660
661template <class Master_matrix>
663 Index columnIndex) const
664{
665 return reducedMatrixR_.get_column_dimension(columnIndex);
666}
667
668template <class Master_matrix>
669inline void RU_matrix<Master_matrix>::add_to(Index sourceColumnIndex, Index targetColumnIndex)
670{
671 reducedMatrixR_.add_to(sourceColumnIndex, targetColumnIndex);
672 // U transposed to avoid row operations
673 if constexpr (Master_matrix::Option_list::is_z2)
674 mirrorMatrixU_.add_to(targetColumnIndex, sourceColumnIndex);
675 else
676 mirrorMatrixU_.multiply_source_and_add_to(
677 operators_->get_characteristic() - 1, targetColumnIndex, sourceColumnIndex);
678}
679
680template <class Master_matrix>
682 const Field_element& coefficient,
683 Index targetColumnIndex)
684{
685 reducedMatrixR_.multiply_target_and_add_to(sourceColumnIndex, coefficient, targetColumnIndex);
686 // U transposed to avoid row operations
687 mirrorMatrixU_.get_column(targetColumnIndex) *= coefficient;
688 mirrorMatrixU_.multiply_source_and_add_to(operators_->get_characteristic() - 1, targetColumnIndex, sourceColumnIndex);
689}
690
691template <class Master_matrix>
693 Index sourceColumnIndex,
694 Index targetColumnIndex)
695{
696 reducedMatrixR_.multiply_source_and_add_to(coefficient, sourceColumnIndex, targetColumnIndex);
697 // U transposed to avoid row operations
698 if constexpr (Master_matrix::Option_list::is_z2) {
699 if (coefficient) mirrorMatrixU_.add_to(targetColumnIndex, sourceColumnIndex);
700 } else {
701 mirrorMatrixU_.multiply_source_and_add_to(
702 operators_->get_characteristic() - coefficient, targetColumnIndex, sourceColumnIndex);
703 }
704}
705
706template <class Master_matrix>
707inline void RU_matrix<Master_matrix>::zero_entry(Index columnIndex, Index rowIndex, bool inR)
708{
709 if (inR) {
710 return reducedMatrixR_.zero_entry(columnIndex, rowIndex);
711 }
712 return mirrorMatrixU_.zero_entry(columnIndex, rowIndex);
713}
714
715template <class Master_matrix>
716inline void RU_matrix<Master_matrix>::zero_column(Index columnIndex, bool inR)
717{
718 if (inR) {
719 return reducedMatrixR_.zero_column(columnIndex);
720 }
721 return mirrorMatrixU_.zero_column(columnIndex);
722}
723
724template <class Master_matrix>
725inline bool RU_matrix<Master_matrix>::is_zero_entry(Index columnIndex, Index rowIndex, bool inR) const
726{
727 if (inR) {
728 return reducedMatrixR_.is_zero_entry(columnIndex, rowIndex);
729 }
730 return mirrorMatrixU_.is_zero_entry(columnIndex, rowIndex);
731}
732
733template <class Master_matrix>
734inline bool RU_matrix<Master_matrix>::is_zero_column(Index columnIndex, bool inR)
735{
736 if (inR) {
737 return reducedMatrixR_.is_zero_column(columnIndex);
738 }
739 return mirrorMatrixU_.is_zero_column(columnIndex);
740}
741
742template <class Master_matrix>
744{
745 if constexpr (Master_matrix::Option_list::has_map_column_container) {
746 return pivotToColumnIndex_.at(cellIndex);
747 } else {
748 return pivotToColumnIndex_[cellIndex];
749 }
750}
751
752template <class Master_matrix>
754{
755 return reducedMatrixR_.get_column(columnIndex).get_pivot();
756}
757
758template <class Master_matrix>
760{
761 if (this == &other) return *this;
762
763 Swap_opt::operator=(other);
764 Pair_opt::operator=(other);
765 Rep_opt::operator=(other);
766 reducedMatrixR_ = other.reducedMatrixR_;
767 mirrorMatrixU_ = other.mirrorMatrixU_;
768 pivotToColumnIndex_ = other.pivotToColumnIndex_;
769 nextEventIndex_ = other.nextEventIndex_;
770 positionToID_ = other.positionToID_;
771 operators_ = other.operators_;
772
773 return *this;
774}
775
776template <class Master_matrix>
778{
779 if (this == &other) return *this;
780
781 Pair_opt::operator=(std::move(other));
782 Swap_opt::operator=(std::move(other));
783 Rep_opt::operator=(std::move(other));
784
785 reducedMatrixR_ = std::move(other.reducedMatrixR_);
786 mirrorMatrixU_ = std::move(other.mirrorMatrixU_);
787 pivotToColumnIndex_ = std::move(other.pivotToColumnIndex_);
788 nextEventIndex_ = std::exchange(other.nextEventIndex_, 0);
789 positionToID_ = std::move(other.positionToID_);
790 operators_ = std::exchange(other.operators_, nullptr);
791}
792
793template <class Master_matrix>
794inline void RU_matrix<Master_matrix>::print()
795{
796 std::cout << "R_matrix:\n";
797 reducedMatrixR_.print();
798 std::cout << "U_matrix:\n";
799 mirrorMatrixU_.print();
800}
801
802template <class Master_matrix>
803inline void RU_matrix<Master_matrix>::_insert_boundary(Index currentIndex)
804{
805 mirrorMatrixU_.insert_column(currentIndex, 1);
806
807 if constexpr (!Master_matrix::Option_list::has_map_column_container) {
808 ID_index pivot = reducedMatrixR_.get_column(currentIndex).get_pivot();
809 if (pivot != Master_matrix::template get_null_value<ID_index>() && pivotToColumnIndex_.size() <= pivot)
810 pivotToColumnIndex_.resize((pivot + 1) * 2, Master_matrix::template get_null_value<Index>());
811 }
812
813 _reduce_last_column(currentIndex);
814 ++nextEventIndex_;
815}
816
817template <class Master_matrix>
819{
820 for (ID_index i = 0; i < reducedMatrixR_.get_number_of_columns(); i++) {
821 mirrorMatrixU_.insert_column(i, 1);
822 }
823}
824
825template <class Master_matrix>
827{
828 if constexpr (Master_matrix::Option_list::has_column_pairings) {
829 Pair_opt::_reserve(reducedMatrixR_.get_number_of_columns());
830 }
831
832 for (Index i = 0; i < reducedMatrixR_.get_number_of_columns(); i++) {
833 if (!(reducedMatrixR_.is_zero_column(i))) {
834 _reduce_column(i, i);
835 } else {
836 _add_bar(get_column_dimension(i), i);
837 }
838 }
839}
840
841template <class Master_matrix>
842inline void RU_matrix<Master_matrix>::_reduce_last_column(Index lastIndex)
843{
844 if (reducedMatrixR_.get_column(lastIndex).is_empty()) {
845 _add_bar(get_column_dimension(lastIndex), nextEventIndex_);
846 return;
847 }
848
849 _reduce_column(lastIndex, nextEventIndex_);
850}
851
852template <class Master_matrix>
853inline void RU_matrix<Master_matrix>::_reduce_column(Index target, Index eventIndex)
854{
855 Column& curr = reducedMatrixR_.get_column(target);
856 ID_index pivot = curr.get_pivot();
857 Index currIndex = _get_column_with_pivot(pivot);
858
859 while (pivot != Master_matrix::template get_null_value<ID_index>() &&
860 currIndex != Master_matrix::template get_null_value<Index>()) {
861 _reduce_column_by(target, currIndex);
862 pivot = curr.get_pivot();
863 currIndex = _get_column_with_pivot(pivot);
864 }
865
866 if (pivot != Master_matrix::template get_null_value<ID_index>()) {
867 if constexpr (Master_matrix::Option_list::has_map_column_container) {
868 pivotToColumnIndex_.try_emplace(pivot, target);
869 } else {
870 pivotToColumnIndex_[pivot] = target;
871 }
872 _update_barcode(pivot, eventIndex);
873 } else {
874 _add_bar(get_column_dimension(target), eventIndex);
875 }
876}
877
878template <class Master_matrix>
879inline void RU_matrix<Master_matrix>::_reduce_column_by(Index target, Index source)
880{
881 Column& curr = reducedMatrixR_.get_column(target);
882 if constexpr (Master_matrix::Option_list::is_z2) {
883 curr += reducedMatrixR_.get_column(source);
884 // to avoid having to do line operations, U is transposed
885 // TODO: explain this somewhere in the documentation...
886 mirrorMatrixU_.get_column(source).push_back(*mirrorMatrixU_.get_column(target).begin());
887 } else {
888 Column& toadd = reducedMatrixR_.get_column(source);
889 Field_element coef = toadd.get_pivot_value();
890 coef = operators_->get_inverse(coef);
891 operators_->multiply_inplace(coef, operators_->get_characteristic() - curr.get_pivot_value());
892
893 curr.multiply_source_and_add(toadd, coef);
894 auto entry = *mirrorMatrixU_.get_column(target).begin();
895 operators_->multiply_inplace(entry.get_element(), operators_->get_characteristic() - coef);
896 // to avoid having to do line operations, U is transposed
897 // TODO: explain this somewhere in the documentation...
898 mirrorMatrixU_.get_column(source).push_back(entry);
899 }
900}
901
902template <class Master_matrix>
904{
905 if (pivot == Master_matrix::template get_null_value<ID_index>())
906 return Master_matrix::template get_null_value<Index>();
907 if constexpr (Master_matrix::Option_list::has_map_column_container) {
908 auto it = pivotToColumnIndex_.find(pivot);
909 if (it == pivotToColumnIndex_.end()) return Master_matrix::template get_null_value<Index>();
910 return it->second;
911 } else {
912 if (pivot >= pivotToColumnIndex_.size()) return Master_matrix::template get_null_value<Index>();
913 return pivotToColumnIndex_[pivot];
914 }
915}
916
917template <class Master_matrix>
918inline void RU_matrix<Master_matrix>::_update_barcode(ID_index birthPivot, Pos_index death)
919{
920 if constexpr (Master_matrix::Option_list::has_column_pairings) {
921 Pair_opt::_update_barcode(birthPivot, death);
922 }
923}
924
925template <class Master_matrix>
926inline void RU_matrix<Master_matrix>::_add_bar(Dimension dim, Pos_index birth)
927{
928 if constexpr (Master_matrix::Option_list::has_column_pairings) {
929 Pair_opt::_add_bar(dim, birth);
930 }
931}
932
933template <class Master_matrix>
934inline void RU_matrix<Master_matrix>::_remove_last_in_barcode(Pos_index eventIndex)
935{
936 if constexpr (Master_matrix::Option_list::has_column_pairings) {
937 Pair_opt::_remove_last(eventIndex);
938 }
939}
940
941} // namespace persistence_matrix
942} // namespace Gudhi
943
944#endif // PM_RU_MATRIX_H
std::enable_if_t< std::is_integral_v< Integer_index > > multiply_target_and_add_to(Integer_index sourceColumnIndex, int coefficient, Integer_index targetColumnIndex)
Dimension get_column_dimension(Index columnIndex) const
std::conditional_t< RU_rep_cycles_options::has_intrusive_rows, boost::intrusive::list< Matrix_entry, boost::intrusive::constant_time_size< false >, boost::intrusive::base_hook< Base_hook_matrix_row > >, std::set< Matrix_entry, RowEntryComp > > Row
Definition Matrix.h:309
std::enable_if_t< std::is_integral_v< Integer_index > > multiply_source_and_add_to(int coefficient, Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
Returned_column & get_column(Index columnIndex)
typename RU_rep_cycles_options::Dimension Dimension
Definition Matrix.h:153
bool is_zero_entry(Index columnIndex, ID_index rowIndex)
typename RU_rep_cycles_options::Index Index
Definition Matrix.h:150
void zero_entry(Index columnIndex, ID_index rowIndex)
Insertion_return insert_boundary(const Boundary_range &boundary, Dimension dim=Matrix::get_null_value< Dimension >())
std::conditional_t< RU_rep_cycles_options::column_type==Column_types::HEAP, Matrix_heap_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::LIST, Matrix_list_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::SET, Matrix_set_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::UNORDERED_SET, Matrix_unordered_set_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::VECTOR, Matrix_vector_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::INTRUSIVE_LIST, Matrix_intrusive_list_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::NAIVE_VECTOR, Matrix_naive_vector_column, std::conditional_t< RU_rep_cycles_options::column_type==Column_types::SMALL_VECTOR, Matrix_small_vector_column, Matrix_intrusive_set_column > > > > > > > > Column
Definition Matrix.h:359
std::enable_if_t< std::is_integral_v< Integer_index > > add_to(Integer_index sourceColumnIndex, Integer_index targetColumnIndex)
void insert_maximal_cell(Index columnIndex, const Boundary_range &boundary, Dimension dim=Matrix::get_null_value< Dimension >())
Matrix structure to store the ordered boundary matrix of a filtered complex in order to compute its ...
Definition RU_matrix.h:47
RU_matrix(const std::vector< Boundary_range > &orderedBoundaries, Column_settings *colSettings)
Constructs a new matrix from the given ranges of Matrix::Entry_representative. Each range corresponds...
Definition RU_matrix.h:474
void remove_maximal_cell(Index columnIndex)
Only available if PersistenceMatrixOptions::has_removable_columns and PersistenceMatrixOptions::has_v...
Definition RU_matrix.h:607
bool is_zero_column(Index columnIndex, bool inR=true)
Indicates if the column at given index has value zero in if inR is true or in if inR is false.
Definition RU_matrix.h:734
typename Matrix< PersistenceMatrixOptions >::ID_index ID_index
Definition RU_matrix.h:67
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 RU_matrix.h:565
void add_to(Index sourceColumnIndex, Index targetColumnIndex)
Adds column at sourceColumnIndex onto the column at targetColumnIndex in the matrix.
Definition RU_matrix.h:669
bool is_zero_entry(Index columnIndex, Index rowIndex, bool inR=true) const
Indicates if the entry at given coordinates has value zero in if inR is true or in if inR is false.
Definition RU_matrix.h:725
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Removes the last cell in t...
Definition RU_matrix.h:622
void insert_boundary(ID_index cellIndex, const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >())
It does the same as the other version, but allows the boundary cells to be identified without restric...
Definition RU_matrix.h:550
typename Matrix< PersistenceMatrixOptions >::Element Field_element
Definition RU_matrix.h:58
Index get_column_with_pivot(Index cellIndex) const
Returns the MatIdx index of the column which has the given row index as pivot in ....
Definition RU_matrix.h:743
RU_matrix(RU_matrix &&other) noexcept
Move constructor.
Definition RU_matrix.h:529
typename Matrix< PersistenceMatrixOptions >::Pos_index Pos_index
Definition RU_matrix.h:68
void multiply_source_and_add_to(const Field_element &coefficient, Index sourceColumnIndex, Index targetColumnIndex)
Multiplies the source column with the coefficient before adding it to the target column....
Definition RU_matrix.h:692
typename Matrix< PersistenceMatrixOptions >::Entry_constructor Entry_constructor
Definition RU_matrix.h:62
RU_matrix(Column_settings *colSettings)
Constructs an empty matrix.
Definition RU_matrix.h:462
void erase_empty_row(Index rowIndex)
If PersistenceMatrixOptions::has_row_access and PersistenceMatrixOptions::has_removable_rows are true...
Definition RU_matrix.h:601
void zero_column(Index columnIndex, bool inR=true)
Zeroes the column at the given index in if inR is true or in if inR is false. Should be used with c...
Definition RU_matrix.h:716
typename Matrix< PersistenceMatrixOptions >::Row Row
Definition RU_matrix.h:60
typename Matrix< PersistenceMatrixOptions >::Field_operators Field_operators
Definition RU_matrix.h:57
Dimension get_max_dimension() const
Returns the maximal dimension of a cell stored in the matrix. Only available if PersistenceMatrixOpti...
Definition RU_matrix.h:650
RU_matrix & operator=(RU_matrix &&other) noexcept
Move assign operator.
Definition RU_matrix.h:777
typename Matrix< PersistenceMatrixOptions >::Column Column
Definition RU_matrix.h:59
void zero_entry(Index columnIndex, Index rowIndex, bool inR=true)
Zeroes the entry at the given coordinates in if inR is true or in if inR is false....
Definition RU_matrix.h:707
typename Matrix< PersistenceMatrixOptions >::Index Index
Definition RU_matrix.h:66
typename Matrix< PersistenceMatrixOptions >::Boundary Boundary
Definition RU_matrix.h:65
Index get_pivot(Index columnIndex)
Returns the row index of the pivot of the given column in .
Definition RU_matrix.h:753
RU_matrix(unsigned int numberOfColumns, Column_settings *colSettings)
Constructs a new empty matrix and reserves space for the given number of columns.
Definition RU_matrix.h:495
typename Matrix< PersistenceMatrixOptions >::Dimension Dimension
Definition RU_matrix.h:69
RU_matrix(const RU_matrix &matrixToCopy, Column_settings *colSettings=nullptr)
Copy constructor. If colSettings is not a null pointer, its value is kept instead of the one in the c...
Definition RU_matrix.h:516
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition RU_matrix.h:388
Dimension get_column_dimension(Index columnIndex) const
Returns the dimension of the given column.
Definition RU_matrix.h:662
Index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition RU_matrix.h:656
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 RU_matrix.h:543
Column & get_column(Index columnIndex, bool inR=true)
Returns the column at the given MatIdx index in if inR is true and in if inR is false....
Definition RU_matrix.h:581
friend void swap(RU_matrix &matrix1, RU_matrix &matrix2) noexcept
Swap operator.
Definition RU_matrix.h:412
void multiply_target_and_add_to(Index sourceColumnIndex, const Field_element &coefficient, Index targetColumnIndex)
Multiplies the target column with the coefficient and then adds the source column to it....
Definition RU_matrix.h:681
RU_matrix & operator=(const RU_matrix &other)
Assign operator.
Definition RU_matrix.h:759
typename Matrix< PersistenceMatrixOptions >::Column_settings Column_settings
Definition RU_matrix.h:63
Row & get_row(Index rowIndex, bool inR=true)
Returns the row at the given row index in if inR is true and in if inR is false....
Definition RU_matrix.h:590
Class managing the barcode for RU_matrix if the option was enabled.
Definition ru_pairing.h:50
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14