Commit Graph

1276 Commits

Author SHA1 Message Date
Keir Mierle 1af2747421 Support disabling Schur specializations in Bazel build
Change-Id: If72bcd9f19ba4b44482b267e45fb2355b1a93ff0
2018-02-08 13:38:00 -08:00
Sameer Agarwal 2145c10539 Improve ExecutionSummary
1. Replace two maps by 1.
2. Update number of calls and the time for the call at the cost
   of a single map lookup.
3. Add Solver::Summary::num_linear_solves.

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

Change-Id: I71eb9be7fb363a8cb066591c4c1761f256c81677
2018-02-05 16:37:27 -08:00
Sameer Agarwal 0251359830 A bunch of minor changes.
1. Fix a typo in auto_diff_cost_function.h
2. Fix and update Solver::Summary::FullReport() text labels.
3. Add logging of the number of residual and jacobian evaluations
   to the full report. The GradientProblemSolver already does this.

Change-Id: I41059af5f0ebe0417accbbc30b0808a4b04b9edb
2018-02-05 15:51:08 -08:00
Sameer Agarwal 0ca99358cc Remove as typo from callbacks.h
Change-Id: I69fdae40adaed812454d7ff4d7e8909a5539e304
2018-02-02 15:01:03 -08:00
Mike Vitus c82dd50962 Removes two unimplemented class functions.
General clean up to the Ceres codebase to remove the functions
Evaluator::Evaluate and ProblemImpl::InternalEvaluate as they are unimplemented.

Change-Id: I77fcb2c5f43aeca69555e953d6472b6c4cd1b778
2018-01-31 20:21:05 +00:00
Sameer Agarwal 78d49f4682 Update EigenTypes to deal with 1 column matrices
Most matrices in Ceres are row-major. Eigen does now
allow statically sized row-major matrices with a single
column.

This CL changes the EigenTypes struct to change the definition
of typedefs to change to ColMajor if this is the case.

This will allow Schur specializations (2,1,6) for example.

Change-Id: I24e7b62d4e1cb5660541062336225bbc9c41c6bf
2018-01-31 04:57:54 -08:00
Sameer Agarwal 202dd9f3a1 Add GradientProblemSolver::Options::update_state_every_iteration
The non-linear least squares solver had the ability to update the
user's parameters every iteration. Now GradientProblemSolver can
do the same.

Also a few minor Sphinx markup related cleanup to the documentation
which were found in the process of updating Sphinx on my machine
and adding the docs for this feature.

This fixes https://github.com/ceres-solver/ceres-solver/issues/246

Change-Id: Ib6b90ac22be8bfb60b14f25ad52082ba371af164
2018-01-25 21:30:09 -08:00
Mike Vitus 30b862d126 Fixes the pose graph example documentation.
Change-Id: Ia20f1463c042785bdae32568de77750d41963c3c
2018-01-19 16:06:00 -08:00
Rodrigo Queiro c12aae5860 Fix macOS build by updating glog
This includes https://github.com/google/glog/pull/285.

Change-Id: I4844d24ae7fc3187d4f4983e34d3a8066422a9c9
2018-01-16 17:09:06 +01:00
Rodrigo Queiro c1075cd313 Create ceres_library() and use to provide :ceres
This doesn't add any configurability to ceres_library() yet, but it
does correctly determine the include path for use with -I, allowing
this to be used as a dependency from other workspaces.

Change-Id: I223b6e63c2ea82ab7f552337f78fffd54f20b0e0
2018-01-15 15:28:13 +01:00
Rodrigo Queiro ac22a97492 Run buildifier on BUILD/WORKSPACE
Change-Id: I80bf7025811128c0795bff3e3f5b61a355d848ba
2018-01-15 15:26:19 +01:00
Rodrigo Queiro 093223454c Add bazel output to .gitignore
Change-Id: Ic7a300381badaf9c5c795da7f82ed10e5a433c3b
2018-01-15 12:23:15 +01:00
Keir Mierle 3f826ef30e Switch Eigen Bazel to a separate file
Change-Id: I547037460e8ec1fa14438d655c10b261daa39d96
2018-01-12 14:09:02 -08:00
Keir Mierle 07f1405300 Add initial Bazel build, including tests.
This allows building and running the Ceres tests, without
needing any external dependencies; they are downloaded and
compiled automatically thanks to the magic of Bazel.

It also opens the door for other projects that use Ceres
easily thanks to Bazel's external dependency support.

Remaining work:
- Skylark macros to allow different Ceres configurations
- Checking to make sure external projects can use this
- Parallelizing bundle_adjustment_test execution

Sample output:

  INFO: Analysed target //:ceres (6 packages loaded).
  INFO: Found 1 target...
  Target //:ceres up-to-date:
    bazel-bin/libceres.a
    bazel-bin/libceres.so
  INFO: Elapsed time: 103.756s, Critical Path: 13.97s
  INFO: Build completed successfully, 131 total actions

Change-Id: I400d3ce43f35b7e7a770da346337e3ffdb500dc2
2018-01-12 21:36:14 +00:00
Rodrigo Queiro 237eb17bdd Consistently use quotes to include Eigen
This makes these files match the convention in the rest of the codebase.

Change-Id: I3a0634274e0e604c575dd3c78fa87f485770e7ff
2018-01-12 18:25:16 +00:00
Janick Martinez Esturo c2da96082b Fix Eigen >= 3.3 compilation if EIGEN_DONT_VECTORIZE set
Would result in compilation error

include/ceres/jet.h:296:59: error: requested alignment is not a positive power of 2
   alignas(kAlignment) Eigen::Matrix<T, N, 1, kAlignOrNot> v;

because CERES_JET_ALIGN_BYTES = EIGEN_MAX_ALIGN_BYTES = 0 in that case.

Change-Id: I247653d3b7555e80891d3fb78676acfa302a9e1d
2018-01-12 17:50:01 +01:00
Sameer Agarwal 579c9afc51 Add an optional dependency on the Google Benchmark library.
Also add a small benchmark for automatic differentiation.

Change-Id: I01c985495a973bc2a2fdc6c33fa1eb5ab788d7ef
2018-01-10 20:47:30 +00:00
Sameer Agarwal ef36667a2c Fix the documentation for CostFunction::Evaluate.
The documentation was overly complex and had mismatched
symbols leading to confusion.

Change-Id: I25709e61ff3f9b9775d8f14a9e63f61931256dac
2018-01-09 14:59:44 -08:00
Sameer Agarwal 29eef08be0 Fix a mathematical typo.
Thanks to Rafael Spring for pointing this out.

Change-Id: I37a403160898f1f2617a360ef8909696d6bdbf74
2018-01-08 15:42:54 -08:00
Alex Stewart eb5b0e861c Add TBB information to Ceres version string.
Change-Id: I8ec87ee57bcdcf54f105b4c368432d93ada2ea59
2017-12-11 11:11:07 +00:00
Alex Stewart 488d401ac3 Cleanup import of TBB in CMake.
- Update FindSuiteSparse to use FindTBB.cmake to find TBB.
- Fix logic handling of TBB=ON if TBB is not found to continue with
  build after disabling TBB rather than throwing a fatal error.
- Use TBB_LIBRARIES instead of TBB_tbb_LIBRARY as a Ceres dependency,
  the former also includes the TBB malloc library.
- Add warning message about GPL licensing if TBB version < 2017.
- Add ‘TBB’ & ‘Mulithreading’ component options to find_package(Ceres),
  where ‘Mulithreading’ is equivalent to ‘TBB’ || ‘OpenMP’.

Change-Id: Ifc7f1d01b050ba6e2097ad1913b178805df4769a
2017-12-11 10:15:32 +00:00
Alex Stewart aab0193c7b Move discussion of dependency licensing to Sphinx docs.
- Also enable EIGENSPARSE option by default as LGPL licensing
  implications are less severe that SuiteSparse’s GPL implications which
  is enabled by default.

Change-Id: Ic7e4fef5cef614d5ce719eeefcc35bf4b63b8dac
2017-12-08 01:24:48 +00:00
Sameer Agarwal 89e53b4ec3 Fix an erroneous namespace comment
Change-Id: Ie1b0b75e1638fbbe0309455e1b4e6229dbdd841c
2017-12-08 00:44:57 +00:00
Mike Vitus 852473b5f8 Changes TBB to use tbb::task_arena instead of tbb::task_scheduler_init.
Fixes the current implementation where the desired number of threads may
not be honored if another tbb::task_scheduler_init is instantiated. We
are using tbb::task_arena to solve this which is only available in newer
versions of TBB.

Also increases the performance by not creating/destroying the TBB setup
via tbb::task_scheduler_init on every iteration evaluation. This
increases the performance in single threaded mode using TBB by 10x.

By not specifically calling tbb::task_scheduler_init, this will either
respect any active tbb::task_scheduler_init instantiations or use the
default TBB settings which is hardware dependent. Ceres will honor the
user's requested number of threads through the task_arenas.

Tested via compiling with TBB enabled and ran the unit tests.

Change-Id: I5538407563449cdb5a0eaf8b8ccab62263912110
2017-12-07 15:00:50 -08:00
Alex Stewart e9009829b5 Fix use of unnamed type as template argument warnings on Clang.
- When compiling Ceres without C++11 but with glog, then the unnamed
  enum results in a compiler warning when
  google::GetReferenceableValue(.) is invoked with the unnamed enum as a
  template parameter (unnamed-type-template-args) which was not legal
  prior to C++11.

Change-Id: Iddbed05e2199865ab915f2c5817ce917bb0609b5
2017-12-01 10:12:54 +00:00
Keir Mierle cb497df619 Add link for CLA in docs; minor fixes
Also fixes a typo in cost_function.h

Change-Id: I45f08fd27fd2f8e5cb5b3f08e0d4f9a3e8822a15
2017-10-24 17:18:02 -07:00
Sameer Agarwal f6df80e8a0 Fix tiny_solver_test
Verify that the final cost is small enough instead of the norm
of the residual vector.

Change-Id: I9591d97d3e8f1c71067d99270967f1e593889843
2017-10-22 22:04:24 -07:00
Sameer Agarwal 030b41dd0e Improve compatibility with ceres::Solver
1. Default linear solver is Eigen::LDLT
2. Options::max_iterations -> Options::max_num_iterations
3. Options::error_threshold -> Options::cost_threshold
4. Options::relative_step_threshold -> Options::parameter_threshold
5. Options::initial_scale_factor -> Options::initial_trust_region_radius
6. The default values of the above parameters have been changed
   to match those in ceres::Solver::Options
7. Status::RUNNING has been removed
8. Update now returns a bool instead of a Status enum and
   the status handling has been included in the main loop.
9. Summary::gradient_norm has been changed to Summary::gradient_max_norm
   to match the convergence test
10. A member variable cost_ has been added which is computed by Update
11. The test for parameter_tolerance based convergence is made
    more robust near zero.
12. Use of double has been replaced by Scalar.
13. Minor clang-formatting

Change-Id: I3cb0e2fd0a0204476bb8718761dc740cdf5e42ce
2017-10-22 21:40:49 -07:00
Keir Mierle dc9bf012c4 Fix tiny solver build break
The solver code must rely on the vectors for
sizing, since not all cost functions will have
NumParameters() or NumResiduals().

Change-Id: Id254ce37507443910edb0064de7907d64558851e
2017-10-19 23:46:53 -07:00
Sameer Agarwal ba73ce120c Improve the convergence performance of TinySolver
1. Default constructor and initialization for Summary.
2. Add Jacobi scaling.
3. Add bounds on the lm diagonal
4. Use the diagonal of J'J as the regularizer instead of identity.
5. Update the computation of rho to match the change in regularization.

As a result of these changes, the performance of TinySolver is
now the same as ceres::Solver, solving 53 out of 54 problems.

Change-Id: Ie08c3389ac2e3964ffa04411734c06b65835358a
2017-10-19 13:52:31 -07:00
Sameer Agarwal 75570a599a Remove an extraneous blank
Change-Id: Id089741300b549b2afe6d591d78f5fe3fdda6c43
2017-10-19 20:24:26 +00:00
Keir Mierle b485002bb7 Replace template use of >>
Older compilers do not support >> to terminate
templates, only > >. Ceres supports old compilers.

Change-Id: I7e43dc9fdac06507b32dd0c9bf1a3bc2a544916b
2017-10-14 16:08:17 -07:00
Sameer Agarwal f87dfe9dde Refactor nist.cc to be compatible with TinySolver
Change-Id: Iec0455ff9fe327fe75dc63f5b80c2ecca2c48e55
2017-10-14 15:58:58 -07:00
Keir Mierle 40effe3b15 Tiny solver autodiff adapter
Change-Id: I29fe736d53b2be32a101ba128cf557726def9a00
2017-10-14 15:51:14 -07:00
Sameer Agarwal 8beedf5cf6 Add TinySolverCostFunctionAdapter
Change-Id: I1905044d09abe5c927cd7e2cda804cba516fd961
2017-10-14 15:12:01 -07:00
Sameer Agarwal cc0bd492bd A number of minor changes to TinySolver
1. Instead of Core/LU just include Eigen/Dense
2. Rename SolverParameters to Options and params to options.
3. Rename Results to Summary.
4. Summary::error_magnitude -> Summary::final_cost.
5. Add Summary::initial_cost.
6. Change definitions of Summary::initial_cost and Summary::final_cost
   to match those used by Ceres::Solver.

Change-Id: Id64b78398f47810ca25938a15423c514fc8c164d
2017-10-14 14:14:14 -07:00
Sameer Agarwal 4d88f50f6b Two changes to TinySolver
1. Change the ordering from NUM_PARAMETERS, NUM_RESIDUALS to
NUM_RESIDUALS, NUM_PARAMETERS in docs and in code.
2. TinySolver::solve -> TinySolver::Solve

Change-Id: I4dca87b971fd9168f1200b53c362669cffc82c1b
2017-10-11 16:09:40 -07:00
Keir Mierle 7928ca003f Initial commit of tiny solver
Tiny solver is targeted towards small dense least square
solves, where the overhead of calling normal Ceres is too
high. For example, when solving for inverse camera
distortion for every pixel location in a many-megapixel
image. Anecdotally, at one point in the past, tiny solver
was ~20x faster than Ceres for the problems it's intended
for. This is due to two key aspects:

  1. Memory is allocated up front: repeated solves incur no
     allocation overhead beyond a few scalars on the stack.
  2. The cost function is fully inlined into the solver
     loop, removing even the cost function call overhead.

Tiny solver originated many years ago as part of
libmv/Blender, where it is still used for distortion solving
today, but the time has come for it to migrate into Ceres.

This commit is just the initial import into Ceres.  Follow
up patches will add further cleanups, and add CostFunction
and Jet adapters to make it easier to call tiny solver
(though by using adapters, some performance advantages will
be lost).

Change-Id: I8079535cd41382b1e0ac0ca2fca141711c72b7f8
2017-10-10 14:32:19 -07:00
Thomas Gamper d727974f30 Report timings with microsecond resolution
In case one has a small problem to solve, where
completion is reached within a few milliseconds,
then four decimal places are not enough to accurately
represent the timings of all the separate sub-steps.
Thus, we extend the reported timings to include
six decimal places.

Change-Id: Iaf88a94a1b8896ea7370c75b1de2f05d8671206e
2017-09-27 13:39:20 +00:00
Sameer Agarwal 2a956099d4 Add missing Eigen traits to Jets
Add highest and lowest traits to the Jet implementation.

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

Change-Id: I7c68fa8e2baa7742880d3faa21f366352e48aacf
2017-09-27 03:57:49 +00:00
Thomas Gamper 28b1147a1d Use high-resolution timer on Windows
This fixes a Windows specific issue where the
problem-summary reports timings as zero, as long as
the time difference in question is smaller than one
second.

Change-Id: Ibd91874294423af6acda2575eae80f01aabed6d3
2017-09-26 13:10:54 +00:00
Keir Mierle 4bea6d7a2d Add a comment about default constructed reference counts=
Change-Id: Ia6b8a75144755d9bcf05c893bb97a1e207da6b0f
2017-09-25 13:09:41 -07:00
Sameer Agarwal 600262e8f8 Delete cost and loss functions when not in use.
Delete CostFunctions and LossFunctions when there are no more
ResidualBlocks referring to them. This is done by maintaining
a map with reference counts for CostFunctions and
LossFunctions.

The same maps are also used at the time of the destruction
of the ProblemImpl object itself. Previously vectors of these
objects were constructed, uniqed and the objects destroyed.

The update to the maps increases the cost of calling AddResidualBlock,
this has been mitigated, actually making AddResidualBlock faster, by
reusing a temporary vector rather than allocating one on the stack
every time.

Change-Id: I28b5287511713d28069ae428e2ff69224c0d03b4
2017-09-25 17:44:15 +00:00
Yury Prokazov 4ffec20a44 Add TBB threading support.
There are platforms where OpenMP is not available. This
patch adds support for Intel Threading Building Blocks (TBB)
as an alternative threading backend.

Change-Id: I94497d7cba0c3cfaccfc992169236f17fe948ae9
2017-09-25 12:43:14 +02:00
Alex Stewart 83f5d74ee6 Fix assert_ndk_version for >= r11.
- RELEASE.TXT was removed in r11 in favour of source.properties, which
  encodes the version number purely numerically, e.g: r15c -> 15.2.xxxx.
- Now we check for either RELEASE.TXT or source.properties and in the
  case of the latter convert the numeric minor version number into the
  standard alphabetic equivalent.

Change-Id: I8596e32f8d425650d9343bfadc3a8b4f62935df0
2017-08-31 09:14:54 +00:00
Alex Stewart 30885841a5 Add docs explaining how to build Ceres with OpenMP on OS X.
Change-Id: If45c12876dc58a042bbdf017de77003a161dc16c
2017-08-31 10:02:11 +01:00
Alex Stewart cc73c77d50 Update LAPACK option to refer to direct use by Ceres only.
- Previously the LAPACK option meant would Ceres link against LAPACK,
  whether directly or indirectly via SuiteSparse (if SUITESPARSE=ON),
  as such if LAPACK=OFF, the use of SuiteSparse was disabled, even if
  it was found.
- To support the use-case of using a limited LAPACK implementation that
  satisfies SuiteSparse’s requirements, but potentially not Ceres’ we
  now adopt the more conventional terminology whereby the LAPACK option
  refers only to whether Ceres itself will directly call LAPACK
  routines, not whether it or any of its dependencies will.
- This means that the LAPACK and SUITESPARSE options are now
  independent.
- Also unnecessary calls to find_package(BLAS), as find_package(LAPACK)
  already searches for BLAS, and appends the resulting libraries to
  LAPACK_LIBRARIES if they are found.

Change-Id: I9cf5fa5e4cb621812f6f0526db8d16a7a39c9c8f
2017-08-13 18:27:21 +00:00
Alex Stewart d8f40912f0 Hide optional SuiteSparse vars in CMake GUI by default.
Change-Id: I7d7a82d1cbb8a6689bb383e4de2b9415ab7a3a81
2017-08-13 19:16:46 +01:00
Alex Stewart ffe7cc3eca Always hide TBB_LIBRARY in CMake GUI by default.
Change-Id: I4e5c0985144b48c977ebab539634f66741922502
2017-08-13 18:59:31 +01:00
Alex Stewart 0aad590005 Fix typo in definition of f3 in powell example (x4 -> x3).
- This was reported as issue #307 by versatran01.

Change-Id: I2c8bbd3466d46b550f81fdadb8b1f4e23b858162
2017-08-13 14:59:41 +01:00