Commit Graph

2257 Commits

Author SHA1 Message Date
Sameer Agarwal 188fe7bf4d [modernize] Use inline constexpr in parameter_dims.h
Change-Id: I493843d5be30c512a69fc517c5622c48faa63088
2026-03-17 12:42:00 -07:00
Sameer Agarwal 532ad49568 [modernize] Use std::clamp and C++17 headers in cubic_interpolation.h
Change-Id: Ief7ff6555aeb3d3be83e999d777160b3c7c1bb9b
2026-03-17 12:39:50 -07:00
Sameer Agarwal 4390b34d5b [modernize] Use if constexpr in EuclideanManifold constructor
Change-Id: I61d4827d7b04feed369c72db3643afda67ea434e
2026-03-17 12:39:05 -07:00
Sameer Agarwal 4bd55bd44c [modernize] Convert kImpossibleValue to inline constexpr in types.h
Change-Id: Ide561296f1bbcc244dd655cf229d08582281b234
2026-03-17 12:31:19 -07:00
Sameer Agarwal ccd1198d72 Make test_util GTest-optional to fix benchmark builds with BUILD_TESTING=OFF
When Ceres is configured with BUILD_TESTING=OFF and BUILD_BENCHMARKS=ON,
benchmarks failed to compile and link due to an unconditional dependency on the
test_util library, which requires Googletest (GTest). This commit addresses the issue
by introducing the CERES_HAS_GTEST macro and making the test utility library
GTest-optional.

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

Change-Id: I615c37eb6f21d36a4b87b2d24632016944eda3bd
2026-03-16 16:19:06 -07:00
Johannes Schönberger 084b3e3b83 Apply deterministic parameter block reordering
Change-Id: I0dc58ce754225310ff1a170cec8a3c71a402df57
2026-02-25 14:19:40 -08:00
Sergiu Deitsch a2bab5af51 Fix ODR violations
Compiling Ceres with Schur specializations and Link Time Optimization
(LTO) results in warnings such as

    /usr/include/eigen3/Eigen/src/Core/ProductEvaluators.h:31:8: warning: type ‘struct evaluator’ violates the C++ One Definition Rule [-Wodr]
       31 | struct evaluator<Product<Lhs, Rhs, Options>> : public product_evaluator<Product<Lhs, Rhs, Options>> {
          |        ^

due to the redefinition of EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD which
alters internal Eigen class definitions and consequently results in ODR
violations.

Avoid the ODR violation by renaming the Eigen namespace in translation
units that redefine EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD.

While the issue is diagnosed in LTO builds of Ceres only, the problem
exists in non-LTO builds as well and per standard the compiler is not
even required to diagnose ODR issues. ODR violations constitute
undefined behavior.

Change-Id: Idf7c7a30cc8d3a86b0d62cbd33bef58783a62ee4
2026-02-17 10:14:21 -08:00
Sergiu Deitsch de96ed58f5 Eliminate benchmark deprecation warnings
Resolve the following warnings issue by the latest version of the
benchmark library:

/Users/runner/work/ceres-solver/ceres-solver/internal/ceres/small_blas_gemv_benchmark.cc:71:54: warning: 'Benchmark' is deprecated: Use ::benchmark::Benchmark instead [-Wdeprecated-declarations]
   71 | static void MatrixSizeArguments(benchmark::internal::Benchmark* benchmark) {
      |

/Users/runner/work/ceres-solver/ceres-solver/internal/ceres/dense_linear_solver_benchmark.cc:67:46: warning: 'Benchmark' is deprecated: Use ::benchmark::Benchmark instead [-Wdeprecated-declarations]
   67 | static void MatrixSizes(benchmark::internal::Benchmark* b) {
      |

/Users/runner/work/ceres-solver/ceres-solver/internal/ceres/invert_psd_matrix_benchmark.cc:80:37: warning: 'Benchmark' is deprecated: Use ::benchmark::Benchmark instead [-Wdeprecated-declarations]
   80 |     ->Apply([](benchmark::internal::Benchmark* benchmark) {
      |

Change-Id: Ice6fe57dc5635698809e368fda23a018f4d7df5a
2026-02-01 08:24:16 -08:00
Sergiu Deitsch 18887f1bd7 Drop removed macos-13 runner
Change-Id: I7f37bb2f71324353a45e39d12792edabfb3956b7
2026-02-01 15:58:57 +01:00
brettmichaelgreen 0c70ed3a1a Document DumpLinearLeastSquaresProblem
Add documentation on the output of DumpLinearLeastSquaresProblem.
This is to clarify confusion brought up on #608

Change-Id: I935cacee1e4345a1d0250aaac322ca2f8e794e66
2025-11-08 15:56:10 -05:00
Sameer Agarwal 345357a952 ClangTidy cleanup
Change-Id: I5b619f3966dfb988f09cc412def649f3d2868808
2025-10-30 17:34:39 -07:00
Sameer Agarwal 4a3f008e6a Fix a bug in inner iterations
Normally we expect it to be the case that inner iteration cost
will be less than the trust region cost, but due to round off
error it can be that it is larger, so make the test for inner
iteration being successful to be stricter.

Change-Id: Icbafe9fc6a311940d5368cca78eeac7ccd5fa943
2025-10-26 18:20:45 -07:00
Sergiu Deitsch f9b7b6651b Support Eigen3 5.0.0
Change-Id: I5cf476a6d8c090861f4ea4a254a35d39e36a6d68
2025-09-28 11:53:07 -07:00
Sergiu Deitsch 77d7044d23 Do not rely on a define for disabling warnings
Using a define to determine whether to disable warnings introduces a
dependency on the header inclusion order and thus can prevent the
warnings from being enabled.

Fixes #1173

Change-Id: I21f5bca78a83bfe4642e9b01abd220b9fbba31a4
2025-09-28 11:50:21 -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
Sergiu Deitsch 4997d0e5b4 Drop removed windows-2019 runner
Change-Id: I75b52ce778f6e74832dbfaf9dc35a99e28c9b51a
2025-08-17 10:51:26 +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
Mackay f616f61eab Update CMakeLists.txt to support CUDA 13
Change-Id: I4a0a0b29a45c1108d27b6f85670c926f5dda0f5e
2025-08-06 21:36:12 -04: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 2dcc72c684 Update Bazel dependencies
Change-Id: I99168221fb229a7c7a41e5e1e0c269d655917e05
2025-06-09 09:10:28 -07:00
Sergiu Deitsch 0e760e0453 Use subsections instead of an enumeration in solving FAQ
This is a follow-up to related changes made in 018bb49e80.

Change-Id: Ife3befe85d7cea5dad5185a424508d590c0d77f7
2025-06-09 09:07:03 -07:00
Sergiu Deitsch 3c3400342b Fix docs typo
Change-Id: Ib3967dc7413455ccb2a1211d892fd1150514522a
2025-06-09 15:20:17 +02:00
Sergiu Deitsch 8a545eb46b Update dependencies to support GCC 15
Previously, compiling using GCC failed with

  In file included from /usr/include/c++/15.1.1/cassert:46,
                   from <ceres-prefix>/third_party/abseil-cpp/absl/container/internal/container_memory.h:18,
                   from <ceres-prefix>/third_party/abseil-cpp/absl/container/flat_hash_map.h:40,
                   from <ceres-prefix>/third_party/abseil-cpp/absl/flags/reflection.h:29,
                   from <ceres-prefix>/third_party/abseil-cpp/absl/flags/reflection.cc:16:
  <ceres-prefix>/third_party/abseil-cpp/absl/container/internal/container_memory.h: In function ‘void* absl::lts_20240116::container_internal::Allocate(Alloc*, size_t)’:
  <ceres-prefix>/third_party/abseil-cpp/absl/container/internal/container_memory.h:66:27: error: ‘uintptr_t’ does not name a type [-Wtemplate-body]
     66 |   assert(reinterpret_cast<uintptr_t>(p) % Alignment == 0 &&
        |                           ^~~~~~~~~
  <ceres-prefix>/third_party/abseil-cpp/absl/container/internal/container_memory.h:31:1: note: ‘uintptr_t’ is defined in header ‘<cstdint>’; this is probably fixable by adding ‘#include <cstdint>’
     30 | #include "absl/utility/utility.h"
    +++ |+#include <cstdint>
     31 |

Additionally, the previous version of Abseil errouneously depends on
googletest when Ceres is consumed which results in issues with
downstream projects. We therefore update both dependencies to avoid
these issues.

Thanks to @adam-ce for figuring out the working versions of Abseil and
googletest.

Fixes #1140

Change-Id: Ie991da04491d42979d51b891a4565cabbb1c604b
2025-06-08 13:23:29 +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
Sergiu Deitsch a1d7bac40f Provide Jet Eigen::NumTraits quiet_NaN and infinity
The definitions are required by Eigen::SelfAdjointEigenSolver.

Change-Id: Ifcc3348b381d9116e6cb3e2d3ec47c7450c3382a
2025-05-15 21:40:16 +02: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
Sameer Agarwal a3fd8ec461 Add a module statement to MODULE.bazel
Change-Id: I504517b5d582c4ce4a538761c41a6ccae6ec9305
2025-05-07 07:43:41 -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 46b4b3b002 Do not discard caller's CMAKE_MODULE_PATH
Ceres CMake package configuration relies on several own find modules
(e.g., for SuiteSparse and METIS). To allow CMake to discover additional
find modules, the CMAKE_MODULE_PATH variable must be updated to include
the directories containing the corresponding find modules.

Previously, before updating CMAKE_MODULE_PATH, Ceres stored the
variable's initial value and then completely replaced it by the
directory containing Ceres's modules. However, a find_dependency failure
would cause an early return preventing CMAKE_MODULE_PATH to be restored.
Thus, any initial user changes to CMAKE_MODULE_PATH would be lost.

Now, instead of completely replacing the CMAKE_MODULE_PATH value we only
prepend additional directories. An early return no longer has a
destructive effect on CMAKE_MODULE_PATH. In a failure case,
CMAKE_MODULE_PATH still contains caller's initial set of directories and
an additional path prepended by Ceres.

Fixes #1024

Change-Id: I80d92a5dff9f3cff651f950c4f8d04ece008b44b
2025-02-19 15:54:17 -08:00
Sergiu Deitsch af39e3b9ee Use standard CMake package configuration mechanism to report failures
Fixes #1123

Change-Id: Idd327c97391395fb23fc458e8d3dae0e5f3d1ed2
2025-02-19 15:53:42 -08:00
Sergiu Deitsch ded29e4243 Do not custom format TBB version
Recent TBB CMake package configurations do not define the
TBB_INTERFACE_VERSION variable. This causes the reported version to be
incomplete, i.e., the version looks as "(2022.0 / )". Use the CMake
specified package variable to report the identified version instead.

Change-Id: Ic7851c821217e20fd6673de5442808ea3d302f4a
2025-02-19 15:53:01 -08:00
Sergiu Deitsch 7d196b4e6a Emit deprecation warning on unscoped import target usage
CMake will print the following warning:

CMake Warning (dev) at CMakeLists.txt:n (target_link_libraries):
  The library that is being linked to, ceres, is marked as being deprecated
  by the owner.  The message provided by the developer is:

  The unscoped import target `ceres' is deprecated and will be removed in a
  future Ceres Solver release.  Please use the Ceres::ceres import target
  instead.

This warning is for project developers.  Use -Wno-dev to suppress it.

Change-Id: I5abc875b1f61e1f47523375d1579a188047c45d4
2025-02-19 15:52:25 -08: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 bcca8fbd4f Use ubuntu-24.04 Github runner in Android Github workflow
The ubuntu-20.04 actions runner image is deprecated will be fully
unsupported by 2025-04-01 (see https://github.com/actions/runner-images/issues/11101).

Change-Id: Ib6e25b5eef020aa5f3f183638725f7702903954a
2025-02-17 17:09:44 -08:00
Sergiu Deitsch cd8c1074b2 Avoid GNU linker LTO warnings in Github workflows
Stop linker emitting warnings such as

  lto-wrapper: warning: using serial compilation of n LTRANS jobs

Change-Id: Ic933ef7b45955eabfa5b06e88cd195077ff9fc86
2025-02-17 17:09:13 -08:00
Sergiu Deitsch 5121022789 Update NDK in Android Github workflow to latest LTS
Change-Id: I278fc0faaac764277d6985f0de23e602f1cde766
2025-02-17 17:08:32 -08:00
Sergiu Deitsch 539dffbec3 Use high-speed linker in Linux Github workflow
Using mold instead of GNU ld reduces the total build time by roughly
5-15 min. (depending on the load).

Change-Id: I66feab4e54c248cf92cc379d0085a93bdfdfef69
2025-02-17 17:08:02 -08:00
Sergiu Deitsch f0720aeb84 Raise minimum required Eigen version to 3.3.4
Ubuntu 22.04 ships with Eigen 3.4.0. The MinGW workaround for -O3
related crashes has been available in Eigen since at least version
3.2.0, see https://gitlab.com/libeigen/eigen/-/commit/cc03c9d68354ea3fed03481de045c185ddc1fc49.

Change-Id: Iebfd6ed1fa55a6b0f5bd57bd920188e7b486d8cb
2025-02-17 17:07:27 -08:00
Sergiu Deitsch 2d2b7b57c7 Ensure DynamicCostFunctionToFunctor to be exported
Fixes #1022

Change-Id: I090790ac4a1f32e6cb318bc32273d63898659dc3
2025-02-17 23:59:36 +01:00
Sergiu Deitsch 1b27b6610c Specify docs requirements
Use `pip install -r docs/requirements.txt` (e.g., in a virtual environment) to install Python dependencies required for building the documentation.

Change-Id: Ied9bd505bd6fc92f8c04f526ebd3ccacec306371
2025-02-17 07:44:47 -08:00