I want to use the gradient of log likelihood in my model to update X as the codes show. Is there any method that I can use the gradient in the model during fitting instead of getting the gradient after fitting it? In other words, it there anyway I can define grad in model block and use it?

```
model {
Xlw,] = to_array_1d((diag_matrix(Al) * to_vector(Xl[w-1,]) + Bl * to_vector(U[s, w-1,]) + grad))
}
```

It seems I should use C++ to achieve this. But I have no idea how to reach the backend code to expose the gradint stuff in the model itself. Thanks ahead!