1. stanc generates a class
2. I add a factory function for creating an instance of the model from a var_context
3. compile the whole thing into a shared object
4. link into a small test program and load the symbol for the factory function
I'm pretty close to getting a working example that constructs and uses a model instance but I have to drop this for a few days. The only difficulty I've run into so far is that boost::dll is not in 1.60.0 so I used the development version of Boost and it seems to work fine for the example (no warnings/errors anyway). Has anybody tried Stan's unit tests with the development version of boost lately?
Krzysztof
Krzysztof
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Thursday, August 11, 2016 at 10:00:20 AM UTC-4, Daniel Lee wrote:
> And what are you trying to do? From what you've described, we should be able to do that from CmdStan without boost. We just choose to build an executable all at once.
Hey, sorry I just posted b/c I knew Ben had been interested in it too. boost::dll makes it reasonably straightforward to used shared libraries as plugins from c++. You basically pass it a path and a symbol alias and it lets you instantiate the relevant function in one step.
I didn't deal with that at all, I think it's a separate issue (?) I just took the output of running stanc on examples/bernoulli/bernoull.stan
and appended the factory function:
// Factory method
static boost::shared_ptr<bernoulli_model> create(stan::io::var_context& context) {
return boost::shared_ptr<bernoulli_model>(
new bernoulli_model(context)
);
}
BOOST_DLL_ALIAS(
bernoulli_model_namespace::create, // <-- this function is exported
create_model // <-- with this alias name
)
} // namespace
The boost::dll can be used to load the factory function and go from there.
Yes, and maybe we could reduce the wrapping that R/Python interfaces have to do down to some simpler calls.
> There are some practical difficulties here (e.g., you'd have to compile
> this shared object for every target platform and manage distributing it).
Yeah, I don't know if that's necessarily worth the effort... I was thinking more of making it easier to cache models locally. Maybe you could generate and pre-compile a lot of models for rstan that would then just need to be downloaded (?) I don't know what the compelling use cases would be outside of a more flexible command line client.
K
> Very cool!
@Ben: Would this stuff allow us to conveniently compile the exposed stan functions for R and save them in order to avoid recompilation every time we restart R?
Other than that this sounds very cool (I understood that this will bring down compilation times and potentially make models sharable between interfaces).
Sebastian