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
9 changes: 5 additions & 4 deletions multipers/gudhi/gudhi/Degree_rips_bifiltration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,11 @@ class Degree_rips_bifiltration
for (size_type g = 0; g < num_generators(); ++g) {
GUDHI_CHECK_code(GUDHI_CHECK(static_cast<size_type>(indices[g]) == g, std::invalid_argument("Unvalid grid.")));

auto d = std::distance(
values.begin(),
std::lower_bound(
values.begin(), values.end(), static_cast<typename OneDimArray::value_type>(generators_[g])));
auto v = static_cast<typename OneDimArray::value_type>(generators_[g]);
auto d = std::distance(values.begin(), std::lower_bound(values.begin(), values.end(), v));
if (d != 0 && std::abs(v - values[d]) > std::abs(v - values[d - 1])) {
--d;
}
generators_[g] = coordinate ? static_cast<T>(d) : static_cast<T>(values[d]);
}
}
Expand Down
9 changes: 5 additions & 4 deletions multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ namespace Gudhi::multi_filtration {
* \f$\mathbb R^n\f$-filtration value. E.g., the filtration value of a simplex, or, of the algebraic generator of a
* module presentation. Different from @ref Multi_parameter_filtration, the underlying container is a vector of vectors
* and therefore less memory efficient, but much more flexible when modifying the filtration value. So, this class is
* preferable if a lot of generators need to be added on the fly or removed. When the filtration values are fixed or
* 1-critical, we recommend @ref Multi_parameter_filtration instead. Implements the concept @ref FiltrationValue of the
* @ref Gudhi::Simplex_tree and the concept @ref Gudhi::multi_persistence::MultiFiltrationValue.
* preferable if a lot of generators need to be added on the fly or removed. But when the filtration value is more or
* less fixed, e.g. for 1-critical filtrations, we recommend @ref Multi_parameter_filtration instead. Implements
* the concept @ref FiltrationValue of the @ref Gudhi::Simplex_tree and the concept
* @ref Gudhi::multi_persistence::MultiFiltrationValue.
*
* @details Overloads `std::numeric_limits` such that:
* - `std::numeric_limits<Dynamic_multi_parameter_filtration>::has_infinity` returns `true`,
Expand Down Expand Up @@ -513,7 +514,7 @@ class Dynamic_multi_parameter_filtration
* @brief Returns the total number of values in the filtration value, that is,
* @ref num_parameters() * @ref num_generators().
*/
size_type num_entries() const { return num_generators() * num_parameters(); }
size_type num_entries() const { return generators_.size() * number_of_parameters_; }

/**
* @brief Returns a filtration value with given number of parameters for which @ref is_plus_inf() returns `true`
Expand Down
28 changes: 18 additions & 10 deletions multipers/gudhi/gudhi/Fields/Multi_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gmpxx.h>
#include <stdexcept>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -258,14 +260,14 @@ class Multi_field_element
*/
friend bool operator!=(const Multi_field_element& f, const Element& v) { return !(v == f); }

/**
* @brief Assign operator.
*/
Multi_field_element& operator=(const Element& value)
{
mpz_mod(element_.get_mpz_t(), value.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
return *this;
}
// /**
// * @brief Assign operator.
// */
// Multi_field_element& operator=(const Element& value)
// {
// mpz_mod(element_.get_mpz_t(), value.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
// return *this;
// }

/**
* @brief Swap operator.
Expand Down Expand Up @@ -302,6 +304,9 @@ class Multi_field_element
[[nodiscard]] std::pair<Multi_field_element, Characteristic> get_partial_inverse(
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.");

Characteristic QR;
mpz_gcd(QR.get_mpz_t(), element_.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)

Expand Down Expand Up @@ -344,8 +349,11 @@ class Multi_field_element
*/
static Multi_field_element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics)
{
if (productOfCharacteristics == 0) {
return Multi_field_element<minimum, maximum>(multiplicativeID_);
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"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();
}
Multi_field_element<minimum, maximum> mult;
for (unsigned int idx = 0; idx < primes_.size(); ++idx) {
Expand Down
10 changes: 9 additions & 1 deletion multipers/gudhi/gudhi/Fields/Multi_field_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gmpxx.h>
#include <stdexcept>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -363,6 +365,9 @@ class Multi_field_operators
const Element& e,
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.");

Characteristic QR;
mpz_gcd(QR.get_mpz_t(), e.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)

Expand Down Expand Up @@ -403,7 +408,10 @@ class Multi_field_operators
*/
[[nodiscard]] Element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics) const
{
if (productOfCharacteristics == nullCharacteristic) {
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"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();
}
Element multIdentity(0);
Expand Down
28 changes: 18 additions & 10 deletions multipers/gudhi/gudhi/Fields/Multi_field_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gmpxx.h>
#include <stdexcept>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -297,14 +299,14 @@ class Shared_multi_field_element
*/
friend bool operator!=(const Shared_multi_field_element& f, const Element& v) { return !(v == f); }

/**
* @brief Assign operator.
*/
Shared_multi_field_element& operator=(const Element& value)
{
mpz_mod(element_.get_mpz_t(), value.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
return *this;
}
// /**
// * @brief Assign operator.
// */
// Shared_multi_field_element& operator=(const Element& value)
// {
// mpz_mod(element_.get_mpz_t(), value.get_mpz_t(), productOfAllCharacteristics_.get_mpz_t());
// return *this;
// }

/**
* @brief Swap operator.
Expand Down Expand Up @@ -344,6 +346,9 @@ class Shared_multi_field_element
[[nodiscard]] std::pair<Shared_multi_field_element, Characteristic> get_partial_inverse(
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.");

Element QR;
mpz_gcd(QR.get_mpz_t(), element_.get_mpz_t(), productOfCharacteristics.get_mpz_t()); // QR <- gcd(x,QS)

Expand Down Expand Up @@ -384,8 +389,11 @@ class Shared_multi_field_element
*/
static Shared_multi_field_element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics)
{
if (productOfCharacteristics == 0) {
return {multiplicativeID_};
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"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();
}
Shared_multi_field_element mult;
for (unsigned int idx = 0; idx < primes_.size(); ++idx) {
Expand Down
34 changes: 21 additions & 13 deletions multipers/gudhi/gudhi/Fields/Multi_field_small.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <limits.h>
#include <numeric>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -304,17 +306,17 @@ class Multi_field_element_with_small_characteristics
return !(v == f);
}

/**
* @brief Assign operator.
*
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
*/
template <typename Integer_type, class = isInteger<Integer_type> >
Multi_field_element_with_small_characteristics& operator=(const Integer_type& value)
{
element_ = _get_value(value);
return *this;
}
// /**
// * @brief Assign operator.
// *
// * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
// */
// template <typename Integer_type, class = isInteger<Integer_type> >
// Multi_field_element_with_small_characteristics& operator=(const Integer_type& value)
// {
// element_ = _get_value(value);
// return *this;
// }

/**
* @brief Swap operator.
Expand Down Expand Up @@ -350,6 +352,9 @@ class Multi_field_element_with_small_characteristics
std::pair<Multi_field_element_with_small_characteristics, Characteristic> get_partial_inverse(
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.");

Characteristic gcd = std::gcd(element_, productOfAllCharacteristics_);

if (gcd == productOfCharacteristics)
Expand Down Expand Up @@ -395,8 +400,11 @@ class Multi_field_element_with_small_characteristics
static Multi_field_element_with_small_characteristics get_partial_multiplicative_identity(
const Characteristic& productOfCharacteristics)
{
if (productOfCharacteristics == 0) {
return Multi_field_element_with_small_characteristics<minimum, maximum>(multiplicativeID_);
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"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();
}
Multi_field_element_with_small_characteristics<minimum, maximum> mult;
for (Characteristic idx = 0; idx < primes_.size(); ++idx) {
Expand Down
10 changes: 9 additions & 1 deletion multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <stdexcept>
#include <numeric>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -324,6 +326,9 @@ class Multi_field_operators_with_small_characteristics
std::pair<Element, Characteristic> get_partial_inverse(const Element& e,
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.");

Characteristic gcd = std::gcd(e, productOfAllCharacteristics_);

if (gcd == productOfCharacteristics) return {0, get_multiplicative_identity()}; // partial inverse is 0
Expand Down Expand Up @@ -362,7 +367,10 @@ class Multi_field_operators_with_small_characteristics
*/
[[nodiscard]] Element get_partial_multiplicative_identity(const Characteristic& productOfCharacteristics) const
{
if (productOfCharacteristics == nullCharacteristic) {
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"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();
}
Element multIdentity = 0;
Expand Down
32 changes: 20 additions & 12 deletions multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <stdexcept>
#include <numeric>

#include <gudhi/Debug_utils.h>

namespace Gudhi {
namespace persistence_fields {

Expand Down Expand Up @@ -346,17 +348,17 @@ class Shared_multi_field_element_with_small_characteristics
return !(v == f);
}

/**
* @brief Assign operator.
*
* @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
*/
template <typename Integer_type, class = isInteger<Integer_type> >
Shared_multi_field_element_with_small_characteristics& operator=(const Integer_type& value)
{
element_ = _get_value(value);
return *this;
}
// /**
// * @brief Assign operator.
// *
// * @tparam Integer_type A native integer type. Should be able to contain the characteristic if signed.
// */
// template <typename Integer_type, class = isInteger<Integer_type> >
// Shared_multi_field_element_with_small_characteristics& operator=(const Integer_type& value)
// {
// element_ = _get_value(value);
// return *this;
// }

/**
* @brief Swap operator.
Expand Down Expand Up @@ -392,6 +394,9 @@ class Shared_multi_field_element_with_small_characteristics
std::pair<Shared_multi_field_element_with_small_characteristics, Characteristic> get_partial_inverse(
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.");

Characteristic gcd = std::gcd(element_, productOfAllCharacteristics_);

if (gcd == productOfCharacteristics)
Expand Down Expand Up @@ -437,7 +442,10 @@ class Shared_multi_field_element_with_small_characteristics
static Shared_multi_field_element_with_small_characteristics get_partial_multiplicative_identity(
const Characteristic& productOfCharacteristics)
{
if (productOfCharacteristics == 0) {
GUDHI_CHECK(productOfCharacteristics >= 0 && productOfCharacteristics <= productOfAllCharacteristics_,
"The given product is not the product of a subset of the current Multi-field characteristics.");

if (productOfCharacteristics == 0 || productOfCharacteristics == productOfAllCharacteristics_) {
return Shared_multi_field_element_with_small_characteristics(multiplicativeID_);
}
Shared_multi_field_element_with_small_characteristics mult;
Expand Down
2 changes: 2 additions & 0 deletions multipers/gudhi/gudhi/Fields/Z2_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class Z2_field_element
*/
Z2_field_element& operator=(Z2_field_element&& other) noexcept
{
if (this == &other) return *this;

element_ = std::exchange(other.element_, false);
return *this;
}
Expand Down
2 changes: 2 additions & 0 deletions multipers/gudhi/gudhi/Fields/Zp_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class Zp_field_element
*/
Zp_field_element& operator=(Zp_field_element&& other) noexcept
{
if (this == &other) return *this;

element_ = std::exchange(other.element_, 0);
return *this;
}
Expand Down
2 changes: 2 additions & 0 deletions multipers/gudhi/gudhi/Fields/Zp_field_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ class Shared_Zp_field_element
*/
Shared_Zp_field_element& operator=(Shared_Zp_field_element&& other) noexcept
{
if (this == &other) return *this;

element_ = std::exchange(other.element_, 0);
return *this;
}
Expand Down
Loading
Loading