diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2021-03-22 00:37:47 +0100 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-04-06 07:37:17 -0400 |
commit | eb91fb04b3d0ca8124b9bea375e3bf72963fa172 (patch) | |
tree | dcf96c9e232b7019a7d81cd16901a95bda8b5471 /gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc | |
parent | 42349ff2855c1bb0148c8191339189b0a4cee675 (diff) |
runtime: fix gr::random API to be fixed-width 64 bit, use XOROSHIRO128+
Seeding being inconsistent between gr::random and things like fastnoise
source is an outstanding issue (#1559).
Fix that by fixing the API, and pivoting to our built-in XOROSHIRO128+,
which is also substantially faster than MT19937.
For that purpose, introduce, and python-bind, a wrapper class that can
be used with STL distribution shapers.
Add a unit test for the (P)RNG.
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc index 8c823e5977..57fbbb2495 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/random_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(random.h) */ -/* BINDTOOL_HEADER_FILE_HASH(95215055c6ad6f78b88d532d3994d29a) */ +/* BINDTOOL_HEADER_FILE_HASH(489c2917f344c75e2001d0c670de7784) */ /***********************************************************************************/ #include <pybind11/complex.h> @@ -29,10 +29,35 @@ namespace py = pybind11; void bind_random(py::module& m) { - + using xoroshiro128p_prng = ::gr::xoroshiro128p_prng; using random = ::gr::random; + py::class_<xoroshiro128p_prng, std::shared_ptr<xoroshiro128p_prng>>( + m, "xoroshiro128p_prng", D(xoroshiro128p_prng)) + + .def(py::init<uint64_t>(), + py::arg("init"), + D(xoroshiro128p_prng, xoroshiro128p_prng, 0)) + .def(py::init<gr::xoroshiro128p_prng const&>(), + py::arg("arg0"), + D(xoroshiro128p_prng, xoroshiro128p_prng, 1)) + + + .def_static("min", &xoroshiro128p_prng::min, D(xoroshiro128p_prng, min)) + + + .def_static("max", &xoroshiro128p_prng::max, D(xoroshiro128p_prng, max)) + + + .def("seed", + &xoroshiro128p_prng::seed, + py::arg("seed"), + D(xoroshiro128p_prng, seed)) + + .def("__call__", &xoroshiro128p_prng::operator()); + + py::class_<random, std::shared_ptr<random>>(m, "random", D(random)) .def(py::init<uint64_t, int64_t, int64_t>(), |