Commit Graph

572 Commits

Author SHA1 Message Date
Sergiu Deitsch 2d2b7b57c7 Ensure DynamicCostFunctionToFunctor to be exported
Fixes #1022

Change-Id: I090790ac4a1f32e6cb318bc32273d63898659dc3
2025-02-17 23:59:36 +01:00
connorlee77 2c90a63af9 Add residuals and jacobian getters to TinySolver.
- Add methods to aceess the cached residuals and jacobian computed in
the optimization process in TinySolver. Usage of such methods will
retrieve the corresponding values associated with the converged
parameter.
- Reorder the Update() call to ensure that the jacobian/residuals
associated with the converged parameter are computed and cached.

Change-Id: If82e19d67d28b057833357f2c9a75b2d0fd139af
2025-02-11 21:07:58 +00:00
Sameer Agarwal 8f1b6123ad GradientProblem & related classes use std::unique_ptr
Previously these classes in analogy with ceres::Problem's interface
had interfaces to allow bare pointers as well as unique_ptrs. This
CL changes the API to always use unique_ptr, this is less error prone
and makes the default ownership semantics clearer.

Change-Id: I7577a90761f341c7e009c248c820f0fec2e6f32d
2024-09-15 21:57:23 +00:00
Sameer Agarwal 80fce72bfd Add mixed precision solves for SUITE_SPARSE
Starting with SuiteSparse version 7.4.0 CHOLMOD has support for single
precision matrices. This allows us to have single precision and mixed
precision solves when using the SUITE_SPARSE backend.

This CL also fixes sparse_cholesky_test which was completely broken for
single precision testing.

Sample performance on my Mac.
/usr/bin/time -l ./bin/bundle_adjuster --input=../../Downloads/problem-3068-310854-pre.txt
<SNIP>

Cost:
Initial                          9.099334e+07
Final                            4.161838e+06
Change                           8.683150e+07

Minimizer iterations                        6
Successful steps                            4
Unsuccessful steps                          2

Time (in seconds):
Preprocessor                         2.528222

  Residual only evaluation           0.142804 (5)
  Jacobian & residual evaluation     0.424014 (4)
  Linear solver                     54.083396 (5)
Minimizer                           54.895752

Postprocessor                        0.024564
Total                               57.448539

Termination:                   NO_CONVERGENCE (Maximum number of iterations reached. Number of iterations: 5.)

       59.04 real       341.24 user         5.49 sys
          5776375808  maximum resident set size
<SNIP>
        616329634071  instructions retired
        929475980510  cycles elapsed
          5375034560  peak memory footprint

/usr/bin/time -l ./bin/bundle_adjuster --input=../../Downloads/problem-3068-310854-pre.txt  -mixed_precision_solves
<SNIP>

Cost:
Initial                          9.099334e+07
Final                            4.148930e+06
Change                           8.684441e+07

Minimizer iterations                        6
Successful steps                            4
Unsuccessful steps                          2

Time (in seconds):
Preprocessor                         2.580217

  Residual only evaluation           0.144098 (5)
  Jacobian & residual evaluation     0.396723 (4)
  Linear solver                     23.636074 (5)
Minimizer                           24.427163

Postprocessor                        0.023790
Total                               27.031170

Termination:                   NO_CONVERGENCE (Maximum number of iterations reached. Number of iterations: 5.)

       28.58 real       128.53 user         2.37 sys
          4818386944  maximum resident set size
<SNIP>
        395186936091  instructions retired
        368802808856  cycles elapsed
          4327029824  peak memory footprint

Change-Id: I1f137b0dd12da8da7f9ced338dd8f20f4bbdf99d
2024-08-24 21:12:54 -07:00
Sameer Agarwal 8f85014dcf Change the version from 2.2.0 to 2.3.0
The dependencies and the API have changed enough that
it is worth incrementing the version number.

Change-Id: I4e2911a91988d97f47320c56072ad1546e20030b
2024-08-24 09:29:51 -07:00
Sameer Agarwal 03caeed1c6 ceres/stringprintf -> absl::strings
Replace ceres::String* with their more modern and performant
absl strings library equivalent and delete our string
manipulation library.

Change-Id: Iecbdba9864e0abf329778f81fdc0708f78f7594f
2024-08-08 07:05:23 -07:00
Sameer Agarwal 9503130830 Delete an unused file memory.h
Change-Id: I7824315b42ff72645f59256e64cf6e82f16af82f
2024-07-23 13:52:46 -07:00
Sameer Agarwal ebb66e655f ceres::internal::FixedArray -> absl::FixedArray
Ceres Solver was using an old forked version of FixedArray,
now that we are using absl, we can use the official version
that ships with it.

Change-Id: Ic88d7f6e8a49b928d611f7cbb04172452b322b01
2024-07-23 13:45:45 -07:00
Sameer Agarwal 3c4f012606 ClangTidy fixes #2
Change-Id: Ib3baa62248342276d63b900b45561323fd81402d
2024-07-21 20:31:32 -07:00
Sameer Agarwal 0ca2db57c7 Fix a number of typos
Change-Id: I0038f9c91dc70c422c01305dc10fca5a22a2f0d0
2024-07-21 15:15:36 -07:00
Sameer Agarwal 7566ebae08 Various cleanups
Change-Id: Ie453e199a128a102bf3d5524a466f549aac0c7ce
2024-07-21 08:14:08 -07:00
Sameer Agarwal 0a53aa9054 Take abseil as a dependency
1. Add abseil-cpp as a submodule. We are tracking the latest LTS
release, which is lts_2024_01_16.
2. Replace glog/gflags with absl::log and absl::flags.
3. Remove miniglog
4. Also take a whack at making the bazel build work with
   abseil-cpp and gtest.

There are a number of TODOs in this CL that still need to be resolved.

Change-Id: I39355ed7d61375be4ebcbc8596d9cc70acc1c678
2024-07-18 00:24:49 -07:00
Mark Shachkov 6fb3dae4ee Add cuDSS as sparse Cholesky solver
cuDSS could be used as an alternative for SuiteSparse and EigenSparse
in case if CUDA capable GPU is available.

Change-Id: I7a567093ce91363478118153e181134ed5804573
2024-07-09 20:23:18 +02:00
Mark Shachkov 522210a08d Reuse macro to format version string
Change-Id: Ib21f2d8f06b6594dae410681d16a738b8b75c89a
2024-05-07 01:47:41 +02:00
MaximSmolskiy 2ffeb943ad Fix typo in AutoDiffManifold comment and docs
Change-Id: I0b50e3e10661578e68f713e34a59f65b3692e745
2024-01-29 03:19:37 +03:00
Sergiu Deitsch 91773746be Simplify instantiation of cost functions and their functors
If arguments are passed to a cost function that can be used to construct
the functor, the latter will be instantiated by the cost function using
std::make_unique to ensure exception safety. This not only avoids static
analysis warnings caused by calling new but also spelling the cost
functor type name multiple times.

Also expand deduction guides for instantiating
Dynamic(Auto|Numeric)DiffCostFunction from std::unique_ptr enabled
constructor overloads.

Finally, make CostFunction default move constructible and assignable but
only through derived classes. This in turn allows derived classes to be
movable without relying on custom implementations of corresponding
operators.

Change-Id: Idee8b9871d862bc9f9f8b5a8d0bedc52863e93c0
2024-01-23 01:34:27 +01:00
Sergiu Deitsch 8b88a9ab49 Use C++17 Bessel functions
Move Bessel functions availability checks from configuration time to
inclusion time to be more robust and allow the use of ABI compatible
compilers (e.g., Ceres is compiled using Clang but is used in a project
compiled using GCC.)

Since libc++ does not yet implement special math functions, we fallback
to their POSIX implementation if available. However, then only the
deprecated BesselJ{0,1,n} are provided.

Fixes #814

Change-Id: Ic3e62452b36e90cb22644cc8e553e3dd1881193f
2024-01-22 20:42:59 +01:00
Sameer Agarwal 2120eae674 Optimize the computation of the LM diagonal in TinySolver
This eliminates an entire vector and computation of a square root
followed by a squaring.

Thanks to @rlabbe for pointing this out.

Change-Id: I0de117b31b9332c61e687f18466d7cb2e2ac611e
2023-10-11 15:14:33 +00:00
Sergiu Deitsch 4519b8d774 Drop use of POSIX M_PI
Change-Id: I37342a366161bb13d6456ecc67569fe12705e05c
2023-10-04 22:59:15 +02:00
Sameer Agarwal b83abdcb19 Add a default value for Solver::Summary::linear_solver_ordering_type
Change-Id: I5c7c9acdc37ba0755d479ac9c6c2872fe89fb492
2023-10-04 13:26:20 -07:00
Sameer Agarwal 399395c4f1 Miscellaneous ClangTidy fixes
Change-Id: Iba2f8b1dccb77cefde750e5079e609b2b2a3ec95
2023-10-03 11:52:09 -07:00
Sergiu Deitsch 4893392195 Rework MSVC warning suppression
Previously, MSVC warning C4996 was suppressed unconditionally in the
entire code base which made it difficult identifying and fixing specific
problems, particularly those in the public interface.

Prefer now to disable warnings at the specific location they occur. This
approach, however, reveals an inconsistency in how Ceres handles POSIX
functions which are declared deprecated by MSVC. Specifically, Bessel
functions use the underscore form whereas the read function does not. To
simplify the logic, we revert to POSIX compatible functions.

C++23 also deprecates std::numeric_limits<T>::has_denorm which MSVC
warns about. Here, we disable the deprecation warning locally to avoid
the warning leaking into the user code.

Fixes #1013

Change-Id: Ida8457cc8dd8770b4384a7c49d16f213b02cdec4
2023-09-30 13:37:39 +02:00
Sameer Agarwal 4588b0fbbf Add an example for EvaluationCallback
Change-Id: Ia488f8b181118c8d07861149c4bd52f7217336ce
2023-09-28 21:49:32 +00:00
Sameer Agarwal 59182a42c3 Update documentation
Update the linear solver documentation thoroughly as it had
bit rotted and was flat out wrong in some places and incomplete
in others.

https://github.com/ceres-solver/ceres-solver/issues/865
https://github.com/ceres-solver/ceres-solver/issues/862

Change-Id: Ic395efabd0589a401e2b971c45869bd881b68a34
2023-09-27 09:27:29 -07:00
Sameer Agarwal dffd8cd71b Add an accessor for the CostFunctor in DynamicAutoDiffCostFunction
https://github.com/ceres-solver/ceres-solver/issues/962

Change-Id: I50c327eb7ac09a894582ee3fb3311825607640c0
2023-09-25 05:44:37 -07:00
Sameer Agarwal 5a30cae583 Preparing for 2.2.0rc1
1. Add a version history
2. Update copyright years across the code base
3. Run format_all.sh
4. Update version strings from 2.1.0 to 2.2.0 in the docs and
   elsewhere.

Change-Id: I46d8d479d54bd6002d532785e67342106e73c9ac
2023-09-21 11:23:38 -07:00
Sergiu Deitsch de9cbde95d Work around MinGW32 manifold_test segfault
Converting fixed size vectors to dynamic ones allows to avoid
segmentation faults in Eigen's packet math if the corresponding
expressions are invoked within GMock matchers.

Fixes #996

Change-Id: I7da5599883825ab0e580678d3d55de19095b41b1
2023-09-08 19:57:43 +02:00
Sameer Agarwal 357482db70 Add NumTraits::max_digits10 for Jets
Change-Id: Ief2c02eeaefba98d2540eb2f3428c65a98e36ef5
2023-07-29 12:35:30 -07:00
Hs293Go 96fdfd2e7a Implement tests for Euler conversion with jets
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: I6bdabf5ee09c000e49ea1757fde724d4bc4ccb92
2023-04-27 16:42:25 -04:00
Sameer Agarwal db1ebd3ff5 Work around lack of constexpr constructors for Jet
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: Ia74a64568815605586c1f326a55cc36b09f33f30
2023-04-18 16:26:24 -07:00
Sameer Agarwal 16a4fa04e2 Further Jet conversion fixes
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: Ib80467eda4120b0483814e9e01e9644dd7ee91a7
2023-04-18 14:58:22 -07:00
Sameer Agarwal 92ad18b8ae Fix a Jet conversion bug in rotation.h
https: //github.com/ceres-solver/ceres-solver/issues/965
Change-Id: I4c99639be6afbfbefea3f9d56b6eaddbe4f23fe9
2023-04-18 09:18:01 -07:00
Dmitriy Korchemkin 54ad3dd03c Reorganize ParallelFor source files
Change-Id: Ic4941919e59210b48e447cbb61e539200c8c89df
2023-04-11 00:33:55 +03:00
Sergiu Deitsch 0315c6ca9a Provide DynamicAutoDiffCostFunction deduction guide
The deduction guide allows to avoid repeating the CostFunctor type.

Change-Id: I2285de37071006a97f89988baa9b7054d82dae86
2023-03-08 23:46:33 +01:00
Sameer Agarwal 79a554ffcf Fix a bug in QuaternionRotatePoint.
In https://ceres-solver-review.git.corp.google.com/c/ceres-solver/+/23802

the computation of the norm of a quaternion

scale = 1/sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);

was replaced by

scale = 1/hypot(q[0], q[1], hypot(q[2], q[3]));

while this appear to be a more accurate computation because of the
use of hypot which can handle over and underflow it introduces a
bug for the case where q[2] = q[3] = 0.

While the hypot(q[2], q[3]) == 0 as scalars, if q[2] and q[3] are
jets, then the derivative will be NaN. Which means that even though
q[0] or q[1] is non-zero and the norm of the quaternion is non-zero,
and the resulting derivative is finite, this way of computing the
scale will produce nans in the derivative of scale.

The following quaternion will replicate the problem described above.

using Jet = ceres::Jet<double, 4>;
std::array<Jet, 4> quaternion = {Jet(1.0, 0), Jet(0.0, 1), Jet(0.0, 2), Jet(0.0, 3)};

This CL reverts the change to QuaternionRotatePoint and
adds a test for it.

Thanks to Jonathan Taylor for reproducing this bug.

Change-Id: I0fbbcc77d6945a38563d82efba4429f4b5278cd5
2023-01-13 11:37:27 -08:00
Sergiu Deitsch cb6b306623 Use hypot to compute the L^2 norm
Change-Id: I908eaaa279452aa16346dfd3f25aac53685e3172
2023-01-05 21:44:53 +01:00
Sameer Agarwal 8e5d83f07d ClangFormat and ClangTidy changes
Change-Id: Ib457dcc55ffb405aeaeac711c20bd9217b32f90e
2022-12-17 17:29:42 -08:00
Alex Stewart 47e03a6d89 Add const accessor for Problem::Options used by Problem
Change-Id: I0fc48178c411887d4487a34599050d342f5344a2
2022-11-05 12:55:28 +00:00
Alex Stewart 6b296f27ff Fix missing namespace qualification and docs for Manifold gtest macro
Change-Id: Iae9a0d13191a777921208cb58d919f0e85b1bf92
2022-10-30 17:49:11 +00:00
Alex Stewart ccf32d70c7 Purge all remaining references to (defunct) LocalParameterization
Change-Id: Iad2a49bfa6916c22929d822e07f754ef77ed023d
2022-10-19 20:00:20 +01:00
Dmitriy Korchemkin b7116824b7 Evaluation benchmark
Benchmark for evaluation of residuals and evaluation of both residuals
and jacobian.

For each input file (in BAL format) specified on the command line two
sets of benchmarks are created for different number of threads.

BAL data is preloaded before starting benchmark.

Usage:
./bin/evaluation_benchmark [flags] input_1.txt ... input_N.txt

Change-Id: I543df65f483e3b186f52785b68bd5e2b3e3552a3
2022-09-21 13:40:03 +03:00
hs293go 2b89ce66f0 Add generalized Euler Angle conversions
Conversions function include Euler Angles to / from Rotation Matrices
and Quaternions. They are generalized for any Euler convention that can
be specified in the arguments. Algorithm is from "Euler angle
conversion", Ken Shoemake, Graphics Gems IV

Change-Id: I7f9ddc0b8d686efca16299d2ba374295744376ce
2022-09-20 22:14:19 +00:00
Sameer Agarwal 4cd257cf4a Let NumericDiffFirstOrderFunction take a dynamically sized parameter vector
Also fix a template naming lint along the way.

Change-Id: Iabb98aeec2ff9609a19c3778b9ea2da37771c985
2022-09-16 10:16:35 -07:00
Joydeep Biswas 829089053e CUDA CGNR, Part 4: CudaCgnrSolver
* Added CudaCgnrSolver, a new CUDA-accelerated CGNR.
* To use CudaCgnrSolver, the user must select CGNR as the linear_solver
  and CUDA_SPARSE as the sparse_linear_algebra_library.
* Updated ConjugateGradientSolver to work with an array of pointers to
  scratch to support CudaVectors as scratch.
* Moved CUDA initialization to run in Solver::Solve as needed.

Some performance comparisons on an Ubuntu 20.04 desktop with an
Intel i9-9940X CPU @ 3.30GHz, and an nVidia Quadro RTX 6000,
all configurations run with 24 threads, and 10 iterations.

=================================================
CGNR + CUDA_SPARSE + IDENTITY Preconditioner
problem-1778-993923-pre.txt
=================================================
Cost:
Initial                          2.563973e+08
Final                            1.724755e+06
Change                           2.546725e+08

Minimizer iterations                       11
Successful steps                            7
Unsuccessful steps                          4

Time (in seconds):
Preprocessor                         4.020158

  Residual only evaluation           1.567092 (10)
  Jacobian & residual evaluation     7.847130 (7)
  Linear solver                     31.688898 (10)
Minimizer                           46.834987

Postprocessor                        0.353974
Total                               51.209120

=================================================
SPARSE_SCHUR (CPU) + SUITE_SPARSE + AMD
problem-1778-993923-pre.txt
=================================================
Cost:
Initial                          2.563973e+08
Final                            1.651617e+06
Change                           2.547457e+08

Minimizer iterations                       11
Successful steps                           11
Unsuccessful steps                          0

Time (in seconds):
Preprocessor                        35.812003

  Residual only evaluation           1.658980 (10)
  Jacobian & residual evaluation    12.218799 (11)
  Linear solver                     76.409992 (10)
Minimizer                           98.809773

Postprocessor                        0.372712
Total                              134.994489

=================================================
ITERATIVE_SCHUR (CPU) + JACOBI Preconditioner
problem-1778-993923-pre.txt
=================================================
Cost:
Initial                          2.563973e+08
Final                            1.684447e+06
Change                           2.547128e+08

Minimizer iterations                       11
Successful steps                            8
Unsuccessful steps                          3

Time (in seconds):
Preprocessor                        15.331614

  Residual only evaluation           1.606114 (10)
  Jacobian & residual evaluation     8.502166 (8)
  Linear solver                    351.910080 (10)
Minimizer                          368.797327

Postprocessor                        0.363536
Total                              384.492478

=================================================
CGNR + CUDA_SPARSE + IDENTITY Preconditioner
problem-13682-4456117-pre.txt
=================================================
Cost:
Initial                          1.126372e+09
Final                            2.269329e+07
Change                           1.103678e+09

Minimizer iterations                       11
Successful steps                            7
Unsuccessful steps                          4

Time (in seconds):
Preprocessor                        19.140087

  Residual only evaluation           8.721920 (10)
  Jacobian & residual evaluation    41.955923 (7)
  Linear solver                    214.121861 (10)
Minimizer                          296.636890

Postprocessor                        1.971827
Total                              317.748804

Change-Id: I3a09f31aa6903f661e91f595afd39d427583e856
2022-08-15 23:44:34 -05:00
Sameer Agarwal 2c78c5f339 Small naming fixups.
use_power_series_expansion_initialization -> use_spse_initialization
max_linear_solve_iterations -> max_linear_solver_iterations

Change-Id: I7775fa9b1ad12e28c8d01d44349b7eaef9b57edd
2022-08-13 11:59:16 -07:00
Mark Shachkov 92d8379532 Enable usage of schur power series expansion preconditioner.
Add an option to use schur power series expansion for initialization
of pcg solution in ITERATIVE_SCHUR linear solver.

Change-Id: Ifb8bce02bc5f5ceebc74f961eefd3f6dd2ffab4a
2022-08-13 21:05:11 +03:00
Mark Shachkov 20e85bbe34 Add power series expansion preconditioner
Implementation of "Power Bundle Adjustment for Large-Scale 3D
Reconstruction" by Weber et. al. added in the form of preconditioner.

Change-Id: Ie85526a5fc46f74256f6dfe9173c3571f7160f3a
2022-08-11 19:34:41 +03:00
Julio L. Paneque f62dccdb37 Fix the Sphere and Line Manifold formulations
This PR changes the Sphere and Line Manifold formulations so that their
tangent spaces represent traveled angles (for the sphere and the line
direction vector) and traveled distance (for the line origin). These
magnitudes were previously halved according to "Hartley & Zisserman
(2nd Edition)", but in the majority of the state of the art this is not
done, following the convention that magnitudes in the tangent space of
the unit sphere represent geodesic distances traveled on that manifold.
The same scale factor appears in the Quaternion Manifold implementation
and will be studied in a further PR.

This PR also adds an additional case in the Sphere Minus operator when
hy_norm == 0. The value of y_minus_x was fixed to 0 but actually its
last term can also be Pi depending on y_last.

Finally, new unit tests for the Plus and Minus operator are added, along
with new tests for the 2D Sphere (a.k.a. Circle) Manifold.

Change-Id: I9456f1675b20da49bede5d6759aabf3cdfb26eae
2022-08-09 09:36:18 +02:00
Julio L. Paneque df55682ba5 Fix Eigen error in 2D sphere manifolds
Since Eigen does not allow to have a RowMajor column vector (see
https://gitlab.com/libeigen/eigen/-/issues/416), the storage order
must be set to ColMajor in that case. This fix adds that special
case when generating 2D sphere manifolds.

Change-Id: I594932e0dafc878e0b348f72524478588e61b34d
2022-08-05 11:25:29 +02:00
Sameer Agarwal 68c53bb395 Remove ceres::LocalParameterization
Change-Id: I3bdf2f6a8857db10c984024a27f490eefd23fefa
2022-07-29 22:29:23 +00:00