Expose_stan_functions C++ code not compliling

I am trying to use integrate_ode_rkf to perform a double definite integration \int_{0}^{x}\int_{0}^{y}f(x, y)dydx. The basic idea is that the first integration wrt y takes place in a user-defined function (of x) and that function is then integrated wrt x to give the result.
The following Stan code is apparently ‘syntactically correct’:

functions {

 
// Example integrand
  real[] integrand_ode(real y, real[] f, real[] theta, real[] x_r, int[] x_i) {
    real df_dx[1]; 
    df_dx[1] = exp(-square(y) - x_r[1]^2) ;
    return(df_dx);
  }
//User-defined function of x after y integrated out
  real ode_integrate(real x, real[] f, real[] theta, real[] xx_r, int[] x_i) {
     
    return(integrate_ode_rk45(integrand_ode, 
                            rep_array(0.0, 1), 
                            0, 
                            rep_array(1.0, 1), 
                            rep_array(0.0, 0), 
                            rep_array(x, 1), 
                            x_i)[1,1]);
  }
  // Final integration wrt x
  real ode_integrate2( ) {
    return(integrate_ode_rk45( ode_integrate, 
                            rep_array(0.0, 1),
                            0, 
                            rep_array(1.0, 1), 
                            rep_array(0.0, 0),
                            rep_array(0.0, 0) , 
                            rep_array(0, 0))[1,1]);

  }
}
data {
}
model {}

but when I use expose_stan_functions an error is generated. In the masses of output (which I can happily attach if it is needed) the key points seem to be

 In file included from /Users/Jeremy1/Rlibs/StanHeaders/include/stan/math/prim/arr.hpp:37:
/Users/Jeremy1/Rlibs/StanHeaders/include/stan/math/prim/arr/functor/coupled_ode_system.hpp:98:15: error: no viable overloaded '='
        dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
        ~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Jeremy1/Rlibs/BH/include/boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp:329:13: note: in instantiation of member function 'stan::math::coupled_ode_system<ode_integrate_functor__, double, double>::operator()' requested here
            sys( get_current_state() , get_current_deriv() , m_t );
            ^
 
                                                                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:537:13: note: candidate function not viable: no known conversion from 'double' to 'const std::__1::vector<double, std::__1::allocator<double> >' for 1st argument
    vector& operator=(const vector& __x);

The problem is with the final stage of the integration but I do not know what the error messages mean.

This seems to be a bug. I’ll look into it.

I think there is a bug in expose_stan_functions where it does not display error messages when the Stan program is malformed (@Krzysztof_Sakrejda, @martinmodrak) but if you try to parse it (under rstan 2.18.1 at least), you get

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

first argument to integrate_ode_rk45 must be the name of a function with signature (real, real[], real[], real[], int[]) : real[]   error in 'model512a615354b7_integral' at line 29, column 44
  -------------------------------------------------
    27:                             rep_array(0.0, 0),
    28:                             rep_array(0.0, 0) , 
    29:                             rep_array(0, 0))[1,1]);
                                                   ^
    30: 
  -------------------------------------------------

PARSER EXPECTED: ")"

Look in the user manual for the correct signatures for such functions, but post again if you can’t get it figured out.

Thanks, Ben. I’ll look into that.
My code parses without comment. I am using rstan 2,17.4. Does that mean I should update something?

Now updated to 2.18.1 and I get the same parser error.

I now have code that works:

functions {

 
// Example integrand
  real[] integrand_ode(real y, real[] f, real[] theta, real[] x, int[] x_i) {
    real df_dx[1]; // Do not change
    df_dx[1] = exp(-y^2 - x[1]^2); // Function of x and y to be integrated
    return(df_dx);
  }
//User-defined function of x after y integrated out
  real[] first_integral(real x, real[] f, real[] theta, real[] x_r, int[] x_i) {     
    return(integrate_ode_rk45(integrand_ode, 
                            rep_array(0.0, 1), // Do not change
                            0.0, // ymin
                            rep_array(1.0, 1), //(ymax, 1)
                            rep_array(0.0, 0), // Do not change
                            rep_array(x, 1), // Do not change
                            x_i)[1,]);// Do not change
  }
  // Final integration wrt x
  real second_integral(real xmin, real xmax ) {
    int x_i[0];
    return(integrate_ode_rk45(  first_integral, 
                            rep_array(0.0, 1),// Do not change
                            xmin,   //xmin
                            rep_array(xmax, 1), // (xmax, 1)
                            rep_array(0.0, 0),// Do not change
                            rep_array(0.0, 0) , // Do not change
                            x_i)[1,1]);// Do not change
  }
}
data {
}
model {}

I’ll check on it.