24#include "pybind11/pybind11.h"
26#include "pybind11/eigen.h"
27#include "pybind11/stl.h"
29#include "ndarray/pybind11.h"
34using namespace pybind11::literals;
41using Sampler = TruncatedGaussianSampler;
42using Evaluator = TruncatedGaussianEvaluator;
43using LogEvaluator = TruncatedGaussianLogEvaluator;
45using PyTruncatedGaussian = py::class_<TruncatedGaussian, std::shared_ptr<TruncatedGaussian>>;
46using PySampler = py::class_<Sampler, std::shared_ptr<Sampler>>;
47using PyEvaluator = py::class_<Evaluator, std::shared_ptr<Evaluator>>;
48using PyLogEvaluator = py::class_<LogEvaluator, std::shared_ptr<LogEvaluator>>;
53template<
typename Class,
typename PyClass>
56 PyClass(wrappers.module, (
"TruncatedGaussian" + name).c_str()),
57 [](
auto &mod,
auto &cls) {
58 cls.def(py::init<TruncatedGaussian const &>(),
"parent"_a);
61 ndarray::Array<Scalar const, 1, 1> const &) const) &Class::operator(),
63 cls.def(
"__call__", (void (Class::*)(ndarray::Array<Scalar const, 2, 1> const &,
64 ndarray::Array<Scalar, 1, 1> const &) const) &
66 "alpha"_a,
"output"_a);
73 return wrappers.
wrapType(
PySampler(wrappers.module,
"TruncatedGaussianSampler"), [](
auto &mod,
auto &cls) {
74 cls.def(py::init<TruncatedGaussian const &, TruncatedGaussian::SampleStrategy>(),
"parent"_a,
77 (Scalar (Sampler::*)(afw::math::Random &, ndarray::Array<Scalar, 1, 1> const &) const) &
80 cls.def(
"__call__", (void (Sampler::*)(afw::math::Random &, ndarray::Array<Scalar, 2, 1> const &,
81 ndarray::Array<Scalar, 1, 1> const &, bool) const) &
83 "rng"_a,
"alpha"_a,
"weights"_a,
"multiplyWeights"_a = false);
87using PySampleStrategy = py::enum_<TruncatedGaussian::SampleStrategy>;
90 return wrappers.
wrapType(PySampleStrategy(wrappers.module,
"SampleStrategy"), [](
auto &mod,
auto &enm) {
91 enm.value(
"DIRECT_WITH_REJECTION", TruncatedGaussian::DIRECT_WITH_REJECTION);
92 enm.value(
"ALIGN_AND_WEIGHT", TruncatedGaussian::ALIGN_AND_WEIGHT);
99 PyTruncatedGaussian(wrappers.module,
"TruncatedGaussian"), [](
auto &mod,
auto &cls) {
100 cls.def_static(
"fromSeriesParameters", &TruncatedGaussian::fromSeriesParameters,
"q0"_a,
"gradient"_a,
102 cls.def_static(
"fromStandardParameters", &TruncatedGaussian::fromStandardParameters,
"mean"_a,
104 cls.def(
"sample", (Sampler (TruncatedGaussian::*)(TruncatedGaussian::SampleStrategy) const) &
105 TruncatedGaussian::sample,
107 cls.def(
"sample", (Sampler (TruncatedGaussian::*)(Scalar) const) &TruncatedGaussian::sample,
108 "minRejectionEfficiency"_a = 0.1);
109 cls.def(
"evaluateLog", &TruncatedGaussian::evaluateLog);
110 cls.def(
"evaluate", &TruncatedGaussian::evaluate);
111 cls.def(
"getDim", &TruncatedGaussian::getDim);
112 cls.def(
"maximize", &TruncatedGaussian::maximize);
113 cls.def(
"getUntruncatedFraction", &TruncatedGaussian::getUntruncatedFraction);
114 cls.def(
"getLogPeakAmplitude", &TruncatedGaussian::getLogPeakAmplitude);
115 cls.def(
"getLogIntegral", &TruncatedGaussian::getLogIntegral);
122 declareSampleStrategy(wrappers);
123 auto clsTruncatedGaussian = declareTruncatedGaussian(wrappers);
124 clsTruncatedGaussian.attr(
"LogEvaluator") = declareEvaluator<LogEvaluator, PyLogEvaluator>(wrappers,
"LogEvaluator");
125 clsTruncatedGaussian.attr(
"Evaluator") = declareEvaluator<Evaluator, PyEvaluator>(wrappers,
"Evaluator");
126 clsTruncatedGaussian.attr(
"Sampler") = declareSampler(wrappers);
A helper class for subdividing pybind11 module across multiple translation units (i....
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void wrapTruncatedGaussian(lsst::cpputils::python::WrapperCollection &wrappers)
py::class_< Sampler, std::shared_ptr< Sampler > > PySampler