Commit Graph

31 Commits

Author SHA1 Message Date
Sameer Agarwal ebb66e655f ceres::internal::FixedArray -> absl::FixedArray
Ceres Solver was using an old forked version of FixedArray,
now that we are using absl, we can use the official version
that ships with it.

Change-Id: Ic88d7f6e8a49b928d611f7cbb04172452b322b01
2024-07-23 13:45:45 -07:00
Sameer Agarwal 0a53aa9054 Take abseil as a dependency
1. Add abseil-cpp as a submodule. We are tracking the latest LTS
release, which is lts_2024_01_16.
2. Replace glog/gflags with absl::log and absl::flags.
3. Remove miniglog
4. Also take a whack at making the bazel build work with
   abseil-cpp and gtest.

There are a number of TODOs in this CL that still need to be resolved.

Change-Id: I39355ed7d61375be4ebcbc8596d9cc70acc1c678
2024-07-18 00:24:49 -07:00
Sergiu Deitsch 91773746be Simplify instantiation of cost functions and their functors
If arguments are passed to a cost function that can be used to construct
the functor, the latter will be instantiated by the cost function using
std::make_unique to ensure exception safety. This not only avoids static
analysis warnings caused by calling new but also spelling the cost
functor type name multiple times.

Also expand deduction guides for instantiating
Dynamic(Auto|Numeric)DiffCostFunction from std::unique_ptr enabled
constructor overloads.

Finally, make CostFunction default move constructible and assignable but
only through derived classes. This in turn allows derived classes to be
movable without relying on custom implementations of corresponding
operators.

Change-Id: Idee8b9871d862bc9f9f8b5a8d0bedc52863e93c0
2024-01-23 01:34:27 +01:00
Sameer Agarwal dffd8cd71b Add an accessor for the CostFunctor in DynamicAutoDiffCostFunction
https://github.com/ceres-solver/ceres-solver/issues/962

Change-Id: I50c327eb7ac09a894582ee3fb3311825607640c0
2023-09-25 05:44:37 -07:00
Sergiu Deitsch 0315c6ca9a Provide DynamicAutoDiffCostFunction deduction guide
The deduction guide allows to avoid repeating the CostFunctor type.

Change-Id: I2285de37071006a97f89988baa9b7054d82dae86
2023-03-08 23:46:33 +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
Sameer Agarwal 8fe8ebc3a6 Add final specifier to public classes
Change-Id: Ib7291dc68d5d4141ee821689743481fc84768606
2022-02-18 15:51:17 -08:00
Sergiu Deitsch c6158e0ab5 Replace NULL by nullptr
Change-Id: I200a40678091b984a01635d8637a487b7ad5cc13
2022-02-14 19:22:21 +01:00
Sergiu Deitsch 484d3414e4 Replace virtual keyword by override
virtual can be ambiguous. Applied changes correspond to clang-tidy fixes
stemming from the modernize-use-override check.

Change-Id: I973afd4680a5df587419777504aeb94467196b89
2022-02-09 00:34:05 +01: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
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
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
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
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
Kuang Fangjun 0d3a84fce5 Fix typos in doc and errors in the demo code.
Change-Id: I237402958ed8747ae438643132fcab90113ac27d
2018-09-22 12:01:20 +08: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
Alex Stewart 1141f4ad1a Fix integer conversion warning in MSVC.
- Raised by cnovel as issue #346:
  https://github.com/ceres-solver/ceres-solver/issues/346.

Change-Id: I90815ab6412834dd793ca7c327002d551da0675b
2018-02-24 18:51:54 +00:00
Sameer Agarwal 78abf0cdfe Introduce a common base class for DynamicAutoDiffCostFunction and DynamicNumericDiffCostFunction.
In the process also move some documentation from the file header to
just above the class declaration.

This change is in response to https://github.com/ceres-solver/ceres-solver/issues/233

Change-Id: I08cff1a94c57b67dd2bd8be4dba8c3fce46b68ab
2016-11-11 07:35:22 -08:00
Keir Mierle 7492b0d8de Update copyright headers with new year and URL
Since Ceres is moving to using GitHub for issues, and the Google
Code URL in the current copyright header will soon become invalid,
update all the headers.

Change-Id: I1fce70375d1bcf098591f07b4d8f01a5c1e0789c
2015-03-18 05:43:23 +00:00
Sameer Agarwal bcc865f81c Remove using namespace std;
For historical reasons we had a "using namespace std;" in port.h. This
is generally a bad idea. So removing it and along the way doing a bunch
of cpplint cleanup.

Change-Id: Ia125601a55ae62695e247fb0250df4c6f86c46c6
2015-01-07 14:26:53 -08:00
Sameer Agarwal 40df20b4aa Add DynamicNumericDiffCostFunction.
This brings the ability to have numerically differentiated
cost functions to be added with its structure decided on
runtime rather than compile time.

And some minor cleanups.

Two things still need to be done.

a. Update the modeling docs.
b. Remove RuntimeNumericDiffCostFunction in ceres::internal
   and replace its usage with DynamicNumericDiffCostFunction.

Change-Id: Ib771f093f29236c95a99df31c584d579b8e36615
2013-10-03 20:10:18 +00:00
Richard Stebbing 6dd18563a1 Fix DynamicAutoDiffCostFunction
Changed DynamicAutoDiffCostFunction to handle multiple derivative
sections as opposed to just a single contiguous block.

In the previous implementation it was assumed that non-constant
parameters occur in a single contiguous block so that constant
parameters could NOT lie between non-constant parameters. Previously,
start_derivative_section was first set as soon as the first
non-constant parameter block (marked by jacobians[i] != NULL) was
encountered. After this, entries in input_jets[parameter_cursor].v were
accessed with `parameter_cursor - start_derivative_section`. For
contiguous non-constant parameter blocks this is fine, but if constant
parameter blocks fall between then this indexing is incorrect because
`parameter_cursor - start_derivative_section` can go out of bounds.

For a concrete example, take a cost function with three parameter
blocks, each of size 1 and with the center block fixed. Assume that
Stride=1 so that two passes are required. On the first pass
start_derivative_section=0, and the first variable block is handled
correctly. At the end of the first pass end_derivative_section=1, so
for the second pass start_derivative_section=1. Now comes the problem.
When parameter_cursor=1, parameter_cursor >= start_derivative_section
so jacobian[1] is checked to be NULL. Since it is NULL (second
parameter block is constant) then nothing is done and
active_parameter_count is NOT incremented. Next, when
parameter_cursor=2, parameter_cursor >= start_derivative_section and
jacobian[2] is checked. Since it is not NULL then
input_jets[parameter_cursor].v[parameter_cursor -
start_derivative_section] is set to 1.0, BUT parameter_cursor -
start_derivative_section = 2 - 1 = 1 which is out of bounds
(input_jets[parameter_cursor].v is only of size Stride=1).

The proposed solution records the start of each contiguous block of
non-constant parameters and indexing into
input_jets[parameter_cursor].v is independent of parameter_cursor.

Change-Id: I388ab6a0bafa35d317491135ec6fe980453ff888
2013-06-19 02:24:31 +01:00
Sameer Agarwal e6707b2411 Lint fixes from William Rucklidge.
Change-Id: I57a6383bb875b24083cd9b7049333292d26f718c
2013-04-16 15:44:23 -07:00
Joydeep Biswas faa72ace9a Update to compile with stricter gcc checks.
Change-Id: Iecb37cbe7201a4d4f42b21b427fa1d35d0183b1b
2013-04-16 10:49:10 -04:00
Sameer Agarwal 931c309b27 Cleanup based on comments by William Rucklidge
Change-Id: If269ba8e388965a8ea32260fd6f17a133a19ab9b
2013-02-25 10:13:29 -08:00
Sameer Agarwal 509f68cfe3 Problem::Evaluate implementation.
1. Add Problem::Evaluate and tests.
2. Remove Solver::Summary::initial/final_*
3. Remove Solver::Options::return_* members.
4. Various cpplint cleanups.

Change-Id: I4266de53489896f72d9c6798c5efde6748d68a47
2013-02-24 19:04:21 +00:00
Sameer Agarwal efb47f39c3 Documentation update
Change-Id: I0fec43bff4fe0ea6cd2d2a8b34dac2330a517da0
2013-02-15 17:10:50 +00:00
Sameer Agarwal 974513a41f Bug fix in DynamicAutoDiffCostFunction
Add handling of constant parameter blocks.

Change-Id: I8b2ea79f47e190604fc4bed27705798240689f71
2013-02-12 14:59:04 -08:00
Keir Mierle 3130b3cea4 Add support for dynamic autodiff
Change-Id: I17d573696172ab691a9653db99a620e4bc1bd0d0
2013-02-11 22:47:10 -08:00