Commit Graph

107 Commits

Author SHA1 Message Date
Sergiu Deitsch f0851667be Fix MSVC compilation errors
Disable the definition of `min`/`max` macros by defining `NOMINMAX`
and prevent macro substitution in the public interface.

Also, quiet floating-point comparisons are defined as template functions
by the MSVC STL which causes compilation errors due to ambiguities in
resolving the template parameter types.

Fixes #668
Fixes #716
Fixes #718

Change-Id: I5fe7832a6a3a7ad0421a2557527528c34b88e9c7
2022-02-27 13:24:42 +01: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
Sergiu Deitsch f90833f5fa Simplify symbol export
Currently, the logic for exporting symbols is rather complicated: when
tests are enabled internal symbols are exported in addition to the
public symbols. Such logic causes several problems. (1) Test binaries
link against a Ceres build that is different from the final release
since fewer optimizations are applied if more symbols are exported. (2)
Also, some toolchains hide symbols by default breaking the existing
logic eventually causing linker errors.

Since internal symbols are not intended to be used outside of the
project, we can compile them into object files and use exactly the same
binary code both for the final build and the tests without relying on
conditionals.

By default, all symbols are now hidden unless annotated as public.
Internal symbols are explicitly marked as not being exported in case
users chose not to hide symbols by default.

Change-Id: I589dd10be2f6f438508783cf99d141af0120057b
2022-02-14 20:19:08 +01:00
Sergiu Deitsch c6158e0ab5 Replace NULL by nullptr
Change-Id: I200a40678091b984a01635d8637a487b7ad5cc13
2022-02-14 19:22:21 +01:00
Sameer Agarwal 9c5f29d46d Use compiler attributes instead of [[deprecated]]
This change is needed because compiler attributes and c++
annotations like [[deprecated]] do not mix well and we need that
for our public API.

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

Change-Id: I79eda795f2912f9af9ab36ee24b8428b47104743
2022-02-11 09:29:21 -08:00
Johannes Beck 4742bf3862 Add LineManifold.
This MR ports the LineParameterization of manifolds. The unit test are
rewritten to use the manifold test facilities.

The LineManifold is extended so that it can also handle dynamic size
ambient space dimensions.

Change-Id: I1fe3cd34b56f74b72ca028c34f5368e9df9fe4d7
2022-02-10 08:52:01 +01: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
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
Sameer Agarwal 98f639f542 Add a macro CERES_GET_FLAG.
This is needed to add a layer of indirection which will allow
us to use gflags in the public version and absl inside Google.

Change-Id: I32f3da23200a01c9b658bbf8aaa66cb8fddc2cc3
2021-03-18 11:07:57 -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 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
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