Commit Graph

445 Commits

Author SHA1 Message Date
Sameer Agarwal 97873ea658 Add some missing includes for glog/logging.h
Change-Id: Ia10c2809eb360bd30efddc0cd941b0de06ac09d6
2021-01-21 13:49:38 -08:00
Sameer Agarwal e84cf10e13 Fix an errant double in TinySolver.
Thanks to Bogdan Burlacu for pointing this out.

Change-Id: I7a59a589c1bf919954e4905df3376e9aeb1a12d7
2020-12-14 08:55:05 -08:00
Mykyta Kozlov 66b4c33e81 updated unit quaternion rotation
Change-Id: I3e5a2ca8e19c1d66437ac16d615867e2a12f8e60
2020-11-18 17:00:13 +00:00
Sameer Agarwal bb127272f9 Fix typos.
Contributed by Ishamis@, IanBoyanZhang@, gkrobner@ & mithunjacob@.

Change-Id: Iab3c19a07a6f3db2486e3557dcb55bfe5de2aee5
2020-10-19 09:32:47 -07:00
Taylor Braun-Jones 3f6d273676 Unify symbol visibility configuration for all compilers
This makes it possible to build unit tests with shared libraries on MSVC.

Change-Id: I1db66a80b2c78c4f3d354e35235244d17bac9809
2020-10-15 16:56:07 -04:00
Nikolaus Demmel 600e8c529e fix minor typos
all timing values in the summary are initialized to -1, so the one
+1 is likely an oversight.

Change-Id: Ie355f3b7da08a56d49d19ca9a5bc48fe5581dee3
2020-10-12 23:01:02 +02:00
Alex Stewart 1fd0be916d Fix default initialisation of IterationCallback::cost
Change-Id: I9f529093fc09424c90dbff8e9648b90b16990623
2020-09-28 18:54:33 +01:00
Sameer Agarwal 921368ce31 Fix a number of typos in covariance.h
Also some minor cleanups in covariance_impl.h

Thanks to Lorenzo Lamia for pointing these out.

Change-Id: Icb4012a367fdd1f249bc1e7019e0114c868e45b6
2020-09-09 09:39:42 -07:00
Nikolaus Demmel 9d762d74f0 fix formatting for public header files
- ensure all public headers files adhere to clang-format
- preserve one-per-line for enums by adding trailing comma
- preserve include order for en/disable_warning.h

Change-Id: I78dbd0527a294ab2ec5f074fb426e48b20c393e6
2020-09-07 23:14:51 +02:00
Sameer Agarwal 8e1d8e32ad A number of small changes.
1. Add a move constructor to NumericDiffCostFunction, DynamicAutoDiffCostfunction
   and DynamicNumericDiffCostFunction.
2. Add optional ownership of the underlying functor.
3. Update docs to reflect this as well as the variadic templates that allow an
   arbitrary number of parameter blocks.

Change-Id: I57bbb51fb9e75f36ec2a661b603beda270f30a19
2020-09-03 10:57:50 -07:00
Julian Kent 368a738e52 AutoDiffCostFunction: optional ownership
Add Ownership semantics to the AutoDiffCostFunction

This allows several benefits, such as pointer ordering always being the
same for numerical repeatability (due to blocks being ordered by
pointer address), memory adjacency for better cache performance, and
reduced allocator pressure / overhead.

This is then made use of in libmv by preallocating the errors and
cost functions into vectors

Change-Id: Ia5b97e7249b55a463264b6e26f7a02291927c9f2
2020-09-03 19:19:53 +02:00
Morten Hannemose 8cbd721c19 Add erf and erfc to jet.h, including tests in jet_test.cc
erf is necessary for evaluating Gaussian functions.
erfc was added because it is so similar to erf.

Change-Id: I5e470dbe013cc938fabb87cde3b0ebf26a90fff4
2020-09-03 17:54:20 +02:00
Sameer Agarwal db2af1be87 Add Problem::EvaluateResidualBlockAssumingParametersUnchanged
Simplify the semantics for Problem::EvaluateResidualBlock to
not ignore the presence of EvaluationCallback and add another method
EvaluateResidualBlockAssumingParametersUnchanged to handle the case
where the user has an EvaluationCallback but knows that the parameter
blocks do not change between calls.

Updated the documentation for the methods and EvaluationCallback to
reflect these semantics.

Also added tests for Evaluation related methods calling i
EvaluationCallback when its present.

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

Change-Id: If0a0c95c2f1f92e9183a90df240104a69a71c46d
2020-08-04 13:59:42 -07:00
Sameer Agarwal 4b8c731d8a Fix a bug in DynamicAutoDiffCostFunction
DynamicAutoDiffCostFunction::Evaluate when provided with a jacobians
array that was non-empty but all its entries are nullptr, would
compute num_active_parameters = 0, and then skip over all the loops
that evaluated the CostFunctor.

The fix is to check if num_active_parameters == 0, and then treat
it as the case where jacobians array is null.

Thanks to Ky Waegel for reporting and providing a reproduction for this.

Change-Id: Ib86930c2c3f722724d249f662bf88238679bbf98
2020-07-31 10:05:52 -07:00
Alex Stewart 5cb5b35a93 Fixed incorrect argument name in RotationMatrixToQuaternion()
- Raised as: https://github.com/ceres-solver/ceres-solver/pull/607 by
  Frank Dellaert

Change-Id: Id3e9f190e814cf18206e2f8c3b1b67b995c21dd5
2020-07-26 20:42:12 +01:00
Alex Stewart 7ef83e0759 Update minimum required C++ version for Ceres to C++14
- Removes all workarounds for pre-C++14 versions
- Removes '11' qualifier from C++ threading option and associated
  defines.
- Fix missing inclusion of 'Multithreading' in reported Ceres components
  when C++ threading model is enabled.
- Update Sphinx documentation to specify C++14 as minimum requirement.

Change-Id: I706c8b367b3221e3c4d1a0aaf669a8f9c911e438
2020-05-30 19:15:03 +01:00
Sameer Agarwal 763398ca4e Update the section on Preconditioners
Re-organize the section, add some more references and details for
existing preconditioners and add documentation for the SUBSET
precondition.

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

Change-Id: I93d0af819c160f5e4ce48b18202f629ddb92ca7b
2020-05-28 05:25:41 +00:00
Bayes Nie 303b078b50 Fix few typos and alter a NULL to nullptr.
Fix typos in docs/source/features.rst and examples/helloworld.cc. Alter a NULL to nullptr in include/ceres/autodiff_cost_function.h

Change-Id: Ibcf00b6ef665ad6be9af14b3add2dd4f3852e7e6
2020-05-25 17:22:40 +00:00
Alex Stewart 99efa54bdb Replace type aliases deprecated/removed in C++17/C++20 from FixedArray
- Raised as issue #551
- Also adds C++20 to the set of ALLOWED_CXX_STANDARDS, although this
  will require a version of CMake >= 3.12.

Change-Id: I0f13c72e93a35391fd2d18590b4243a329a2322c
2020-05-24 19:18:38 +01:00
huangqinjin 646959ef11 Do not export class template LineParameterization
For MSVC, instantiating a dllimport class template will cause error C2491:
definition of dllimport function not allowed.

Change-Id: Icc7f7ea84598df0a5436f48ffc2bab5cfab93921
2020-05-07 11:22:20 +00:00
huangqinjin 072c8f070e Initialize integer variables with integer instead of double
Change-Id: I652aca4ceb3129706a5d5e38afe9f16b61200a5b
2020-05-07 11:19:55 +00:00
Alex Stewart 8c36bcc81f Use inline & -inlinehint-threshold in auto-diff benchmarks
- This results in the same performance as the original solution of
  increasing -inline-threshold, but this approach is more viable to
  incorporate in a large code base as its effects are more targeted.

Change-Id: Id798dbca7d3050de0ea847a5ecc69484ac78a2cf
2020-04-27 18:47:22 +01:00
Sameer Agarwal 40b27482a2 Add std::numeric_limit specialization for Jets
This allows users to use std::numeric_limits on templated functors.

Change-Id: I403cec5c9826033ce7dfd6047deb64f66c35f806
2020-04-21 09:35:30 -07:00
Darius Rueckert e751d6e4f0 Remove AutodiffCodegen
- Remove Codegen files
- Revert Jet and Rotation

Change-Id: I005c5f98f2b6dfa5c7fd88d998b6aa83e47dab60
2020-04-08 10:43:53 +02:00
Sameer Agarwal 2281c6ed24 Fixes for comments from William Rucklidge
Change-Id: I64fcc25532cc66dc4cb7e2ea7ccfb220b0cb7e1f
2020-04-02 16:43:42 -07:00
Sameer Agarwal 41675682dc Fix a MSVC type deduction bug in ComputeHouseholderVector
A recent change made this function templated and MSVC 16 has trouble
doing automatic argument deduction, so the type of the template is
simplified and all callsites are explicitly annotated with the type
of the arguments.

Change-Id: I83cd0269e6e82c4a8f4e391f5fc03b92c942f74d
2020-04-02 08:13:55 -07:00
Sameer Agarwal 27183d661e Allow LocalParameterizations to have zero local size.
Local parameterizations with zero tangent/local size will cause the
corresponding parameter block to be treated as constant.

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

Change-Id: I554a2acc420f5dd9d0cc7f97b691877eb057b2c0
2020-04-02 06:49:42 -07:00
Sameer Agarwal ab0d373e46 Fix a comment in autodiff.h
Change-Id: I613e537c834e3f29cd92808c65ddb74f112974cc
2020-03-24 12:30:46 -07:00
Johannes Beck 84fdac38e0 Add const to GetCovarianceMatrix*
This CL adds const to the functions GetCovarianceMatrix and
GetCovarianceMatrixInTangentSpace.

Change-Id: Ibe2cafebede47977a9aabcac8d245f30af184fd1
2020-03-24 16:19:55 +00:00
Johannes Beck 6bde61d6be Add line local parameterization.
This CL adds a local parameterization for a n-dimensional
line, which is represented as an origin point and a direction.
The line direction is updated in the same way as a
homogeneous vector and the origin point is updated
perpendicular to the line direction.

Change-Id: I733f395e5cc4250abf9778c26fe0a5ae1de6b624
2020-03-23 22:36:39 -07:00
Sameer Agarwal 2c1c0932e9 Update documentation in autodiff.h
Change-Id: Icc2753b4f5be95022ffd92e479cdd3d9d7959d4c
2020-03-23 11:15:32 -07:00
Darius Rueckert 8904fa4887 Inline Jet initialization in Autodiff
Inlining the Jet initialzation is mandatory for good performance
in autodiff, because all the constants in the dual part can be
propagated into the cost functor.

This patch unrolls the initialization loop with templates and adds
EIGEN_ALWAYS_INLINE to the constructors.

Change-Id: Ic89d645984f3e1df6c63948236da823ba60d9620
2020-03-23 15:20:57 +01:00
Darius Rueckert 5c85f21799 Use ArraySelector in Autodiff
The class ArraySelector is now used in autodiff to store the
parameters and residuals. This reduces overhead of FixedArray
for fixed-sized residuals and allows more optimizations due
to inlining and unrolling.

Change-Id: Ibadc5644e64d672f7a555e250fb1f8da262f9d4f
2020-03-23 14:06:02 +01:00
Darius Rueckert 80477ff073 Add class ArraySelector
The ArraySelector selects the best array implementation based on
template arguments.

Change-Id: I93c6db1a638e924b85292e63bca9525610ec2e2f
2020-03-20 19:12:25 +01:00
Darius Rueckert e7a30359ee Pass kNumResiduals to Autodiff
The compile-time constant kNumResiduals is now passed to the
autodiff functions as a template parameter. This will be used
by future patches to optimize autodiff performance.

Change-Id: Ia2b2cc99b88752e8f12f4ce2542b1963bda552f5
2020-03-20 15:57:34 +01:00
Enrique Fernandez 6da364713f Fix Tukey loss function
Since the output of LossFunction::Evaluate is multiplied by 0.5, the
current implementation of the Tukey loss function must be multiplied
by 2.

Change-Id: Ia94753eef1a375fe48cc2e0d2cc61350904c8248
2020-03-17 19:42:03 +00:00
Darius Rueckert 75dd30faed Simplify GenerateCodeForFunctor
- Don't trace residual -> Use input cost functor instead
- Remove unnecessary copy from tmp jacobian array
- Fix indent of generated Evaluate() function

Change-Id: I23e09987d8ec30f7202a93eb253648505dcaaa4e
2020-03-12 09:22:59 +01:00
Darius Rueckert 9049688c60 Default Initialize ExpressionRef to Zero
The default constructor of ExpressionRef now creates a compile
time constant zero assignment. This patch is required, because
a reason change in Jet assumes default 0 initialization.

Change-Id: I8185cef587c17ab828896bce1e768170f8229d4e
2020-03-10 09:30:34 +01:00
Julian Kent bf1aff2f0e Fix 3+ nested Jet constructor
In Jet types, there is an attempt to set the derivative to 0.
However, if the derivative is not directly a scalar but a Jet<Jet>,
this cannot be constructed directly from a 0 literal. This is solved
by using the default constructor for the scalar type instead of 0.

The typical use case for this is adding constraints to the second
derivative of a curve in an Autodiff cost function.

Change-Id: Id480096632a731f312be12e294b3d6e244211529
2020-03-07 12:23:16 +01:00
Darius Rueckert 13c7a22cee Codegen Optimizer API
This patch adds the classes Optimizer and OptimizationPass, which
define the core API of the codegen optimization.

A single (trivial) optimization is added that removes NOP
expressions from a graph.

Change-Id: I0430d6ffc61a474f997475ff787a81a9c69cfe23
2020-02-18 10:50:10 +01:00
Darius Rueckert 032d5844c2 AutoDiff Code Generation - CMake Integration
This patch integrates the code generation module into the build
system. All depenendcies are tracked through CMake targets.
Modifying the cost functor will automatically trigger code
re-generation.

All this functionality is defined in the CMake function
ceres_generate_cost_function_implementation_for_functor
in CeresCodeGeneration.cmake. A hello world usage example
is included in examples/CMakeLists.txt.

Change-Id: I23b8b6698d1ea51cf3d788a47afcf39f8c5ce327
2020-02-13 13:57:14 +01:00
Darius Rueckert d82de91b88 Add ExpressionGraph::Erase(ExpressionId)
Add the function ExpressionGraph::Erase and a test-case for it.
Erase removes the given expression from the graph by shifting
all later expressions to the front. Indices and references
are updated accordingly.

Change-Id: Ic0449ccf28b369600fd2959a7e2a919d47f4cbe3
2020-02-10 16:19:55 +01:00
Darius Rueckert c8e35e19fd Add namespaces to generated functions and constants
The generated function names now include the containing namespace.
For example:
	std::abs(...)
	std::sin(...)
	ceres::Ternary(...)

This patch also fixes the generation of inf/nan compile time constants,
using std::numeric_limits.

Change-Id: I4a36b09c68dd2adabed49fd4f7f37c8229ab7377
2020-02-07 14:51:18 +01:00
Alex Stewart 75e575cae0 Fix use of incomplete type in defaulted Problem methods
- As Problem contains a unique_ptr<ProblemImpl> and as defaulted
  methods are declared inline where ProblemImpl's implementation is not
  available use of '= default' will generate compile errors on strict
  compilers.
- This CL moves the definition of defaulted methods to the
  implementation.

Change-Id: I7d79757cf684378fadef8e6f4000c84387018cdb
2020-01-19 16:57:38 +00:00
Darius Rueckert 8def196166 Remove ExpressionRef Move Constructor
The move constructor and move =operator are not required. They make
the code more complex and prone to bugs. The few saved assignments
are all trivial and are optimized away by the compiler or our
optimizer.

In fact, there is a bug in the current move-constructor implementation
that occurs, for example, when moving Eigen matrices around.

Change-Id: I013796495bb39f3f27677111bd0aaf49e2454e20
2020-01-14 17:00:31 +01:00
Johannes Beck f26f954105 Fix windows MSVC build.
This CL improves the build experience with MSVC:
- It adds the build flag '/bigobj' otherwise the build of
  the unit test fails.
- It adds the flag '/wd4267' to suppress signed / unsigned int
  conversions (size_t to int).
- It removes the use of std::aligned_storage from FixedArray.
  This has been done from the Abseil Team and is in the
  absl::FixedArray. Those changes has been ported to ceres.
  This fixes the alignemnt for older MSVC versions due to a
  bug in the implementation of std::aligned_storage, and
  prevents the use of the macro '_ENABLE_EXTENDED_ALIGNED_STORAGE'
  for newer MSVC versions, which is problematic as it could affect
  user code.
- Fix of the fixed array unit test. Due to the use of std::tuple
  instead of absl::tuple in ceres::internal::FixedArray, the
  unit test needs to reflect that change as well.
- Replaces 'add_definitions' with 'add_compile_options' for
  compiler flags as suggested by the cmake documentation.

Change-Id: I63f08cd6c0a8db8c9931289b909b4deafd75b039
2020-01-07 17:25:54 +00:00
Darius Rueckert fdf9cfd320 Add functions to find the matching ELSE, ENDIF expressions
ExpressionId FindMatchingEndif(ExpressionId id)
   - Finds the closing ENDIF expression for a given IF expression.

ExpressionId FindMatchingElse(ExpressionId id)
   - Finds the ELSE expression for a given IF expression.
   - Returns -1, if this IF doesn't have an else

This patch is a preparation to the code analyzing required
for various optimization passes.

Change-Id: I893102a757c6a0bcacbcc1190c2b8ef08314eb97
2020-01-07 09:35:09 +01:00
Johannes Beck a384a7e96e Remove not used using declaration
This CL removes a not used using declaration
which will cause a warning when compiled with
-Wunused-local-typedef under gcc.

Change-Id: Ie4cfd5d1fed9bee860e387545e60d92d257da4f4
2019-12-31 13:38:46 +01:00
Darius Rueckert a60136b7aa Add COMMENT ExpressionType
The comment expression allows the user to insert single-line
comments into the generated code. These will not be moved or
optimized away.

Comment expressions should make it easier to understand the
generated autodiff code.

Change-Id: Ie87d0698aa6af2aac8a437a13b25e0fef33dbfdc
2019-12-18 09:44:33 +01:00
Sameer Agarwal f212c92954 Let Problem::SetParameterization be called more than once.
https://github.com/ceres-solver/ceres-solver/issues/501

Change-Id: Ia94e6e62553e97fa2052db2cbebc5c472e26a406
2019-12-17 19:00:06 +00:00