lsst.meas.modelfit  13.0-9-g2ccb577+7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Pages
sampler.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2013 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include "pybind11/pybind11.h"
25 
26 #include "numpy/arrayobject.h"
27 #include "ndarray/pybind11.h"
28 
30 #include "lsst/afw/table/BaseRecord.h"
31 #include "lsst/afw/table/BaseTable.h"
32 #include "lsst/afw/table/Catalog.h"
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace meas {
39 namespace modelfit {
40 namespace {
41 
42 using PySamplingObjective = py::class_<SamplingObjective, std::shared_ptr<SamplingObjective>>;
43 using PySampler = py::class_<Sampler, std::shared_ptr<Sampler>>;
44 
45 PYBIND11_PLUGIN(sampler) {
46  py::module::import("lsst.afw.table");
47  py::module::import("lsst.meas.modelfit.mixture");
48  py::module::import("lsst.meas.modelfit.likelihood");
49 
50  py::module mod("sampler");
51 
52  if (_import_array() < 0) {
53  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
54  return nullptr;
55  }
56 
57  PySamplingObjective clsSamplingObjective(mod, "SamplingObjective");
58  clsSamplingObjective.def("getParameterDim", &SamplingObjective::getParameterDim);
59  clsSamplingObjective.def("__call__", &SamplingObjective::operator(), "parameters"_a, "sample"_a);
60 
61  PySampler clsSampler(mod, "Sampler");
62  clsSampler.def("run", &Sampler::run, "objective"_a, "proposal"_a, "samples"_a);
63 
64  return mod.ptr();
65 }
66 }
67 }
68 }
69 } // namespace lsst::meas::modelfit::anonymous