Loading...
Searching...
No Matches
matrix_dimension_holders.h
Go to the documentation of this file.
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2022-24 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PM_MATRIX_DIM_HOLDER_H
#define PM_MATRIX_DIM_HOLDER_H
#include <utility> //std::swap, std::move & std::exchange
#include <vector>
namespace Gudhi {
namespace persistence_matrix {
struct Dummy_matrix_dimension_holder
{
template <typename Dimension>
Dummy_matrix_dimension_holder([[maybe_unused]] Dimension maximalDimension) {}
friend void swap([[maybe_unused]] Dummy_matrix_dimension_holder& d1,
[[maybe_unused]] Dummy_matrix_dimension_holder& d2) {}
};
// TODO: find an easy way to give access to get_null_value<Dimension>() to replace the -1s
template <typename Dimension>
class Matrix_max_dimension_holder
{
public:
Matrix_max_dimension_holder(Dimension maximalDimension = -1) : maxDim_(maximalDimension){};
Matrix_max_dimension_holder(const Matrix_max_dimension_holder& toCopy) : maxDim_(toCopy.maxDim_){};
Matrix_max_dimension_holder(Matrix_max_dimension_holder&& other) noexcept
: maxDim_(std::exchange(other.maxDim_, -1)){};
Dimension get_max_dimension() const { return maxDim_; };
Matrix_max_dimension_holder& operator=(const Matrix_max_dimension_holder& other) {
std::swap(maxDim_, other.maxDim_);
return *this;
};
friend void swap(Matrix_max_dimension_holder& matrix1, Matrix_max_dimension_holder& matrix2) {
std::swap(matrix1.maxDim_, matrix2.maxDim_);
}
protected:
Dimension maxDim_;
void update_up(Dimension dimension) {
if (maxDim_ == -1 || maxDim_ < dimension) maxDim_ = dimension;
};
};
template <typename Dimension>
class Matrix_all_dimension_holder
{
public:
Matrix_all_dimension_holder(Dimension maximalDimension = -1)
: dimensions_(maximalDimension < 0 ? 0 : maximalDimension + 1, 0), maxDim_(maximalDimension) {
if (maxDim_ != -1) dimensions_[maxDim_] = 1;
};
Matrix_all_dimension_holder(const Matrix_all_dimension_holder& toCopy)
: dimensions_(toCopy.dimensions_), maxDim_(toCopy.maxDim_){};
Matrix_all_dimension_holder(Matrix_all_dimension_holder&& other) noexcept
: dimensions_(std::move(other.dimensions_)), maxDim_(std::exchange(other.maxDim_, -1)){};
Dimension get_max_dimension() const { return maxDim_; };
Matrix_all_dimension_holder& operator=(Matrix_all_dimension_holder other) {
std::swap(maxDim_, other.maxDim_);
dimensions_.swap(other.dimensions_);
return *this;
};
friend void swap(Matrix_all_dimension_holder& matrix1, Matrix_all_dimension_holder& matrix2) {
std::swap(matrix1.maxDim_, matrix2.maxDim_);
matrix1.dimensions_.swap(matrix2.dimensions_);
}
protected:
std::vector<unsigned int> dimensions_;
Dimension maxDim_;
void update_up(unsigned int dimension) {
if (dimensions_.size() <= dimension) dimensions_.resize(dimension + 1, 0);
++(dimensions_[dimension]);
maxDim_ = dimensions_.size() - 1;
};
void update_down(unsigned int dimension) {
--(dimensions_[dimension]); // assumes dimension already exists and is not 0
while (!dimensions_.empty() && dimensions_.back() == 0) dimensions_.pop_back();
maxDim_ = dimensions_.size() - 1;
};
};
} // namespace persistence_matrix
} // namespace Gudhi
#endif // PM_MATRIX_DIM_HOLDER_H
Gudhi::persistence_matrix::Matrix_all_dimension_holder::Matrix_all_dimension_holder
Matrix_all_dimension_holder(const Matrix_all_dimension_holder &toCopy)
Copy constructor.
Definition matrix_dimension_holders.h:135
Gudhi::persistence_matrix::Matrix_all_dimension_holder::Matrix_all_dimension_holder
Matrix_all_dimension_holder(Matrix_all_dimension_holder &&other) noexcept
Move constructor.
Definition matrix_dimension_holders.h:142
Gudhi::persistence_matrix::Matrix_all_dimension_holder::get_max_dimension
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition matrix_dimension_holders.h:150
Gudhi::persistence_matrix::Matrix_all_dimension_holder::swap
friend void swap(Matrix_all_dimension_holder &matrix1, Matrix_all_dimension_holder &matrix2)
Swap operator.
Definition matrix_dimension_holders.h:163
Gudhi::persistence_matrix::Matrix_all_dimension_holder::operator=
Matrix_all_dimension_holder & operator=(Matrix_all_dimension_holder other)
Assign operator.
Definition matrix_dimension_holders.h:155
Gudhi::persistence_matrix::Matrix_all_dimension_holder::Matrix_all_dimension_holder
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
Gudhi::persistence_matrix::Matrix_max_dimension_holder::get_max_dimension
Dimension get_max_dimension() const
Returns the maximal dimension of a cell represented in the matrix.
Definition matrix_dimension_holders.h:84
Gudhi::persistence_matrix::Matrix_max_dimension_holder::Matrix_max_dimension_holder
Matrix_max_dimension_holder(Matrix_max_dimension_holder &&other) noexcept
Move constructor.
Definition matrix_dimension_holders.h:76
Gudhi::persistence_matrix::Matrix_max_dimension_holder::operator=
Matrix_max_dimension_holder & operator=(const Matrix_max_dimension_holder &other)
Assign operator.
Definition matrix_dimension_holders.h:89
Gudhi::persistence_matrix::Matrix_max_dimension_holder::swap
friend void swap(Matrix_max_dimension_holder &matrix1, Matrix_max_dimension_holder &matrix2)
Swap operator.
Definition matrix_dimension_holders.h:96
Gudhi::persistence_matrix::Matrix_max_dimension_holder::Matrix_max_dimension_holder
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
Gudhi::persistence_matrix::Matrix_max_dimension_holder::Matrix_max_dimension_holder
Matrix_max_dimension_holder(const Matrix_max_dimension_holder &toCopy)
Copy constructor.
Definition matrix_dimension_holders.h:70
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14