diff --git a/src/Ripser/utilities/ripser.cc b/src/Ripser/utilities/ripser.cc index f422edd404..6dabba826b 100644 --- a/src/Ripser/utilities/ripser.cc +++ b/src/Ripser/utilities/ripser.cc @@ -1,4 +1,9 @@ -// Based on Ripser commit 140670f2c76997404601e43d8054151f46be9fd7 +/* Based on Ripser commit 140670f2c76997404601e43d8054151f46be9fd7 + * Modification(s): + * - YYYY/MM Author: Description of the modification + * - 2024 Marc Glisse: Heavy refactoring +*/ + /* Ripser: a lean C++ code for computation of Vietoris-Rips persistence barcodes diff --git a/src/python/gudhi/_ripser.cc b/src/python/gudhi/_ripser.cc index 2ef06ffc42..56e528f248 100644 --- a/src/python/gudhi/_ripser.cc +++ b/src/python/gudhi/_ripser.cc @@ -2,7 +2,7 @@ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. * Author(s): Marc Glisse * - * Copyright (C) 2023 Inria + * Copyright (C) 2024 Inria * * Modification(s): * - YYYY/MM Author: Description of the modification @@ -31,25 +31,6 @@ PYBIND11_MAKE_OPAQUE(Vd); PYBIND11_MAKE_OPAQUE(V2f); PYBIND11_MAKE_OPAQUE(V2d); -//templatestruct Numpy_euclidean { -// typedef Tag_other Category; -// typedef int vertex_t; -// typedef T value_t; -// -// decltype(std::declval&>().template unchecked<2>()) data; -// -// int size() const { return data.shape(0); } -// -// T operator()(int i, int j) const { -// T dist = 0; -// for (int k=0; kstruct Full { typedef Tag_dense Category; typedef int vertex_t; @@ -90,23 +71,6 @@ py::list doit(DistanceMatrix&& dist, int max_dimension, typename DistanceMatrix: return ret; } -//template -//py::list euclidean(py::array_t points, int max_dimension, T max_edge_length, unsigned homology_coeff_field) { -// Numpy_euclidean dist{points.template unchecked<2>()}; -// if(dist.data.ndim() != 2) -// throw std::runtime_error("points must be a 2-dimensional array"); -// -// // ripser_auto should already do that -//#if 0 -// // optional as a trick to allow destruction where I want it, without hiding dist in some scope that ends too early. -// std::optional release_local(std::in_place); -// compressed_distance_matrix, LOWER_TRIANGULAR> dist(dist_); -// release_local.reset(); -//#endif -// -// return doit(std::move(dist), max_dimension, max_edge_length, homology_coeff_field); -//} - template py::list full(py::array_t matrix, int max_dimension, T max_edge_length, unsigned homology_coeff_field) { Full dist{matrix.template unchecked<2>()}; @@ -130,19 +94,9 @@ py::list lower(py::object low_mat, int max_dimension, double max_edge_length, un ++rowi; }; + // optional as a trick to allow destruction where I want it std::optional release_local(std::in_place); Dist dist(std::move(distances)); - -#if 0 - // Compute the radius and possibly use it as threshold - for (int i = 0; i < dist.size(); ++i) { - double r_i = -std::numeric_limits::infinity(); - for (int j = 0; j < dist.size(); ++j) - r_i = std::max(r_i, dist(i, j)); - max_edge_length = std::min(max_edge_length, r_i); - } -#endif - release_local.reset(); return doit(std::move(dist), max_dimension, max_edge_length, homology_coeff_field); @@ -150,6 +104,7 @@ py::list lower(py::object low_mat, int max_dimension, double max_edge_length, un template py::list sparse(py::array_t is_, py::array_t js_, py::array_t fs_, int num_vertices, int max_dimension, T max_edge_length, unsigned homology_coeff_field) { + // Duplicate entries and self loops are forbidden auto is = is_.unchecked(); auto js = js_.unchecked(); auto fs = fs_.unchecked(); @@ -180,7 +135,7 @@ py::list sparse(py::array_t is_, py::array_t js_, py::array_t fs_, int py::list lower_to_coo(py::object low_mat, double max_edge_length) { // Cannot release the GIL since we keep accessing Python objects. // TODO: full_to_coo for numpy arrays? - // Should we compute the cone radius at the same time? (requires a vector of maxima) + // Should we compute the cone radius at the same time? std::vector is, js; std::vector fs; int rowi = 0; @@ -231,13 +186,10 @@ PYBIND11_MODULE(_ripser, m) { py::bind_vector(m, "VectorPairFloat" , py::buffer_protocol()); py::bind_vector(m, "VectorPairDouble", py::buffer_protocol()); // Remove the default for max_dimension? - //m.def("_euclidean", euclidean, py::arg("points").noconvert(), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); - //m.def("_euclidean", euclidean, py::arg("points"), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); m.def("_full", full, py::arg("matrix").noconvert(), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); m.def("_full", full, py::arg("matrix"), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); m.def("_lower", lower, py::arg("matrix"), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); // We could do a version with long, but copying the arrays of integers shouldn't be too costly - // TODO doc: duplicate entries forbidden m.def("_sparse", sparse, py::arg("row"), py::arg("col"), py::arg("data").noconvert(), py::arg("num_vertices"), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); m.def("_sparse", sparse, py::arg("row"), py::arg("col"), py::arg("data"), py::arg("num_vertices"), py::arg("max_dimension") = std::numeric_limits::max(), py::arg("max_edge_length") = std::numeric_limits::infinity(), py::arg("homology_coeff_field") = 2); // Not directly an interface to Ripser... @@ -246,5 +198,3 @@ PYBIND11_MODULE(_ripser, m) { } // We could also create a RipsComplex class, that allows looking at a simplex, querying its (co)boundary, etc. But I am not convinced it is worth the effort. - -// TODO: split into 3 files (sparse, full, lower) to help compilation. diff --git a/src/python/include/circle20 b/src/python/include/circle20 deleted file mode 100644 index 0110bb15ff..0000000000 --- a/src/python/include/circle20 +++ /dev/null @@ -1,20 +0,0 @@ -1.0 0.0 -0.9510565162951535 0.3090169943749474 -0.8090169943749475 0.5877852522924731 -0.5877852522924731 0.8090169943749475 -0.30901699437494745 0.9510565162951535 -6.123233995736766e-17 1.0 --0.30901699437494734 0.9510565162951536 --0.587785252292473 0.8090169943749475 --0.8090169943749473 0.5877852522924732 --0.9510565162951535 0.3090169943749475 --1.0 1.2246467991473532e-16 --0.9510565162951536 -0.3090169943749473 --0.8090169943749476 -0.587785252292473 --0.5877852522924732 -0.8090169943749473 --0.30901699437494756 -0.9510565162951535 --1.8369701987210297e-16 -1.0 -0.30901699437494723 -0.9510565162951536 -0.5877852522924729 -0.8090169943749476 -0.8090169943749473 -0.5877852522924734 -0.9510565162951535 -0.3090169943749476 diff --git a/src/python/include/circle30 b/src/python/include/circle30 deleted file mode 100644 index 8cd179f2b4..0000000000 --- a/src/python/include/circle30 +++ /dev/null @@ -1,30 +0,0 @@ -1.0 0.0 -0.9781476007338057 0.20791169081775931 -0.9135454576426009 0.40673664307580015 -0.8090169943749475 0.5877852522924731 -0.6691306063588582 0.7431448254773941 -0.5000000000000001 0.8660254037844386 -0.30901699437494745 0.9510565162951535 -0.10452846326765368 0.9945218953682733 --0.10452846326765333 0.9945218953682734 --0.30901699437494734 0.9510565162951536 --0.4999999999999998 0.8660254037844387 --0.6691306063588579 0.7431448254773945 --0.8090169943749473 0.5877852522924732 --0.9135454576426008 0.40673664307580043 --0.9781476007338056 0.20791169081775973 --1.0 1.2246467991473532e-16 --0.9781476007338057 -0.20791169081775907 --0.9135454576426011 -0.4067366430757998 --0.8090169943749476 -0.587785252292473 --0.6691306063588585 -0.743144825477394 --0.5000000000000004 -0.8660254037844384 --0.30901699437494756 -0.9510565162951535 --0.10452846326765423 -0.9945218953682733 -0.10452846326765299 -0.9945218953682734 -0.30901699437494723 -0.9510565162951536 -0.49999999999999933 -0.866025403784439 -0.6691306063588578 -0.7431448254773946 -0.8090169943749473 -0.5877852522924734 -0.9135454576426005 -0.40673664307580093 -0.9781476007338056 -0.20791169081775987 diff --git a/src/python/include/circle50 b/src/python/include/circle50 deleted file mode 100644 index cbc93979a9..0000000000 --- a/src/python/include/circle50 +++ /dev/null @@ -1,50 +0,0 @@ -1.0 0.0 -0.9921147013144779 0.12533323356430426 -0.9685831611286311 0.2486898871648548 -0.9297764858882513 0.368124552684678 -0.8763066800438636 0.4817536741017153 -0.8090169943749475 0.5877852522924731 -0.7289686274214116 0.6845471059286887 -0.6374239897486896 0.7705132427757893 -0.5358267949789965 0.8443279255020151 -0.42577929156507266 0.9048270524660196 -0.30901699437494745 0.9510565162951535 -0.18738131458572452 0.9822872507286887 -0.0627905195293133 0.9980267284282716 --0.0627905195293134 0.9980267284282716 --0.18738131458572482 0.9822872507286886 --0.30901699437494756 0.9510565162951535 --0.4257792915650727 0.9048270524660195 --0.5358267949789969 0.844327925502015 --0.6374239897486897 0.7705132427757893 --0.7289686274214117 0.6845471059286885 --0.8090169943749473 0.5877852522924732 --0.8763066800438636 0.4817536741017152 --0.9297764858882515 0.36812455268467775 --0.9685831611286311 0.24868988716485482 --0.9921147013144779 0.1253332335643041 --1.0 -3.216245299353273e-16 --0.9921147013144779 -0.12533323356430429 --0.9685831611286311 -0.24868988716485502 --0.9297764858882512 -0.3681245526846783 --0.8763066800438635 -0.4817536741017154 --0.8090169943749472 -0.5877852522924734 --0.7289686274214116 -0.6845471059286887 --0.6374239897486895 -0.7705132427757894 --0.5358267949789963 -0.8443279255020153 --0.42577929156507216 -0.9048270524660198 --0.30901699437494756 -0.9510565162951535 --0.18738131458572463 -0.9822872507286887 --0.06279051952931321 -0.9980267284282716 -0.06279051952931372 -0.9980267284282716 -0.18738131458572513 -0.9822872507286886 -0.30901699437494723 -0.9510565162951536 -0.4257792915650726 -0.9048270524660196 -0.5358267949789968 -0.844327925502015 -0.63742398974869 -0.770513242775789 -0.7289686274214119 -0.6845471059286883 -0.8090169943749478 -0.5877852522924726 -0.8763066800438636 -0.4817536741017153 -0.9297764858882515 -0.36812455268467786 -0.9685831611286312 -0.2486898871648545 -0.9921147013144779 -0.1253332335643038