Commit Graph

1521 Commits

Author SHA1 Message Date
Alex Stewart aa6ef417f3 Specify Eigen3_DIR in iOS and Android Travis CI builds
- Required after updates to use Eigen's own Eigen3Config.cmake instead
  of our original FindEigen.cmake module.

Change-Id: I9b5ad43fa153713c64fc01d638611e9bae3a169b
2019-12-13 13:52:39 +00:00
Alex Stewart 4655f2549c Use find_package() instead of find_dependency() in CeresConfig.cmake
- Revert to original usage for compatibility with the stated minimum
  required CMake version: 3.5

Change-Id: Ifb15f97a1d8e9cc5742564bc22a8761840c08e06
2019-12-13 11:56:06 +00:00
NeroBurner a548766d14 Use glfags target
Update the usage of Google Flags (gflags) library the same way Glog
updated it [1]. This pushes the minimum required gflags version to
v2.2.0.

Remove the ceres specific define of CERES_GFLAGS_NAMESPACE and directly
use GFLAGS_NAMESPACE defined in gflags/gflags_declare.h [2].

In CeresConfig.cmake the hard coded paths for gflags are ommited.
Instead we rely on the gflagsConfig file to get closer to a relocatable
CeresConfig.cmake.
Furthermore use the find_dependency() [4] cmake function specifically
created for cmake-config files.

This change builds upon the explicit PUBLIC/PRIVATE link change [3].

[1] https://github.com/google/glog/pull/199
[2] https://github.com/gflags/gflags/blob/d9b184bd0026b16bb4c2fded75d56fb2cce50d66/src/gflags_declare.h.in#L43
[3] https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16220
[4] https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Change-Id: I9861a2699f2702bf1a5e99d07863a7e6639b7c39
2019-12-12 14:00:59 +00:00
NeroBurner 33dd469a53 Use Eigen3::Eigen target
Since version 3.3 Eigen provides Eigen3Config.cmake with the imported
target Eigen3::Eigen. [1]
Use this imported target as descibed in Eigen-Wiki [2]

In the CeresConfig file improve relocatability by removing absolute
paths to the compiled dependencies. Instead find the used Eigen3::Eigen.
Furthermore use the find_dependency() [4] CMake function instead of the
find_package() call in CeresConfig.

This commit relies on all targets to be explicitly linked private or
public as done in the the change [3]

[1] https://bitbucket.org/eigen/eigen/pull-requests/257/cmake-imported-target-take-2/diff
[2] https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html
[3] https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16220
[4] https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Change-Id: I44f44a089083f7169bcf430b59775242e4eb72d1
2019-12-12 14:56:00 +01:00
Darius Rueckert 47e784bb41 NULL-jacobians are handled correctly in generated autodiff code
The autodiff code generator is extended in the following ways:
  - Evaluate the complete jacobian into a temporary array
  - Copy the temporary jacobian to the result if != NULL

Change-Id: If5ed0bff3b31e93a2d7d5dc718862cb648dba474
2019-12-10 15:19:48 +01:00
Darius Rueckert edd54b83e1 Update Jet.h and rotation.h to use the new IF/ELSE macros
Also use branchless implementation for isfinite(Jet),
isinf(Jet), isnan(Jet), and isnormal(Jet).

Change-Id: Ia881df03ba873e0560d67e976ab1e99e199eb523
2019-12-09 18:30:30 +01:00
Darius Rueckert 848c1f90c0 Update return type in code generator and add tests for logical functions
Change-Id: I128f8ccc21c2c3a2c79674ac28dd9a5b26b58772
2019-12-09 17:57:10 +01:00
Darius Rueckert 5010421bb7 Add the expression return type as a member to Expression
Before this patch the return type was implicitly defined by the
ExpressionType. This patch separates this connection and allows
each Expression to have one of the predefined types (scalar,
boolean, void).

This patch is required to add support for the functions isfinite,
isinf, isnan, and isnormal. These are function taking a double and
returning a bool.

This also moves some complexity of the code generator to the
Expression, because the generator can direclty get the c++ type.

Change-Id: I8b32bab1bfab2f668875e506d6f3b789a5d1f3fd
2019-12-09 17:13:05 +01:00
Darius Rueckert f4dc670ee8 Improve testing of the codegen system
- Move codegen tests to a sub directory
- Add tests for all functions of Expression, ExpressionRef, and ExpressionGraph
- Respect dependencies during tests: The ExpressionGraph test doesn't
  use ExpressionRef anymore.

The new tests revealed a few bugs so the following changes were made:

- Expression::MakeNop now resets the current expression with the default
  constructed NOP expression
- ExpressionGraph::Insert now updates the lhs_id the same way as
  InsertBack()

Change-Id: I6a18925c1e4d972c29ec1219f2073b4eaf2df737
2019-12-09 15:13:07 +01:00
Darius Rueckert 572ec4a5a5 Rework Expression creation and insertion
Objects of 'Expression' can now be freely created and copied around.
This creation does NOT add them to the active ExpressionGraph any
more. The insertion into the graph is now done by ExpressionRef,
which explicitly call graph.add(...) in each operation.

This change brings the following advantages:

1. 'Expression' is now stand-alone and side-effect free
   - Remove the dependency Expression->ExpressionGraph
   - Expressions can be created by the optimizer

2. Explicit graph insertion
  - Previously CreateCompileTimeConstant not only created an
    expression, but also inserted it into the active graph. Now
    this insertion is done explicitly by ExpressionRef

3. It is now easier to insert new types and members
  - Should be straight forward now, because we got rid of the
    3-way dependency
  - This is a preparation patch for the new return-type member in
    https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16224

Change-Id: Icef2fe529a4db001a10d1fb6816c9dc681b14ff2
2019-12-06 13:35:21 +01:00
Darius Rueckert c7337154e9 Disable the code generation module by default
After this patch, users have to add -DCODE_GENERATION=ON to the
cmake command, if they want to compile the code generation module.
A warning is printed if they enable code generation.

This informs the users that the code generation is still under
development and should be used with care. Also, we don't break
the master branch immediately if one of the bigger codegen
patches fails to build on some platform.

When this system is finished, we can enable it by default or
remove this option again.

Change-Id: Ib26498f0d5bd8b3c165807ffd774c057c2d21d39
2019-12-05 17:44:07 +01:00
NeroBurner 7fa0f3db41 Explicitly state PUBLIC/PRIVATE when linking
when using the command target_link_libraries explicitly state if the
linked library needs to be linked publicly or only private

Change-Id: I44eb7cb7ed06fdab12412963e6ce705b1fb718b4
2019-12-04 07:08:09 +00:00
Sameer Agarwal 4362a21699 Run clang-format on the public headers.
Also update copyright year.

Change-Id: I8508d4fd4564c646ec2281a1b3b2c36136b54b46
2019-12-03 14:50:37 -08:00
Darius Rueckert c56702aacc Fix installation of codegen headers
Change-Id: I32751ea992ac3658827941c0dda4753da194affb
2019-12-03 10:40:45 +01:00
Darius Rueckert 0d03e74dc7 Fix the include in the autodiff codegen example
Change-Id: I7fccdcc5a6799eed55c5483f3f2507db649eb272
2019-12-02 17:20:11 +01:00
Darius Rueckert d160264403 Autodiff Codegen Part 4: Public API
The public API for the Autodiff Codegen system consist of a single
function, GenerateCodeForFunctor. This function takes as template
argument a cost functor type and the residual/parameter structure.
The output is the C++ for the residual and derivative. This class
mainly serves as a wrapper for the different codegen modules.

Change-Id: I8ee974199219805d54eed5e07c0e8d1394940779
2019-12-02 17:09:03 +01: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
Alex Stewart 1084c5460a Quote all configure-expanded paths
- Required when the paths may include whitespace or special characters.

Change-Id: I573b4cabf5681bcbe7a545afe4acf9e9f61433e8
2019-11-25 20:26:28 +00:00
Darius Rueckert 3d756b07c1 Test Expressions with 'insert' instead of a macro
Change-Id: Id39a957dfe02ecd55a9f4bdd0e7952f1941d38bf
2019-11-25 12:02:53 +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 6ba8c57d28 Fix expression_test IsArithmetic
Change-Id: I77b799655321df4d4ffb21d8289c0f2c519786d7
2019-11-15 18:03:11 +01:00
Alex Stewart 2b494cfb36 Update Travis CI to Bionic & Xcode 11.2
- Fix Homebrew Ruby errors by forcing brew update before install.
- Remove use of custom Eigen 3.3.4 on Linux in favour of default Bionic
  3.3.4 package.
- Update Android NDK version to R20b and build for arm64-v8.
- Fix erroneous string -> STRING in iOS toolchain file.

Change-Id: I041c2a08b92b8307c12bd8967159beb6984e3c65
2019-11-14 20:39:30 +00:00
Alex Stewart a3dde68770 Require Xcode >= 11.2 on macOS 10.15 (Catalina)
- As detailed in a previous CL, Xcode 11.0-1 exhibited a -fstack-check
  bug on 10.15 Catalina that broke alignment for at least AVX
  instructions causing segfaults from within Eigen.
- As Xcode 11.2 fixes this issue, and is probably a more reliable fix
  than -fno-stack-check, we now require the user update in this case.

Change-Id: I482748fe5f40f82e7daf4da133cdfabbd95ffc89
2019-11-14 09:44:38 +00: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
Alex Stewart 52d6477a42 Detect and disable -fstack-check on macOS 10.15 with Xcode 11
- On macOS 10.15 and Xcode 11 -fstack-check is enabled by default. This
  breaks SIMD alignment (and other alignment) as detailed here:
  https://forums.developer.apple.com/thread/121887 resulting in random
  segfaults from within Eigen.
- The underlying problem also exists with earlier OS versions running
  Xcode 11 if -fstack-check is explicitly enabled.
- This CL explicitly disables -fstack-check on affected versions of
  macOS 10.15 and Xcode 11.

Change-Id: I74d964281c360710d5fb722ac59e6930b0fdcc41
2019-11-01 20:11:25 +00:00
Chris Choi 46ca461b7e Fix gradient_check_relative_precision docs typo
In the docs, `Solver::Options::gradient_check_relative_precision` is
documented to have a default precision of 1e08. That is incorrect, it
should be 1e-8.

Change-Id: Ib6b29e356738de4b555c77f7ffd1224d0cae4b6a
2019-10-21 16:19:29 +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
Sameer Agarwal ba62397d80 Run clang-format on jet.h
Change-Id: Ib865eecaa468330483b40244d62d432b40560712
2019-09-29 12:58:56 -07:00
Sameer Agarwal 667062dcc8 Introduce BlockSparseMatrixData
A number of algorithms like the SchurEliminator do not need
access to the full BlockSparseMatrix interface. They only
need read only access to the values array and the block structure.

This change introduces, BlockSparseDataMatrix a struct that carries
these two bits of information and modifies the Schur type algorithms
to use it.

What this change will allow us to do, in a subsequent CL is to
take the values array of a BlockSparseMatrix and pair it with
a different blocks structure for subset preconditioning.

Change-Id: I1808f12531b586c9ff4d6a70b3d390c7b0d9f441
2019-09-24 06:53:30 -07:00
Sameer Agarwal 17becf4610 Remove a CHECK failure from covariance_impl.cc
The CHECK was to see if SuiteSparseQR returns a non-null QR
factorization. However this can cause problems in production, so its
better to return false and let the user deal with the failure in
factorization.

Change-Id: I4e67f343e30547f4257d0315d507df9864c06dcc
2019-09-11 19:57:36 -07:00
Sameer Agarwal d7f428e5c7 Add a missing cast in rotation.h
Thanks to Lukas Post (@deutschepost) for reporting this.

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

Change-Id: I6d9d0ca5feab3a1f4cf47613537e8cd7ab1ba479
2019-08-07 06:42:28 -07:00
Sameer Agarwal ea4d66e7e5 clang-tidy fixes.
1. Mismatched variable names in local_parameterization.h/cc
2. Add missing final directives in iterative_refiner_test.cc

Change-Id: I954ef00d74c3b5d99f3659cc5c6ee2293fa9ff92
2019-08-06 16:58:21 -07:00
Sameer Agarwal be15b842a7 Integrate the SchurEliminatorForOneFBlock for the case <2,3,6>
Also run clang-format on schur_complement_solver.cc.

A more elaborate integration is not done, because it will cause
binary bloat.

Change-Id: Idf4e9e1794f7401a39f05fb145ec06459209a1e1
2019-08-06 16:34:47 +00:00
Sameer Agarwal 087b28f1b6 Remove use of SetUsage as it creates compilation problems.
Change-Id: Ifd0be489823fb8260e2c599389de943f4a1574d3
2019-08-06 05:09:55 -07:00
Sameer Agarwal 573046d7f7 Protect declarations of lapack functions under CERES_NO_LAPACK
If Ceres is compiled without a LAPACK implementation, there is
no need to declare these function signatures.

Thanks to David Sinuela for reporting this.

Change-Id: I048d1f9d38cef55368d33e74d363cd39f425dbf4
2019-08-05 07:27:10 -07:00
Sameer Agarwal 71d638ef32 Add a specialized schur eliminator.
Add a new specialized Schur Eliminator for the case where there is
exactly one F block and all dimensions are known at compile time.

Benchmark on my macbook shoes ~3x speedup for Eliminate and 4x speedup for BackSubstitute.
Similar speedups are observed on other platforms.

------------------------------------------------------------------------------------------
Benchmark                                                   Time           CPU Iterations
------------------------------------------------------------------------------------------
BM_SchurEliminatorEliminate/10                           4176 ns       4132 ns     153522
BM_SchurEliminatorEliminate/64                          24392 ns      24234 ns      29993
BM_SchurEliminatorEliminate/512                        169632 ns     168709 ns       3872
BM_SchurEliminatorEliminate/4096                      1296407 ns    1292873 ns        519
BM_SchurEliminatorEliminate/10000                     3159652 ns    3149532 ns        216
BM_SchurEliminatorForOneFBlockEliminate/10               1187 ns       1184 ns     603953
BM_SchurEliminatorForOneFBlockEliminate/64               7917 ns       7898 ns      87558
BM_SchurEliminatorForOneFBlockEliminate/512             57629 ns      57485 ns      12035
BM_SchurEliminatorForOneFBlockEliminate/4096           484680 ns     480757 ns       1459
BM_SchurEliminatorForOneFBlockEliminate/10000         1157237 ns    1150735 ns        566
BM_SchurEliminatorBackSubstitute/10                       681 ns        679 ns    1070500
BM_SchurEliminatorBackSubstitute/64                      3899 ns       3887 ns     182883
BM_SchurEliminatorBackSubstitute/512                    33632 ns      33467 ns      22582
BM_SchurEliminatorBackSubstitute/4096                  241117 ns     240257 ns       2884
BM_SchurEliminatorBackSubstitute/10000                 631869 ns     626992 ns       1146
BM_SchurEliminatorForOneFBlockBackSubstitute/10           139 ns        138 ns    5021341
BM_SchurEliminatorForOneFBlockBackSubstitute/64           898 ns        892 ns     780396
BM_SchurEliminatorForOneFBlockBackSubstitute/512         7344 ns       7286 ns      87059
BM_SchurEliminatorForOneFBlockBackSubstitute/4096       57634 ns      57345 ns      11642
BM_SchurEliminatorForOneFBlockBackSubstitute/10000     153129 ns     152320 ns       4949

Change-Id: Iae64e96c91beb44b807df0e0572d202df7cdaed8
2019-08-05 07:15:41 -07:00
Sameer Agarwal 2ffddaccfe Use override & final instead of just using virtual.
This is safer than using virtual and this lead to a minor
bug fixes.

Change-Id: Id69cb1cc569bf6bf245f22f029c7871b6c712568
2019-07-25 16:29:14 -07:00
Sameer Agarwal e4577dd6d9 Use override instead of virtual for subclasses.
Now that we are using c++11, it is safer to use override in subclasses
instead of virtual.

This CL does it for the interface, a follow up CL will do it for
other parts of the code base.

Change-Id: Ice8d0f4355cb700019d7a9c1566fbff0099e97d6
2019-07-25 23:26:24 +00:00
Frank 3e5db5bc27 Fixing documentation typo.
- Matrix had two columns squeezed together

Change-Id: I5f18df15364bd8507db98d43f8a547a9efab0913
2019-07-19 03:03:00 +09:00
Alex Stewart 82d325b731 Avoid memory allocations in Accelerate Sparse[Refactor/Solve]().
- Maintain scratch workspaces for solving/refactoring instead of
  forcing Sparse[Refactor/Solve]() to reallocate space on each call.

Change-Id: Idb9eda9c9c6cc7570cfdf851e59e5bf6b39521ce
2019-07-16 11:10:36 +00:00
Sameer Agarwal f66b513826 Fix some clang-tidy warnings.
Change-Id: Ic71bf0fc561edc22e3051d156fac630fcfea5d92
2019-07-15 13:23:04 -07:00
Alex Stewart 0428e2dd0f Fix missing #include of <memory>
Change-Id: I11a4e232305e3866ed418a65041aa87ce385c071
2019-07-12 18:23:26 +01:00