Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support evaluation on residuals and Jacobian from pyceres.Problem #49

Merged
merged 8 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions _pyceres/core/crs_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ namespace py = pybind11;

namespace {
py::tuple ConvertCRSToPyTuple(const ceres::CRSMatrix& crsMatrix) {
std::vector<int> rows, cols;
std::vector<double> values;
size_t n_values = crsMatrix.values.size();
B1ueber2y marked this conversation as resolved.
Show resolved Hide resolved
py::array_t<int> rows(n_values), cols(n_values);
py::array_t<double> values(n_values);

int* rows_data = static_cast<int*>(rows.request().ptr);
int* cols_data = static_cast<int*>(cols.request().ptr);
double* values_data = static_cast<double*>(values.request().ptr);
B1ueber2y marked this conversation as resolved.
Show resolved Hide resolved

int counter = 0;
for (int row = 0; row < crsMatrix.num_rows; ++row) {
B1ueber2y marked this conversation as resolved.
Show resolved Hide resolved
for (int k = crsMatrix.rows[row]; k < crsMatrix.rows[row + 1]; ++k) {
rows.push_back(row);
cols.push_back(crsMatrix.cols[k]);
values.push_back(crsMatrix.values[k]);
rows_data[counter] = row;
cols_data[counter] = crsMatrix.cols[k];
values_data[counter] = crsMatrix.values[k];
counter++;
}
}

Expand All @@ -38,6 +45,5 @@ void BindCRSMatrix(py::module& m) {
.def_readonly("rows", &CRSMatrix::rows)
.def_readonly("cols", &CRSMatrix::cols)
.def_readonly("values", &CRSMatrix::values)
.def("to_tuple",
[](CRSMatrix& self) { return ConvertCRSToPyTuple(self); });
.def("to_tuple", &ConvertCRSToPyTuple);
}
Loading