Vector-valued functions with manual gradients in external C++

Thanks Bob. The version that was compiling was before I’d added the jacobian, but the compiler wasn’t complaining about those lines.

I think I’ve confused myself looking at other examples of precomputed gradients where the result of make_callback_var is returned (albeit for scalar returns).

With your suggested edits and returning dydt I’m now getting a different error:

/home/alecks/git/MinimalODEExample/odefunc.hpp:37: error: invalid use of incomplete type ‘class stan::math::var_value<Eigen::Matrix<stan::math::var_value<double>, -1, 1>, void>’
   37 |   stan::math::make_callback_var(dydt, [y_arena, jacobian](auto& res){
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |     y_arena.adj() += jacobian.transpose() * res.adj();
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |   });
      | 
In file included from stan/lib/stan_math/stan/math/rev/core/vari.hpp:4,
                 from stan/lib/stan_math/stan/math/rev/core/var.hpp:8,
                 from stan/lib/stan_math/stan/math/rev/meta/conditional_var_value.hpp:4,
                 from stan/lib/stan_math/stan/math/rev/meta.hpp:6,
                 from stan/lib/stan_math/stan/math/rev/core/accumulate_adjoints.hpp:5,
                 from stan/lib/stan_math/stan/math/rev/core.hpp:4,
                 from stan/lib/stan_math/stan/math/rev.hpp:8:
stan/lib/stan_math/stan/math/rev/core/var_value_fwd_declare.hpp:8:7: note: declaration of ‘class stan::math::var_value<Eigen::Matrix<stan::math::var_value<double>, -1, 1>, void>’
    8 | class var_value;
      |       ^~~~~~~~~

Apologies if I’m missing something obvious! Current version and log attached.

error.txt (23.9 KB)
odefunc.hpp (2.3 KB)