Commit Graph

1055 Commits

Author SHA1 Message Date
Sergiu Deitsch a35bd1bf90 Use = default for trivial special members
Applied changes correspond to clang-tidy fixes
stemming from the modernize-use-equals-default check.

Change-Id: I254b0908a76d464131564b637cd0e42a6b03fb5a
2022-02-09 18:38:52 +01:00
Sameer Agarwal db67e621e4 Fix dense_cholesky_test.cc comma handling.
Change-Id: I61e73a99b089ac083d9b5f0c784aa1a3c5ee7a02
2022-02-08 17:13:05 -08:00
Sergiu Deitsch 484d3414e4 Replace virtual keyword by override
virtual can be ambiguous. Applied changes correspond to clang-tidy fixes
stemming from the modernize-use-override check.

Change-Id: I973afd4680a5df587419777504aeb94467196b89
2022-02-09 00:34:05 +01:00
Sameer Agarwal 2092a720ec Fix some nits.
Change-Id: I1af74d6ae8c6c368642989f1b1e857999264a454
2022-02-08 13:40:39 -08:00
Joydeep Biswas 36d6d86908 Add support for dense CUDA solvers #1
1. Add CUDADenseCholesky64Bit, CUDADenseCholesky32Bit, & tests.
   CUDADenseCholesky32Bit uses the legacy versions of potrf/potrs
   in cuSolverDN, while CUDADenseCholesky64Bit uses the new 64-bit
   versions available since Cuda 11.1. The legacy versions are
   provided since some platforms such as the Nvidia Jetsons only
   support Cuda 10.2.
2. Expose CUDA as a new option under DenseLinearAlgebraLibraryType.
   The relevant option to string and string to option helper functions
   are modified accordingly.
3. Add cuda as a dense_linear_algebra_library option in bundle_adjuster
   to demonstrate the use of the new CUDA option.

Change-Id: I23615e1d301df5185ed646b3e33ee802508dae86
2022-02-07 19:26:29 -06:00
Johannes Beck af5e48c71f Add SphereManifold.
This MR adds SphereManifold ported from
HomogeneousVectorParameterization. Additionally the minus operator
and jacobian evaluation was implemented.

The unit tests were almost completly reimplemented and uses the
test facilities provided for manifolds.

Change-Id: Iccf72a2333bc921ff24c4d831db35020c653ee86
2022-02-07 22:19:37 +01:00
Sergiu Deitsch 182cb01c57 Normalize Jet classification and comparison
Complete support for all floating-point classification functions
(fpclassify, signbit) and consistently apply all overloads recursively
to the scalar part of a Jet only. This is now inline with how comparison
operators work. Sanity checks of derivatives should be performed
explicitly on the dual part of a Jet due an ambiguity on reducing the
classification results of multiple values.

Provide an fdim overload (in addition to fmin and fmax) and support
quiet versions of comparison operators also applied recursively to the
scalar part of a Jet but without type promotion.

Additionally, deprecate Ceres legacy classification functions. New code
should use C++11 function names for consistency.

Finally, simplify expressions using introduced scalar classification and
comparison.

Change-Id: I397e37425760717b991eb7ae5da0892f20c5a365
2022-02-07 21:51:42 +01:00
Sameer Agarwal 9dbd289897 Loosen tolerances in dense_qr_test.cc
Change-Id: I97f093f5f374465ca40d2a1a774373a3718e3302
2022-02-07 12:20:35 -08:00
Sameer Agarwal cab853fd5f Add DenseQR Interface
1. Add EigenDenseQR & tests.
   This implementation now uses an in place decomposition,
   which means that we are not allocating, deallocating
   memory every call.
2. Add LAPACKDenseQR and tests.
   The LAPACK implementation instead of using dgels which is a
   routine which does the factorization and solve in one
   call, now uses dgeqrf for factorization and then
   dormqr and dtrtrs for solving. This allows us to
   have a factorize and solve interface like DenseCholesky.
   And opens the door to iterative refinement and mixed
   precision solves.
3. The refactor also allows us to simplify the interface to
   DenseSparseMatrix considerably. The internals of this
   class were complicated because we had the AppendDiagonal
   and RemoveDiagonal methods and we did not want to allocate
   deallocate memory every call. But since we pay the cost
   of the copy anyways, we can just hold that buffer
   in DenseQRSolver.
4. Delete lapack.cc/h
5. The net result is that everything seems to be a bit faster.
   For LAPACK we are not doing some of the scaling work that
   dgels was doing. For Eigen I think it maybe the inplace
   decomposition.

Benchmark                                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------------------
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/1/1                          -0.1154         -0.1159           692           612           691           611
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/2/1                          -0.1601         -0.1553           717           603           712           601
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/3/1                          -0.1673         -0.1575           733           610           724           610
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/6/2                          -0.1008         -0.1003           886           797           884           796
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/10/3                         -0.1489         -0.1514          1283          1092          1281          1087
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/12/4                         -0.1040         -0.1104          1556          1394          1553          1381
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/20/5                         -0.0007         -0.0097          1911          1910          1908          1890
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/40/5                         -0.1033         -0.1022          2981          2673          2957          2655
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/100/10                       -0.0147         +0.0015          9275          9138          9026          9040
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/200/10                       -0.1408         -0.1284         15093         12968         14778         12880
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/200/20                       -0.0310         -0.0355         38973         37765         38837         37460
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/1/1                         -0.1228         -0.1256           736           646           731           640
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/2/1                         -0.1401         -0.1396           740           636           735           633
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/3/1                         -0.1731         -0.1695           744           615           738           613
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/6/2                         -0.1399         -0.1408          1121           965          1113           956
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/10/3                        -0.1110         -0.1145          1571          1397          1560          1382
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/12/4                        -0.1411         -0.1417          2006          1722          1993          1710
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/20/5                        -0.1740         -0.1729          2741          2264          2724          2253
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/40/5                        -0.0966         -0.1123          3462          3128          3425          3040
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/100/10                      -0.0387         -0.0998         10365          9964         10339          9307
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/200/10                      -0.2044         -0.2049         16031         12754         15998         12720
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/200/20                      -0.2391         -0.2386         35777         27223         35716         27193

Change-Id: I782f0d7664efe1435eebda92ddf47a0fe66c9c72
2022-02-07 11:54:01 -08:00
Alex Stewart 8ae054ad91 Fix missing declaration warning in autodiff_manifold_test
Change-Id: I33326faaf3f204db5e9e255d87c82d83ec4b710f
2022-02-07 14:42:49 +00:00
Sameer Agarwal 408af7b1a8 Move the constructor and destructor for SchurComplementSolver
Change-Id: I277778d039b6acfe03e0c46f91bd71673f215345
2022-02-07 06:39:47 -08:00
Sameer Agarwal d51672d1cc Move the constructor and destructor for DenseSchurComplementSolver
Change-Id: I8d852c3e6af28d6d70742f0d1607154d47bec9bd
2022-02-07 06:26:07 -08:00
Sameer Agarwal 177b2f99dc Use benchmark version 1.6 compatible syntax.
This is needed to make the dense_linear_solver_benchmark.cc
compile with the currently stable versions of the benchmark
library available on various linux distributions.

Change-Id: I1e391d5c2d16250d213bcfa3d50f9560aad9a363
2022-02-07 05:54:13 -08:00
Sameer Agarwal 9367ec9cc9 Add a benchmark for dense linear solvers.
Change-Id: I06c39d62f4e0981be8ef5476b5f13b2b2a1fe794
2022-02-02 10:13:46 -08:00
Sergiu Deitsch 7d6524daff Support fma Jet
Change-Id: I9b1ad49611e3e6f117190d56512ef2ec4bdbb1c1
2022-02-01 20:52:27 +01:00
Sameer Agarwal 5a99e42e19 ClangTidy fixes
Change-Id: I188d6332c16f4c91bf92309e1eb524863e0c13ed
2022-01-26 13:26:20 -08:00
Sameer Agarwal 475db73d0c Fix build breakage when LAPACK support is disabled.
Parts of dense_cholesky.h/cc need to be enabled/disabled using
CERES_NO_LAPACK.

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

Change-Id: Id555e16723e31580eaa81562dba8d745a9210b0a
2022-01-24 09:25:08 -08:00
Sameer Agarwal 095c9197fe Fix iterative_refiner_test.cc
Change-Id: I5f578ec1f7dc003c8da96ad410e95cacd2527076
2022-01-23 12:23:54 -08:00
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 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 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 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 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