Commit Graph

95 Commits

Author SHA1 Message Date
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
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
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 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 ab0d373e46 Fix a comment in autodiff.h
Change-Id: I613e537c834e3f29cd92808c65ddb74f112974cc
2020-03-24 12:30:46 -07: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
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 d1703db45a Moved AutoDiffCodeGen macros to a separate (public) header
User defined cost functors have to include this new header
instead of internal/expression_ref.h. This hides some
complexity of ExpressionRef and reduces compile time outside
of code generation mode.

This patch also removes the dependency ExpressionRef->Jet.

Change-Id: Ie3f93648775e14881dc5cfab213bbc983c6cfeee
2019-12-02 16:17:19 +01:00
Darius Rueckert 5ce6c063db Fix ExpressionRef copy constructor and add a move constructor
The move constructor of ExpressionRef now implements the copy
elision, which was incorrectly done by the copy constructor.

This patch also updates the CMakeList to only add the
Expression tests for gcc. This is currently required, because
the AutoDiffCodeGen system relies on implementation defined
behaviour. (Evalution order + copy elision)

Change-Id: Ib17aeb22bd4d81de6d838b55c1b6497fb3740d0e
2019-12-01 12:38:01 +01:00
Darius Rueckert a90b5a12c6 Pass ExpressionRef by const reference instead of by value
Currently there is a bug in the copy constructor of ExpressionRef.
Fixing this bug, will create new expressions each time a copy is
executed. To reduce the amount of copy expression we pass
ExpressionRef by const reference now.

Change-Id: I0f81fb3d08aa4c66b9191f3138650f17023af67e
2019-11-27 17:26:01 +01:00
Darius Rueckert ea057678c5 Remove MakeFunctionCall() and add test for Ternary
Change-Id: Icf798a939a9868bc66c295ef0867ec075d4860da
2019-11-26 10:03:29 +01:00
Darius Rueckert 486d81812e Add ExpressionGraph::InsertExpression
This functions allows the insertion of new expression anywhere into
the graph. All references are updated. This will be used by semantic
expression testing and by the optimizer.

Change-Id: Ieafcfec7672f6328106dc0511c85d6fb5bd64d97
2019-11-22 09:31:20 +01:00
Darius Rueckert 3831a1dd37 Expression and ExpressionGraph comparison
- Add operator== for comparing Expressions and ExpressionGraphs.
 - Remove the broken Jet-test for now. (Will be added again later)

Change-Id: I3ee1599e8a0b50fa61c16f30812c78db7333f273
2019-11-21 22:32:59 +01:00
Darius Rueckert 9bb1dcb841 Remove definition of ExpressionRef::ExpressionRef(double&);
Due to the removed definition, calling this method will result
in a compile-time error instead of a run-time error.

Change-Id: Iac2514c05d79a66fcbad124587d08eb9309aa6a5
2019-11-21 16:31:39 +01:00
Darius Rueckert 5be2e48835 Autodiff Codegen Part 3: CodeGenerator
Add the class CodeGenerator, which is able to convert
objects of ExpressionGraph into strings.

Change-Id: Iff94fdbd3f2e055a78871b1a9947f1ca5ae3cd17
2019-11-20 10:18:18 +01:00
Darius Rueckert 6cd6330437 Remove unused ExpressionTypes
- Remove TERNARY (replaced by function call)
- Combine PARAMETER and RUNTIME_CONSTANT into INPUT_ASSIGNMENT

Change-Id: Id35fb45da08a9f80c1ac0dab7008deb0b3922835
2019-11-19 17:02:59 +01:00
Darius Rueckert 7d0d69a4df Fix ExpressionRef
- Add missing copy constructor
- Add make functions for input/output expressions
- Add missing ExpressionRef overload for MakeRuntimeConstant
- Add ExpressionRef overloads for common functions (cos,exp,...)
- Make ExpressionRef constructor from double implicit
- Add simple test for using ExpressionRef in Jets.
- Rename expression test macro

Change-Id: I071dc6717e4034a281662021998a91e80636da27
2019-11-18 17:18:15 +01:00
Darius Rueckert 6fd4f072d0 Autodiff Codegen Part 2: Conditionals
- Expression types for if/else blocks
- CERES_IF/ELSE macros
- Multiple assignment to the same variable

Change-Id: If529516f243f31823d1ef7b8827bb6f2390e418d
2019-11-13 09:19:36 +01:00
Darius Rueckert 4247d420fa Autodiff Codegen Part 1: Expressions
This patch adds the 'Expression' class, which is a fundamental
building block of automatic code generation. The expressions can
be used as scalar types for cost functors as well as Jets.
Dynamic branching is not yet supported.

Change-Id: I8c61bee5c307e0eec20fd39382683ea90f720dff
2019-10-16 07:54:23 +08:00
Johannes Beck 939253c208 Fix Eigen alignment issues.
For proper alignment on the heap Eigen needs to have a custom
allocator. There are two forms, new and in-place new. To make sure
that memory is aligned using new, one needs to overload new by
adding EIGEN_MAKE_ALIGNED_OPERATOR_NEW to any struct which contains a
fixed size Eigen type either through inheritance or as a direct or
indirect member. For the in-place new one need to use the
Eigen::aligned_allocator (e.g. for std::vector, std::list,
FixedArray, etc.). For more details see:
https://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__Alignement.html

This CL adds EIGEN_MAKE_ALIGNED_OPERATOR_NEW to all structs, which
contain fixed-size Eigen types and uses the Eigen::aligned_allocator
for containers which stores structs of fixed-size Eigen types.

Change-Id: I06c6c4fc74a6835918d5d1c571b7814a14c029d8
2019-04-15 22:09:24 +02:00
Sameer Agarwal bf67daf79e Add the missing <array> header to fixed_array.h
Change-Id: I1f48bd6eab0c6b189d01c68d4940a586a968581f
2019-04-11 10:35:04 -07:00
Johannes Beck 25e1cdbb6f Switch to FixedArray implementation from abseil.
This PR changes the implementation of the current fixed array to the
abseil one, which has proper allocator support.
Some minor changes are made to make the fixed array implementation
self-contained (no dependent to abseil):
- No address sanitizer support (red zones, etc.)
- Remove of noexecpt specified for copy and move constructor.
- Remove of 'at' function as Ceres does not use exceptions.
- Use std::tuple instead of absl::CompressedTuple as it uses the  abseil
  utility header which includes a whole bunch of other headers.

Change-Id: I43445b42c37f944509b5353a587d0efce74cbccf
2019-04-08 19:44:16 +00:00
Sameer Agarwal 056ba9bb1d Add AutoDiffFirstOrderFunction
This is to FirstOrderFunction, what AutoDiffCostFunction is to CostFunction.
This allows users of GradientSolver to be able to define objective functions
without requiring them to define the derivatives.

The implementation uses the same Jet objects for computing the gradient as
is used by AutoDiffCostFunction.

Change-Id: Ide6e60532a3adab9be9899ba9b368dc267fd2dbb
2019-03-03 06:50:56 +00:00
Sameer Agarwal e243fd292d remove the use of DCHECK_NOTNULL from numeric_diff.h
Change-Id: I7fc258812b1fe4aa727eaeb9b9b834d04a631abd
2018-11-02 06:33:21 -07:00
Johannes Beck 5ec88f6e44 Fix Jacobian evaluation for constant parameter
This CL fixes a regression bug in numeric differentiation where the
differentiation is called even if the parameter block is hold constant.
This resulted into a write to a nullptr.

A unit test is added for Jacobian evaluation of constant parameters.

Change-Id: Ia0f7c6cc7ef18f0f2cd6d758a839729b8ff606a0
2018-11-02 08:51:24 +01:00
Johannes Beck 8eef94de4e Sized cost function using variadic templates
This PR changes the interface of sized_cost_fucntion,
autodiff_cost_function and numeric_diff_costfunction from using ten
hardcoded parameter blocks to a variable number of parameter blocks
using variadic templates.

Trailing parameter blocks of size zero are now considered as error.

Change-Id: I37b9a0a420ef0eda6476a46672bbf6bd57e19760
2018-10-23 20:46:16 +02:00
Sameer Agarwal feeadb476a Swap the order of definition of IsValidParameterDimensionSequence.
This triggered a compiler error on clang + linux.

Change-Id: I8628c1b342980c50792f664d04d37465c17bf618
2018-10-10 20:50:39 -07:00
Johannes Beck 7edb3a6b92 Add parameter dims for variadic sized cost function
The class parameter dims is a helper class that holds the parameter
dimensions. The parameter dimensions are either dynamic or the
sizes are known at compile time. It is used to pass parameter block
dimensions around (e.g. between functions or classes).

Also the dimensions of the parameter blocks are checked at compile
time and must be greater than zero. This means trailing zero parameter
blocks will result in a compile error.

Change-Id: I4decf2f09e63fdb0fd652022b2be2a1cfd9c4478
2018-10-09 22:35:17 +02:00
Johannes Beck 336a6be5a4 Adding integer sequence and algorithms
This PR adds integer sequence and two algorithms (sum and exclusive
scan). Those will be needed to implement a sized cost function using
variadic templates.

Change-Id: I8e98d7c11fac94286fe9c364633406e59438f059
2018-10-08 20:42:15 +02:00
Johannes Beck e004eba85c Simplifying Init in manual contructor
All Init() function overloads are replaced by a perfect forwarding Init
function using variadic templates.

Change-Id: I42d0e236d274174982a4e56c0d73ec2776ed96f8
2018-09-27 20:49:44 +02:00
Kuang Fangjun 72d8e1cdb1 Fix typos.
Change-Id: I61296f42354eab797c55c1435ca46b3475b767e9
2018-09-20 22:52:39 +08:00
Kuang Fangjun 57067a2545 fix typos.
Change-Id: I6d3a5eb93e29596823afc5eb11f9a79806078bc0
2018-09-18 09:29:05 +08:00
Alex Stewart 16f9b34c3b Remove Intel TBB threading support.
- In light of the C++11 threads threading option this is no longer
  necessary for cross-platform threading support and did not offer a
  noticeable performance gain over either the C++11 threads
  implementation or OpenMP.

Change-Id: Icb588d520888c19a1775171795b55bcaffb3d256
2018-07-03 18:05:36 +00:00
Alex Stewart 8f41ca6abc Add Apple's Accelerate framework as a sparse linear algebra library.
- Currently DynamicSparseNormalCholeskySolver is unsupported for
  Accelerate.

Change-Id: I03b5a86bb22fef249c4aecd48947a613e8eff7a5
2018-06-29 09:43:03 +01:00
Sameer Agarwal dc8ef467e3 Move max_align_t handling into jet.h
This was currently buried in port.h. Since there is exactly one use
of the max_align_t handling, it is better from a readability
and cleanliness perspective to have this in jet.h.

Change-Id: I2f3dde75df7c333bd95393b9e4fc4cd5160d6afb
2018-04-23 10:03:45 -07:00
Sameer Agarwal 31f24521cc Deprecate macros.h and fpclassify.h
1. Replace CERES_DISALLOW_* with explicitly deleted constructors.
2. Replace use of CERES_ARRAY_SIZE and stack allocated arrays
   with std::vector.
3. Move CERES_ALIGN_* macros into manual_constructor.h, which is
   the one place they are used and will be deprecated along with that
   file.
4. Introduce isnan,isnormal,isinf and isfinite for Jets.
5. Replace IsNormal,IsFinite,IsNaN and IsInfinite with corresponding
   c++11 function calls.

Change-Id: I04f33a221aae77d247602150988b6d4aa4efeeab
2018-04-18 09:54:42 -07:00
Sameer Agarwal e49507cbea More C++ification.
"> >" -> ">>"
"> > >" -> ">>>"

Change-Id: Id1ddd9dbf030fe21d57207741b4ca8403068e55b
2018-04-03 10:58:15 -07:00
Keir Mierle 7c4e8a454e Replace scoped_ptr with C++11's unique_ptr
Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b
2018-04-02 14:47:47 -07:00
Sameer Agarwal ffae101c75 Removed CERES_USE_CXX11
Remove the special handling for tr1::shared_ptr.

Change-Id: Ic405dcfe881dd6560d236956f84bfb8911d0bcbb
2018-03-29 15:16:49 -07:00
Mike Vitus 5fcd3155f4 Fixes the configuration check in port.h.
Fixes a bug introduced in 12280 that incorrectly used xor for multiple
values.

Tested it manually by verifying it would fail for 2, 3, or 4 of them
defined.

Change-Id: I90c2662f4744aceaf0119dbbe072beced3f67c9a
2018-02-27 10:51:02 -08:00
Mike Vitus 7b2717582a Adds C++11 parallel for implementation.
Implements ParallelFor using the C++11 based ThreadPool.  The C++11
parallel for is 50-70% faster than single threaded, and 20-30% slower
than TBB.

Tested by compiling with OpenMP, TBB, and C++11 Threading support and
ran the unit tests.  Ran bazel as well.

Change-Id: I7fd6c9037ff9f200ce6999b5f39918995bb6b8ea
2018-02-26 16:12:03 -08: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
Keir Mierle 40effe3b15 Tiny solver autodiff adapter
Change-Id: I29fe736d53b2be32a101ba128cf557726def9a00
2017-10-14 15:51:14 -07:00
Sameer Agarwal 2dd907744d Ensure that partial evaluation of residuals triggers an error
ResidualBlock evaluation has logic to ensure that CostFunction
should always fill out the residual and jacobian arrays completely
by using a special value to pre-populate these arrays.

This works for CostFunctions with analytical Jacobians but not for
AutoDiffCostFunction and NumericDiffCostFunction Jacobians.

There is no way to fix this for NumericDiffCostFunctions without
introducing significant performance penalties but the residual
evaluation fails, which should be enough to catch such errors.

For AutoDiffCostFunction the way the Jets are default initialized
was sidestepping this check. So now, the Jet that is used to
capture the output residuals is now initialized with
kImpossibleValue, which will ensure that if the user forgets
to fill all output fields, it triggers an evaluation error.

This change required that ceres::internal::kImpossibleValue be moved
out of array_utils.h/cc to types.h.

Change-Id: I35bb0946cf0785a5d43c7b5459a2272848fb2a9b
2017-01-16 10:00:36 -08:00
Alex Stewart 3fa415bd0c Enable support for AVX instructions for Jets.
- Eigen versions < 3.3 only supported SIMD instructions that required
  16-byte alignment (SSE), whereas Eigen >= 3.3 also supports AVX
  instructions which require 32+-byte alignment.
- Previously we only ever requested 16-byte alignment for Jets (if >=
  C++11 was enabled) which resulted in Eigen assertions being triggered
  on some compilers as reported as Issue #251:
  https://github.com/ceres-solver/ceres-solver/issues/251.
- Now we use Eigen’s EIGEN_MAX_ALIGN_BYTES macro, defined in Eigen >=
  3.3 to specify the byte alignment for Jets when C++11 is enabled for
  Eigen >= 3.3.  For Eigen versions < 3.3, we maintain the previous
  behaviour of 16.

Change-Id: I749af7a70ae794e0c2a59301128db781e338422c
2017-01-05 19:12:45 +00:00