23 #include <pybind11/pybind11.h>
25 #include <pybind11/stl.h>
33 using namespace pybind11::literals;
35 template <
typename ImageT>
37 mod.def(
"randomUniformImage", (
void (*)(ImageT *,
Random &))randomUniformImage<ImageT>);
38 mod.def(
"randomUniformPosImage", (
void (*)(ImageT *,
Random &))randomUniformPosImage<ImageT>);
39 mod.def(
"randomUniformIntImage",
40 (
void (*)(ImageT *,
Random &,
unsigned long))randomUniformIntImage<ImageT>);
41 mod.def(
"randomFlatImage",
42 (
void (*)(ImageT *,
Random &,
double const,
double const))randomFlatImage<ImageT>);
43 mod.def(
"randomGaussianImage", (
void (*)(ImageT *,
Random &))randomGaussianImage<ImageT>);
44 mod.def(
"randomChisqImage", (
void (*)(ImageT *,
Random &,
double const))randomChisqImage<ImageT>);
45 mod.def(
"randomPoissonImage", (
void (*)(ImageT *,
Random &,
double const))randomPoissonImage<ImageT>);
49 py::class_<Random> clsRandom(mod,
"Random");
52 py::enum_<Random::Algorithm>(clsRandom,
"Algorithm")
53 .value(
"MT19937", Random::Algorithm::MT19937)
54 .value(
"RANLXS0", Random::Algorithm::RANLXS0)
55 .value(
"RANLXS1", Random::Algorithm::RANLXS1)
56 .value(
"RANLXS2", Random::Algorithm::RANLXS2)
57 .value(
"RANLXD1", Random::Algorithm::RANLXD1)
58 .value(
"RANLXD2", Random::Algorithm::RANLXD2)
59 .value(
"RANLUX", Random::Algorithm::RANLUX)
60 .value(
"RANLUX389", Random::Algorithm::RANLUX389)
61 .value(
"CMRG", Random::Algorithm::CMRG)
62 .value(
"MRG", Random::Algorithm::MRG)
63 .value(
"TAUS", Random::Algorithm::TAUS)
64 .value(
"TAUS2", Random::Algorithm::TAUS2)
65 .value(
"GFSR4", Random::Algorithm::GFSR4)
66 .value(
"NUM_ALGORITHMS", Random::Algorithm::NUM_ALGORITHMS)
70 clsRandom.def(py::init<Random::Algorithm, unsigned long>(),
"algorithm"_a = Random::Algorithm::MT19937,
72 clsRandom.def(py::init<std::string const &, unsigned long>(),
"algorithm"_a,
"seed"_a = 1);
91 clsRandom.def(
"getState", [](
Random &
self) -> py::object {
93 return py::reinterpret_steal<py::object>(PyBytes_FromStringAndSize(state.
data(), state.
size()));
95 clsRandom.def(
"setState", [](
Random &
self,
py::bytes const &state) {
self.setState(state); });
98 declareRandomImage<lsst::afw::image::Image<double>>(mod);
99 declareRandomImage<lsst::afw::image::Image<float>>(mod);