Let NumericDiffFirstOrderFunction take a dynamically sized parameter vector

Also fix a template naming lint along the way.

Change-Id: Iabb98aeec2ff9609a19c3778b9ea2da37771c985
This commit is contained in:
Sameer Agarwal
2022-09-15 15:10:13 -07:00
committed by Sameer Agarwal
parent 6c27ac6d50
commit 4cd257cf4a
5 changed files with 129 additions and 29 deletions
@@ -106,6 +106,29 @@ inline bool VariadicEvaluate(const Functor& functor,
return VariadicEvaluateImpl<ParameterDims>(functor, input, output, &functor);
}
// When differentiating dynamically sized CostFunctions, VariadicEvaluate
// expects a functor with the signature:
//
// bool operator()(double const* const* parameters, double* cost) const
//
// However for NumericDiffFirstOrderFunction, the functor has the signature
//
// bool operator()(double const* parameters, double* cost) const
//
// This thin wrapper adapts the latter to the former.
template <typename Functor>
class FirstOrderFunctorAdapter {
public:
explicit FirstOrderFunctorAdapter(const Functor& functor)
: functor_(functor) {}
bool operator()(double const* const* parameters, double* cost) const {
return functor_(*parameters, cost);
}
private:
const Functor& functor_;
};
} // namespace ceres::internal
#endif // CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_