I’m trying to write a C++ user defined function which in Stan would be

``````  vector ode_rhs_c(real time, vector xz,
int C_nnz, vector C_w, array[] int C_v, array[] int C_u,
real I1, real tau0, real K, vector eta);

vector ode_rhs(real time, vector xz,
int C_nnz, vector C_w, array[] int C_v, array[] int C_u,
real I1, real tau0, real K, vector eta) {
int nn = rows(eta);
vector[nn] x = xz[1:nn];
vector[nn] z = xz[nn+1:2*nn];
vector[nn] gx = csr_matrix_times_vector(nn, nn, C_w, C_v, C_u, x);
vector[nn] dx = 1.0 - x.*x.*x - 2.0*x.*x - z + I1;
vector[nn] dz = (1/tau0)*(4*(x - eta) - z - K*gx);
return append_row(dx, dz);
}
``````

in this gist here,

``````user_header.hpp:82:14: error: no viable overloaded '+='
where `g_x` is a `VectorXd` and `xz.adj()` is a Cwise something or other. I’m a bit confused about how updates to `adj()` should be correctly implemented as I’ve tried to read the math lib docs and some of the implementations in the math lib, where I thought I was doing the right thing. If anyone could shed some light it would be much appreciated!
edit bonus points for why `adj()` vs `adj_op()` vs `val_op()` … ?
Aarrg, it was a `const` problem: to do `x.adj() += gx`, `x` can’t be `const` or else the compiler complains about seemingly unrelated and irrelevant things.