math icon indicating copy to clipboard operation
math copied to clipboard

Ambiguity between `fwd` and `mix` signatures for `hessian()`

Open andrjohns opened this issue 1 year ago • 2 comments

Description

With the current signatures for hessian in fwd and mix, it is not possible to call the fwd implementation with double types.

mix/functor/hessian.hpp:

template <typename F>
void hessian(const F& f, const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
             double& fx, Eigen::Matrix<double, Eigen::Dynamic, 1>& grad,
             Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& H)

fwd/functor/hessian.hpp:

template <typename T, typename F>
void hessian(const F& f, const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& fx,
             Eigen::Matrix<T, Eigen::Dynamic, 1>& grad,
             Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& H)

Because the scalar type is explicit in the mix signature and templated in the fwd signature, calls to hessian with double types will always resolve to the mix implementation. This makes testing/validation (or even just use as an alternative) a bit of a hurdle.

I think any kind of fix for this would imply a breaking change (changing function names/arguments), so could be bundled in the 5.0 release (@SteveBronder)?

Current Version:

v4.8.1

andrjohns avatar Apr 28 '24 16:04 andrjohns