LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
Functions
random.cc File Reference
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "lsst/afw/image/Image.h"
#include "lsst/afw/math/Random.h"

Go to the source code of this file.

Functions

template<typename ImageT >
void declareRandomImage (py::module &mod)
 
 PYBIND11_MODULE (random, mod)
 

Function Documentation

◆ declareRandomImage()

template<typename ImageT >
void declareRandomImage ( py::module &  mod)

Definition at line 36 of file random.cc.

36  {
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>);
46 }
A class that can be used to generate sequences of random numbers according to a number of different a...
Definition: Random.h:57

◆ PYBIND11_MODULE()

PYBIND11_MODULE ( random  ,
mod   
)

Definition at line 48 of file random.cc.

48  {
49  py::class_<Random> clsRandom(mod, "Random");
50 
51  /* Member types and enums */
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)
67  .export_values();
68 
69  /* Constructors */
70  clsRandom.def(py::init<Random::Algorithm, unsigned long>(), "algorithm"_a = Random::Algorithm::MT19937,
71  "seed"_a = 1);
72  clsRandom.def(py::init<std::string const &, unsigned long>(), "algorithm"_a, "seed"_a = 1);
73 
74  /* Members */
75  clsRandom.def("deepCopy", &Random::deepCopy);
76  clsRandom.def("getAlgorithm", &Random::getAlgorithm);
77  clsRandom.def("getAlgorithmName", &Random::getAlgorithmName);
78  clsRandom.def_static("getAlgorithmNames", &Random::getAlgorithmNames);
79  clsRandom.def("getSeed", &Random::getSeed);
80  clsRandom.def("uniform", &Random::uniform);
81  clsRandom.def("uniformPos", &Random::uniformPos);
82  clsRandom.def("uniformInt", &Random::uniformInt);
83  clsRandom.def("flat", &Random::flat);
84  clsRandom.def("gaussian", &Random::gaussian);
85  clsRandom.def("chisq", &Random::chisq);
86  clsRandom.def("poisson", &Random::poisson);
87 
88  // getState and setState are special, their std::string cannot
89  // be converted to a Python string (needs to go to bytes instead)
90  // thus use the same solution as employed with Swig
91  clsRandom.def("getState", [](Random &self) -> py::object {
92  std::string state = self.getState();
93  return py::reinterpret_steal<py::object>(PyBytes_FromStringAndSize(state.data(), state.size()));
94  });
95  clsRandom.def("setState", [](Random &self, py::bytes const &state) { self.setState(state); });
96 
97  /* Module level */
98  declareRandomImage<lsst::afw::image::Image<double>>(mod);
99  declareRandomImage<lsst::afw::image::Image<float>>(mod);
100 }
STL class.
T data(T... args)
T size(T... args)
A class that can be used to generate sequences of random numbers according to a number of different a...
Definition: Random.h:57
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199