Yes, that’s the one.

There’s a bit of confusion here and it comes from the Math library’s use of template metaprogramming. We actually use patterns that are well described in “Modern C++ Design” and used extensively by Boost and Eigen, but coming into C++ from different languages (or even from non-heavily-templated C++), this might seem a little tricky.

We’ve written generic templated functions. In particular, you’ve run into `check_not_nan`

. If you look at the source, you’ll see:

```
template <typename T_y>
struct not_nan<T_y, true> {
static void check(const char* function, const char* name, const T_y& y) {
for (size_t n = 0; n < stan::length(y); n++) {
if (is_nan(value_of_rec(stan::get(y, n))))
domain_error_vec(function, name, y, n, "is ", ", but must not be nan!");
}
}
};
```

This is super-awesome. We’ve defined a templated function that doesn’t rely on Eigen or even `std::vector`

. Then we partially specialized it for `bool is_vec = true`

without knowing what those things are.

If we never include `Eigen`

or `vector`

, this code is there, but never used. We’re in the clear. Now… if we happen to define a `get(...)`

function that works for `Eigen::Matrix`

, then we can use the `check_is_nan`

function for `Eigen::Matrix`

. If we only include `stan/math/prim/scal/err/check_not_nan.hpp`

, then we’ll only be brining in stan/math/prim/scal/meta/get.hpp. That doesn’t tell us how to operate with `Eigen::Matrix`

. So… we need to include the template specialization before we include `check_not_nan`

. This is where it gets complicated… we need to include it first, then make sure we instantiate the template too.

We take care of all of that by using the big headers:

`stan/math/prim/mat.hpp`

or `stan/math/rev/mat.hpp`

. If you look at those includes, it has things in a particular order.

I don’t know where you’re using it, but you really need to be including the correct template metaprograms before you include `check_not_nan`

(like `get`

and `value_of_rec`

). Or… just use the big header as we suggest here: https://github.com/stan-dev/math/wiki/Include-order-of-headers