Custom c++ using cmdstanr?

A drawback of the cmdstan’s approach to external C++ files is that the function need to be put inside the same namespace as the model.

So whatever you have in your external file, you need to place it in

namespace test_model_namespace {

// .. contents of the file

}

The namespace is always: "name of the model"+"_model_namespace".

What rstan does here is it takes the C++ file of the model, places the include inside the namespace and then compiles the model. While that approach works, I honestly dont like it very much. A cleaner solution would be to handle that in stanc compiler (see https://github.com/stan-dev/stanc3/issues/712).
Maybe there is a way around this in the meantime.

2 Likes