Commit Graph

1740 Commits

Author SHA1 Message Date
Sameer Agarwal 6d06e9b98f Add DenseCholesky
Like SparseCholesky, the DenseCholesky interface abstracts
away the solution of dense linear systems using Cholesky factorization.
This allows the client code to not worry about the type of dense
linear algebra library being used.

DenseNormalCholeskySolver and DenseSchurComplementSolver code
is considerably simpler as a result.

Change-Id: Ie15f09ee376d5f9a64609e6a55ad83e99c76352a
2022-01-23 09:00:36 -08:00
Sameer Agarwal 77c0c4d09c Migrate examples to use Manifolds
Also change NULL to nullptr.

Change-Id: I80a2328185d7891f61e07e64d5c1b59e74588ac7
2022-01-22 11:18:19 -08:00
Sameer Agarwal 19eef54fc2 Rename Quaternion to QuaternionManifold.
Also rename EigenQuaternion to EigenQuaternionManiold.

Change-Id: I7095fa61cfabf97a328b02fb027f5a2a8dd499ae
2022-01-22 11:07:52 -08:00
Sameer Agarwal ca6d841c25 Add AutoDiffManifold
AutoDiffManifold allows the user to define a templated
functor that implements the Plus and Minus operations
on the Manifold and will compute the Jacobians needed
to define the Manifold object using automatic differentiation.

Change-Id: Ibd073c25847389308ca1ab66e6f5fe78aae77205
2022-01-22 10:54:01 -08:00
Sameer Agarwal 97d7e07372 Move the manifold testing matchers to manifold_test_utils.h
Change-Id: Ie295fdf32e056f30b5b533df11755e2674d4dad6
2022-01-19 14:31:00 -08:00
Sameer Agarwal 16436b34bc Fix some more clang-tidy suggestions.
Change-Id: Ic4bb725df1e0b49f2e14c889136433841d98ae22
2022-01-19 10:19:16 -08:00
Sameer Agarwal dcdefc2164 Fix a bunch of clang-tidy suggestions.
Change-Id: Ic7ce800ba33569c141d45ab6d27657987f303b93
2022-01-19 09:47:23 -08:00
Sameer Agarwal d8a1b69abf Remove an unused variable from gradient_checker.cc
Change-Id: Ib2bfb3d1efacf197e14fa04ac18370d35060b322
2022-01-19 07:05:44 -08:00
Sameer Agarwal 611b46b54b Remove the use of CHECK_NOTNULL.
Change-Id: I6aa7dd5b44bd42807118b4b0b565d6fa8b227371
2022-01-19 07:00:32 -08:00
Sameer Agarwal 125a0e9be5 LocalParameterization -> Manifold #1
Manifolds are now part of the public API and co-exist
with LocalParameterizations.

1. Add Manifolds to the Problem API.
   a. AddParameterBlock(double*, int, Manifold*)
   b. SetParameterization(double*, Manifold*)
   b. GetManifold(const double*)
   c. HasManifold(const double*)

2. Internally Ceres now only uses Manifolds. When the user uses
   a LocalParameterization, it is wrapped in a ManifoldAdapter.

3. To preserve the API semantics while keeping the internals clean
   we need a new map in ProblemImpl which stores the association
   between parameter blocks and local parameterizations. This
   is temporary, it will go away once this transition is complete.

4. There are NO algorithmic changes, as in we are not using
   any of the expanded interface of the Manifold objects yet.
   That will come later.

5. All tests that use LocalParameterization have been duplicated
   to use Manifolds, and when this transition is complete the
   LocalParameterization based tests will be deleted.

6. Public documentation for the API has been updated. Deprecation
   notices to the documentation as well as C++ annotations will come
   later.

7. Similar changes have been made to GradientProblem.

Change-Id: I8e03c8ced6e141876ef3eca5740c113afa788f0c
2022-01-18 15:59:45 -08:00
Sameer Agarwal 00bfbae11f Add missing algorithm header to manifold.cc
Change-Id: I6211c65658ee124fc6a6587923e3ceadca76e24a
2022-01-12 20:44:45 -08:00
Sameer Agarwal 1d5aff059c Refactor jet_tests.cc
1. Break tests for one function into its own TEST instance.
2. Use a gmock matcher which gives better logging, previously
   we were using a function which in turn used another function
   in test_utils. It made tracking down the failing test very
   hard.
3. Disable a hypot3 underflow and overflow test when using
   libc++ as the three argument in libc++ is borked.
4. The use of the matcher has made a number of comments redundant
   so I have removed them.

This is the first step in cleaning up these tests and then expanding
them.

Change-Id: Ib0c827f44432e2496e50b8cda3e06c26bdf50f08
2022-01-12 10:13:41 -08:00
Sameer Agarwal fbd693091d Fix two unused variable warnings.
Change-Id: Iaabb47ea45aa09d92b911df79b4f2fd7ee60ae15
2022-01-12 06:03:23 -08:00
Sameer Agarwal c0cb42e5f9 Add Problem::HasParameterization
This will help the transition from LocalParameterization to Manifolds,
since most uses of Problem::GetParameterization is to just check
whether a parameter block has a local parameterization associated
with it or not.

Change-Id: Ib3539f377eaed853d7542c9844ec1487aa0fb4d6
2022-01-11 21:05:56 -08:00
Sameer Agarwal 7e2f9d9d41 Add EigenQuaternion manifold and tests for it.
Change-Id: I579a45a2921424a07d03b3b4d9cfcbc0ab529f9b
2022-01-11 14:40:21 -08:00
Sameer Agarwal b81a8bbb7a Add the Quaternion manifold and tests.
Change-Id: I0a396a5834168c1526d6f2b8c99a1ad3348ad657
2022-01-07 04:59:02 -08:00
Sameer Agarwal 4a01dcb887 Add more invariants and documentation to manifold_test.cc
Change-Id: I62e040679cc4fd4c5a7486885ebb4ad1a08b7b45
2022-01-06 09:50:30 -08:00
Sameer Agarwal bdd80fcce8 Improve Manifold testing
1. Increase number of trials.
2. Make all the matchers per point.
3. Add matchers for delta = 0.
4. Add a macro which invokes all the matchers, reducing boilerplate

Change-Id: Ia1bf110323c5877a1b92aef34c12c39008256f05
2022-01-05 13:06:30 -08:00
Sameer Agarwal ce1537030b Fixed missing headers in manifold.h
https://github.com/ceres-solver/ceres-solver/issues/739

Change-Id: Ia4079b025c53f75abb7145a4b8f5eacaddf8fc67
2021-12-30 12:16:43 -08:00
Sameer Agarwal 23b204d7e6 LocalParameterization -> Manifold #1
This is the first in a series of changes that will eventually
replace the LocalParameterization interface with the richer
Manifold interface.

1. Add the Manifold interface.
2. Add implementations and test for:
   a. EuclideanManifold (formerly the IdentityParameterization)
   b. SubsetManifold (formerly the SubsetParameterization)
   c. ProductManifold (formerly the ProductParameterization)

The testing has been completely re-done, where instead of adhoc
testing, we now define a number of matchers which explicitly
enforce the invariants demanded by the Manifold interface.

Change-Id: I3f296d0964388d52b027c99dc86b7730d24d55fa
2021-12-29 17:27:28 -08:00
Alex Stewart c2fab6502e Fix docs of supported sparse backends for mixed_precision_solves option
- Also adds documentation of mixed precision solves to Sphinx docs.
- Fix reference to Sphinx theme used (RTD not better).
- Fix NOTE syntax in use_explicit_schur_complement Sphinx docs.

Change-Id: I7bdac0f07eb737f49b05e3fcaa3eebd087355d2d
2021-12-15 20:58:47 +00:00
Alex Stewart 8cb441c49a Fix missing declaration warnings in GCC
- Follow up to commit https://github.com/ceres-solver/ceres-solver/commit/54ba6c27b504f43b59b0d91da0165995c66d9a3d
  which enabled -Wmissing-declarations and fixed all previous
  infractions.

Change-Id: Ia10b49b4c9bc12c0f7bec2b8c0706f38be18f1dc
2021-12-15 18:20:14 +00:00
Sameer Agarwal d2b7f337ce Remove split.cc from the bazel sources.
Change-Id: I15eb78eaccabb3c00610b3d8bfcb22a6156105df
2021-12-14 11:58:58 -08:00
Sameer Agarwal 206061a6ba Use standard c++ types in jet_test.cc
Change-Id: I8fb91bf04626eba1ceda676dc6564b9798d6a4a9
2021-11-30 11:26:18 -08:00
Sergiu Deitsch 1f374a9fe5 Support promotion in comparison between Jet and scalars
Previously, Jet did not allow comparison between its value and a scalar
of another type. Specifically, the comparison was limited to scalars of
the same type effectively disabling standard promotion rules. Instead,
users would be required either to cast values to target Jet arithmetic
type or explicitly construct a Jet instance that can be eventually used
for comparison purposes.

However, such a behavior is not intuitive and causes problems with types
that rely on standard promotion rules (e.g., std::complex in some
implementations).

This changeset extends the comparison operators by enabling logical
comparisons between a Jet and values compatible to the underlying scalar
type (e.g., int). To be as generic as possible, the types allowed to be
passed to comparison operators are constrained using SFINAE. This in
turn allows a recursive expansion of jets and therefore the comparison
of a nested jets with a scalar.

The changes alleviate problems described in #414 and also allow the use
of special functions from Boost.Math, e.g., for computing the reciprocal
using boost::math::pow<-1>(...).

Change-Id: I3625791e6c8c2c0bfbffbbdb09e179a32e57f306
2021-11-29 21:33:28 +01:00
Sergiu Deitsch 06e68dbc5a Avoid midpoint overflow in the differential
Change-Id: I8c75a819db33f4105e62942cddc83b2653318169
2021-11-28 01:04:27 +01:00
Sergiu Deitsch 276d24c73a Fix C++20 compilation
Several std::allocator<> members were deprecated in C++17 and
subsequently removed in C++20. Drop deprecated members altogether since
these are unused anyway.

Change-Id: Ic26471a4b1cb3ccc1fdf3231400c81827b0ff712
2021-11-27 02:05:39 +01:00
Sergiu Deitsch b1391e0625 Support midpoint Jet
Provide autodiff support for C++20 std::midpoint if the standard is
active.

Change-Id: I1308a1e514bef4c74f08f655cbf803fa43503ce5
2021-11-25 21:14:32 +01:00
Sergiu Deitsch 8426526dff Support lerp Jet
Provide autodiff support for C++20 std::lerp if the standard is active.

Change-Id: I04ef6f17c707dd5f8ac426d9127b221e17aa08d6
2021-11-25 21:02:25 +01:00
Sergiu Deitsch 57c2796890 support 3-argument hypot jet
C++17 provides a three argument hypot(x, y, z) which can now be used
for jets if the standard is active.

Change-Id: Ide62e101f780fe738bb2d4f826b10daf94c585b3
2021-11-22 17:26:01 +01:00
Sameer Agarwal 123fba61cf Eigen::MappedSparseMatrix -> Eigen::Map<Eigen::SparseMatrix>
Eigen::MappedSparseMatrix has been deprecated and removed from
Eigen at HEAD.

Thanks to rmlarsen@ for fixing this.

Change-Id: I34f3b0dda2bb91ee8cc65a20e53a3d7de6929221
2021-11-21 10:33:23 -08:00
Sergiu Deitsch 3f950c66d8 reworked copysign tests
Zero sign propagation is not always guaranteed. Replace signbit checks
by checks for -nan and +nan sign.

Change-Id: If2ba367e4116d4e6a008a83cf2bc6a8851b27af7
2021-11-19 11:17:51 +01:00
Sergiu Deitsch 48cb54d1b2 fix fmin and fmax NaN handling
fmin and fmax do not handle NaNs correctly. Also, the comparison
operator for floating-point numbers may raise FE_INVALID if one of the
arguments is NaN. Both functions, however, are not subject to any of the
error conditions specified by the error handling for related
floating-point operators and functions.

Change-Id: Ic6bb65f18568066dba3c739a2df06f5fc3131a80
2021-11-19 03:13:56 +00:00
Sergiu Deitsch 552a4e5170 support log10 jet
Change-Id: I1425f7c8fc891cf941a162b8e5b427b5ab4e71da
2021-11-18 23:11:31 +01:00
Sergiu Deitsch 4e49c54223 reuse expm1 result for differential
We can reuse the expm1 result to compute the differential and eliminate
the extra exp call.

Change-Id: Ibd4f0564ab6da99fc23fbf6462408cfc3408fda1
2021-11-18 19:21:40 +01:00
Alex Stewart 8d3e64dd5e Use modern-style Eigen3 CMake variables
Change-Id: I4c14aa54552b3f718dff90eb397cb030aeb6ecd4
2021-11-16 19:51:06 +00:00
Sergiu Deitsch 2fba61434b support log1p and expm1 jet
Currently, it is not possible to accurately evaluate the derivative of
d/dx log(1 + x) under all circumstances and significant deviations from
the actual derivative d/dx log1p(x) can occur. This changeset introduces
the necessary Jet overload and its inverse, expm1.

Change-Id: Ifcf88f6d684f61ba86bbe49f0d551b703f34ad0d
2021-11-16 00:14:39 +01:00
Sergiu Deitsch a668cabbcf support norm jet
norm allows to compute the squared magnitude both of complex and real
numbers. While Jet does not support decaying of a std::complex to a
scalar performed by norm, the function is still useful when applied to
scalars alone for computing the square.

Change-Id: I27a3513f53f37fb3960411362e80d170d1ae6f74
2021-11-15 22:29:44 +00:00
Sergiu Deitsch a3a4b6d77f support copysign jet
libc++ (default on macOS) uses the copysign function for std::complex
multiplication which causes compilation errors such as these if
std::complex is combined with jets:

/Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:607:19: error: no matching function for call to 'copysign'
            __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a);
                  ^~~~~~~~
foo.hpp:218:39: note: in instantiation of function template specialization 'std::__1::operator*<ceres::Jet<double, 3> >' requested here
    std::complex<Scalar> result = lhs * rhs;

copysign is also useful in other situations where the sign is required
allowing it to compute without branching.

Change-Id: I84b2d23374f1bf3bae32833016bb686d97d74054
2021-11-15 23:27:33 +01:00
Sergiu Deitsch b75dac1694 fix abs jet test comment
The comment suggests a non-existing (incorrect) test. Update the comment
and extend the test.

Change-Id: I362f0b5a2e81d286b672476bdb4394ed20263eb1
2021-11-15 18:34:34 +00:00
Sergiu Deitsch 034bf566f0 use copysign for abs jet
abs() implementation does not correctly handle the sign of the
infinitesimal part when the value is a NaN. Define the function in terms
of copysign which is the only portable way of manipulating the sign of
a NaN value.

Change-Id: I2f13fb1db62d35ca8b09e6bff1c05a736cb91513
2021-11-14 17:07:14 +01:00
Dmitriy Korchemkin 31008453fe Add example for BiCubicInterpolator
Add example of BiCubicInterpolator usage, for both analytic and
automatic differentiation

Change-Id: I2e52bec5e0721a21a789e714a126ea24b1c0ce8b
2021-10-06 20:26:18 +03:00
Sameer Agarwal 7ef4a12218 Add a section on implicit and inverse function theorems
Change-Id: I0e6c7d2850a33d03aa629579f049ad44a7618621
2021-10-01 12:05:06 -07:00
Sameer Agarwal 686428f5cd Move the further reading section to bibliography
Change-Id: I673e74587486cdf5f91a146605dafa8fc2df6ee6
2021-09-24 05:44:45 -07:00
Sameer Agarwal e47d87fdd6 Add a note about Trigg's correction
Add a pointer about how the theory and practice of Trigg's correction
for loss function differs when the second derivative of the loss
function becomes positive.

https://github.com/ceres-solver/ceres-solver/issues/573

Change-Id: Ic22ce91cc230f7ed7fa7b70a1cc2050919039828
2021-09-24 05:02:40 -07:00
Sameer Agarwal d2852518d6 Fix the docs for Problem::RemoveResidualBlock & Problem::RemoveParameterBlock
The documentation was out of date about how memory management is
done in Problem.

https://github.com/ceres-solver/ceres-solver/issues/699

Change-Id: Ie55027796bc372cdcbaaca2bf2c93643c303a8e5
2021-09-23 09:32:11 -07:00
Sameer Agarwal 06e02a1735 Delete unused files split.h/cc
Change-Id: I67a4542389a0c1162875975efd23cdfbe797c6bc
2021-09-18 06:10:26 -07:00
Sameer Agarwal ac7268da52 Fix an 80cols issue in covariance_impl.cc
Change-Id: I2422282919e7100ac852be2176cd754941a8b472
2021-09-15 06:22:29 -07:00
Sameer Agarwal 17dccef91b Add NumericDiffFirstOrderFunction
This has been a long requested feature so that users can minimize
functions using numeric differentiation.

As part of this, I have also redone rosenbrock.cc, which now has three
variants.

rosenbrock.cc now uses automatic differentiation.
rosenbrock_numeric_diff.cc uses numeric differentiation.
rosenbrock_analytic_diff.cc uses analytic derivatives.

This is analogus to how the helloworld example code is structured.

The tutorial for GradientProblemSolver has also been updated to reflect
this.

https://github.com/ceres-solver/ceres-solver/issues/691

Change-Id: Ib0fb9e35127fe4c8299d4793bea3558722c70dd7
2021-09-15 06:21:02 -07:00
Sameer Agarwal 03d64141ae Fix a incorrect check in reorder_program.cc
Thanks to William Gandler for pointing this out.

Change-Id: I7a4e0eebd2e557f7572df7455d7fa77527c087b6
2021-09-14 17:36:07 -07:00