-
-
Notifications
You must be signed in to change notification settings - Fork 49
Description
I would like to start the discussion of simplifying including C++ code inside a Stan model.
This is not something for this release obviously but I think is worth doing.
Current state
In Cmdstan, if you specify an external hpp file via the USER_HEADER, the code in the included hpp file needs to be in the namespace of the model you are including it into. To me, that is very annoying as that makes the external .hpp file really not seamlessly reusable without some sort of script trickery. It also makes it difficult to share the external C++ code.
Rstan circumvents this by post-processing the generated C++ code and including that hpp file inside the namespace.
I am not sure how Pystan does this if at all.
Proposal
This is more of a question than a proposal. Would it be ok if we did something close to what Rstan does, but in stanc.
Meaning that for #include "code.stan" nothing changes, but #include "code.hpp" would get enclosed in the model namespace. Though we might also want to include C++ code not inside the namespace (for C++ includes for example).
So we have a few options imo:
#include "code.hpp"is include as is after the C++ is generated, but#include "code.stanhpp"is included inside the namespace- annotatation to mark an include you wish to place inside the namespace. Something like:
@InModelCppNamespace
#include "code.hpp"