From d68ddc94bd82c48a4433ae0b3b1b3f10c167ed0b Mon Sep 17 00:00:00 2001 From: Hind Date: Wed, 28 Apr 2021 14:05:03 +0200 Subject: Add points (dataset type) before the underlying model (sphere) as a module --- .../gudhi/datasets/generators/points/sphere.cc | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/python/gudhi/datasets/generators/points/sphere.cc (limited to 'src/python/gudhi/datasets/generators/points/sphere.cc') diff --git a/src/python/gudhi/datasets/generators/points/sphere.cc b/src/python/gudhi/datasets/generators/points/sphere.cc new file mode 100644 index 00000000..79392ef0 --- /dev/null +++ b/src/python/gudhi/datasets/generators/points/sphere.cc @@ -0,0 +1,61 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Hind Montassif + * + * Copyright (C) 2021 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +#include +#include + +#include +#include + +#include + +namespace py = pybind11; + + +typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kern; + +py::array_t generate_points_on_sphere(size_t num_points, int dim, double radius) { + + py::array_t points({num_points, (size_t)dim}); + + py::buffer_info buf = points.request(); + double *ptr = static_cast(buf.ptr); + + 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(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(sphere, m) { + m.attr("__license__") = "LGPL v3"; + m.def("generate_random_points", &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 R^d + + :param num_points: The number of points to be generated. + :type num_points: unsigned integer + :param dim: The dimension. + :type dim: integer + :param radius: The radius. + :type radius: float + :rtype: numpy array of float + :returns: the generated points on a sphere. + )pbdoc"); +} -- cgit v1.2.3