summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHind <hind.montassif@gmail.com>2021-04-26 11:47:36 +0200
committerHind <hind.montassif@gmail.com>2021-04-26 11:47:36 +0200
commite59b1cfd338a80a769c0e2b6d677b9474b07beb3 (patch)
treebfcb620876086b5aed7675cb4cb4bdfdbd9b51b3 /src
parentdb7ce3487e526741c0408b00c2cffda0048b0026 (diff)
Replace assert with GUDHI_CHECK
Make the function non-template Change typing and casting
Diffstat (limited to 'src')
-rw-r--r--src/python/gudhi/random_point_generators.cc34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/python/gudhi/random_point_generators.cc b/src/python/gudhi/random_point_generators.cc
index 4306ba98..6eb40429 100644
--- a/src/python/gudhi/random_point_generators.cc
+++ b/src/python/gudhi/random_point_generators.cc
@@ -12,6 +12,7 @@
#include <pybind11/numpy.h>
#include <gudhi/random_point_generators.h>
+#include <gudhi/Debug_utils.h>
#include <CGAL/Epick_d.h>
@@ -20,36 +21,33 @@ namespace py = pybind11;
typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kern;
-template <typename Kernel>
py::array_t<double> generate_points_on_sphere(size_t num_points, int dim, double radius) {
-
- py::array_t<double> points({(int)num_points, dim});
-
+
+ py::array_t<double> points({num_points, (size_t)dim});
+
py::buffer_info buf = points.request();
double *ptr = static_cast<double *>(buf.ptr);
- assert(num_points == buf.shape[0]);
- assert(dim == buf.shape[1]);
-
- std::vector<typename Kernel::Point_d> points_generated;
- {
- py::gil_scoped_release release;
- points_generated = Gudhi::generate_points_on_sphere_d<Kernel>(num_points, dim, radius);
-
- for (size_t i = 0; i < num_points; i++)
- for (size_t j = 0; j < (size_t)dim; j++)
- ptr[i*dim+j] = points_generated[i][j];
- }
+ GUDHI_CHECK(num_points == buf.shape[0], "Py array first dimension not matching num_points on sphere");
+ GUDHI_CHECK(dim == buf.shape[1], "Py array second dimension not matching the ambient space dimension");
+
+
+ py::gil_scoped_release release;
+ auto points_generated = Gudhi::generate_points_on_sphere_d<Kern>(num_points, dim, radius);
+
+ for (size_t i = 0; i < num_points; i++)
+ for (int j = 0; j < dim; j++)
+ ptr[i*dim+j] = points_generated[i][j];
return points;
}
PYBIND11_MODULE(random_point_generators, m) {
m.attr("__license__") = "LGPL v3";
- m.def("generate_points_on_sphere_d", &generate_points_on_sphere<Kern>,
+ m.def("generate_points_on_sphere_d", &generate_points_on_sphere,
py::arg("num_points"), py::arg("dim"), py::arg("radius") = 1,
R"pbdoc(
- Generate random i.i.d. points uniformly on a (d-1)-sphere in Rd
+ Generate random i.i.d. points uniformly on a (d-1)-sphere in R^d
:param num_points: The number of points to be generated.
:type num_points: unsigned integer