Commit Graph

1392 Commits

Author SHA1 Message Date
Sergiu Deitsch f9b7b6651b Support Eigen3 5.0.0
Change-Id: I5cf476a6d8c090861f4ea4a254a35d39e36a6d68
2025-09-28 11:53:07 -07:00
Sergiu Deitsch d4e3ba3173 Ensure consistent visibility attributes
Change-Id: Ib80d655a3601a716956bbd2b977d295a809307c1
2025-09-28 11:49:17 -07:00
Sergiu Deitsch 6f00e41111 Reuse constants
Change-Id: I306da23d26667e801cfa4fb12306cdd92af09a65
2025-09-28 18:04:54 +02:00
Sergiu Deitsch 93e66f0d94 Fixed discrepancy in QuaternionRotatePoint for different orders
Fixes #1178

Change-Id: I0430ffb384ea53a863ba72f076043f0f772db4e1
2025-08-17 10:52:12 +02:00
Sameer Agarwal b92ade3e11 Reorder the fields in ParameterBlock
This CL reorders the fields to group the hot fields together to increase data density. This CL doesn’t change functionality but expects to reduce cache misses and save CPU.

Change-Id: I313493a187ac6ebc607b311c39415c79a94f00c8
2025-08-13 15:02:50 -07:00
Johannes Bruenger bae3cf781d Fix typo in logged warning
Change-Id: Ibf74392b26cbe01bf7ba898491b4442cbdef8b57
2025-08-04 20:11:55 +02:00
Matt Vitelli c380195d31 Fix threading bug in CovarianceImpl.
This change fixes a bug in ceres::CovarianceImpl where a new thread was always being created even when num_threads=1. After this fix, when num_threads=1, CovarianceImpl should run single-threaded and will not create any additional threads.

Change-Id: I784e359f8afe3e7e6d72930500a10e909bfe9308
2025-07-31 23:00:36 -07:00
Sergiu Deitsch 8c50a34a1c Reuse rotation functionality in (Eigen)QuaternionManifold
Allow to specify the memory layout of quaternion coefficients using a
template parameter which defaults to Ceres coefficients order.

The changes are, for the most part, backwards compatible unless the
floating-point type is explicitly specified, e.g., as
&ceres::QuaternionToAngleAxis<double> to obtain a pointer to the
corresponding function. In such rare use cases, the coefficients order
must be given explicitly first as
ceres::QuaternionToAngleAxis<ceres::CeresQuaternionOrder>. In normal
situations, however, this should not be needed.

Change-Id: I05dd80f0593672dec656cc785cf06fe5268aee74
2025-06-19 18:15:51 +02:00
Sergiu Deitsch 370631f01f Use Euler parameters in QuaternionPlusImpl
Define the relation between the axis-angle representation of a rotation
and the corresponding unit quaternion as

  q(𝐞) = cos(𝜃/2) + sin(𝜃/2)/𝜃·𝐞

where 𝐞 = 𝜃𝛚 is the rotation vector given by the rotation angle 𝜃 and
the unit axis of rotation 𝛚 instead of

  q(𝐞) = cos(𝜃) + sin(𝜃)/𝜃·𝐞 .

This brings the former relation closer to the available functionality
provided by ceres/rotation.h.

Fixes #941

Change-Id: Id40c065f78593887ecc52e67a068737d7eb5bda6
2025-06-13 16:23:24 -07:00
Sergiu Deitsch 968f928907 Do not restrict Grid1D and Grid2D output to double
Fixes #1158

Change-Id: Ibeb4188393023308231c32b944f2c9dfdd674a60
2025-06-13 15:43:57 -07:00
Sergiu Deitsch 4148d6a353 Allow AngleAxisRotatePoint to be applied in-place
Thanks to @CatInTheRain for the suggestion.

Fixes #1163

Change-Id: I4e148c62891979e1ec01b91f95d3e2d04501c8ef
2025-06-10 23:14:28 +02:00
Sergiu Deitsch 9c22db814c Fix typos in CMake comments
Thanks to @valgur for spotting the mistakes.

Change-Id: I2b32acbb3c822d1ebb4defed53734be6d3371698
2025-06-09 22:48:54 +02:00
Sergiu Deitsch 83133357dd Partially revert hypot arguments zero checks
Unfortunately, libc++'s 3-argument std::hypot implementation is
numerically unstable until LLVM 19.x. Therefore, checking the arguments
for zeros is insufficient since an underflow can still occur resulting
in a zero norm which requires another check. As such, division by zero
cannot be reliably avoided.

Change-Id: I189c8dc722aaec1ebc3ec8b1a177e1d8ac3b36db
2025-05-20 21:31:10 +02:00
Sergiu Deitsch c15da00398 Avoid division by zero
Run cleanly under -fsanitize=float-divide-by-zero.

Change-Id: I99e92a50c60971c9f771774e58dbe65be7c675ec
2025-05-18 10:02:39 -07:00
Sameer Agarwal b5b63b5b66 ClangTidy fixes
Change-Id: Ib60fd2815875b4dc1fdb8402fb35758868302842
2025-05-07 08:33:32 -07:00
Sameer Agarwal 5d7baac258 ClangTidy fixes
Change-Id: Iae5a6b0067c726a5c5f6a88acee15a574cb46be6
2025-05-07 08:26:26 -07:00
Sergey Sharybin a43073a389 Fix vector operations benchmark compilation
Some of the benchmark functions use the same name as other functions
in the ceres namespace. For example Axpby defines both benchmark but
also an utility function in eigen_vector_ops.h. It seems to confuse
some compilers and leads to a compilation error rooting deeper into
the benchmark header itself: it seems that the compiler can not
deduct which of the instances of such functions to use.

Wrapping the file into an anonymous namespace solves the problem.
Alternative could be to use benchmark namespace to make thins more
explicit, for example ceres::internal::benchmark.

Tested on the following configuration:
- macOS 15.4
- Xcode 16.3
- Apple M3 CPU
- google-benchmark 1.9.2 installed via homebrew

Change-Id: Id127015dd22de99c6c3da88e71f255736e0bed82
2025-04-03 14:23:24 +02:00
Sergiu Deitsch ca4da54950 Use LINK_LIBRARY generator expression only for static absl
Change-Id: I348434be68a7bf112513cacf5791095cba8f95b3
2025-02-19 17:52:31 +01:00
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 3db40b8013 Use std::string_view in EventLogger
Change-Id: If23504e146826f143220b031a5fbc2be2013d127
2024-09-29 09:43:26 -07:00
Sameer Agarwal 01a06ef7b1 Add an EventLogger to TrustRegionPreprocessor
Change-Id: I808567a6462f9326f385e88fdf2849537595ef7b
2024-09-28 13:19:09 -07:00
Sameer Agarwal 8c740b83ee ClangTidy fixes
Change-Id: I8d1a0258fc586040bd1cb5cc6131fdad2fe134eb
2024-09-18 21:41:18 -07:00
Sameer Agarwal 42475eec77 Use absl::btree_map instead of std::map
Change-Id: Iece280a6cb0f37fa0bc572046b9d7f79ca825ebc
2024-09-17 12:18:31 -07:00
Sergiu Deitsch e1385cc7e7 Fix MSVC build
Previously missed instance of preprocessor directives used in a macro
expansion.

Change-Id: I2f1e4ad95036851fa502a9ea01d2a9684a3e0f9d
2024-09-17 00:00:37 +02:00
Sameer Agarwal 39b7cbaa5d Use absl hash containers for graph algorithms
This reduces pre-processor time when finding an
ordering automatically substantially.

Before:

ComputeStableSchurOrdering
                                        Delta   Cumulative
              CreateHessianGraph :    0.50324      0.50324
                     Preordering :    0.00692      0.51017
            StableIndependentSet :    0.26341      0.77358
         ConstantParameterBlocks :    0.00095      0.77453
                           Total :    0.23978      1.01431

After:

ComputeStableSchurOrdering
                                        Delta   Cumulative
              CreateHessianGraph :    0.17183      0.17183
                     Preordering :    0.00226      0.17409
            StableIndependentSet :    0.12510      0.29919
         ConstantParameterBlocks :    0.00073      0.29991
                           Total :    0.01638      0.31629

Change-Id: I50bbac69f8b3f19240a61a218913cebf34da0db5
2024-09-16 21:51:54 +00:00
Sergiu Deitsch 00b33b6523 Fix MSVC build
Using preprocessor directives in a macro expansion is a (non-standard)
language extension that is not supported by MSVC.

Change-Id: I6e158b108a9c13cd277afb96cab2017ac192e3a2
2024-09-16 23:16:07 +02:00
Sameer Agarwal 0a7845fef4 Unbreak the build due to a silly typo
Change-Id: Ib05cb3ceeb974b1099bc7b090f77e109ddcd7166
2024-09-15 21:24:47 -07:00
Sameer Agarwal 88f2cb32cd ClangTidy fixes
Change-Id: I1f4d6975fd1b9629d1db0d529d9ee92d79c11e84
2024-09-15 20:12:27 -07:00
Sameer Agarwal c59882eca0 ClangTidy fixes
Change-Id: I421b29e218c045c5d8bef42c840fa366d7c011fc
2024-09-15 22:29:56 +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 ecae3de151 Fix a declaration order problem in sparse_cholesky_test.cc
Change-Id: Ie74069e8716145c244955bf907e2bae79f48972f
2024-08-26 16:57:17 +00:00
Sameer Agarwal 8964e52b01 ClangTidy fixes
Change-Id: Id7358fcdccae69b46b479d55ed6aee80efd3431e
2024-08-26 09:18:17 -07: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 9186dcc49c Add the ability to use system installed versions of abseil and googletest
If the user has checked out the submodules in third_party, they will be
used, otherwise we will try and find the system installed versions of
these dependencies and use them if they are modern enough.

Change-Id: I52164bc48a6ea804b85cdda05fee9cb94632f6c0
2024-08-14 21:16:57 -07:00
Sameer Agarwal 6726cd5073 Fix absl::log_flags linking on Linux
Generator expressions were introduced in CMake version 3.24. Without
them including absl::log_flags as an internal dependency causes
linking problems on some platforms. So for platforms with an older
CMake version we make absl::log_flags a public dependency.

Change-Id: I686f41e76b0ac17a03f1cd1d614372a7f130dfd9
2024-08-12 07:06:34 -07:00
Sameer Agarwal 4aa57d8096 Replace string_view with string.
The use of string_view causes problems with absl::StrCat
in certain compilation configurations.

Change-Id: I1beda82692378bf9cf378a7d42df46de8491d1c9
2024-08-09 17:02:53 -07:00
Sameer Agarwal f45b98709d More ClangTidy Fixes
Change-Id: I286a9b6402812707e64f71952eeb79b755ec43d9
2024-08-09 16:35:09 -07:00
Sameer Agarwal a3afe3d724 ClangTidy fixes
Change-Id: I2ed57cd6f84bae81686a833834bf00ddef91f61b
2024-08-09 16:24:07 -07:00
Sameer Agarwal 0bd9e63dcc Add absl/log/vlog_is_on.h when using VLOG_IS_ON
Previously this header was included in absl/log/log.h
but going forward this header will not be included.

Change-Id: Ie663b221d90e32a852fb00dfe20f731dcd1dcf6b
2024-08-09 16:15:22 -07:00
Sameer Agarwal b97ffeadbb Use absl::time
Replace WallTimeInSeconds with absl::Now and use
absl::Time and absl::Duration objects instead of doubles.

wall_time.h/cc -> event_logger.h/cc

Change-Id: I41279961368840fbdf6bb3456ffdbdf2f9bfb85b
2024-08-08 07:18:44 -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 0ecdb82616 Link to absl::log_flags
This enables control of logging using commandline flags.

Fixes https://github.com/ceres-solver/ceres-solver/issues/1090

Change-Id: Ia0fd6abf4a8e6dfa8bc4e71d2263d622a28b0268
2024-08-08 06:59:39 -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 c181b6dbc4 ClangTidy fixes part 3
Change-Id: I69587f663b8d91a465ed068a82f9e09e3b7a72e2
2024-07-22 07:25:14 -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 6b9a690009 ClangTidy cleanup part 1
Change-Id: Id592fc68b8f184cd002df9d94a68d05fbbf9c24d
2024-07-21 14:55:46 -07:00
Sameer Agarwal 68eeba2c2c Add a missing include
Change-Id: I3060e80a69374f7a2db31121715d0d892a54d311
2024-07-21 13:25:45 -07:00
Sameer Agarwal 1e19a11f5f Add a missing include
Change-Id: I0a3fa842183bc7cb9ba00b17d6181cebc3eac50d
2024-07-21 08:24:31 -07:00