These are instructions from @syclik on how to test a single model (.stan
file) for compilability with a main()
within stan-dev/stan
.
Let’s say you wanted to test this Stan file: src/test/test-models/good/map_rect.stan
If you type:
> make src/test/test-models/good/map_rect.hpp-test
then it’ll do a number of things (in this order):
-
build test/test-models/stanc
— it’s a stripped down version of the compiler -
generate the C++: it goes from
map_rect.stan
tomap_rect.hpp
-
the
*-test
target attempts to compile it by including it into a file with amain()
. That file with themain()
is generated like this:
test/test-model-main.cpp:
@mkdir -p test
@touch $@
@echo "int main() {" >> $@
@echo " stan::io::var_context *data = NULL;" >> $@
@echo " stan_model model(*data);" >> $@
@echo >> $@
@echo " std::vector<stan::math::var> params;" >> $@
@echo " std::vector<double> x_r;" >> $@
@echo " std::vector<int> x_i;" >> $@
@echo >> $@
@echo " model.log_prob<false, false>(params, x_i);" >> $@
@echo " model.log_prob<false, true>(params, x_i);" >> $@
@echo " model.log_prob<true, false>(params, x_i);" >> $@
@echo " model.log_prob<true, true>(params, x_i);" >> $@
@echo " model.log_prob<false, false>(x_r, x_i);" >> $@
@echo " model.log_prob<false, true>(x_r, x_i);" >> $@
@echo " model.log_prob<true, false>(x_r, x_i);" >> $@
@echo " model.log_prob<true, true>(x_r, x_i);" >> $@
@echo >> $@
@echo " return 0;" >> $@
@echo "}" >> $@
@echo >> $@
Thanks, @syclik.