diff options
author | Vincent Rouvreau <vincent.rouvreau@inria.fr> | 2021-11-02 10:53:05 +0100 |
---|---|---|
committer | Vincent Rouvreau <vincent.rouvreau@inria.fr> | 2021-11-02 10:53:05 +0100 |
commit | 003abb66b7c657356328bc24306e2c5aef02b1d4 (patch) | |
tree | 0530c8987c824da79ecddd22485f143831a4c71f /src/python/gudhi/datasets | |
parent | b1f604312adb6a9240f8e8b7effcd4bd7251e82b (diff) | |
parent | 8adb46d8a54f1a0dd71ea686473cc4ca9f5d2f67 (diff) |
Merge master and fix conflicts
Diffstat (limited to 'src/python/gudhi/datasets')
-rw-r--r-- | src/python/gudhi/datasets/__init__.py | 0 | ||||
-rw-r--r-- | src/python/gudhi/datasets/generators/__init__.py | 0 | ||||
-rw-r--r-- | src/python/gudhi/datasets/generators/points.cc | 68 |
3 files changed, 68 insertions, 0 deletions
diff --git a/src/python/gudhi/datasets/__init__.py b/src/python/gudhi/datasets/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/python/gudhi/datasets/__init__.py diff --git a/src/python/gudhi/datasets/generators/__init__.py b/src/python/gudhi/datasets/generators/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/python/gudhi/datasets/generators/__init__.py diff --git a/src/python/gudhi/datasets/generators/points.cc b/src/python/gudhi/datasets/generators/points.cc new file mode 100644 index 00000000..d658946b --- /dev/null +++ b/src/python/gudhi/datasets/generators/points.cc @@ -0,0 +1,68 @@ +/* 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 <pybind11/pybind11.h> +#include <pybind11/numpy.h> + +#include <gudhi/random_point_generators.h> +#include <gudhi/Debug_utils.h> + +#include <CGAL/Epick_d.h> + +namespace py = pybind11; + + +typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kern; + +py::array_t<double> generate_points_on_sphere(size_t n_samples, int ambient_dim, double radius, std::string sample) { + + if (sample != "random") { + throw pybind11::value_error("This sample type is not supported"); + } + + py::array_t<double> points({n_samples, (size_t)ambient_dim}); + + py::buffer_info buf = points.request(); + double *ptr = static_cast<double *>(buf.ptr); + + GUDHI_CHECK(n_samples == buf.shape[0], "Py array first dimension not matching n_samples on sphere"); + GUDHI_CHECK(ambient_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>(n_samples, ambient_dim, radius); + + for (size_t i = 0; i < n_samples; i++) + for (int j = 0; j < ambient_dim; j++) + ptr[i*ambient_dim+j] = points_generated[i][j]; + + return points; +} + +PYBIND11_MODULE(points, m) { + m.attr("__license__") = "LGPL v3"; + m.def("sphere", &generate_points_on_sphere, + py::arg("n_samples"), py::arg("ambient_dim"), + py::arg("radius") = 1., py::arg("sample") = "random", + R"pbdoc( + Generate random i.i.d. points uniformly on a (d-1)-sphere in R^d + + :param n_samples: The number of points to be generated. + :type n_samples: integer + :param ambient_dim: The ambient dimension d. + :type ambient_dim: integer + :param radius: The radius. Default value is `1.`. + :type radius: float + :param sample: The sample type. Default and only available value is `"random"`. + :type sample: string + :rtype: numpy array of float + :returns: the generated points on a sphere. + )pbdoc"); +} |