Skip to content

Commit

Permalink
Merge pull request #64 from lsst/tickets/DM-14828
Browse files Browse the repository at this point in the history
DM-14828: Update pybind11 wrappers for 2.2
  • Loading branch information
r-owen committed Jul 21, 2018
2 parents c37dbc2 + 869ab77 commit 7a94e69
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 73 deletions.
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/adaptiveImportanceSampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ using PyImportanceSamplerControl =
using PyAdaptiveImportanceSampler =
py::class_<AdaptiveImportanceSampler, std::shared_ptr<AdaptiveImportanceSampler>, Sampler>;

PYBIND11_PLUGIN(adaptiveImportanceSampler) {
py::module mod("adaptiveImportanceSampler");

PYBIND11_MODULE(adaptiveImportanceSampler, mod) {
py::module::import("lsst.afw.table");
py::module::import("lsst.afw.math");
py::module::import("lsst.meas.modelfit.sampler");
Expand All @@ -68,9 +66,8 @@ PYBIND11_PLUGIN(adaptiveImportanceSampler) {
&AdaptiveImportanceSampler::computeNormalizedPerplexity);
clsAdaptiveImportanceSampler.def("computeEffectiveSampleSizeFraction",
&AdaptiveImportanceSampler::computeEffectiveSampleSizeFraction);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/cmodel/cmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyCModelAlgorithm declareCModelAlgorithm(py::module &mod) {
return cls;
}

PYBIND11_PLUGIN(cmodel) {
PYBIND11_MODULE(cmodel, mod) {
py::module::import("lsst.afw.geom.ellipses");
py::module::import("lsst.afw.detection");
py::module::import("lsst.meas.modelfit.model");
Expand All @@ -212,18 +212,15 @@ PYBIND11_PLUGIN(cmodel) {
py::module::import("lsst.meas.modelfit.pixelFitRegion");
py::module::import("lsst.meas.modelfit.unitTransformedLikelihood");

py::module mod("cmodel");

declareCModelStageControl(mod);
auto clsControl = declareCModelControl(mod);
declareCModelStageResult(mod);
auto clsResult = declareCModelResult(mod);
auto clsAlgorithm = declareCModelAlgorithm(mod);
clsAlgorithm.attr("Control") = clsControl;
clsAlgorithm.attr("Result") = clsResult;

return mod.ptr();
}

}
}
}
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/meas/modelfit/integrals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ namespace meas {
namespace modelfit {
namespace {

PYBIND11_PLUGIN(integrals) {
py::module mod("integrals");
PYBIND11_MODULE(integrals, mod) {
mod.def("phid", &detail::phid);
mod.def("bvnu", &detail::bvnu);
return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/likelihood.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ namespace {

using PyLikelihood = py::class_<Likelihood, std::shared_ptr<Likelihood>>;

PYBIND11_PLUGIN(likelihood) {
PYBIND11_MODULE(likelihood, mod) {
py::module::import("lsst.meas.modelfit.model");

py::module mod("likelihood");

PyLikelihood cls(mod, "Likelihood");
cls.def("getDataDim", &Likelihood::getDataDim);
cls.def("getAmplitudeDim", &Likelihood::getAmplitudeDim);
Expand All @@ -55,9 +53,8 @@ PYBIND11_PLUGIN(likelihood) {
cls.def("getModel", &Likelihood::getModel);
cls.def("computeModelMatrix", &Likelihood::computeModelMatrix, "modelMatrix"_a, "nonlinear"_a,
"doApplyWeights"_a = true);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/mixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,16 @@ static PyMixture declareMixture(py::module &mod) {
return cls;
}

PYBIND11_PLUGIN(mixture) {
PYBIND11_MODULE(mixture, mod) {
py::module::import("lsst.afw.math");

py::module mod("mixture");

auto clsMixtureComponent = declareMixtureComponent(mod);
auto clsMixtureUpdateRestriction = declareMixtureUpdateRestriction(mod);
auto clsMixture = declareMixture(mod);
clsMixture.attr("Component") = clsMixtureComponent;
clsMixture.attr("UpdateRestriction") = clsMixtureUpdateRestriction;

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ namespace {

using PyModel = py::class_<Model, std::shared_ptr<Model>>;

PYBIND11_PLUGIN(model) {
PYBIND11_MODULE(model, mod) {
py::module::import("lsst.shapelet");
py::module::import("lsst.meas.modelfit.priors");
py::module::import("lsst.meas.modelfit.unitSystem");

py::module mod("model");

PyModel cls(mod, "Model");

py::enum_<Model::CenterEnum>(cls, "CenterEnum")
Expand Down Expand Up @@ -87,9 +85,8 @@ PYBIND11_PLUGIN(model) {
"ellipses"_a, "nonlinear"_a, "fixed"_a);
cls.def("transformParameters", &Model::transformParameters, "transform"_a, "nonlinear"_a, "amplitudes"_a,
"fixed"_a);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/multiModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ namespace {

using PyMultiModel = py::class_<MultiModel, std::shared_ptr<MultiModel>, Model>;

PYBIND11_PLUGIN(multiModel) {
PYBIND11_MODULE(multiModel, mod) {
py::module::import("lsst.meas.modelfit.model");

py::module mod("multiModel");

PyMultiModel cls(mod, "MultiModel");
cls.def(py::init<ModelVector, MultiModel::NameVector const &>(), "components"_a, "prefixes"_a);
cls.def("getComponents", &MultiModel::getComponents);

// All other MultiModel methods are virtuals already inherited from
// wrappers for Model.

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/optimizer/optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,11 @@ static PyOptimizer declareOptimizer(py::module &mod) {
return cls;
}

PYBIND11_PLUGIN(optimizer) {
PYBIND11_MODULE(optimizer, mod) {
py::module::import("lsst.meas.modelfit.model");
py::module::import("lsst.meas.modelfit.likelihood");
py::module::import("lsst.meas.modelfit.priors");

py::module mod("optimizer");

auto clsObjective = declareOptimizerObjective(mod);
auto clsControl = declareOptimizerControl(mod);
auto clsHistoryRecorder = declareOptimizerHistoryRecorder(mod);
Expand All @@ -183,9 +181,8 @@ PYBIND11_PLUGIN(optimizer) {
cls.attr("HistoryRecorder") = clsHistoryRecorder;

mod.def("solveTrustRegion", &solveTrustRegion, "x"_a, "F"_a, "g"_a, "r"_a, "tolerance"_a);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/pixelFitRegion/pixelFitRegion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ namespace {
using PyPixelFitRegionControl = py::class_<PixelFitRegionControl, std::shared_ptr<PixelFitRegionControl>>;
using PyPixelFitRegion = py::class_<PixelFitRegion, std::shared_ptr<PixelFitRegion>>;

PYBIND11_PLUGIN(pixelFitRegion) {
PYBIND11_MODULE(pixelFitRegion, mod) {
py::module::import("lsst.afw.image");
py::module::import("lsst.afw.detection");
py::module::import("lsst.afw.geom.ellipses");

py::module mod("pixelFitRegion");

using Control = PixelFitRegionControl;

PyPixelFitRegionControl clsControl(mod, "PixelFitRegionControl");
Expand Down Expand Up @@ -76,9 +74,8 @@ PYBIND11_PLUGIN(pixelFitRegion) {
cls.def_readonly("maxBadPixelFraction", &PixelFitRegion::maxBadPixelFraction);
cls.def_readonly("usedMinEllipse", &PixelFitRegion::usedMinEllipse);
cls.def_readonly("usedMaxEllipse", &PixelFitRegion::usedMaxEllipse);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/priors/priors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,15 @@ static void declareSoftenedLinearPrior(py::module &mod) {
// virtual methods already wrapped by Prior base class
}

PYBIND11_PLUGIN(priors) {
PYBIND11_MODULE(priors, mod) {
py::module::import("lsst.meas.modelfit.mixture");

py::module mod("priors");

declarePrior(mod);
declareMixturePrior(mod);
declareSemiEmpiricalPrior(mod);
declareSoftenedLinearPrior(mod);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/psf/psf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,17 @@ void declareGeneral(py::module &mod) {
// MultiShapeletPsfLikelihood intentionally not exposed to Python.
}

PYBIND11_PLUGIN(psf) {
PYBIND11_MODULE(psf, mod) {
py::module::import("lsst.afw.image");
py::module::import("lsst.afw.geom.ellipses");
py::module::import("lsst.meas.base");
py::module::import("lsst.shapelet");
py::module::import("lsst.meas.modelfit.optimizer");

py::module mod("psf");

declareDoubleShapelet(mod);
declareGeneral(mod);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@ namespace {
using PySamplingObjective = py::class_<SamplingObjective, std::shared_ptr<SamplingObjective>>;
using PySampler = py::class_<Sampler, std::shared_ptr<Sampler>>;

PYBIND11_PLUGIN(sampler) {
PYBIND11_MODULE(sampler, mod) {
py::module::import("lsst.afw.table");
py::module::import("lsst.meas.modelfit.mixture");
py::module::import("lsst.meas.modelfit.likelihood");

py::module mod("sampler");

PySamplingObjective clsSamplingObjective(mod, "SamplingObjective");
clsSamplingObjective.def("getParameterDim", &SamplingObjective::getParameterDim);
clsSamplingObjective.def("__call__", &SamplingObjective::operator(), "parameters"_a, "sample"_a);

PySampler clsSampler(mod, "Sampler");
clsSampler.def("run", &Sampler::run, "objective"_a, "proposal"_a, "samples"_a);

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/truncatedGaussian.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ static PyClass declareEvaluator(py::module &mod, std::string const &name) {
return cls;
}

PYBIND11_PLUGIN(truncatedGaussian) {
PYBIND11_MODULE(truncatedGaussian, mod) {
py::module::import("lsst.afw.math");

py::module mod("truncatedGaussian");

PyTruncatedGaussian cls(mod, "TruncatedGaussian");
py::enum_<TruncatedGaussian::SampleStrategy>(cls, "SampleStrategy")
.value("DIRECT_WITH_REJECTION", TruncatedGaussian::DIRECT_WITH_REJECTION)
Expand Down Expand Up @@ -108,9 +106,8 @@ PYBIND11_PLUGIN(truncatedGaussian) {
"rng"_a, "alpha"_a, "weights"_a, "multiplyWeights"_a = false);

cls.attr("Sampler") = clsSampler;

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/unitSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ namespace {
using PyUnitSystem = py::class_<UnitSystem, std::shared_ptr<UnitSystem>>;
using PyLocalUnitTransform = py::class_<LocalUnitTransform, std::shared_ptr<LocalUnitTransform>>;

PYBIND11_PLUGIN(unitSystem) {
PYBIND11_MODULE(unitSystem, mod) {
py::module::import("lsst.afw.image");

py::module mod("unitSystem");

// Data member wrappers in this module are intentionally read-only;
// setting them in Python should never be necessary and hence always
// represents a mistake we want to fail on as early as possible.
Expand All @@ -65,9 +63,8 @@ PYBIND11_PLUGIN(unitSystem) {
clsLocalUnitTransform.def(py::init<afw::geom::Point2D const &, UnitSystem const &, UnitSystem const &>(),
"sourcePixel"_a, "source"_a, "destination"_a);
clsLocalUnitTransform.def(py::init<>());

return mod.ptr();
}

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/meas/modelfit/unitTransformedLikelihood.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ using PyEpochFootprint = py::class_<EpochFootprint, std::shared_ptr<EpochFootpri
using PyUnitTransformedLikelihood =
py::class_<UnitTransformedLikelihood, std::shared_ptr<UnitTransformedLikelihood>, Likelihood>;

PYBIND11_PLUGIN(unitTransformedLikelihood) {
PYBIND11_MODULE(unitTransformedLikelihood, mod) {
py::module::import("lsst.afw.geom.ellipses");
py::module::import("lsst.afw.detection");
py::module::import("lsst.afw.image");
py::module::import("lsst.meas.modelfit.model");
py::module::import("lsst.meas.modelfit.likelihood");
py::module::import("lsst.meas.modelfit.unitSystem");

py::module mod("unitTransformedLikelihood");

PyUnitTransformedLikelihoodControl clsControl(mod, "UnitTransformedLikelihoodControl");
LSST_DECLARE_CONTROL_FIELD(clsControl, UnitTransformedLikelihoodControl, usePixelWeights);
LSST_DECLARE_CONTROL_FIELD(clsControl, UnitTransformedLikelihoodControl, weightsMultiplier);
Expand All @@ -80,9 +78,8 @@ PYBIND11_PLUGIN(unitTransformedLikelihood) {
afw::geom::SpherePoint const &, std::vector<std::shared_ptr<EpochFootprint>> const &,
UnitTransformedLikelihoodControl const &>(),
"model"_a, "fixed"_a, "fitSys"_a, "position"_a, "epochFootprintList"_a, "ctrl"_a);

return mod.ptr();
}

}
}
}
Expand Down

0 comments on commit 7a94e69

Please sign in to comment.