Skip to content

Commit

Permalink
add support for partial evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ueber2y committed Jun 20, 2024
1 parent 97319e6 commit 0fd4d44
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions _pyceres/core/problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ void BindProblem(py::module& m) {
.def_readwrite("disable_all_safety_checks",
&options::disable_all_safety_checks);

// TODO: bind Problem::Evaluate
py::class_<ceres::Problem::EvaluateOptions>(m, "EvaluateOptions")
.def(py::init<>())
// Doesn't make sense to wrap this as you can't see the pointers in python
//.def_readwrite("parameter_blocks",&ceres::Problem::EvaluateOptions)
.def("set_parameter_blocks", [](ceres::Problem::EvaluateOptions& self, std::vector<py::array_t<double>>& blocks) {
self.parameter_blocks.clear();
for (auto it = blocks.begin(); it != blocks.end(); ++it) {
py::buffer_info info = it->request();
self.parameter_blocks.push_back(static_cast<double*>(info.ptr));
}
})
.def_readwrite("apply_loss_function",
&ceres::Problem::EvaluateOptions::apply_loss_function)
.def_readwrite("num_threads",
Expand Down Expand Up @@ -234,11 +238,20 @@ void BindProblem(py::module& m) {
[](ceres::Problem& self, ResidualBlockIDWrapper& residual_block_id) {
self.RemoveResidualBlock(residual_block_id.id);
})
.def("evaluate_residuals",
[](ceres::Problem& self,
const ceres::Problem::EvaluateOptions& options) {
std::vector<double> residuals;
self.Evaluate(options, nullptr, &residuals, nullptr, nullptr);
return residuals;
},
py::arg("options") = ceres::Problem::EvaluateOptions())
.def("evaluate_jacobian",
[](ceres::Problem& self,
const ceres::Problem::EvaluateOptions& options) {
ceres::CRSMatrix jacobian;
self.Evaluate(options, nullptr, nullptr, nullptr, &jacobian);
return jacobian;
});
},
py::arg("options") = ceres::Problem::EvaluateOptions());
}

0 comments on commit 0fd4d44

Please sign in to comment.