Skip to content
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
113 changes: 62 additions & 51 deletions multipers/gudhi/Persistence_slices_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "gudhi/multi_simplex_tree_helpers.h"
#include "gudhi/persistence_matrix_options.h"
#include "gudhi/Multi_parameter_filtered_complex.h"
#include "gudhi/Multi_persistence/Persistence_interface_matrix.h"
#include "gudhi/Multi_persistence/Persistence_interface_vineyard.h"
#include "gudhi/Multi_persistence/Persistence_interface_homology.h"
#include "gudhi/Multi_persistence/Persistence_interface_cohomology.h"
#include "gudhi/Dynamic_multi_parameter_filtration.h"
#include "gudhi/Degree_rips_bifiltration.h"
Expand Down Expand Up @@ -39,26 +40,26 @@ enum Filtration_containers_strs : std::uint8_t {

using Available_columns = Gudhi::persistence_matrix::Column_types;

template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
struct Multi_persistence_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
using Index = std::uint32_t;
static const bool has_matrix_maximal_dimension_access = false;
static const bool has_column_pairings = true;
static const bool has_vine_update = true;
static const bool can_retrieve_representative_cycles = true;
};

template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
struct Multi_persistence_Clement_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
using Index = std::uint32_t;
static const bool has_matrix_maximal_dimension_access = false;
static const bool has_column_pairings = true;
static const bool has_vine_update = true;
static const bool is_of_boundary_type = false;
static const Gudhi::persistence_matrix::Column_indexation_types column_indexation_type =
Gudhi::persistence_matrix::Column_indexation_types::POSITION;
static const bool can_retrieve_representative_cycles = true;
};
// template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
// struct Multi_persistence_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
// using Index = std::uint32_t;
// static const bool has_matrix_maximal_dimension_access = false;
// static const bool has_column_pairings = true;
// static const bool has_vine_update = true;
// static const bool can_retrieve_representative_cycles = true;
// };

// template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
// struct Multi_persistence_Clement_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
// using Index = std::uint32_t;
// static const bool has_matrix_maximal_dimension_access = false;
// static const bool has_column_pairings = true;
// static const bool has_vine_update = true;
// static const bool is_of_boundary_type = false;
// static const Gudhi::persistence_matrix::Column_indexation_types column_indexation_type =
// Gudhi::persistence_matrix::Column_indexation_types::POSITION;
// static const bool can_retrieve_representative_cycles = true;
// };

template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
struct No_vine_multi_persistence_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
Expand All @@ -68,50 +69,61 @@ struct No_vine_multi_persistence_options : Gudhi::persistence_matrix::Default_op
static const bool has_vine_update = false;
};

template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET,
bool row_access = true>
struct fix_presentation_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
using Index = std::uint32_t;
static const bool has_row_access = row_access;
static const bool has_map_column_container = false;
static const bool has_removable_columns = false; // WARN : idx will change if map is not true
// template <Gudhi::persistence_matrix::Column_types column_type = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET,
// bool row_access = true>
// struct fix_presentation_options : Gudhi::persistence_matrix::Default_options<column_type, true> {
// using Index = std::uint32_t;
// static const bool has_row_access = row_access;
// static const bool has_map_column_container = false;
// static const bool has_removable_columns = false; // WARN : idx will change if map is not true
// };

template <Gudhi::persistence_matrix::Column_types col = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
struct Multi_persistence_vineyard_ru_options : Gudhi::vineyard::Default_vineyard_options {
static constexpr bool is_RU = true;
static const Gudhi::persistence_matrix::Column_types column_type = col;
};

template <Available_columns col>
using BackendOptionsWithVine = Multi_persistence_options<col>;
template <Gudhi::persistence_matrix::Column_types col = Gudhi::persistence_matrix::Column_types::INTRUSIVE_SET>
struct Multi_persistence_vineyard_chain_options : Gudhi::vineyard::Default_vineyard_options {
static constexpr bool is_RU = false;
static const Gudhi::persistence_matrix::Column_types column_type = col;
};

// template <Available_columns col>
// using BackendOptionsWithVine = Multi_persistence_options<col>;
template <Available_columns col>
using BackendOptionsWithoutVine = No_vine_multi_persistence_options<col>;

template <Available_columns col>
using ClementBackendOptionsWithVine = Multi_persistence_Clement_options<col>;
// template <Available_columns col>
// using ClementBackendOptionsWithVine = Multi_persistence_Clement_options<col>;

// using SimplicialStructure = Gudhi::multiparameter::truc_interface::SimplicialStructure;
template <typename Filtration>
using StructureStuff = Gudhi::multi_persistence::Multi_parameter_filtered_complex<Filtration>;

template <Available_columns col>
using MatrixBackendNoVine = Gudhi::multi_persistence::Persistence_interface_matrix<BackendOptionsWithoutVine<col>>;
template <Available_columns col, class Filtration>
using MatrixBackendNoVine = Gudhi::multi_persistence::Persistence_interface_homology<BackendOptionsWithoutVine<col>, Filtration>;

template <Available_columns col>
using MatrixBackendVine = Gudhi::multi_persistence::Persistence_interface_matrix<BackendOptionsWithVine<col>>;
using MatrixBackendVine = Gudhi::multi_persistence::Persistence_interface_vineyard<Multi_persistence_vineyard_ru_options<col>>;

template <Available_columns col>
using ClementMatrixBackendVine =
Gudhi::multi_persistence::Persistence_interface_matrix<ClementBackendOptionsWithVine<col>>;
using ClementMatrixBackendVine = Gudhi::multi_persistence::Persistence_interface_vineyard<Multi_persistence_vineyard_chain_options<col>>;
template <typename Filtration>
using GraphBackendVine = Gudhi::multiparameter::truc_interface::Persistence_backend_h0<StructureStuff<Filtration>>;

template <typename value_type = float>
using Filtration_value = Gudhi::multi_filtration::Multi_parameter_filtration<value_type, false, true>;

template <Available_columns col = Available_columns::INTRUSIVE_SET>
using SimplicialNoVineMatrixTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, MatrixBackendNoVine<col>>;
template <class Filtration, Available_columns col = Available_columns::INTRUSIVE_SET>
using SimplicialNoVineMatrixTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, MatrixBackendNoVine<col, Filtration>>;

template <Available_columns col = Available_columns::INTRUSIVE_SET>
using GeneralVineTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, MatrixBackendVine<col>>;

template <Available_columns col = Available_columns::INTRUSIVE_SET>
using GeneralNoVineTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, MatrixBackendNoVine<col>>;
template <class Filtration, Available_columns col = Available_columns::INTRUSIVE_SET>
using GeneralNoVineTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, MatrixBackendNoVine<col, Filtration>>;

template <Available_columns col = Available_columns::INTRUSIVE_SET>
using GeneralVineClementTruc = Gudhi::multi_persistence::Slicer<Filtration_value<>, ClementMatrixBackendVine<col>>;
Expand All @@ -128,8 +140,8 @@ using Multi_critical_filtration_value = Gudhi::multi_filtration::Multi_parameter
template <Available_columns col = Available_columns::INTRUSIVE_SET>
using KCriticalVineTruc = Gudhi::multi_persistence::Slicer<Multi_critical_filtration_value<>, MatrixBackendVine<col>>;

template <bool is_vine, Available_columns col = Available_columns::INTRUSIVE_SET>
using Matrix_interface = std::conditional_t<is_vine, MatrixBackendVine<col>, MatrixBackendNoVine<col>>;
template <bool is_vine, class Filtration, Available_columns col = Available_columns::INTRUSIVE_SET>
using Matrix_interface = std::conditional_t<is_vine, MatrixBackendVine<col>, MatrixBackendNoVine<col, Filtration>>;

template <Filtration_containers_strs fil_container, bool is_k_critical, typename value_type>
using filtration_options = std::conditional_t<fil_container == Filtration_containers_strs::Dynamic_multi_parameter_filtration,
Expand All @@ -138,13 +150,12 @@ using filtration_options = std::conditional_t<fil_container == Filtration_contai
Gudhi::multi_filtration::Multi_parameter_filtration<value_type, false, !is_k_critical>,
Gudhi::multi_filtration::Degree_rips_bifiltration<value_type, false, !is_k_critical>>>;

template <bool is_vine,
bool is_k_critical,
typename value_type,
Available_columns col = Available_columns::INTRUSIVE_SET,
Filtration_containers_strs filt_cont = Filtration_containers_strs::Multi_parameter_filtration>
using MatrixTrucPythonInterface =
Gudhi::multi_persistence::Slicer<filtration_options<filt_cont,is_k_critical, value_type>, Matrix_interface<is_vine, col>>;
// template <bool is_vine,
// bool is_k_critical,
// typename value_type,
// Available_columns col = Available_columns::INTRUSIVE_SET,
// Filtration_containers_strs filt_cont = Filtration_containers_strs::Multi_parameter_filtration>
// using MatrixTrucPythonInterface = Gudhi::multi_persistence::Slicer<filtration_options<filt_cont,is_k_critical, value_type>, Matrix_interface<is_vine, Filtration, col>>;

enum class BackendsEnum : std::uint8_t { Matrix, Graph, Clement, GudhiCohomology };

Expand All @@ -154,7 +165,7 @@ struct PersBackendOptsImpl;

template <bool is_vine, Available_columns col, typename Filtration>
struct PersBackendOptsImpl<BackendsEnum::Matrix, is_vine, col, Filtration> {
using type = Matrix_interface<is_vine, col>;
using type = Matrix_interface<is_vine, Filtration, col>;
};

template <bool is_vine, Available_columns col, typename Filtration>
Expand Down
17 changes: 10 additions & 7 deletions multipers/gudhi/gudhi/Degree_rips_bifiltration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
#include <vector>
#include <initializer_list>

#ifdef GUDHI_USE_TBB
#include <oneapi/tbb/parallel_for.h>
#endif

#include <gudhi/Debug_utils.h>
#include <gudhi/simple_mdspan.h>
#include <gudhi/Multi_filtration/multi_filtration_utils.h>
#include <gudhi/Simplex_tree/filtration_value_utils.h>
#include <gudhi/Multi_parameter_filtration.h>
#include <gudhi/Dynamic_multi_parameter_filtration.h>
#include <oneapi/tbb/concurrent_vector.h>

namespace Gudhi::multi_filtration {

Expand Down Expand Up @@ -1708,7 +1711,8 @@ class Degree_rips_bifiltration

GUDHI_CHECK_code(const OneDimArray &indices = grid[1]);
const OneDimArray &values = grid[0];
auto todo = [&](size_type g) {

auto project_generator = [&](size_type g) {
GUDHI_CHECK_code(GUDHI_CHECK(static_cast<size_type>(indices[g]) == g, std::invalid_argument("Unvalid grid.")));

auto v = static_cast<typename OneDimArray::value_type>(generators_[g]);
Expand All @@ -1718,11 +1722,12 @@ class Degree_rips_bifiltration
}
generators_[g] = coordinate ? static_cast<T>(d) : static_cast<T>(values[d]);
};

#ifdef GUDHI_USE_TBB
tbb::parallel_for(size_type{0}, num_generators(), [&](size_type g) { todo(g); });
tbb::parallel_for(size_type(0), num_generators(), project_generator);
#else
for (size_type g = 0; g < num_generators(); ++g) {
todo(g);
project_generator(g);
}
#endif
}
Expand Down Expand Up @@ -1842,9 +1847,7 @@ class Degree_rips_bifiltration

#ifdef GUDHI_USE_TBB
std::vector<U> projections(f.num_generators());
tbb::parallel_for(size_type{0}, f.num_generators(), [&](size_type g) {
projections[g] = project_generator(g);
});
tbb::parallel_for(size_type{0}, f.num_generators(), [&](size_type g) { projections[g] = project_generator(g); });
if constexpr (Co) {
return *std::max_element(projections.begin(), projections.end());
} else {
Expand Down
22 changes: 18 additions & 4 deletions multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
#include <vector>
#include <initializer_list>

#ifdef GUDHI_USE_TBB
#include <oneapi/tbb/parallel_for.h>
#endif

#include <gudhi/Debug_utils.h>
#include <gudhi/Multi_filtration/Multi_parameter_generator.h>
#include <gudhi/Multi_filtration/multi_filtration_utils.h>
#include <oneapi/tbb/parallel_for.h>

namespace Gudhi::multi_filtration {

Expand Down Expand Up @@ -1856,9 +1859,8 @@ class Dynamic_multi_parameter_filtration
std::invalid_argument("The grid should not be smaller than the number of parameters in the filtration value."));

#ifdef GUDHI_USE_TBB
tbb::parallel_for(size_type(0), num_generators(), [&](size_type i){
generators_[i].project_onto_grid(grid, coordinate);
});
tbb::parallel_for(
size_type(0), num_generators(), [&](size_type i) { generators_[i].project_onto_grid(grid, coordinate); });
#else
for (Generator &g : generators_) {
g.project_onto_grid(grid, coordinate);
Expand Down Expand Up @@ -1946,6 +1948,17 @@ class Dynamic_multi_parameter_filtration
{
if (f.num_generators() == 1) return compute_linear_projection(f.generators_[0], x);

#ifdef GUDHI_USE_TBB
std::vector<U> projections(f.num_generators());
tbb::parallel_for(size_type{0}, f.num_generators(), [&](size_type g) {
projections[g] = compute_linear_projection(f.generators_[g], x);
});
if constexpr (Co) {
return *std::max_element(projections.begin(), projections.end());
} else {
return *std::min_element(projections.begin(), projections.end());
}
#else
if constexpr (Co) {
U projection = std::numeric_limits<U>::lowest();
for (const Generator &g : f.generators_) {
Expand All @@ -1961,6 +1974,7 @@ class Dynamic_multi_parameter_filtration
}
return projection;
}
#endif
}

/**
Expand Down
8 changes: 5 additions & 3 deletions multipers/gudhi/gudhi/Fields/Multi_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber, Clément Maria
*
* Copyright (C) 2022-24 Inria
* Copyright (C) 2022 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
Expand Down Expand Up @@ -305,7 +305,8 @@ class Multi_field_element
const Characteristic& productOfCharacteristics) const
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

Characteristic QR;
mpz_gcd(QR.get_mpz_t(), element_.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)
Expand Down Expand Up @@ -350,7 +351,8 @@ class Multi_field_element
static Multi_field_element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics)
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

if (productOfCharacteristics == 0 || productOfCharacteristics == productOfAllCharacteristics_) {
return get_multiplicative_identity();
Expand Down
8 changes: 5 additions & 3 deletions multipers/gudhi/gudhi/Fields/Multi_field_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber, Clément Maria
*
* Copyright (C) 2022-24 Inria
* Copyright (C) 2022 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
Expand Down Expand Up @@ -366,7 +366,8 @@ class Multi_field_operators
const Characteristic& productOfCharacteristics) const
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

Characteristic QR;
mpz_gcd(QR.get_mpz_t(), e.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)
Expand Down Expand Up @@ -409,7 +410,8 @@ class Multi_field_operators
[[nodiscard]] Element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics) const
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

if (productOfCharacteristics == nullCharacteristic || productOfCharacteristics == productOfAllCharacteristics_) {
return get_multiplicative_identity();
Expand Down
8 changes: 5 additions & 3 deletions multipers/gudhi/gudhi/Fields/Multi_field_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber, Clément Maria
*
* Copyright (C) 2022-24 Inria
* Copyright (C) 2022 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
Expand Down Expand Up @@ -347,7 +347,8 @@ class Shared_multi_field_element
const Characteristic& productOfCharacteristics) const
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

Element QR;
mpz_gcd(QR.get_mpz_t(), element_.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)
Expand Down Expand Up @@ -390,7 +391,8 @@ class Shared_multi_field_element
static Shared_multi_field_element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics)
{
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");
std::invalid_argument(
"The given product is not the product of a subset of the current Multi-field characteristics."));

if (productOfCharacteristics == 0 || productOfCharacteristics == productOfAllCharacteristics_) {
return get_multiplicative_identity();
Expand Down
Loading