Commit Graph

14 Commits

Author SHA1 Message Date
Sameer Agarwal c8493fc366 Convert internal enums to be class enums.
Change-Id: Ide89c7115c3b12c0f2452a2969dc5523b3a7970f
2022-05-16 12:47:15 -07:00
Sameer Agarwal caf614a6c1 Modernize code using c++17 constructs
Mostly done using

find . \( -name '*.cc' -o -name '*.h' \) -a -type f -exec clang-tidy -p \
cmake-build -checks='-*,google-*,modernize-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type' {} -fix \;

Change-Id: Ifccbcabe7a1d9a32a09d28ac4f3f8466696c1a50
2022-04-22 06:11:18 -07:00
Sameer Agarwal 4705159858 Add missing includes for config.h
covariance.h was using SUITE_SPARSE even when SUITESPARSE
was disabled because it did not have config.h included in it
so it did not see that CERES_NO_SUITESPARSE was defined.

Add more config.h includes to files that are using these
configuration macros.

Change-Id: I6b1d2c2bd9e559de40a6332cd6be85ad4da3377b
2022-03-12 15:55:19 -08:00
Sergiu Deitsch c8658c8992 Modernize more
Apply clang-tidy Google and modernize fixes without trailing return type
using:

$ clang-tidy -p <build-dir> \
  -checks='-*,google-*,modernize-*,-modernize-use-trailing-return-type' {} -fix

Change-Id: I7450cc58ea9abf928f73a467e87876083217fa26
2022-02-26 22:16:56 +00:00
Sameer Agarwal ae65219e04 ClangTidy cleanups
1. NULL -> nullptr
2. foo.reset(new Bar) -> = foo = std::make_unique<Bar>()
3. Missing std library includes & prefixes

Change-Id: I260b261b484554be681ee5a7398126fdb3b3a789
2022-02-09 10:06:49 -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
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
Nikolaus Demmel 7b8f675bfd fix formatting for (non-generated) internal source files
- Change formatting standard to Cpp11. Main difference is not having
  the space between two closing >> for nested templates. We don't
  choose c++14, because older versions of clang-format (version 9
  and earlier) don't know this value yet, and it doesn't make a
  difference in the formatting.
- Apply clang-format to all (non generated) internal source files.
- Manually fix some code sections (clang-format on/off) and c-strings
- Exclude some embedded external files with very different formatting
  (gtest/gmock)
- Add script to format all source files

Change-Id: Ic6cea41575ad6e37c9e136dbce176b0d505dc44d
2020-09-21 02:52:07 +02:00
Sergey Sharybin 54ba6c27b5 Fix missing declaration warnings in Ceres code
This commit includes the following:

- Changes to CMake to make it safer to see which compiler flags are supported,
  so this way we do not need to worry about version checks in CMake.

- Unix platforms (which includes both Linux and Apple as far as i can tell)
  will now enable -Wmissing-declarations warning for the whole Ceres.

- Changes in all sources to solve missing declaration warning. In most cases
  it was either matter of using static qualifier or moving functions to an
  anonymous namespace.

  In one case the function got removed, since it seems to be unused.

  Additionally, in slam examples there was a non-inlined function implementation
  in a header, which is a direct way to cause linking errors if other .cc file
  will include that helper header.

- All third party sources (which is currently only gmock) has this extra
  paranoid warning disabled.

This warning is important in the following cases:

- Detect helper functions which are not needed anymore.
- Avoid unnoticed pollution of namespace.
- Avoid bad level calls.
- Avoid missing updates in header files after changes in implementation file.
- Helps integrating Ceres into software where paranoid warnings are important.

Change-Id: I9b1044aced3910d8c6b2356cfe2bf57f3c8c58db
2019-04-23 12:16:28 +02:00
Sameer Agarwal 6e527392da Update googletest/googlemock to db9b85e2.
Also update all callsites to use INSTANTIATE_TEST_SUITE_P instead
of INSTANTIATE_TEST_CASE_P which has been deprecated.

Also some minor clang-format changes.

Change-Id: If9d0a77931536ac0765d8435068d00e4471f59d0
2019-03-02 22:42:20 -08:00
Keir Mierle 7c4e8a454e Replace scoped_ptr with C++11's unique_ptr
Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b
2018-04-02 14:47:47 -07:00
Mike Vitus f408f89e8b Adds a Ceres Context structure.
A Ceres Context holds common global state that can be re-used within
Ceres.  The Context current contains a thread pool if compiling with
C++11 threading support.  Threads are expensive to create and destroy so
it is good to maintain across multiple Ceres solves.

Tested by compiling with and without TBB support and ran unit tests. Ran
bazel as well.

Change-Id: I82f598dfae642aa0e81a6039dc174608a5e8dbfb
2018-02-26 10:37:53 -08:00
Sameer Agarwal 15dc18a532 Change how ifdefs are used in dense_linear_solver_test.
It appears that interspersing ifdefs with macros causes problems
with Visual Studio. This patch changes the way we condition
the tests for dense linear solvers based on whether LAPACK is
available or not.

Change-Id: I306247496265c3551edad6bc8fcec9d4cf09e68d
2017-06-12 21:30:27 -07:00
Sameer Agarwal efa091122d Refactor unsymmetric_linear_solver_test
1. Break up unsymmetric_linear_solver_test into
   a. dense_linear_solver_test which covers DENSE_QR and
      DENSE_NORMAL_CHOLESKY.
   b. sparse_normal_cholesky_solver_test which covers
      SPARSE_NORMAL_CHOLESKY.

2. dense_linear_solver_test has been completely re-written. It now
   uses value parameterized tests for better logging. The number of
   test problems as been increased to 2. Last but not the least
   the actual test of correctness is not based on a golden solution
   computed using another linear solver. We now compute the residual
   and ensure that it is small.

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

Change-Id: I9546a43e8ae85c31b2096a99405e47da326755ee
2017-06-08 08:18:37 -04:00