Convert sum benchmark to use var<mat>#2
Convert sum benchmark to use var<mat>#2bbbales2 wants to merge 2 commits intoJamesYang007:masterfrom
var<mat>#2Conversation
|
Actually maybe I made |
|
@JamesYang007 I was converting more of these, in the StochasticVolatility example as-is I'm getting outputs like: The 0.815 makes me think something is broken, and so I'll look into that, but the way this is written the auto operator()(Eigen::Matrix<stan::math::var, Eigen::Dynamic, 1>& x) const
{
using namespace stan::math;
using vec_t = Eigen::Matrix<var, Eigen::Dynamic, 1>;
size_t N = (x.size() - 3) / 2;
Eigen::Map<vec_t> h_std(x.data(), N);
Eigen::Map<vec_t> h(x.data() + N, N);
auto& phi = x(2*N);
auto& sigma = x(2*N + 1);
auto& mu = x(2*N + 2);
h = h_std * sigma;
...;
}Not something like: auto operator()(Eigen::Matrix<stan::math::var, Eigen::Dynamic, 1>& x) const
{
using namespace stan::math;
using vec_t = Eigen::Matrix<var, Eigen::Dynamic, 1>;
size_t N = (x.size() - 3) / 2;
Eigen::Map<vec_t> h_std(x.data(), N);
auto& phi = x(N);
auto& sigma = x(N + 1);
auto& mu = x(N + 2);
vec_t h = h_std * sigma;
...;
}I see the default implementation is like this too. I wanna change it :D. |
|
Ah I didn't want to allocate more than I needed to. The parameter x for operator() is supposed to represent the entire parameter vector and h is a (transformed) parameter. Some libraries (like Stan) allow for this kind of "viewer" logic which generally saves time so I wanted to give them the advantage if they supported it. |
Converted one! As we get the rest of the
var<mat>stuff in place we can convert the rest.FastAD sum:
Stan sum: