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
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
36{
37 template <typename Dimension>
38 Dummy_matrix_dimension_holder([[maybe_unused]] Dimension maximalDimension) {}
39
40 friend void swap([[maybe_unused]] Dummy_matrix_dimension_holder& d1,
41 [[maybe_unused]] Dummy_matrix_dimension_holder& d2) {}
42};
43
44// TODO: find an easy way to give access to get_null_value<Dimension>() to replace the -1s
45
55template <typename Dimension>
57{
58 public:
64 Matrix_max_dimension_holder(Dimension maximalDimension = -1) : maxDim_(maximalDimension){};
70 Matrix_max_dimension_holder(const Matrix_max_dimension_holder& toCopy) : maxDim_(toCopy.maxDim_){};
77 : maxDim_(std::exchange(other.maxDim_, -1)){};
78
84 Dimension get_max_dimension() const { return maxDim_; };
85
90 std::swap(maxDim_, other.maxDim_);
91 return *this;
92 };
97 std::swap(matrix1.maxDim_, matrix2.maxDim_);
98 }
99
100 protected:
101 Dimension maxDim_;
103 void update_up(Dimension dimension) {
104 if (maxDim_ == -1 || maxDim_ < dimension) maxDim_ = dimension;
105 };
106};
107
117template <typename Dimension>
119{
120 public:
126 Matrix_all_dimension_holder(Dimension maximalDimension = -1)
127 : dimensions_(maximalDimension < 0 ? 0 : maximalDimension + 1, 0), maxDim_(maximalDimension) {
128 if (maxDim_ != -1) dimensions_[maxDim_] = 1;
129 };
136 : dimensions_(toCopy.dimensions_), maxDim_(toCopy.maxDim_){};
143 : dimensions_(std::move(other.dimensions_)), maxDim_(std::exchange(other.maxDim_, -1)){};
144
150 Dimension get_max_dimension() const { return maxDim_; };
151
156 std::swap(maxDim_, other.maxDim_);
157 dimensions_.swap(other.dimensions_);
158 return *this;
159 };
164 std::swap(matrix1.maxDim_, matrix2.maxDim_);
165 matrix1.dimensions_.swap(matrix2.dimensions_);
166 }
167
168 protected:
169 std::vector<unsigned int> dimensions_;
170 Dimension maxDim_;
172 void update_up(unsigned int dimension) {
173 if (dimensions_.size() <= dimension) dimensions_.resize(dimension + 1, 0);
174 ++(dimensions_[dimension]);
175 maxDim_ = dimensions_.size() - 1;
176 };
177
178 void update_down(unsigned int dimension) {
179 --(dimensions_[dimension]); // assumes dimension already exists and is not 0
180 while (!dimensions_.empty() && dimensions_.back() == 0) dimensions_.pop_back();
181 maxDim_ = dimensions_.size() - 1;
182 };
183};
184
185} // namespace persistence_matrix
186} // namespace Gudhi
187
188#endif // PM_MATRIX_DIM_HOLDER_H
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition: matrix_dimension_holders.h:119
Matrix_all_dimension_holder(const Matrix_all_dimension_holder &toCopy)
Copy constructor.
Definition: matrix_dimension_holders.h:135
Matrix_all_dimension_holder(Matrix_all_dimension_holder &&other) noexcept
Move constructor.
Definition: matrix_dimension_holders.h:142
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition: matrix_dimension_holders.h:150
friend void swap(Matrix_all_dimension_holder &matrix1, Matrix_all_dimension_holder &matrix2)
Swap operator.
Definition: matrix_dimension_holders.h:163
Matrix_all_dimension_holder & operator=(Matrix_all_dimension_holder other)
Assign operator.
Definition: matrix_dimension_holders.h:155
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:126
Class managing the maximal dimension of a cell represented in the inheriting matrix,...
Definition: matrix_dimension_holders.h:57
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition: matrix_dimension_holders.h:84
Matrix_max_dimension_holder(Matrix_max_dimension_holder &&other) noexcept
Move constructor.
Definition: matrix_dimension_holders.h:76
Matrix_max_dimension_holder & operator=(const Matrix_max_dimension_holder &other)
Assign operator.
Definition: matrix_dimension_holders.h:89
friend void swap(Matrix_max_dimension_holder &matrix1, Matrix_max_dimension_holder &matrix2)
Swap operator.
Definition: matrix_dimension_holders.h:96
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:64
Matrix_max_dimension_holder(const Matrix_max_dimension_holder &toCopy)
Copy constructor.
Definition: matrix_dimension_holders.h:70
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of Matrix_max_dimension_holder or Matrix_all_dimension_holder,...
Definition: matrix_dimension_holders.h:36