Sorry, this is a question that I know that I should be able to answer from the headers, but I can’t. I have one function `foo1`

that returns a scalar `var`

with precomputed vector gradients. I have a second function `foo2`

that calls `foo1`

, but I can’t interpret the header files well enough to understand how to recover those precomputed gradients.

More specifically, I have one function `foo2`

with signature

```
var foo2(const Eigen::Matrix<var, Eigen::Dynamic,1>& alpha_,
const Eigen::Matrix<var, Eigen::Dynamic,1>& beta_,
const double& x_,
std::ostream* pstream)
```

and inside `foo2`

I call `foo1`

, e.g.

```
var k;
k = foo1(alpha_, beta_, t, q, pstream);
// foo1 has precomputed gradients
// how do I recover gradients that are in k?
```

I want to precompute the gradients dfoo2/dalpha and dfoo2/dbeta, but to do so, I need the precomputed gradients dk/dalpha and dk/dbeta;

I have already precomputed the gradients in `foo1`

like so:

```
var foo1(const Eigen::Matrix<var, Eigen::Dynamic,1>& alpha_,
const Eigen::Matrix<var, Eigen::Dynamic,1>& beta_,
const double& t_,
const int q,
std::ostream* pstream)
// Calculate double k
// Calculate vector dk_dalpha with size N
// Calculate vector dk_dbeta with size N
size_t NN = 2*N;
vari** varis = ChainableStack::memalloc_.alloc_array<vari*>(NN);
double* partials = ChainableStack::memalloc_.alloc_array<double>(NN);
for (int i=0; i<N; i++) {
varis[i] = alpha_(i).vi_;
partials[i] = dk_dalpha(i);
}
for (int i=N; i<NN; i++){
varis[i] = beta_(i-N).vi_;
partials[i] = dk_dbeta(i-N);
}
return( var(new precomputed_gradients_vari(k, NN, varis, partials)));
```

I have verified that `foo1`

works and can be sampled from correctly using NUTS.

What I can’t figure out is how to access the gradients that `foo1`

precomputed and should be stored inside of `k`

. Specifically, I can’t tell from the headers how to access the vector valued partial of a `var`

. Any help would be appreciated.

Thanks.