summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorHind-M <hind.montassif@gmail.com>2021-07-01 15:56:11 +0200
committerHind-M <hind.montassif@gmail.com>2021-07-01 15:56:11 +0200
commit62b63fd55442b152b934dc0c9ed662970ddb32dc (patch)
tree2761d546ba943a40a2973b499e884e7d21442c07 /src/python
parent68031184fb94cf19c8b3c6f0de122db447693847 (diff)
Move primality test to Field_Zp::init
Throw exception when not prime Add tests
Diffstat (limited to 'src/python')
-rw-r--r--src/python/gudhi/cubical_complex.pyx2
-rw-r--r--src/python/gudhi/periodic_cubical_complex.pyx2
-rw-r--r--src/python/gudhi/simplex_tree.pxd2
-rw-r--r--src/python/include/Persistent_cohomology_interface.h20
4 files changed, 3 insertions, 23 deletions
diff --git a/src/python/gudhi/cubical_complex.pyx b/src/python/gudhi/cubical_complex.pyx
index 28fbe3af..adc40499 100644
--- a/src/python/gudhi/cubical_complex.pyx
+++ b/src/python/gudhi/cubical_complex.pyx
@@ -35,7 +35,7 @@ cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<>>":
Cubical_complex_persistence_interface(Bitmap_cubical_complex_base_interface * st, bool persistence_dim_max) nogil
- void compute_persistence(int homology_coeff_field, double min_persistence) nogil
+ void compute_persistence(int homology_coeff_field, double min_persistence) nogil except+
vector[pair[int, pair[double, double]]] get_persistence() nogil
vector[vector[int]] cofaces_of_cubical_persistence_pairs() nogil
vector[int] betti_numbers() nogil
diff --git a/src/python/gudhi/periodic_cubical_complex.pyx b/src/python/gudhi/periodic_cubical_complex.pyx
index d353d2af..0eaa5867 100644
--- a/src/python/gudhi/periodic_cubical_complex.pyx
+++ b/src/python/gudhi/periodic_cubical_complex.pyx
@@ -32,7 +32,7 @@ cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Periodic_cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<Gudhi::cubical_complex::Bitmap_cubical_complex_periodic_boundary_conditions_base<double>>>":
Periodic_cubical_complex_persistence_interface(Periodic_cubical_complex_base_interface * st, bool persistence_dim_max) nogil
- void compute_persistence(int homology_coeff_field, double min_persistence) nogil
+ void compute_persistence(int homology_coeff_field, double min_persistence) nogil except +
vector[pair[int, pair[double, double]]] get_persistence() nogil
vector[vector[int]] cofaces_of_cubical_persistence_pairs() nogil
vector[int] betti_numbers() nogil
diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd
index 3b8ea4f9..006a24ed 100644
--- a/src/python/gudhi/simplex_tree.pxd
+++ b/src/python/gudhi/simplex_tree.pxd
@@ -78,7 +78,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>":
Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st, bool persistence_dim_max) nogil
- void compute_persistence(int homology_coeff_field, double min_persistence) nogil
+ void compute_persistence(int homology_coeff_field, double min_persistence) nogil except +
vector[pair[int, pair[double, double]]] get_persistence() nogil
vector[int] betti_numbers() nogil
vector[int] persistent_betti_numbers(double from_value, double to_value) nogil
diff --git a/src/python/include/Persistent_cohomology_interface.h b/src/python/include/Persistent_cohomology_interface.h
index 6877f190..e5a3dfba 100644
--- a/src/python/include/Persistent_cohomology_interface.h
+++ b/src/python/include/Persistent_cohomology_interface.h
@@ -43,21 +43,6 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
}
};
- bool is_prime(int n) {
- // Primality test using 6k+-1 optimization.
- if (n <= 3)
- return n > 1;
- if ((n % 2 == 0) || (n % 3 == 0))
- return false;
- int i = 5;
- while (i*i <= n) {
- if ((n % i == 0) || (n % (i + 2) == 0))
- return false;
- i += 6;
- }
- return true;
- }
-
public:
Persistent_cohomology_interface(FilteredComplex* stptr, bool persistence_dim_max=false)
: Base(*stptr, persistence_dim_max),
@@ -65,11 +50,6 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
// TODO: move to the constructors?
void compute_persistence(int homology_coeff_field, double min_persistence) {
- // Check that homology_coeff_field is a prime number (including not null)
- if(!is_prime(homology_coeff_field)) {
- std::cerr << "Warning: The persistence was not computed ; homology_coeff_field must be a prime number";
- return;
- }
Base::init_coefficients(homology_coeff_field);
Base::compute_persistent_cohomology(min_persistence);
}