| 1 |
#include "pycolmap/helpers.h" |
| 2 |
|
| 3 |
#include <ceres/ceres.h> |
| 4 |
#include <pybind11/eigen.h> |
| 5 |
#include <pybind11/pybind11.h> |
| 6 |
|
| 7 |
// Some important ceres bindings for using crucial pycolmap features (e.g. |
| 8 |
// bundle adjustment) without pyceres. |
| 9 |
// |
| 10 |
// Branched from |
| 11 |
// https://github.com/cvg/pyceres/blob/main/_pyceres/core/types.h |
| 12 |
// https://github.com/cvg/pyceres/blob/main/_pyceres/core/solver.h |
| 13 |
void BindCeresTypes(py::module& m) { |
| 14 |
auto ownt = py::enum_<ceres::Ownership>(m, "Ownership", py::module_local()) |
| 15 |
.value("DO_NOT_TAKE_OWNERSHIP", |
| 16 |
ceres::Ownership::DO_NOT_TAKE_OWNERSHIP) |
| 17 |
.value("TAKE_OWNERSHIP", ceres::Ownership::TAKE_OWNERSHIP) |
| 18 |
.export_values(); |
| 19 |
AddStringToEnumConstructor(ownt); |
| 20 |
|
| 21 |
auto mt = |
| 22 |
py::enum_<ceres::MinimizerType>(m, "MinimizerType", py::module_local()) |
| 23 |
.value("LINE_SEARCH", ceres::MinimizerType::LINE_SEARCH) |
| 24 |
.value("TRUST_REGION", ceres::MinimizerType::TRUST_REGION); |
| 25 |
AddStringToEnumConstructor(mt); |
| 26 |
|
| 27 |
auto linesearcht = |
| 28 |
py::enum_<ceres::LineSearchType>(m, "LineSearchType", py::module_local()) |
| 29 |
.value("ARMIJO", ceres::LineSearchType::ARMIJO) |
| 30 |
.value("WOLFE", ceres::LineSearchType::WOLFE); |
| 31 |
AddStringToEnumConstructor(linesearcht); |
| 32 |
|
| 33 |
auto lsdt = |
| 34 |
py::enum_<ceres::LineSearchDirectionType>( |
| 35 |
m, "LineSearchDirectionType", py::module_local()) |
| 36 |
.value("BFGS", ceres::LineSearchDirectionType::BFGS) |
| 37 |
.value("LBFGS", ceres::LineSearchDirectionType::LBFGS) |
| 38 |
.value("NONLINEAR_CONJUGATE_GRADIENT", |
| 39 |
ceres::LineSearchDirectionType::NONLINEAR_CONJUGATE_GRADIENT) |
| 40 |
.value("STEEPEST_DESCENT", |
| 41 |
ceres::LineSearchDirectionType::STEEPEST_DESCENT); |
| 42 |
AddStringToEnumConstructor(lsdt); |
| 43 |
|
| 44 |
auto lsit = |
| 45 |
py::enum_<ceres::LineSearchInterpolationType>( |
| 46 |
m, "LineSearchInterpolationType", py::module_local()) |
| 47 |
.value("BISECTION", ceres::LineSearchInterpolationType::BISECTION) |
| 48 |
.value("CUBIC", ceres::LineSearchInterpolationType::CUBIC) |
| 49 |
.value("QUADRATIC", ceres::LineSearchInterpolationType::QUADRATIC); |
| 50 |
AddStringToEnumConstructor(lsit); |
| 51 |
|
| 52 |
auto ncgt = |
| 53 |
py::enum_<ceres::NonlinearConjugateGradientType>( |
| 54 |
m, "NonlinearConjugateGradientType", py::module_local()) |
| 55 |
.value("FLETCHER_REEVES", |
| 56 |
ceres::NonlinearConjugateGradientType::FLETCHER_REEVES) |
| 57 |
.value("HESTENES_STIEFEL", |
| 58 |
ceres::NonlinearConjugateGradientType::HESTENES_STIEFEL) |
| 59 |
.value("POLAK_RIBIERE", |
| 60 |
ceres::NonlinearConjugateGradientType::POLAK_RIBIERE); |
| 61 |
AddStringToEnumConstructor(ncgt); |
| 62 |
|
| 63 |
auto linsolt = |
| 64 |
py::enum_<ceres::LinearSolverType>( |
| 65 |
m, "LinearSolverType", py::module_local()) |
| 66 |
.value("DENSE_NORMAL_CHOLESKY", |
| 67 |
ceres::LinearSolverType::DENSE_NORMAL_CHOLESKY) |
| 68 |
.value("DENSE_QR", ceres::LinearSolverType::DENSE_QR) |
| 69 |
.value("SPARSE_NORMAL_CHOLESKY", |
| 70 |
ceres::LinearSolverType::SPARSE_NORMAL_CHOLESKY) |
| 71 |
.value("DENSE_SCHUR", ceres::LinearSolverType::DENSE_SCHUR) |
| 72 |
.value("SPARSE_SCHUR", ceres::LinearSolverType::SPARSE_SCHUR) |
| 73 |
.value("ITERATIVE_SCHUR", ceres::LinearSolverType::ITERATIVE_SCHUR) |
| 74 |
.value("CGNR", ceres::LinearSolverType::CGNR); |
| 75 |
AddStringToEnumConstructor(linsolt); |
| 76 |
|
| 77 |
auto dogt = |
| 78 |
py::enum_<ceres::DoglegType>(m, "DoglegType", py::module_local()) |
| 79 |
.value("TRADITIONAL_DOGLEG", ceres::DoglegType::TRADITIONAL_DOGLEG) |
| 80 |
.value("SUBSPACE_DOGLEG", ceres::DoglegType::SUBSPACE_DOGLEG); |
| 81 |
AddStringToEnumConstructor(dogt); |
| 82 |
|
| 83 |
auto trst = py::enum_<ceres::TrustRegionStrategyType>( |
| 84 |
m, "TrustRegionStrategyType", py::module_local()) |
| 85 |
.value("LEVENBERG_MARQUARDT", |
| 86 |
ceres::TrustRegionStrategyType::LEVENBERG_MARQUARDT) |
| 87 |
.value("DOGLEG", ceres::TrustRegionStrategyType::DOGLEG); |
| 88 |
AddStringToEnumConstructor(trst); |
| 89 |
|
| 90 |
auto prt = |
| 91 |
py::enum_<ceres::PreconditionerType>( |
| 92 |
m, "PreconditionerType", py::module_local()) |
| 93 |
.value("IDENTITY", ceres::PreconditionerType::IDENTITY) |
| 94 |
.value("JACOBI", ceres::PreconditionerType::JACOBI) |
| 95 |
.value("SCHUR_JACOBI", ceres::PreconditionerType::SCHUR_JACOBI) |
| 96 |
.value("CLUSTER_JACOBI", ceres::PreconditionerType::CLUSTER_JACOBI) |
| 97 |
.value("CLUSTER_TRIDIAGONAL", |
| 98 |
ceres::PreconditionerType::CLUSTER_TRIDIAGONAL); |
| 99 |
AddStringToEnumConstructor(prt); |
| 100 |
|
| 101 |
auto vct = py::enum_<ceres::VisibilityClusteringType>( |
| 102 |
m, "VisibilityClusteringType", py::module_local()) |
| 103 |
.value("CANONICAL_VIEWS", |
| 104 |
ceres::VisibilityClusteringType::CANONICAL_VIEWS) |
| 105 |
.value("SINGLE_LINKAGE", |
| 106 |
ceres::VisibilityClusteringType::SINGLE_LINKAGE); |
| 107 |
AddStringToEnumConstructor(vct); |
| 108 |
|
| 109 |
auto dlalt = |
| 110 |
py::enum_<ceres::DenseLinearAlgebraLibraryType>( |
| 111 |
m, "DenseLinearAlgebraLibraryType", py::module_local()) |
| 112 |
.value("EIGEN", ceres::DenseLinearAlgebraLibraryType::EIGEN) |
| 113 |
.value("LAPACK", ceres::DenseLinearAlgebraLibraryType::LAPACK) |
| 114 |
.value("CUDA", ceres::DenseLinearAlgebraLibraryType::CUDA); |
| 115 |
AddStringToEnumConstructor(dlalt); |
| 116 |
|
| 117 |
auto slalt = |
| 118 |
py::enum_<ceres::SparseLinearAlgebraLibraryType>( |
| 119 |
m, "SparseLinearAlgebraLibraryType", py::module_local()) |
| 120 |
.value("SUITE_SPARSE", |
| 121 |
ceres::SparseLinearAlgebraLibraryType::SUITE_SPARSE) |
| 122 |
.value("EIGEN_SPARSE", |
| 123 |
ceres::SparseLinearAlgebraLibraryType::EIGEN_SPARSE) |
| 124 |
.value("ACCELERATE_SPARSE", |
| 125 |
ceres::SparseLinearAlgebraLibraryType::ACCELERATE_SPARSE) |
| 126 |
.value("CUDA_SPARSE", |
| 127 |
ceres::SparseLinearAlgebraLibraryType::CUDA_SPARSE) |
| 128 |
.value("NO_SPARSE", ceres::SparseLinearAlgebraLibraryType::NO_SPARSE); |
| 129 |
AddStringToEnumConstructor(slalt); |
| 130 |
|
| 131 |
auto logt = |
| 132 |
py::enum_<ceres::LoggingType>(m, "LoggingType", py::module_local()) |
| 133 |
.value("SILENT", ceres::LoggingType::SILENT) |
| 134 |
.value("PER_MINIMIZER_ITERATION", |
| 135 |
ceres::LoggingType::PER_MINIMIZER_ITERATION); |
| 136 |
AddStringToEnumConstructor(logt); |
| 137 |
|
| 138 |
auto cbrt = |
| 139 |
py::enum_<ceres::CallbackReturnType>( |
| 140 |
m, "CallbackReturnType", py::module_local()) |
| 141 |
.value("SOLVER_CONTINUE", ceres::CallbackReturnType::SOLVER_CONTINUE) |
| 142 |
.value("SOLVER_ABORT", ceres::CallbackReturnType::SOLVER_ABORT) |
| 143 |
.value("SOLVER_TERMINATE_SUCCESSFULLY", |
| 144 |
ceres::CallbackReturnType::SOLVER_TERMINATE_SUCCESSFULLY); |
| 145 |
AddStringToEnumConstructor(cbrt); |
| 146 |
|
| 147 |
auto dft = |
| 148 |
py::enum_<ceres::DumpFormatType>(m, "DumpFormatType", py::module_local()) |
| 149 |
.value("CONSOLE", ceres::DumpFormatType::CONSOLE) |
| 150 |
.value("TEXTFILE", ceres::DumpFormatType::TEXTFILE); |
| 151 |
AddStringToEnumConstructor(dft); |
| 152 |
|
| 153 |
auto termt = |
| 154 |
py::enum_<ceres::TerminationType>( |
| 155 |
m, "TerminationType", py::module_local()) |
| 156 |
.value("CONVERGENCE", ceres::TerminationType::CONVERGENCE) |
| 157 |
.value("NO_CONVERGENCE", ceres::TerminationType::NO_CONVERGENCE) |
| 158 |
.value("FAILURE", ceres::TerminationType::FAILURE) |
| 159 |
.value("USER_SUCCESS", ceres::TerminationType::USER_SUCCESS) |
| 160 |
.value("USER_FAILURE", ceres::TerminationType::USER_FAILURE); |
| 161 |
AddStringToEnumConstructor(termt); |
| 162 |
} |
| 163 |
|
| 164 |
void BindCeresSolver(py::module& m) { |
| 165 |
using Options = ceres::Solver::Options; |
| 166 |
py::classh<Options> PyOptions(m, "SolverOptions", py::module_local()); |
| 167 |
PyOptions.def(py::init<>()) |
| 168 |
.def(py::init<const Options&>()) |
| 169 |
.def("IsValid", |
| 170 |
[](const Options& self) { |
| 171 |
std::string error; |
| 172 |
bool valid = self.IsValid(&error); |
| 173 |
return std::make_pair(valid, error); |
| 174 |
}) |
| 175 |
.def_readwrite("minimizer_type", &Options::minimizer_type) |
| 176 |
.def_readwrite("line_search_direction_type", |
| 177 |
&Options::line_search_direction_type) |
| 178 |
.def_readwrite("line_search_type", &Options::line_search_type) |
| 179 |
.def_readwrite("nonlinear_conjugate_gradient_type", |
| 180 |
&Options::nonlinear_conjugate_gradient_type) |
| 181 |
.def_readwrite("max_lbfgs_rank", &Options::max_lbfgs_rank) |
| 182 |
.def_readwrite("use_approximate_eigenvalue_bfgs_scaling", |
| 183 |
&Options::use_approximate_eigenvalue_bfgs_scaling) |
| 184 |
.def_readwrite("line_search_interpolation_type", |
| 185 |
&Options::line_search_interpolation_type) |
| 186 |
.def_readwrite("min_line_search_step_size", |
| 187 |
&Options::min_line_search_step_size) |
| 188 |
.def_readwrite("line_search_sufficient_function_decrease", |
| 189 |
&Options::line_search_sufficient_function_decrease) |
| 190 |
.def_readwrite("max_line_search_step_contraction", |
| 191 |
&Options::max_line_search_step_contraction) |
| 192 |
.def_readwrite("min_line_search_step_contraction", |
| 193 |
&Options::min_line_search_step_contraction) |
| 194 |
.def_readwrite("max_num_line_search_step_size_iterations", |
| 195 |
&Options::max_num_line_search_step_size_iterations) |
| 196 |
.def_readwrite("max_num_line_search_direction_restarts", |
| 197 |
&Options::max_num_line_search_direction_restarts) |
| 198 |
.def_readwrite("line_search_sufficient_curvature_decrease", |
| 199 |
&Options::line_search_sufficient_curvature_decrease) |
| 200 |
.def_readwrite("max_line_search_step_expansion", |
| 201 |
&Options::max_line_search_step_expansion) |
| 202 |
.def_readwrite("trust_region_strategy_type", |
| 203 |
&Options::trust_region_strategy_type) |
| 204 |
.def_readwrite("dogleg_type", &Options::dogleg_type) |
| 205 |
.def_readwrite("use_nonmonotonic_steps", &Options::use_nonmonotonic_steps) |
| 206 |
.def_readwrite("max_consecutive_nonmonotonic_steps", |
| 207 |
&Options::max_consecutive_nonmonotonic_steps) |
| 208 |
.def_readwrite("max_num_iterations", &Options::max_num_iterations) |
| 209 |
.def_readwrite("max_solver_time_in_seconds", |
| 210 |
&Options::max_solver_time_in_seconds) |
| 211 |
.def_property( |
| 212 |
"num_threads", |
| 213 |
[](const Options& self) { return self.num_threads; }, |
| 214 |
[](Options& self, int n_threads) { |
| 215 |
int effective_n_threads = colmap::GetEffectiveNumThreads(n_threads); |
| 216 |
self.num_threads = effective_n_threads; |
| 217 |
#if CERES_VERSION_MAJOR < 2 |
| 218 |
self.num_linear_solver_threads = effective_n_threads; |
| 219 |
#endif // CERES_VERSION_MAJOR |
| 220 |
}) |
| 221 |
.def_readwrite("initial_trust_region_radius", |
| 222 |
&Options::initial_trust_region_radius) |
| 223 |
.def_readwrite("max_trust_region_radius", |
| 224 |
&Options::max_trust_region_radius) |
| 225 |
.def_readwrite("min_trust_region_radius", |
| 226 |
&Options::min_trust_region_radius) |
| 227 |
.def_readwrite("min_relative_decrease", &Options::min_relative_decrease) |
| 228 |
.def_readwrite("min_lm_diagonal", &Options::min_lm_diagonal) |
| 229 |
.def_readwrite("max_lm_diagonal", &Options::max_lm_diagonal) |
| 230 |
.def_readwrite("max_num_consecutive_invalid_steps", |
| 231 |
&Options::max_num_consecutive_invalid_steps) |
| 232 |
.def_readwrite("function_tolerance", &Options::function_tolerance) |
| 233 |
.def_readwrite("gradient_tolerance", &Options::gradient_tolerance) |
| 234 |
.def_readwrite("parameter_tolerance", &Options::parameter_tolerance) |
| 235 |
.def_readwrite("linear_solver_type", &Options::linear_solver_type) |
| 236 |
.def_readwrite("preconditioner_type", &Options::preconditioner_type) |
| 237 |
.def_readwrite("visibility_clustering_type", |
| 238 |
&Options::visibility_clustering_type) |
| 239 |
.def_readwrite("dense_linear_algebra_library_type", |
| 240 |
&Options::dense_linear_algebra_library_type) |
| 241 |
.def_readwrite("sparse_linear_algebra_library_type", |
| 242 |
&Options::sparse_linear_algebra_library_type) |
| 243 |
.def_readwrite("use_explicit_schur_complement", |
| 244 |
&Options::use_explicit_schur_complement) |
| 245 |
.def_readwrite("dynamic_sparsity", &Options::dynamic_sparsity) |
| 246 |
.def_readwrite("use_inner_iterations", &Options::use_inner_iterations) |
| 247 |
.def_readwrite("inner_iteration_tolerance", |
| 248 |
&Options::inner_iteration_tolerance) |
| 249 |
.def_readwrite("min_linear_solver_iterations", |
| 250 |
&Options::min_linear_solver_iterations) |
| 251 |
.def_readwrite("max_linear_solver_iterations", |
| 252 |
&Options::max_linear_solver_iterations) |
| 253 |
.def_readwrite("eta", &Options::eta) |
| 254 |
.def_readwrite("jacobi_scaling", &Options::jacobi_scaling) |
| 255 |
.def_readwrite("logging_type", &Options::logging_type) |
| 256 |
.def_readwrite("minimizer_progress_to_stdout", |
| 257 |
&Options::minimizer_progress_to_stdout) |
| 258 |
.def_readwrite("trust_region_problem_dump_directory", |
| 259 |
&Options::trust_region_problem_dump_directory) |
| 260 |
.def_readwrite("trust_region_problem_dump_format_type", |
| 261 |
&Options::trust_region_problem_dump_format_type) |
| 262 |
.def_readwrite("check_gradients", &Options::check_gradients) |
| 263 |
.def_readwrite("gradient_check_relative_precision", |
| 264 |
&Options::gradient_check_relative_precision) |
| 265 |
.def_readwrite( |
| 266 |
"gradient_check_numeric_derivative_relative_step_size", |
| 267 |
&Options::gradient_check_numeric_derivative_relative_step_size) |
| 268 |
.def_readwrite("update_state_every_iteration", |
| 269 |
&Options::update_state_every_iteration); |
| 270 |
MakeDataclass(PyOptions); |
| 271 |
|
| 272 |
using Summary = ceres::Solver::Summary; |
| 273 |
py::classh<Summary> PySummary(m, "SolverSummary", py::module_local()); |
| 274 |
PySummary.def(py::init<>()) |
| 275 |
.def(py::init<const Summary&>()) |
| 276 |
.def("BriefReport", &Summary::BriefReport) |
| 277 |
.def("FullReport", &Summary::FullReport) |
| 278 |
.def("IsSolutionUsable", &Summary::IsSolutionUsable) |
| 279 |
.def_readwrite("minimizer_type", &Summary::minimizer_type) |
| 280 |
.def_readwrite("termination_type", &Summary::termination_type) |
| 281 |
.def_readwrite("message", &Summary::message) |
| 282 |
.def_readwrite("initial_cost", &Summary::initial_cost) |
| 283 |
.def_readwrite("final_cost", &Summary::final_cost) |
| 284 |
.def_readwrite("fixed_cost", &Summary::fixed_cost) |
| 285 |
.def_readwrite("num_successful_steps", &Summary::num_successful_steps) |
| 286 |
.def_readwrite("num_unsuccessful_steps", &Summary::num_unsuccessful_steps) |
| 287 |
.def_readwrite("num_inner_iteration_steps", |
| 288 |
&Summary::num_inner_iteration_steps) |
| 289 |
.def_readwrite("num_line_search_steps", &Summary::num_line_search_steps) |
| 290 |
.def_readwrite("preprocessor_time_in_seconds", |
| 291 |
&Summary::preprocessor_time_in_seconds) |
| 292 |
.def_readwrite("minimizer_time_in_seconds", |
| 293 |
&Summary::minimizer_time_in_seconds) |
| 294 |
.def_readwrite("postprocessor_time_in_seconds", |
| 295 |
&Summary::postprocessor_time_in_seconds) |
| 296 |
.def_readwrite("total_time_in_seconds", &Summary::total_time_in_seconds) |
| 297 |
.def_readwrite("linear_solver_time_in_seconds", |
| 298 |
&Summary::linear_solver_time_in_seconds) |
| 299 |
.def_readwrite("num_linear_solves", &Summary::num_linear_solves) |
| 300 |
.def_readwrite("residual_evaluation_time_in_seconds", |
| 301 |
&Summary::residual_evaluation_time_in_seconds) |
| 302 |
.def_readwrite("num_residual_evaluations", |
| 303 |
&Summary::num_residual_evaluations) |
| 304 |
.def_readwrite("jacobian_evaluation_time_in_seconds", |
| 305 |
&Summary::jacobian_evaluation_time_in_seconds) |
| 306 |
.def_readwrite("num_jacobian_evaluations", |
| 307 |
&Summary::num_jacobian_evaluations) |
| 308 |
.def_readwrite("inner_iteration_time_in_seconds", |
| 309 |
&Summary::inner_iteration_time_in_seconds) |
| 310 |
.def_readwrite("line_search_cost_evaluation_time_in_seconds", |
| 311 |
&Summary::line_search_cost_evaluation_time_in_seconds) |
| 312 |
.def_readwrite("line_search_gradient_evaluation_time_in_seconds", |
| 313 |
&Summary::line_search_gradient_evaluation_time_in_seconds) |
| 314 |
.def_readwrite( |
| 315 |
"line_search_polynomial_minimization_time_in_seconds", |
| 316 |
&Summary::line_search_polynomial_minimization_time_in_seconds) |
| 317 |
.def_readwrite("line_search_total_time_in_seconds", |
| 318 |
&Summary::line_search_total_time_in_seconds) |
| 319 |
.def_readwrite("num_parameter_blocks", &Summary::num_parameter_blocks) |
| 320 |
.def_readwrite("num_parameters", &Summary::num_parameters) |
| 321 |
.def_readwrite("num_effective_parameters", |
| 322 |
&Summary::num_effective_parameters) |
| 323 |
.def_readwrite("num_residual_blocks", &Summary::num_residual_blocks) |
| 324 |
.def_readwrite("num_residuals", &Summary::num_residuals) |
| 325 |
.def_readwrite("num_parameter_blocks_reduced", |
| 326 |
&Summary::num_parameter_blocks_reduced) |
| 327 |
.def_readwrite("num_parameters_reduced", &Summary::num_parameters_reduced) |
| 328 |
.def_readwrite("num_effective_parameters_reduced", |
| 329 |
&Summary::num_effective_parameters_reduced) |
| 330 |
.def_readwrite("num_residual_blocks_reduced", |
| 331 |
&Summary::num_residual_blocks_reduced) |
| 332 |
.def_readwrite("num_residuals_reduced", &Summary::num_residuals_reduced) |
| 333 |
.def_readwrite("is_constrained", &Summary::is_constrained) |
| 334 |
.def_readwrite("num_threads_given", &Summary::num_threads_given) |
| 335 |
.def_readwrite("num_threads_used", &Summary::num_threads_used) |
| 336 |
#if CERES_VERSION_MAJOR < 2 |
| 337 |
.def_readwrite("num_linear_solver_threads_given", |
| 338 |
&Summary::num_linear_solver_threads_given) |
| 339 |
.def_readwrite("num_linear_solver_threads_used", |
| 340 |
&Summary::num_linear_solver_threads_used) |
| 341 |
#endif |
| 342 |
.def_readwrite("linear_solver_type_given", |
| 343 |
&Summary::linear_solver_type_given) |
| 344 |
.def_readwrite("linear_solver_type_used", |
| 345 |
&Summary::linear_solver_type_used) |
| 346 |
.def_readwrite("schur_structure_given", &Summary::schur_structure_given) |
| 347 |
.def_readwrite("schur_structure_used", &Summary::schur_structure_used) |
| 348 |
.def_readwrite("inner_iterations_given", &Summary::inner_iterations_given) |
| 349 |
.def_readwrite("inner_iterations_used", &Summary::inner_iterations_used) |
| 350 |
.def_readwrite("preconditioner_type_given", |
| 351 |
&Summary::preconditioner_type_given) |
| 352 |
.def_readwrite("preconditioner_type_used", |
| 353 |
&Summary::preconditioner_type_used) |
| 354 |
.def_readwrite("visibility_clustering_type", |
| 355 |
&Summary::visibility_clustering_type) |
| 356 |
.def_readwrite("trust_region_strategy_type", |
| 357 |
&Summary::trust_region_strategy_type) |
| 358 |
.def_readwrite("dogleg_type", &Summary::dogleg_type) |
| 359 |
.def_readwrite("dense_linear_algebra_library_type", |
| 360 |
&Summary::dense_linear_algebra_library_type) |
| 361 |
.def_readwrite("sparse_linear_algebra_library_type", |
| 362 |
&Summary::sparse_linear_algebra_library_type) |
| 363 |
.def_readwrite("line_search_direction_type", |
| 364 |
&Summary::line_search_direction_type) |
| 365 |
.def_readwrite("line_search_type", &Summary::line_search_type) |
| 366 |
.def_readwrite("line_search_interpolation_type", |
| 367 |
&Summary::line_search_interpolation_type) |
| 368 |
.def_readwrite("nonlinear_conjugate_gradient_type", |
| 369 |
&Summary::nonlinear_conjugate_gradient_type) |
| 370 |
.def_readwrite("max_lbfgs_rank", &Summary::max_lbfgs_rank); |
| 371 |
MakeDataclass(PySummary); |
| 372 |
|
| 373 |
using IterSummary = ceres::IterationSummary; |
| 374 |
py::classh<IterSummary> PyIterSummary( |
| 375 |
m, "IterationSummary", py::module_local()); |
| 376 |
PyIterSummary.def(py::init<>()) |
| 377 |
.def(py::init<const IterSummary&>()) |
| 378 |
.def_readonly("iteration", &IterSummary::iteration) |
| 379 |
.def_readonly("step_is_valid", &IterSummary::step_is_valid) |
| 380 |
.def_readonly("step_is_nonmonotonic", &IterSummary::step_is_nonmonotonic) |
| 381 |
.def_readonly("step_is_successful", &IterSummary::step_is_successful) |
| 382 |
.def_readonly("cost", &IterSummary::cost) |
| 383 |
.def_readonly("cost_change", &IterSummary::cost_change) |
| 384 |
.def_readonly("gradient_max_norm", &IterSummary::gradient_max_norm) |
| 385 |
.def_readonly("gradient_norm", &IterSummary::gradient_norm) |
| 386 |
.def_readonly("step_norm", &IterSummary::step_norm) |
| 387 |
.def_readonly("relative_decrease", &IterSummary::relative_decrease) |
| 388 |
.def_readonly("trust_region_radius", &IterSummary::trust_region_radius) |
| 389 |
.def_readonly("eta", &IterSummary::eta) |
| 390 |
.def_readonly("step_size", &IterSummary::step_size) |
| 391 |
.def_readonly("line_search_function_evaluations", |
| 392 |
&IterSummary::line_search_function_evaluations) |
| 393 |
.def_readonly("line_search_gradient_evaluations", |
| 394 |
&IterSummary::line_search_gradient_evaluations) |
| 395 |
.def_readonly("line_search_iterations", |
| 396 |
&IterSummary::line_search_iterations) |
| 397 |
.def_readonly("linear_solver_iterations", |
| 398 |
&IterSummary::linear_solver_iterations) |
| 399 |
.def_readonly("iteration_time_in_seconds", |
| 400 |
&IterSummary::iteration_time_in_seconds) |
| 401 |
.def_readonly("step_solver_time_in_seconds", |
| 402 |
&IterSummary::step_solver_time_in_seconds) |
| 403 |
.def_readonly("cumulative_time_in_seconds", |
| 404 |
&IterSummary::cumulative_time_in_seconds); |
| 405 |
} |
| 406 |
|
| 407 |
void BindCeres(py::module& m_parent) { |
| 408 |
py::module_ m = m_parent.def_submodule("pyceres"); |
| 409 |
|
| 410 |
BindCeresTypes(m); |
| 411 |
BindCeresSolver(m); |
| 412 |
} |