23 #include <pybind11/pybind11.h>
25 #include <pybind11/stl.h>
33 using namespace pybind11::literals;
37 template <
typename ImageT>
39 wrappers.wrap([](
auto &mod) {
40 mod.def(
"randomUniformImage", (
void (*)(ImageT *,
Random &))randomUniformImage<ImageT>);
41 mod.def(
"randomUniformPosImage", (
void (*)(ImageT *,
Random &))randomUniformPosImage<ImageT>);
42 mod.def(
"randomUniformIntImage",
43 (
void (*)(ImageT *,
Random &,
unsigned long))randomUniformIntImage<ImageT>);
44 mod.def(
"randomFlatImage",
45 (
void (*)(ImageT *,
Random &,
double const,
double const))randomFlatImage<ImageT>);
46 mod.def(
"randomGaussianImage", (
void (*)(ImageT *,
Random &))randomGaussianImage<ImageT>);
47 mod.def(
"randomChisqImage", (
void (*)(ImageT *,
Random &,
double const))randomChisqImage<ImageT>);
48 mod.def(
"randomPoissonImage", (
void (*)(ImageT *,
Random &,
double const))randomPoissonImage<ImageT>);
53 auto clsRandom = wrappers.wrapType(py::class_<Random>(wrappers.module,
"Random"), [](
auto &mod,
56 cls.def(py::init<Random::Algorithm, unsigned long>(),
"algorithm"_a = Random::Algorithm::MT19937,
58 cls.def(py::init<std::string const &, unsigned long>(),
"algorithm"_a,
"seed"_a = 1);
61 cls.def(
"deepCopy", &Random::deepCopy);
62 cls.def(
"getAlgorithm", &Random::getAlgorithm);
63 cls.def(
"getAlgorithmName", &Random::getAlgorithmName);
64 cls.def_static(
"getAlgorithmNames", &Random::getAlgorithmNames);
65 cls.def(
"getSeed", &Random::getSeed);
66 cls.def(
"uniform", &Random::uniform);
67 cls.def(
"uniformPos", &Random::uniformPos);
68 cls.def(
"uniformInt", &Random::uniformInt);
69 cls.def(
"flat", &Random::flat);
70 cls.def(
"gaussian", &Random::gaussian);
71 cls.def(
"chisq", &Random::chisq);
72 cls.def(
"poisson", &Random::poisson);
77 cls.def(
"getState", [](Random &self) -> py::object {
78 std::string state = self.getState();
79 return py::reinterpret_steal<py::object>(PyBytes_FromStringAndSize(state.data(), state.size()));
81 cls.def(
"setState", [](
Random &
self,
py::bytes const &state) {
self.setState(state); });
84 wrappers.wrapType(py::enum_<Random::Algorithm>(clsRandom,
"Algorithm"), [](
auto &mod,
auto &enm) {
85 enm.value(
"MT19937", Random::Algorithm::MT19937);
86 enm.value(
"RANLXS0", Random::Algorithm::RANLXS0);
87 enm.value(
"RANLXS1", Random::Algorithm::RANLXS1);
88 enm.value(
"RANLXS2", Random::Algorithm::RANLXS2);
89 enm.value(
"RANLXD1", Random::Algorithm::RANLXD1);
90 enm.value(
"RANLXD2", Random::Algorithm::RANLXD2);
91 enm.value(
"RANLUX", Random::Algorithm::RANLUX);
92 enm.value(
"RANLUX389", Random::Algorithm::RANLUX389);
93 enm.value(
"CMRG", Random::Algorithm::CMRG);
94 enm.value(
"MRG", Random::Algorithm::MRG);
95 enm.value(
"TAUS", Random::Algorithm::TAUS);
96 enm.value(
"TAUS2", Random::Algorithm::TAUS2);
97 enm.value(
"GFSR4", Random::Algorithm::GFSR4);
98 enm.value(
"NUM_ALGORITHMS", Random::Algorithm::NUM_ALGORITHMS);
103 void wrapRandom(lsst::utils::python::WrapperCollection &wrappers) {
104 wrappers.addSignatureDependency(
"lsst.afw.image");
106 declareRandomImage<lsst::afw::image::Image<double>>(wrappers);
107 declareRandomImage<lsst::afw::image::Image<float>>(wrappers);
table::Key< table::Array< std::uint8_t > > bytes
A class that can be used to generate sequences of random numbers according to a number of different a...
void wrapRandom(lsst::utils::python::WrapperCollection &)
void declareRandomImage(lsst::utils::python::WrapperCollection &wrappers)
void declareRandom(lsst::utils::python::WrapperCollection &wrappers)
A base class for image defects.