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-24 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
17#ifndef PM_RU_MATRIX_H
18#define PM_RU_MATRIX_H
19
20#include <vector>
21#include <utility> //std::swap, std::move & std::exchange
22#include <iostream> //print() only
23
24namespace Gudhi {
25namespace persistence_matrix {
26
38template <class Master_matrix>
39class RU_matrix : public Master_matrix::RU_pairing_option,
40 public Master_matrix::RU_vine_swap_option,
41 public Master_matrix::RU_representative_cycles_option
42{
43 public:
47 using Field_operators = typename Master_matrix::Field_operators;
48 using Field_element_type = typename Master_matrix::element_type;
49 using Column_type = typename Master_matrix::Column_type;
50 using Row_type = typename Master_matrix::Row_type;
52 using Cell_constructor = typename Master_matrix::Cell_constructor;
53 using Column_settings = typename Master_matrix::Column_settings;
55 using boundary_type = typename Master_matrix::boundary_type;
56 using index = typename Master_matrix::index;
57 using id_index = typename Master_matrix::id_index;
58 using pos_index = typename Master_matrix::pos_index;
59 using dimension_type = typename Master_matrix::dimension_type;
67 RU_matrix(Column_settings* colSettings);
87 template <class Boundary_type = boundary_type>
88 RU_matrix(const std::vector<Boundary_type>& orderedBoundaries,
89 Column_settings* colSettings);
97 RU_matrix(unsigned int numberOfColumns, Column_settings* colSettings);
107 RU_matrix(const RU_matrix& matrixToCopy,
108 Column_settings* colSettings = nullptr);
114 RU_matrix(RU_matrix&& other) noexcept;
115
134 template <class Boundary_type = boundary_type>
135 void insert_boundary(const Boundary_type& boundary, dimension_type dim = -1);
152 template <class Boundary_type = boundary_type>
153 void insert_boundary(id_index faceIndex, const Boundary_type& boundary, dimension_type dim = -1);
168 Column_type& get_column(index columnIndex, bool inR = true);
183 Row_type& get_row(index rowIndex, bool inR = true);
201 void erase_empty_row(index rowIndex);
214 void remove_maximal_face(index columnIndex);
221 void remove_last();
222
242 dimension_type get_column_dimension(index columnIndex) const;
243
254 void add_to(index sourceColumnIndex, index targetColumnIndex);
267 void multiply_target_and_add_to(index sourceColumnIndex,
268 const Field_element_type& coefficient,
269 index targetColumnIndex);
282 void multiply_source_and_add_to(const Field_element_type& coefficient,
283 index sourceColumnIndex,
284 index targetColumnIndex);
285
296 void zero_cell(index columnIndex, index rowIndex, bool inR = true);
306 void zero_column(index columnIndex, bool inR = true);
318 bool is_zero_cell(index columnIndex, index rowIndex, bool inR = true) const;
331 bool is_zero_column(index columnIndex, bool inR = true);
332
340 index get_column_with_pivot(index faceIndex) const;
347 index get_pivot(index columnIndex);
348
355 void reset(Column_settings* colSettings) {
356 reducedMatrixR_.reset(colSettings);
357 mirrorMatrixU_.reset(colSettings);
358 pivotToColumnIndex_.clear();
359 nextEventIndex_ = 0;
360 if constexpr (!Master_matrix::Option_list::is_z2){
361 operators_ = &(colSettings->operators);
362 }
363 }
364
368 RU_matrix& operator=(const RU_matrix& other);
372 friend void swap(RU_matrix& matrix1, RU_matrix& matrix2) {
373 swap(static_cast<typename Master_matrix::RU_pairing_option&>(matrix1),
374 static_cast<typename Master_matrix::RU_pairing_option&>(matrix2));
375 swap(static_cast<typename Master_matrix::RU_vine_swap_option&>(matrix1),
376 static_cast<typename Master_matrix::RU_vine_swap_option&>(matrix2));
377 swap(static_cast<typename Master_matrix::RU_representative_cycles_option&>(matrix1),
378 static_cast<typename Master_matrix::RU_representative_cycles_option&>(matrix2));
379 swap(matrix1.reducedMatrixR_, matrix2.reducedMatrixR_);
380 swap(matrix1.mirrorMatrixU_, matrix2.mirrorMatrixU_);
381 matrix1.pivotToColumnIndex_.swap(matrix2.pivotToColumnIndex_);
382 std::swap(matrix1.nextEventIndex_, matrix2.nextEventIndex_);
383 std::swap(matrix1.operators_, matrix2.operators_);
384 }
385
386 void print(); // for debug
387
388 private:
389 using swap_opt = typename Master_matrix::RU_vine_swap_option;
390 using pair_opt = typename Master_matrix::RU_pairing_option;
391 using rep_opt = typename Master_matrix::RU_representative_cycles_option;
392 using dictionnary_type = typename Master_matrix::template dictionnary_type<index>;
393 using barcode_type = typename Master_matrix::barcode_type;
394 using bar_dictionnary_type = typename Master_matrix::bar_dictionnary_type;
395 using r_matrix_type = typename Master_matrix::Boundary_matrix_type;
396 using u_matrix_type = typename Master_matrix::Base_matrix_type;
397
398 friend rep_opt; // direct access to the two matrices
399 friend swap_opt; // direct access to the two matrices
400
401 r_matrix_type reducedMatrixR_;
402 // TODO: make U not accessible by default and add option to enable access? Inaccessible, it
403 // needs less options and we could avoid some ifs.
404 u_matrix_type mirrorMatrixU_;
405 dictionnary_type pivotToColumnIndex_;
406 pos_index nextEventIndex_;
407 Field_operators* operators_;
410 void _insert_boundary(index currentIndex);
411 void _initialize_U();
412 void _reduce();
413 void _reduce_last_column(index lastIndex);
414 void _reduce_column(index target, index eventIndex);
415 void _reduce_column_by(index target, index source);
416 void _update_barcode(pos_index birth, pos_index death);
417 void _add_bar(dimension_type dim, pos_index birth);
418
419 constexpr barcode_type& _barcode();
420 constexpr bar_dictionnary_type& _indexToBar();
421};
422
423template <class Master_matrix>
425 : pair_opt(),
426 swap_opt(),
427 rep_opt(),
428 reducedMatrixR_(colSettings),
429 mirrorMatrixU_(colSettings),
430 nextEventIndex_(0),
431 operators_(nullptr)
432{
433 if constexpr (!Master_matrix::Option_list::is_z2){
434 operators_ = &(colSettings->operators);
435 }
436}
437
438template <class Master_matrix>
439template <class Boundary_type>
440inline RU_matrix<Master_matrix>::RU_matrix(const std::vector<Boundary_type>& orderedBoundaries,
441 Column_settings* colSettings)
442 : pair_opt(),
443 swap_opt(),
444 rep_opt(),
445 reducedMatrixR_(orderedBoundaries, colSettings),
446 mirrorMatrixU_(orderedBoundaries.size(), colSettings),
447 nextEventIndex_(orderedBoundaries.size()),
448 operators_(nullptr)
449{
450 if constexpr (!Master_matrix::Option_list::is_z2){
451 operators_ = &(colSettings->operators);
452 }
453
454 if constexpr (Master_matrix::Option_list::has_map_column_container) {
455 pivotToColumnIndex_.reserve(orderedBoundaries.size());
456 } else {
457 pivotToColumnIndex_.resize(orderedBoundaries.size(), -1);
458 }
459
460 _initialize_U();
461 _reduce();
462}
463
464template <class Master_matrix>
465inline RU_matrix<Master_matrix>::RU_matrix(unsigned int numberOfColumns,
466 Column_settings* colSettings)
467 : pair_opt(),
468 swap_opt(),
469 rep_opt(),
470 reducedMatrixR_(numberOfColumns, colSettings),
471 mirrorMatrixU_(numberOfColumns, colSettings),
472 nextEventIndex_(0),
473 operators_(nullptr)
474{
475 if constexpr (!Master_matrix::Option_list::is_z2){
476 operators_ = &(colSettings->operators);
477 }
478
479 if constexpr (Master_matrix::Option_list::has_map_column_container) {
480 pivotToColumnIndex_.reserve(numberOfColumns);
481 } else {
482 pivotToColumnIndex_.resize(numberOfColumns, -1);
483 }
484 if constexpr (Master_matrix::Option_list::has_column_pairings) {
485 _indexToBar().reserve(numberOfColumns);
486 }
487 if constexpr (Master_matrix::Option_list::has_vine_update) {
488 swap_opt::positionToRowIdx_.reserve(numberOfColumns);
489 }
490}
491
492template <class Master_matrix>
494 Column_settings* colSettings)
495 : pair_opt(static_cast<const pair_opt&>(matrixToCopy)),
496 swap_opt(static_cast<const swap_opt&>(matrixToCopy)),
497 rep_opt(static_cast<const rep_opt&>(matrixToCopy)),
498 reducedMatrixR_(matrixToCopy.reducedMatrixR_, colSettings),
499 mirrorMatrixU_(matrixToCopy.mirrorMatrixU_, colSettings),
500 pivotToColumnIndex_(matrixToCopy.pivotToColumnIndex_),
501 nextEventIndex_(matrixToCopy.nextEventIndex_),
502 operators_(colSettings == nullptr ? matrixToCopy.operators_ : nullptr)
503{
504 if constexpr (!Master_matrix::Option_list::is_z2){
505 if (colSettings != nullptr) operators_ = &(colSettings->operators);
506 }
507}
508
509template <class Master_matrix>
511 : pair_opt(std::move(static_cast<pair_opt&>(other))),
512 swap_opt(std::move(static_cast<swap_opt&>(other))),
513 rep_opt(std::move(static_cast<rep_opt&>(other))),
514 reducedMatrixR_(std::move(other.reducedMatrixR_)),
515 mirrorMatrixU_(std::move(other.mirrorMatrixU_)),
516 pivotToColumnIndex_(std::move(other.pivotToColumnIndex_)),
517 nextEventIndex_(std::exchange(other.nextEventIndex_, 0)),
518 operators_(std::exchange(other.operators_, nullptr))
519{}
520
521template <class Master_matrix>
522template <class Boundary_type>
523inline void RU_matrix<Master_matrix>::insert_boundary(const Boundary_type& boundary, dimension_type dim)
524{
525 auto id = reducedMatrixR_.insert_boundary(boundary, dim);
526 if constexpr (Master_matrix::Option_list::has_vine_update) swap_opt::positionToRowIdx_.push_back(id);
527 _insert_boundary(id);
528}
529
530template <class Master_matrix>
531template <class Boundary_type>
533 const Boundary_type& boundary,
534 dimension_type dim)
535{
536 if constexpr (Master_matrix::Option_list::has_vine_update) {
537 swap_opt::positionToRowIdx_.push_back(faceIndex);
538 }
539 _insert_boundary(reducedMatrixR_.insert_boundary(faceIndex, boundary, dim));
540}
541
542template <class Master_matrix>
544 bool inR)
545{
546 if (inR) {
547 return reducedMatrixR_.get_column(columnIndex);
548 }
549 return mirrorMatrixU_.get_column(columnIndex);
550}
551
552template <class Master_matrix>
554{
555 static_assert(Master_matrix::Option_list::has_row_access, "'get_row' is not implemented for the chosen options.");
556
557 if (inR) {
558 return reducedMatrixR_.get_row(rowIndex);
559 }
560 return mirrorMatrixU_.get_row(rowIndex);
561}
562
563template <class Master_matrix>
565{
566 reducedMatrixR_.erase_empty_row(rowIndex);
567}
568
569template <class Master_matrix>
571{
572 static_assert(Master_matrix::Option_list::has_removable_columns && Master_matrix::Option_list::has_vine_update,
573 "'remove_maximal_face' is not implemented for the chosen options.");
574
575 // TODO: is there an easy test to verify maximality even without row access?
576
577 for (index curr = columnIndex; curr < nextEventIndex_ - 1; ++curr) {
578 swap_opt::vine_swap(curr);
579 }
580
581 remove_last();
582}
583
584template <class Master_matrix>
586{
587 static_assert(Master_matrix::Option_list::has_removable_columns,
588 "'remove_last' is not implemented for the chosen options.");
589
590 if (nextEventIndex_ == 0) return; // empty matrix
591 --nextEventIndex_;
592
593 // assumes PosIdx == MatIdx for boundary matrices.
594 if constexpr (Master_matrix::Option_list::has_column_pairings) {
595 if constexpr (Master_matrix::hasFixedBarcode) {
596 auto& bar = _barcode()[_indexToBar()[nextEventIndex_]];
597 if (bar.death == static_cast<pos_index>(-1)) { // birth
598 _barcode().pop_back(); // sorted by birth and nextEventIndex_ has to be the heighest one
599 } else { // death
600 bar.death = -1;
601 };
602 _indexToBar().pop_back();
603 } else { // birth order eventually shuffled by vine updates. No sort possible to keep the matchings.
604 auto it = _indexToBar().find(nextEventIndex_);
605 typename barcode_type::iterator bar = it->second;
606
607 if (bar->death == static_cast<pos_index>(-1))
608 _barcode().erase(bar);
609 else
610 bar->death = -1;
611
612 _indexToBar().erase(it);
613 }
614 }
615
616 mirrorMatrixU_.remove_last();
617 if constexpr (Master_matrix::Option_list::has_map_column_container) {
618 pivotToColumnIndex_.erase(reducedMatrixR_.remove_last());
619 } else {
620 id_index lastPivot = reducedMatrixR_.remove_last();
621 if (lastPivot != static_cast<id_index>(-1)) pivotToColumnIndex_[lastPivot] = -1;
622 }
623
624 if constexpr (Master_matrix::Option_list::has_vine_update) {
625 swap_opt::positionToRowIdx_.pop_back();
626 }
627}
628
629template <class Master_matrix>
631{
632 return reducedMatrixR_.get_max_dimension();
633}
634
635template <class Master_matrix>
637{
638 return reducedMatrixR_.get_number_of_columns();
639}
640
641template <class Master_matrix>
643 index columnIndex) const
644{
645 return reducedMatrixR_.get_column_dimension(columnIndex);
646}
647
648template <class Master_matrix>
649inline void RU_matrix<Master_matrix>::add_to(index sourceColumnIndex, index targetColumnIndex)
650{
651 reducedMatrixR_.add_to(sourceColumnIndex, targetColumnIndex);
652 //U transposed to avoid row operations
653 if constexpr (Master_matrix::Option_list::has_vine_update)
654 mirrorMatrixU_.add_to(targetColumnIndex, sourceColumnIndex);
655 else
656 mirrorMatrixU_.add_to(sourceColumnIndex, targetColumnIndex);
657}
658
659template <class Master_matrix>
661 const Field_element_type& coefficient,
662 index targetColumnIndex)
663{
664 reducedMatrixR_.multiply_target_and_add_to(sourceColumnIndex, coefficient, targetColumnIndex);
665 mirrorMatrixU_.multiply_target_and_add_to(sourceColumnIndex, coefficient, targetColumnIndex);
666}
667
668template <class Master_matrix>
670 index sourceColumnIndex,
671 index targetColumnIndex)
672{
673 reducedMatrixR_.multiply_source_and_add_to(coefficient, sourceColumnIndex, targetColumnIndex);
674 mirrorMatrixU_.multiply_source_and_add_to(coefficient, sourceColumnIndex, targetColumnIndex);
675}
676
677template <class Master_matrix>
678inline void RU_matrix<Master_matrix>::zero_cell(index columnIndex, index rowIndex, bool inR)
679{
680 if (inR) {
681 return reducedMatrixR_.zero_cell(columnIndex, rowIndex);
682 }
683 return mirrorMatrixU_.zero_cell(columnIndex, rowIndex);
684}
685
686template <class Master_matrix>
687inline void RU_matrix<Master_matrix>::zero_column(index columnIndex, bool inR)
688{
689 if (inR) {
690 return reducedMatrixR_.zero_column(columnIndex);
691 }
692 return mirrorMatrixU_.zero_column(columnIndex);
693}
694
695template <class Master_matrix>
696inline bool RU_matrix<Master_matrix>::is_zero_cell(index columnIndex, index rowIndex, bool inR) const
697{
698 if (inR) {
699 return reducedMatrixR_.is_zero_cell(columnIndex, rowIndex);
700 }
701 return mirrorMatrixU_.is_zero_cell(columnIndex, rowIndex);
702}
703
704template <class Master_matrix>
705inline bool RU_matrix<Master_matrix>::is_zero_column(index columnIndex, bool inR)
706{
707 if (inR) {
708 return reducedMatrixR_.is_zero_column(columnIndex);
709 }
710 return mirrorMatrixU_.is_zero_column(columnIndex);
711}
712
713template <class Master_matrix>
715 index faceIndex) const
716{
717 if constexpr (Master_matrix::Option_list::has_map_column_container) {
718 return pivotToColumnIndex_.at(faceIndex);
719 } else {
720 return pivotToColumnIndex_[faceIndex];
721 }
722}
723
724template <class Master_matrix>
726{
727 return reducedMatrixR_.get_column(columnIndex).get_pivot();
728}
729
730template <class Master_matrix>
732{
733 swap_opt::operator=(other);
734 pair_opt::operator=(other);
735 rep_opt::operator=(other);
736 reducedMatrixR_ = other.reducedMatrixR_;
737 mirrorMatrixU_ = other.mirrorMatrixU_;
738 pivotToColumnIndex_ = other.pivotToColumnIndex_;
739 nextEventIndex_ = other.nextEventIndex_;
740 operators_ = other.operators_;
741 return *this;
742}
743
744template <class Master_matrix>
746{
747 std::cout << "R_matrix:\n";
748 reducedMatrixR_.print();
749 std::cout << "U_matrix:\n";
750 mirrorMatrixU_.print();
751}
752
753template <class Master_matrix>
754inline void RU_matrix<Master_matrix>::_insert_boundary(index currentIndex)
755{
756 if constexpr (Master_matrix::Option_list::is_z2) {
757 mirrorMatrixU_.insert_column({currentIndex});
758 } else {
759 mirrorMatrixU_.insert_column({{currentIndex, 1}});
760 }
761
762 if constexpr (!Master_matrix::Option_list::has_map_column_container) {
763 while (pivotToColumnIndex_.size() <= currentIndex)
764 pivotToColumnIndex_.resize((pivotToColumnIndex_.size() + 1) * 2, -1);
765 }
766
767 _reduce_last_column(currentIndex);
768 ++nextEventIndex_;
769}
770
771template <class Master_matrix>
773{
774 typename std::conditional<Master_matrix::Option_list::is_z2, index, std::pair<index, Field_element_type> >::type id;
775 if constexpr (!Master_matrix::Option_list::is_z2) id.second = 1;
776
777 for (id_index i = 0; i < reducedMatrixR_.get_number_of_columns(); i++) {
778 if constexpr (Master_matrix::Option_list::is_z2)
779 id = i;
780 else
781 id.first = i;
782 mirrorMatrixU_.insert_column({id});
783 }
784}
785
786template <class Master_matrix>
788{
789 if constexpr (Master_matrix::Option_list::has_column_pairings) {
790 _indexToBar().reserve(reducedMatrixR_.get_number_of_columns());
791 }
792 if constexpr (Master_matrix::Option_list::has_vine_update) {
793 swap_opt::positionToRowIdx_.reserve(reducedMatrixR_.get_number_of_columns());
794 }
795
796 for (index i = 0; i < reducedMatrixR_.get_number_of_columns(); i++) {
797 if constexpr (Master_matrix::Option_list::has_vine_update) {
798 swap_opt::positionToRowIdx_.push_back(i);
799 }
800 if (!(reducedMatrixR_.is_zero_column(i))) {
801 _reduce_column(i, i);
802 } else {
803 _add_bar(get_column_dimension(i), i);
804 }
805 }
806}
807
808template <class Master_matrix>
809inline void RU_matrix<Master_matrix>::_reduce_last_column(index lastIndex)
810{
811 if (reducedMatrixR_.get_column(lastIndex).is_empty()) {
812 _add_bar(get_column_dimension(lastIndex), nextEventIndex_);
813 return;
814 }
815
816 _reduce_column(lastIndex, nextEventIndex_);
817}
818
819template <class Master_matrix>
820inline void RU_matrix<Master_matrix>::_reduce_column(index target, index eventIndex)
821{
822 auto get_column_with_pivot_ = [&](id_index pivot) -> index {
823 if (pivot == static_cast<id_index>(-1)) return -1;
824 if constexpr (Master_matrix::Option_list::has_map_column_container) {
825 auto it = pivotToColumnIndex_.find(pivot);
826 if (it == pivotToColumnIndex_.end())
827 return -1;
828 else
829 return it->second;
830 } else {
831 return pivotToColumnIndex_[pivot];
832 }
833 };
834
835 Column_type& curr = reducedMatrixR_.get_column(target);
836 id_index pivot = curr.get_pivot();
837 index currIndex = get_column_with_pivot_(pivot);
838
839 while (pivot != static_cast<id_index>(-1) && currIndex != static_cast<index>(-1)) {
840 _reduce_column_by(target, currIndex);
841 pivot = curr.get_pivot();
842 currIndex = get_column_with_pivot_(pivot);
843 }
844
845 if (pivot != static_cast<id_index>(-1)) {
846 if constexpr (Master_matrix::Option_list::has_map_column_container) {
847 pivotToColumnIndex_.try_emplace(pivot, target);
848 } else {
849 pivotToColumnIndex_[pivot] = target;
850 }
851 _update_barcode(pivot, eventIndex);
852 } else {
853 _add_bar(get_column_dimension(target), eventIndex);
854 }
855}
856
857template <class Master_matrix>
858inline void RU_matrix<Master_matrix>::_reduce_column_by(index target, index source)
859{
860 Column_type& curr = reducedMatrixR_.get_column(target);
861 if constexpr (Master_matrix::Option_list::is_z2) {
862 curr += reducedMatrixR_.get_column(source);
863 //to avoid having to do line operations during vineyards, U is transposed
864 //TODO: explain this somewhere in the documentation...
865 if constexpr (Master_matrix::Option_list::has_vine_update)
866 mirrorMatrixU_.get_column(source) += mirrorMatrixU_.get_column(target);
867 else
868 mirrorMatrixU_.get_column(target) += mirrorMatrixU_.get_column(source);
869 } else {
870 Column_type& toadd = reducedMatrixR_.get_column(source);
871 Field_element_type coef = toadd.get_pivot_value();
872 coef = operators_->get_inverse(coef);
873 operators_->multiply_inplace(coef, operators_->get_characteristic() - curr.get_pivot_value());
874
875 curr.multiply_source_and_add(toadd, coef);
876 mirrorMatrixU_.multiply_source_and_add_to(coef, source, target);
877 // mirrorMatrixU_.get_column(target).multiply_source_and_add(mirrorMatrixU_.get_column(source), coef);
878 }
879}
880
881template <class Master_matrix>
882inline void RU_matrix<Master_matrix>::_update_barcode(pos_index birth, pos_index death)
883{
884 if constexpr (Master_matrix::Option_list::has_column_pairings) {
885 if constexpr (Master_matrix::hasFixedBarcode || !Master_matrix::Option_list::has_removable_columns) {
886 _barcode()[_indexToBar()[birth]].death = death;
887 _indexToBar().push_back(_indexToBar()[birth]);
888 } else {
889 auto& barIt = _indexToBar().at(birth);
890 barIt->death = death;
891 _indexToBar().try_emplace(death, barIt); // list so iterators are stable
892 }
893 }
894}
895
896template <class Master_matrix>
897inline void RU_matrix<Master_matrix>::_add_bar(dimension_type dim, pos_index birth)
898{
899 if constexpr (Master_matrix::Option_list::has_column_pairings) {
900 _barcode().emplace_back(dim, birth, -1);
901 if constexpr (Master_matrix::hasFixedBarcode || !Master_matrix::Option_list::has_removable_columns) {
902 _indexToBar().push_back(_barcode().size() - 1);
903 } else {
904 _indexToBar().try_emplace(birth, --_barcode().end());
905 }
906 }
907}
908
909template <class Master_matrix>
911{
912 if constexpr (Master_matrix::Option_list::has_vine_update)
913 return swap_opt::template RU_pairing<Master_matrix>::barcode_;
914 else
915 return pair_opt::barcode_;
916}
917
918template <class Master_matrix>
919inline constexpr typename RU_matrix<Master_matrix>::bar_dictionnary_type& RU_matrix<Master_matrix>::_indexToBar()
920{
921 if constexpr (Master_matrix::Option_list::has_vine_update)
922 return swap_opt::template RU_pairing<Master_matrix>::indexToBar_;
923 else
924 return pair_opt::indexToBar_;
925}
926
927} // namespace persistence_matrix
928} // namespace Gudhi
929
930#endif // PM_RU_MATRIX_H
Data structure for matrices, and in particular thought for matrices representing filtered complexes i...
Definition matrix.h:143
bool is_zero_cell(index columnIndex, id_index rowIndex)
Indicates if the cell at given coordinates has value zero.
Definition matrix.h:1880
void zero_cell(index columnIndex, id_index rowIndex)
Zeroes the cell at the given coordinates. Not available for chain matrices and for base matrices with...
Definition matrix.h:1836
bool is_zero_column(index columnIndex)
Indicates if the column at given index has value zero.
Definition matrix.h:1899
returned_column_type & get_column(index columnIndex)
Returns the column at the given MatIdx index. For RU matrices, is equivalent to get_column(columnInde...
Definition matrix.h:1609
void erase_empty_row(id_index rowIndex)
The effect varies depending on the matrices and the options:
Definition matrix.h:1680
id_index get_pivot(index columnIndex)
Returns the row index of the pivot of the given column. Only available for non-basic matrices.
Definition matrix.h:1930
void remove_maximal_face(index columnIndex)
Only available for RU and chain matrices and if PersistenceMatrixOptions::has_removable_columns and P...
Definition matrix.h:1690
dimension_type get_max_dimension() const
Returns the maximal dimension of a face stored in the matrix. Only available for non-basic matrices a...
Definition matrix.h:1732
typename std::conditional< PersistenceMatrixOptions::has_intrusive_rows, boost::intrusive::list< Cell_type, boost::intrusive::constant_time_size< false >, boost::intrusive::base_hook< base_hook_matrix_row > >, std::set< Cell_type, RowCellComp > >::type Row_type
Type of the rows stored in the matrix. Is either an intrusive list of Cell_type (not ordered) if Pers...
Definition matrix.h:281
typename std::conditional< hasFixedBarcode, std::vector< Bar >, typename std::conditional< PersistenceMatrixOptions::has_removable_columns, std::list< Bar >, std::vector< Bar > >::type >::type barcode_type
Type of the computed barcode. It is either a list of Matrix::Bar or a vector of Matrix::Bar,...
Definition matrix.h:450
returned_row_type & get_row(id_index rowIndex)
Only available if PersistenceMatrixOptions::has_row_access is true. Returns the row at the given row ...
Definition matrix.h:1637
dimension_type get_column_dimension(index columnIndex) const
Returns the dimension of the given face. Only available for non-basic matrices.
Definition matrix.h:1747
typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::HEAP, Heap_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::LIST, List_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::SET, Set_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::UNORDERED_SET, Unordered_set_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::VECTOR, Vector_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::INTRUSIVE_LIST, Intrusive_list_column_type, typename std::conditional< PersistenceMatrixOptions::column_type==Column_types::NAIVE_VECTOR, Naive_vector_column_type, Intrusive_set_column_type >::type >::type >::type >::type >::type >::type >::type Column_type
Type of the columns stored in the matrix. The type depends on the value of PersistenceMatrixOptions::...
Definition matrix.h:370
typename PersistenceMatrixOptions::index_type index
Definition matrix.h:146
std::enable_if_t< std::is_integral_v< Index_type > > add_to(Index_type sourceColumnIndex, Index_type targetColumnIndex)
Adds column at sourceColumnIndex onto the column at targetColumnIndex in the matrix....
Definition matrix.h:1757
insertion_return_type 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 matrix.h:1572
std::enable_if_t< std::is_integral_v< Index_type > > multiply_target_and_add_to(Index_type sourceColumnIndex, int coefficient, Index_type targetColumnIndex)
Multiplies the target column with the coefficient and then adds the source column to it....
Definition matrix.h:1777
void insert_column(const Container_type &column)
Inserts a new ordered column at the end of the matrix by copying the given range of cell_rep_type....
Definition matrix.h:1538
void remove_last()
Removes the last inserted column/face from the matrix. If the matrix is non basic,...
Definition matrix.h:1718
void zero_column(index columnIndex)
Zeroes the column at the given index. Not available for chain matrices and for base matrices with col...
Definition matrix.h:1858
index get_column_with_pivot(id_index faceIndex) const
Returns the MatIdx index of the column which has the given row index as pivot. Only available for RU ...
Definition matrix.h:1918
Matrix & operator=(Matrix other)
Assign operator.
Definition matrix.h:1939
std::enable_if_t< std::is_integral_v< Index_type > > multiply_source_and_add_to(int coefficient, Index_type sourceColumnIndex, Index_type targetColumnIndex)
Multiplies the source column with the coefficient before adding it to the target column....
Definition matrix.h:1807
index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition matrix.h:1741
typename PersistenceMatrixOptions::dimension_type dimension_type
Definition matrix.h:149
Matrix structure to store the ordered boundary matrix of a filtered complex in order to compute its ...
Definition ru_matrix.h:42
index get_pivot(index columnIndex)
Returns the row index of the pivot of the given column in .
Definition ru_matrix.h:725
dimension_type get_max_dimension() const
Returns the maximal dimension of a face stored in the matrix. Only available if PersistenceMatrixOpti...
Definition ru_matrix.h:630
Column_type & 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:543
typename Master_matrix::dimension_type dimension_type
Definition ru_matrix.h:59
void add_to(index sourceColumnIndex, index targetColumnIndex)
Adds column at sourceColumnIndex onto the column at targetColumnIndex in the matrix.
Definition ru_matrix.h:649
typename Master_matrix::pos_index pos_index
Definition ru_matrix.h:58
void remove_last()
Only available if PersistenceMatrixOptions::has_removable_columns is true. Removes the last face in t...
Definition ru_matrix.h:585
index get_number_of_columns() const
Returns the current number of columns in the matrix.
Definition ru_matrix.h:636
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:687
index get_column_with_pivot(index faceIndex) const
Returns the MatIdx index of the column which has the given row index as pivot in ....
Definition ru_matrix.h:714
typename Master_matrix::Column_type Column_type
Definition ru_matrix.h:49
typename Master_matrix::index index
Definition ru_matrix.h:56
typename Master_matrix::element_type Field_element_type
Definition ru_matrix.h:48
typename Master_matrix::Cell_constructor Cell_constructor
Definition ru_matrix.h:52
Row_type & 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:553
void remove_maximal_face(index columnIndex)
Only available if PersistenceMatrixOptions::has_removable_columns and PersistenceMatrixOptions::has_v...
Definition ru_matrix.h:570
void zero_cell(index columnIndex, index rowIndex, bool inR=true)
Zeroes the cell at the given coordinates in if inR is true or in if inR is false....
Definition ru_matrix.h:678
friend void swap(RU_matrix &matrix1, RU_matrix &matrix2)
Swap operator.
Definition ru_matrix.h:372
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 ru_matrix.h:523
typename Master_matrix::Field_operators Field_operators
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false.
Definition ru_matrix.h:47
typename Master_matrix::id_index id_index
Definition ru_matrix.h:57
dimension_type get_column_dimension(index columnIndex) const
Returns the dimension of the given column.
Definition ru_matrix.h:642
typename Master_matrix::Row_type Row_type
Definition ru_matrix.h:51
void multiply_source_and_add_to(const Field_element_type &coefficient, index sourceColumnIndex, index targetColumnIndex)
Multiplies the source column with the coefficiant before adding it to the target column....
Definition ru_matrix.h:669
void erase_empty_row(index rowIndex)
If PersistenceMatrixOptions::has_row_access and PersistenceMatrixOptions::has_removable_rows are true...
Definition ru_matrix.h:564
void multiply_target_and_add_to(index sourceColumnIndex, const Field_element_type &coefficient, index targetColumnIndex)
Multiplies the target column with the coefficiant and then adds the source column to it....
Definition ru_matrix.h:660
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:705
void reset(Column_settings *colSettings)
Resets the matrix to an empty matrix.
Definition ru_matrix.h:355
typename Master_matrix::boundary_type boundary_type
Definition ru_matrix.h:55
bool is_zero_cell(index columnIndex, index rowIndex, bool inR=true) const
Indicates if the cell at given coordinates has value zero in if inR is true or in if inR is false.
Definition ru_matrix.h:696
RU_matrix & operator=(const RU_matrix &other)
Assign operator.
Definition ru_matrix.h:731
typename Master_matrix::Column_settings Column_settings
Definition ru_matrix.h:54
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14