14 releases

0.3.0 Feb 26, 2024
0.2.2 Feb 26, 2024
0.2.1 Mar 3, 2023
0.2.1-beta.0 Feb 27, 2023
0.1.2 Jan 24, 2023

#670 in Algorithms

Download history 57/week @ 2024-07-20 167/week @ 2024-07-27 72/week @ 2024-08-03 57/week @ 2024-08-10 37/week @ 2024-08-17 100/week @ 2024-08-24 417/week @ 2024-08-31 334/week @ 2024-09-07 592/week @ 2024-09-14 137/week @ 2024-09-21 321/week @ 2024-09-28 238/week @ 2024-10-05 39/week @ 2024-10-12 54/week @ 2024-10-19 661/week @ 2024-10-26 36/week @ 2024-11-02

827 downloads per month
Used in light-curve-feature

MIT/Apache

130KB
2.5K SLoC

Rust 2K SLoC // 0.0% comments C++ 256 SLoC // 0.0% comments

ceres-solver-rs

Rust bindings for Ceres Solver

Test pre-commit.ci status docs.rs Crates.io

cargo add ceres-solver --features=source

Ceres Solver is a C++ library for large optimization problems. It can be used to solve Non-linear Least Squares problems with constraints and general optimization problems. Here we provide a Rust binding for this library.

The earliest Ceres Solver version tested is 2.0, but the bindings may work with older versions

This project consists of three crates:

  • ceres-solver is a safe Rust bindings
  • ceres-solver-sys is an unsafe Rust bindings written with the usage of cxx
  • ceres-solver-src is an optional no-code crate to build and distribute a minimal static Ceres Solver library

To build Ceres Solver statically and link it to your project, use source Cargo feature, which would add ceres-solver-src dependency into your project. Another Cargo feature is v2_1, which should be used when linked with Ceres Solver 2.1 or newer.

Status of the binding support

Current implementation of the binding is not complete. The following list shows the status of the binding support:

  • Non-linear Least squares
    • Problem - basic class for NLLS, supports adding residual blocks, setting boundary conditions, marking parameter blocks to be constant/variable, and solving the problem
    • CostFunction - user provides both residual and Jacobian
    • SizedCostFunction - same but with the residual vector shape is known at compile time
    • AutoDiffCostFunction - user provides residual and Jacobian is computed by automatic differentiation
    • DynamicAutoDiffCostFunction - same but with the residual vector shape is unknown at compile time
    • NumericDiffCostFunction - user provides residual and Jacobian is computed by numerical differentiation
    • CostFunctionToFunctor and DynamicCostFunctionToFunctor - adapter to use CostFunction as a mix of all other cost functions
    • ConditionedCostFunction - adapter to use CostFunction with different conditioning
    • GradientChecker - helper class to check the correctness of the Jacobian
    • NormalPrior - changes a cost function to use a covariance matrix instead of a simple scalar product
    • LossFunction - a function applied to the squared norm of the residual vector, both custom and Ceres stack loss functions are supported
    • Manifold, AutoDiffManifold
    • EvaluationCallback
  • Solver - Solver class itself is not implemented, but the following nested classes are supported:
    • Solver::Options
      • Minimizer options
      • Line search options
      • Trust region options
      • Linear solver options
      • Preconditioner options
      • Sparse and dense linear algebra library selection
      • Setting of the number of threads
      • Bundle adjustment options
      • Logging options
      • Validation of the options
      • Callbacks
    • Solver::Summary
      • Brief and full reports
      • Cost function evaluation statistics
      • Time statistics
  • Jets
  • Covariance estimation
  • General unconstrained minimization

Please don't hesitate to create an issue to request prioritization of any functionality that may have been prioritized.

Dependencies

~0.6–3.5MB
~60K SLoC