23 #include <pybind11/pybind11.h> 25 #include <pybind11/stl.h> 30 namespace py = pybind11;
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::module mod(
"_random",
"Python wrapper for afw _random library");
51 py::class_<Random> clsRandom(mod,
"Random");
54 py::enum_<Random::Algorithm>(clsRandom,
"Algorithm")
55 .value(
"MT19937", Random::Algorithm::MT19937)
56 .value(
"RANLXS0", Random::Algorithm::RANLXS0)
57 .value(
"RANLXS1", Random::Algorithm::RANLXS1)
58 .value(
"RANLXS2", Random::Algorithm::RANLXS2)
59 .value(
"RANLXD1", Random::Algorithm::RANLXD1)
60 .value(
"RANLXD2", Random::Algorithm::RANLXD2)
61 .value(
"RANLUX", Random::Algorithm::RANLUX)
62 .value(
"RANLUX389", Random::Algorithm::RANLUX389)
63 .value(
"CMRG", Random::Algorithm::CMRG)
64 .value(
"MRG", Random::Algorithm::MRG)
65 .value(
"TAUS", Random::Algorithm::TAUS)
66 .value(
"TAUS2", Random::Algorithm::TAUS2)
67 .value(
"GFSR4", Random::Algorithm::GFSR4)
68 .value(
"NUM_ALGORITHMS", Random::Algorithm::NUM_ALGORITHMS)
72 clsRandom.def(py::init<Random::Algorithm, unsigned long>(),
"algorithm"_a = Random::Algorithm::MT19937,
74 clsRandom.def(py::init<std::string const &, unsigned long>(),
"algorithm"_a,
"seed"_a = 1);
75 clsRandom.def(py::init<std::shared_ptr<lsst::pex::policy::Policy>
const>(),
"policy"_a);
94 clsRandom.def(
"getState", [](
Random &
self) -> py::object {
95 std::string state =
self.getState();
96 return py::reinterpret_steal<py::object>(PyBytes_FromStringAndSize(state.data(), state.size()));
98 clsRandom.def(
"setState", [](
Random &
self, py::bytes
const &state) {
self.setState(state); });
101 declareRandomImage<lsst::afw::image::Image<double>>(mod);
102 declareRandomImage<lsst::afw::image::Image<float>>(mod);
double poisson(double const mu)
Returns a random variate from the poisson distribution with mean mu.
static std::vector< std::string > const & getAlgorithmNames()
std::string getAlgorithmName() const
unsigned long uniformInt(unsigned long n)
Returns a uniformly distributed random integer from 0 to n-1.
double chisq(double const nu)
Returns a random variate from the chi-squared distribution with nu degrees of freedom.
void declareRandomImage(py::module &mod)
double flat(double const a, double const b)
Returns a random variate from the flat (uniform) distribution on [a, b).
unsigned long getSeed() const
double gaussian()
Returns a gaussian random variate with mean 0 and standard deviation 1
double uniformPos()
Returns a uniformly distributed random double precision floating point number from the generator...
Random deepCopy() const
Creates a deep copy of this random number generator.
double uniform()
Returns a uniformly distributed random double precision floating point number from the generator...
Algorithm getAlgorithm() const
A class that can be used to generate sequences of random numbers according to a number of different a...
PYBIND11_PLUGIN(_approximate)