matrix_dimension_holders.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 
18 #ifndef PM_MATRIX_DIM_HOLDER_H
19 #define PM_MATRIX_DIM_HOLDER_H
20 
21 #include <utility> //std::swap, std::move & std::exchange
22 #include <vector>
23 
24 namespace Gudhi {
25 namespace persistence_matrix {
26 
35  template <typename dimension_type>
36  Dummy_matrix_dimension_holder([[maybe_unused]] dimension_type maximalDimension) {}
37 
38  friend void swap([[maybe_unused]] Dummy_matrix_dimension_holder& d1,
39  [[maybe_unused]] Dummy_matrix_dimension_holder& d2) {}
40 };
41 
51 template <typename dimension_type>
53 {
54  public:
60  Matrix_max_dimension_holder(dimension_type maximalDimension = -1) : maxDim_(maximalDimension){};
66  Matrix_max_dimension_holder(const Matrix_max_dimension_holder& toCopy) : maxDim_(toCopy.maxDim_){};
73  : maxDim_(std::exchange(other.maxDim_, -1)){};
74 
80  dimension_type get_max_dimension() const { return maxDim_; };
81 
86  std::swap(maxDim_, other.maxDim_);
87  return *this;
88  };
93  std::swap(matrix1.maxDim_, matrix2.maxDim_);
94  }
95 
96  protected:
97  dimension_type maxDim_;
99  void update_up(dimension_type dimension) {
100  if (maxDim_ == -1 || maxDim_ < dimension) maxDim_ = dimension;
101  };
102 };
103 
113 template <typename dimension_type>
115 {
116  public:
122  Matrix_all_dimension_holder(dimension_type maximalDimension = -1)
123  : dimensions_(maximalDimension < 0 ? 0 : maximalDimension + 1, 0), maxDim_(maximalDimension) {
124  if (maxDim_ != -1) dimensions_[maxDim_] = 1;
125  };
132  : dimensions_(toCopy.dimensions_), maxDim_(toCopy.maxDim_){};
139  : dimensions_(std::move(other.dimensions_)), maxDim_(std::exchange(other.maxDim_, -1)){};
140 
146  dimension_type get_max_dimension() const { return maxDim_; };
147 
152  std::swap(maxDim_, other.maxDim_);
153  dimensions_.swap(other.dimensions_);
154  return *this;
155  };
160  std::swap(matrix1.maxDim_, matrix2.maxDim_);
161  matrix1.dimensions_.swap(matrix2.dimensions_);
162  }
163 
164  protected:
165  std::vector<unsigned int> dimensions_;
166  dimension_type maxDim_;
168  void update_up(unsigned int dimension) {
169  if (dimensions_.size() <= dimension) dimensions_.resize(dimension + 1, 0);
170  ++(dimensions_[dimension]);
171  maxDim_ = dimensions_.size() - 1;
172  };
173 
174  void update_down(unsigned int dimension) {
175  --(dimensions_[dimension]); // assumes dimension already exists and is not 0
176  while (!dimensions_.empty() && dimensions_.back() == 0) dimensions_.pop_back();
177  maxDim_ = dimensions_.size() - 1;
178  };
179 };
180 
181 } // namespace persistence_matrix
182 } // namespace Gudhi
183 
184 #endif // PM_MATRIX_DIM_HOLDER_H
Class managing the maximal dimension of a face represented in the inheritating matrix,...
Definition: matrix_dimension_holders.h:115
Matrix_all_dimension_holder & operator=(Matrix_all_dimension_holder other)
Assign operator.
Definition: matrix_dimension_holders.h:151
Matrix_all_dimension_holder(const Matrix_all_dimension_holder &toCopy)
Copy constructor.
Definition: matrix_dimension_holders.h:131
dimension_type get_max_dimension() const
Returns the maximal dimension of a face represented in the matrix.
Definition: matrix_dimension_holders.h:146
friend void swap(Matrix_all_dimension_holder &matrix1, Matrix_all_dimension_holder &matrix2)
Swap operator.
Definition: matrix_dimension_holders.h:159
Matrix_all_dimension_holder(Matrix_all_dimension_holder &&other) noexcept
Move constructor.
Definition: matrix_dimension_holders.h:138
Matrix_all_dimension_holder(dimension_type maximalDimension=-1)
Default constructor. If a dimension is specified, stores it as the maximal value.
Definition: matrix_dimension_holders.h:122
Class managing the maximal dimension of a face represented in the inheritating matrix,...
Definition: matrix_dimension_holders.h:53
Matrix_max_dimension_holder & operator=(const Matrix_max_dimension_holder &other)
Assign operator.
Definition: matrix_dimension_holders.h:85
friend void swap(Matrix_max_dimension_holder &matrix1, Matrix_max_dimension_holder &matrix2)
Swap operator.
Definition: matrix_dimension_holders.h:92
Matrix_max_dimension_holder(dimension_type maximalDimension=-1)
Default constructor. If a dimension is specified, stores it as the maximal value.
Definition: matrix_dimension_holders.h:60
Matrix_max_dimension_holder(Matrix_max_dimension_holder &&other) noexcept
Move constructor.
Definition: matrix_dimension_holders.h:72
Matrix_max_dimension_holder(const Matrix_max_dimension_holder &toCopy)
Copy constructor.
Definition: matrix_dimension_holders.h:66
dimension_type get_max_dimension() const
Returns the maximal dimension of a face represented in the matrix.
Definition: matrix_dimension_holders.h:80
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of Matrix_max_dimension_holder or Matrix_all_dimension_holder,...
Definition: matrix_dimension_holders.h:34