Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

borders of representative cycles #26

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions multipers/gudhi/gudhi/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ class Matrix {
std::swap(matrix1.colSettings_, matrix2.colSettings_);
}

void print(); // for debug
void print(Index startCol = 0, Index endCol = -1, Index startRow = 0, Index endRow = -1); // for debug

//TODO: change the behaviour for boundary matrices.
/**
Expand Down Expand Up @@ -1344,21 +1344,23 @@ class Matrix {
* returned.
*/
void update_representative_cycles();
/**
* @brief Only available if @ref PersistenceMatrixOptions::can_retrieve_representative_cycles is true.
* Returns all representative cycles of the current filtration.
*
* @return A const reference to the vector of representative cycles.
*/
const std::vector<Cycle>& get_representative_cycles();
/**
* @brief Only available if @ref PersistenceMatrixOptions::can_retrieve_representative_cycles is true.
* Returns the cycle representing the given bar.
*
* @param bar A bar from the current barcode.
* @return A const reference to the cycle representing @p bar.
*/
const Cycle& get_representative_cycle(const Bar& bar);
// /**
// * @brief Only available if @ref PersistenceMatrixOptions::can_retrieve_representative_cycles is true.
// * Returns all representative cycles of the current filtration.
// *
// * @return A const reference to the vector of representative cycles.
// */
// const std::vector<Cycle>& get_representative_cycles();
// /**
// * @brief Only available if @ref PersistenceMatrixOptions::can_retrieve_representative_cycles is true.
// * Returns the cycle representing the given bar.
// *
// * @param bar A bar from the current barcode.
// * @return A const reference to the cycle representing @p bar.
// */
// const Cycle& get_representative_cycle(const Bar& bar);
std::vector<std::vector<std::vector<typename Matrix<PersistenceMatrixOptions>::ID_index> > >
get_representative_cycles_as_borders(bool detailed = false);

private:
using Underlying_matrix =
Expand Down Expand Up @@ -1931,9 +1933,9 @@ inline Matrix<PersistenceMatrixOptions>& Matrix<PersistenceMatrixOptions>::opera
}

template <class PersistenceMatrixOptions>
inline void Matrix<PersistenceMatrixOptions>::print()
inline void Matrix<PersistenceMatrixOptions>::print(Index startCol, Index endCol, Index startRow, Index endRow)
{
return matrix_.print();
return matrix_.print(startCol, endCol, startRow, endRow);
}

template <class PersistenceMatrixOptions>
Expand Down Expand Up @@ -2035,20 +2037,28 @@ inline void Matrix<PersistenceMatrixOptions>::update_representative_cycles()
matrix_.update_representative_cycles();
}

template <class PersistenceMatrixOptions>
inline const std::vector<typename Matrix<PersistenceMatrixOptions>::Cycle>&
Matrix<PersistenceMatrixOptions>::get_representative_cycles()
{
static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
return matrix_.get_representative_cycles();
}
// template <class PersistenceMatrixOptions>
// inline const std::vector<typename Matrix<PersistenceMatrixOptions>::Cycle>&
// Matrix<PersistenceMatrixOptions>::get_representative_cycles()
// {
// static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
// return matrix_.get_representative_cycles();
// }

// template <class PersistenceMatrixOptions>
// inline const typename Matrix<PersistenceMatrixOptions>::Cycle&
// Matrix<PersistenceMatrixOptions>::get_representative_cycle(const Bar& bar)
// {
// static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
// return matrix_.get_representative_cycle(bar);
// }

template <class PersistenceMatrixOptions>
inline const typename Matrix<PersistenceMatrixOptions>::Cycle&
Matrix<PersistenceMatrixOptions>::get_representative_cycle(const Bar& bar)
{
static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles, "This method was not enabled.");
return matrix_.get_representative_cycle(bar);
inline std::vector<std::vector<std::vector<typename Matrix<PersistenceMatrixOptions>::ID_index> > >
Matrix<PersistenceMatrixOptions>::get_representative_cycles_as_borders(bool detailed) {
static_assert(PersistenceMatrixOptions::can_retrieve_representative_cycles && PersistenceMatrixOptions::is_z2,
"This method was not enabled.");
return matrix_.get_representative_cycles_as_borders(detailed);
}

template <class PersistenceMatrixOptions>
Expand Down
23 changes: 14 additions & 9 deletions multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Base_matrix : public Master_matrix::template Base_swap_option<Base_matrix<
}
}

void print(); // for debug
void print(Index startCol = 0, Index endCol = -1, Index startRow = 0, Index endRow = -1); // for debug

private:
using Swap_opt = typename Master_matrix::template Base_swap_option<Base_matrix<Master_matrix> >;
Expand Down Expand Up @@ -597,27 +597,32 @@ inline Base_matrix<Master_matrix>& Base_matrix<Master_matrix>::operator=(const B
}

template <class Master_matrix>
inline void Base_matrix<Master_matrix>::print()
inline void Base_matrix<Master_matrix>::print(Index startCol, Index endCol, Index startRow, Index endRow)
{
_orderRowsIfNecessary();
if (endCol == static_cast<Index>(-1)) endCol = nextInsertIndex_;
if (endRow == static_cast<Index>(-1)) endRow = nextInsertIndex_;
std::cout << "Base_matrix:\n";
for (Index i = 0; i < nextInsertIndex_; ++i) {
for (Index i = startCol; i < endCol && i < nextInsertIndex_; ++i) {
const Column& col = matrix_[i];
for (const auto& e : col.get_content(nextInsertIndex_)) {
if (e == 0u)
auto cont = col.get_content(endRow);
for (Index j = startRow; j < endRow; ++j) {
if (cont[j] == 0u)
std::cout << "- ";
else
std::cout << e << " ";
std::cout << cont[j] << " ";
}
std::cout << "\n";
}
std::cout << "\n";
if constexpr (Master_matrix::Option_list::has_row_access) {
std::cout << "Row Matrix:\n";
for (Index i = 0; i < nextInsertIndex_; ++i) {
for (Index i = startRow; i < endRow && i < nextInsertIndex_; ++i) {
const auto& row = (*RA_opt::rows_)[i];
for (const auto& entry : row) {
std::cout << entry.get_column_index() << " ";
auto it = row.begin();
std::advance(it, startCol);
for (; it != row.end() && startCol < endCol; ++it, ++startCol) {
std::cout << it->get_column_index() << " ";
}
std::cout << "(" << i << ")\n";
}
Expand Down
24 changes: 15 additions & 9 deletions multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cassert>
#include <iostream> //print() only
#include <iterator>
#include <vector>
#include <utility> //std::swap, std::move & std::exchange

Expand Down Expand Up @@ -349,7 +350,7 @@ class Boundary_matrix : public Master_matrix::Matrix_dimension_option,
}
}

void print(); // for debug
void print(Index startCol = 0, Index endCol = -1, Index startRow = 0, Index endRow = -1); // for debug

private:
using Dim_opt = typename Master_matrix::Matrix_dimension_option;
Expand Down Expand Up @@ -709,29 +710,34 @@ inline Boundary_matrix<Master_matrix>& Boundary_matrix<Master_matrix>::operator=
}

template <class Master_matrix>
inline void Boundary_matrix<Master_matrix>::print()
inline void Boundary_matrix<Master_matrix>::print(Index startCol, Index endCol, Index startRow, Index endRow)
{
if (endCol == static_cast<Index>(-1)) endCol = nextInsertIndex_;
if (endRow == static_cast<Index>(-1)) endRow = nextInsertIndex_;
if constexpr (activeSwapOption) {
if (Swap_opt::rowSwapped_) Swap_opt::_orderRows();
}
std::cout << "Boundary_matrix:\n";
for (Index i = 0; i < nextInsertIndex_; ++i) {
for (Index i = startCol; i < endCol && i < nextInsertIndex_; ++i) {
Column& col = matrix_[i];
for (auto e : col.get_content(nextInsertIndex_)) {
if (e == 0u)
auto cont = col.get_content(endRow);
for (Index j = startRow; j < endRow; ++j) {
if (cont[j] == 0u)
std::cout << "- ";
else
std::cout << e << " ";
std::cout << cont[j] << " ";
}
std::cout << "\n";
}
std::cout << "\n";
if constexpr (Master_matrix::Option_list::has_row_access) {
std::cout << "Row Matrix:\n";
for (ID_index i = 0; i < nextInsertIndex_; ++i) {
for (ID_index i = startRow; i < endRow && i < nextInsertIndex_; ++i) {
const auto& row = (*RA_opt::rows_)[i];
for (const typename Column::Entry& entry : row) {
std::cout << entry.get_column_index() << " ";
auto it = row.begin();
std::advance(it, startCol);
for (; it != row.end() && startCol < endCol; ++it, ++startCol) {
std::cout << it->get_column_index() << " ";
}
std::cout << "(" << i << ")\n";
}
Expand Down
10 changes: 5 additions & 5 deletions multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class RU_matrix : public Master_matrix::RU_pairing_option,
std::swap(matrix1.operators_, matrix2.operators_);
}

void print(); // for debug
void print(Index startCol = 0, Index endCol = -1, Index startRow = 0, Index endRow = -1); // for debug

private:
using Swap_opt = typename Master_matrix::RU_vine_swap_option;
Expand Down Expand Up @@ -538,7 +538,7 @@ inline void RU_matrix<Master_matrix>::insert_boundary(ID_index cellIndex,
if constexpr (Master_matrix::Option_list::has_vine_update) {
if (cellIndex != nextEventIndex_) {
Swap_opt::_positionToRowIdx().emplace(nextEventIndex_, cellIndex);
if (Master_matrix::Option_list::has_column_pairings) {
if constexpr (Master_matrix::Option_list::has_column_pairings) {
Swap_opt::template RU_pairing<Master_matrix>::idToPosition_.emplace(cellIndex, nextEventIndex_);
}
}
Expand Down Expand Up @@ -733,12 +733,12 @@ inline RU_matrix<Master_matrix>& RU_matrix<Master_matrix>::operator=(const RU_ma
}

template <class Master_matrix>
inline void RU_matrix<Master_matrix>::print()
inline void RU_matrix<Master_matrix>::print(Index startCol, Index endCol, Index startRow, Index endRow)
{
std::cout << "R_matrix:\n";
reducedMatrixR_.print();
reducedMatrixR_.print(startCol, endCol, startRow, endRow);
std::cout << "U_matrix:\n";
mirrorMatrixU_.print();
mirrorMatrixU_.print(startCol, endCol, startCol, endCol);
}

template <class Master_matrix>
Expand Down

This file was deleted.

Loading
Loading