Refactor the core automatic and numeric differentiation internal helpers
to utilize C++17 features for improved readability and maintainability:
- Added IntegerSequenceTraits to provide a uniform compile-time interface
for accessing head and tail of std::integer_sequence.
- Eliminated recursive template meta-programming in autodiff.h, replacing
it with fold expressions and std::index_sequence.
- Simplified core helper functions like Make1stOrderPerturbation into
unrolled loops.
- Refactored EvaluateJacobianForParameterBlocks from a recursive struct
to a recursive function template using if constexpr.
- Updated NumericDiffCostFunction and NumericDiffFirstOrderFunction
to use the modernized internal helper API.
Change-Id: I934034f7434fc05a8855565b2b534d325f920584
- Add constructors taking std::unique_ptr and ceres::Ownership to
AutoDiffCostFunction, NumericDiffCostFunction, and their dynamic
and first-order counterparts.
- Standardize delegating constructor style to use parentheses.
- Standardize ownership check in destructors.
- Fix documentation typos and example code in headers.
- Add comprehensive tests for Ownership and unique_ptr constructors.
Change-Id: I573abd695cdd89905997b573620e8d99d1cacca2
Modernize the construction and initialization logic of AutoDiffCostFunction,
NumericDiffCostFunction, AutoDiffFirstOrderFunction,
NumericDiffFirstOrderFunction, DynamicAutoDiffCostFunction,
DynamicNumericDiffCostFunction, and CostFunctionToFunctor by utilizing
C++17 features:
- Simplify constructor delegation using if constexpr, removing the need for
internal InitTag structures.
- Use std::is_constructible_v for cleaner SFINAE in variadic constructors.
- Add static_assert to catch improper usage of DYNAMIC residuals/parameters
at compile-time.
- Add Ownership support to AutoDiffFirstOrderFunction,
DynamicAutoDiffCostFunction, and DynamicNumericDiffCostFunction.
- Simplify CostFunctionToFunctor::operator() using variadic parameter packs.
- Use this->num_residuals() for consistent and clear access to base class
state.
- Minor code quality improvements and removal of redundant template
parameters.
Change-Id: Id760a26ba2ceca4fb2939ef7632f2f1d9cc430c9
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
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
1. Add a version history
2. Update copyright years across the code base
3. Run format_all.sh
4. Update version strings from 2.1.0 to 2.2.0 in the docs and
elsewhere.
Change-Id: I46d8d479d54bd6002d532785e67342106e73c9ac
- The intended use-case for these accessors is in client code tests to
support verification of the configuration with which cost functions
were constructed.
Change-Id: Ib77afa6409804ba7f724138f579e0c51b154f5ad
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
This CL removes a not used using declaration
which will cause a warning when compiled with
-Wunused-local-typedef under gcc.
Change-Id: Ie4cfd5d1fed9bee860e387545e60d92d257da4f4
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
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
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
1. Add answers to a number of FAQs.
2. Add a note to the documentation for NumericDiffCostFunction that
NumericDiffOptions needs to be documented and mentioned.
3. Update the docs for Solver::Options::numeric_derivative_relative_step_size
to indicate that this setting only applies to the gradient checker.
4. Remove deprecated constructors from NumericDiffCostFunction and
DynamicNumericDiffCostFunction.
Change-Id: If8fc011b2a5996dbc2c51268aa477550ed014a1c
This method numerically computes function derivatives in different
scales, extrapolating between intermediate results to conserve function
evaluations. Adaptive differentiation is essential to produce accurate
results for functions with noisy derivatives.
Full changelist:
-Created a new type of NumericDiffMethod (RIDDERS).
-Implemented EvaluateRiddersJacobianColumn in NumericDiff.
-Created unit tests with f(x) = x^2 + [random noise] and
f(x) = exp(x).
Change-Id: I2d6e924d7ff686650272f29a8c981351e6f72091
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
1. Update AutoDiffCostFunction template parameters to be consistent
with NumericDiffCostFunction.
2. Update the documentation for NumericDiffCostFunction and
AutoDiffCostFunction.
Change-Id: I113038abb5bedebb0f6f326f2a4ac31480d785fc
1. Bug fix in NumericDiffCostFunction (Thanks to Nicolas Brodu).
2. Minor documentation update in solver.h
3. Version history update.
4. Bump the version and ABI version.
Change-Id: I951574ddd0b2c4c03b9c79ff33eb9bea549071e7
The interface for NumericDiffCostFunction and AutoDiffCostFunction
are not comparable. They both accept variadic functors.
The change is backward compatible, as it still supports numeric
differentiation of CostFunction objects.
Some refactoring of documentation and code in auto_diff_cost_function
and its relatives was also done to make things consistent.
Change-Id: Ib5f230a1d4a85738eb187803b9c1cd7166bb3b92
Eigen3 does not allow column vectors to be stored in row-major
format. NumericDiffCostFunction by default stores its Jacobian
matrices in row-major format. This works fine if the residual
contains more than one variable. But if the residual block
depends on one variable and has more than one residuals, the
resulting Jacobian matrix is a column matrix in row-major format
resulting in a compile time error.
The fix is to check the template parameters and switch to column-major
storage as needed.
Thanks to Lena Gieseke for reporting this.
Change-Id: Icc51c5b38e1f3609e0e1ecb3c4e4a02aecd72c3b