I forgot about the rev header, good catch!
@mwmclean if the indexing is intentional (or just working as intended), you can make the following changes to your StanHeaders and the program will run:
First, find the log_sum_exp
header file that handles primitive types (double
):
system.file("include", "stan", "math", "prim", "mat", "fun",
"log_sum_exp.hpp",
package = "StanHeaders")
Below line 26, add the following:
if (size_zero(x))
return 0;
The function should now look like:
template <int R, int C>
double log_sum_exp(const Eigen::Matrix<double, R, C>& x) {
if (size_zero(x))
return 0;
const double max = x.maxCoeff();
return max + std::log((x.array() - max).exp().sum());
}
At the top of the file, add the following with the other #include
statements:
#include <stan/math/prim/scal/fun/size_zero.hpp>
Next, find the log_sum_exp
header file that handles autodiff variables:
system.file("include", "stan", "math", "rev", "mat", "fun",
"log_sum_exp.hpp",
package = "StanHeaders")
At the bottom of the file, below line 53, add:
if (size_zero(x))
return 0;
The function should now look like:
template <int R, int C>
inline var log_sum_exp(const Eigen::Matrix<var, R, C>& x) {
if (size_zero(x))
return var(0.0);
return var(new internal::log_sum_exp_matrix_vari(x));
}
Next, add the #include <stan/math/prim/scal/fun/size_zero.hpp>
statement add the top of the file
et voila! (Hopefully) working!