Loading...
Searching...
No Matches
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 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
18
19#ifndef PM_MATRIX_DIM_HOLDER_H
20#define PM_MATRIX_DIM_HOLDER_H
21
22#include <utility> //std::swap, std::move & std::exchange
23#include <vector>
24
25namespace Gudhi {
26namespace persistence_matrix {
27
35struct Dummy_matrix_dimension_holder {
36 template <typename Dimension>
37 Dummy_matrix_dimension_holder([[maybe_unused]] Dimension maximalDimension)
38 {}
39
40 friend void swap([[maybe_unused]] Dummy_matrix_dimension_holder& d1,
41 [[maybe_unused]] Dummy_matrix_dimension_holder& d2) noexcept
42 {}
43};
44
45// TODO: find an easy way to give access to get_null_value<Dimension>() to replace the -1s
46
56template <typename Dimension>
58{
59 public:
65 Matrix_max_dimension_holder(Dimension maximalDimension = -1) : maxDim_(maximalDimension) {};
78 : maxDim_(std::exchange(other.maxDim_, -1)) {};
79
81
87 Dimension get_max_dimension() const { return maxDim_; };
88
93
98 {
99 if (this == &other) return *this;
100
101 maxDim_ = std::exchange(other.maxDim_, -1);
102 return *this;
103 };
104
108 friend void swap(Matrix_max_dimension_holder& matrix1, Matrix_max_dimension_holder& matrix2) noexcept
109 {
110 std::swap(matrix1.maxDim_, matrix2.maxDim_);
111 }
112
113 protected:
114 void _update_up(Dimension dimension)
115 {
116 if (maxDim_ == -1 || maxDim_ < dimension) maxDim_ = dimension;
117 };
118
119 void _reset() { maxDim_ = -1; }
120
121 private:
122 Dimension maxDim_;
123};
124
134template <typename Dimension>
136{
137 public:
143 Matrix_all_dimension_holder(Dimension maximalDimension = -1)
144 : dimensions_(maximalDimension < 0 ? 0 : maximalDimension + 1, 0), maxDim_(maximalDimension)
145 {
146 if (maxDim_ != -1) dimensions_[maxDim_] = 1;
147 };
148
161 : dimensions_(std::move(other.dimensions_)), maxDim_(std::exchange(other.maxDim_, -1)) {};
162
164
170 Dimension get_max_dimension() const { return maxDim_; };
171
176
181 {
182 if (this == &other) return *this;
183
184 dimensions_ = std::move(other.dimensions_);
185 maxDim_ = std::exchange(other.maxDim_, -1);
186 return *this;
187 };
188
192 friend void swap(Matrix_all_dimension_holder& matrix1, Matrix_all_dimension_holder& matrix2) noexcept
193 {
194 std::swap(matrix1.maxDim_, matrix2.maxDim_);
195 matrix1.dimensions_.swap(matrix2.dimensions_);
196 }
197
198 protected:
199 void _update_up(unsigned int dimension)
200 {
201 if (dimensions_.size() <= dimension) dimensions_.resize(dimension + 1, 0);
202 ++(dimensions_[dimension]);
203 maxDim_ = dimensions_.size() - 1;
204 };
205
206 void _update_down(unsigned int dimension)
207 {
208 --(dimensions_[dimension]); // assumes dimension already exists and is not 0
209 while (!dimensions_.empty() && dimensions_.back() == 0) dimensions_.pop_back();
210 maxDim_ = dimensions_.size() - 1;
211 };
212
213 void _reset()
214 {
215 dimensions_.clear();
216 maxDim_ = -1;
217 }
218
219 private:
220 std::vector<unsigned int> dimensions_;
221 Dimension maxDim_;
222};
223
224} // namespace persistence_matrix
225} // namespace Gudhi
226
227#endif // PM_MATRIX_DIM_HOLDER_H
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition matrix_dimension_holders.h:136
Matrix_all_dimension_holder & operator=(Matrix_all_dimension_holder &&other) noexcept
Move assign operator.
Definition matrix_dimension_holders.h:180
Matrix_all_dimension_holder & operator=(const Matrix_all_dimension_holder &other)=default
Assign operator.
Matrix_all_dimension_holder(Matrix_all_dimension_holder &&other) noexcept
Move constructor.
Definition matrix_dimension_holders.h:160
friend void swap(Matrix_all_dimension_holder &matrix1, Matrix_all_dimension_holder &matrix2) noexcept
Swap operator.
Definition matrix_dimension_holders.h:192
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition matrix_dimension_holders.h:170
Matrix_all_dimension_holder(Dimension maximalDimension=-1)
Default constructor. If a dimension is specified, stores it as the maximal value.
Definition matrix_dimension_holders.h:143
Matrix_all_dimension_holder(const Matrix_all_dimension_holder &toCopy)=default
Copy constructor.
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition matrix_dimension_holders.h:58
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition matrix_dimension_holders.h:87
Matrix_max_dimension_holder & operator=(const Matrix_max_dimension_holder &other)=default
Assign operator.
Matrix_max_dimension_holder(Matrix_max_dimension_holder &&other) noexcept
Move constructor.
Definition matrix_dimension_holders.h:77
Matrix_max_dimension_holder(Dimension maximalDimension=-1)
Default constructor. If a dimension is specified, stores it as the maximal value.
Definition matrix_dimension_holders.h:65
friend void swap(Matrix_max_dimension_holder &matrix1, Matrix_max_dimension_holder &matrix2) noexcept
Swap operator.
Definition matrix_dimension_holders.h:108
Matrix_max_dimension_holder & operator=(Matrix_max_dimension_holder &&other) noexcept
Move assign operator.
Definition matrix_dimension_holders.h:97
Matrix_max_dimension_holder(const Matrix_max_dimension_holder &toCopy)=default
Copy constructor.
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14