Skip to content

Commit c0a65e2

Browse files
authored
Merge pull request #2932 from stan-dev/feature/compile_info
Add virtual function model_compile_info to the model_base.hpp
2 parents 2cddcf5 + 17729d3 commit c0a65e2

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

src/stan/lang/generator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <stan/lang/generator/generate_member_var_decls.hpp>
7171
#include <stan/lang/generator/generate_member_var_decls_all.hpp>
7272
#include <stan/lang/generator/generate_model_name_method.hpp>
73+
#include <stan/lang/generator/generate_model_compile_info_method.hpp>
7374
#include <stan/lang/generator/generate_model_typedef.hpp>
7475
#include <stan/lang/generator/generate_namespace_end.hpp>
7576
#include <stan/lang/generator/generate_namespace_start.hpp>

src/stan/lang/generator/generate_cpp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stan/lang/generator/generate_log_prob.hpp>
1717
#include <stan/lang/generator/generate_member_var_decls_all.hpp>
1818
#include <stan/lang/generator/generate_model_name_method.hpp>
19+
#include <stan/lang/generator/generate_model_compile_info_method.hpp>
1920
#include <stan/lang/generator/generate_model_typedef.hpp>
2021
#include <stan/lang/generator/generate_namespace_end.hpp>
2122
#include <stan/lang/generator/generate_namespace_start.hpp>
@@ -70,6 +71,7 @@ void generate_cpp(const program& prog, const std::string& model_name,
7071
generate_dims_method(prog, o);
7172
generate_write_array_method(prog, model_name, o);
7273
generate_model_name_method(model_name, o);
74+
generate_model_compile_info_method(o);
7375
generate_constrained_param_names_method(prog, o);
7476
generate_unconstrained_param_names_method(prog, o);
7577
generate_class_decl_end(o);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef STAN_LANG_GENERATOR_GENERATE_MODEL_COMPILE_INFO_METHOD_HPP
2+
#define STAN_LANG_GENERATOR_GENERATE_MODEL_COMPILE_INFO_METHOD_HPP
3+
4+
#include <stan/lang/ast.hpp>
5+
#include <stan/lang/generator/constants.hpp>
6+
#include <ostream>
7+
#include <string>
8+
9+
namespace stan {
10+
namespace lang {
11+
12+
/**
13+
* Generate the <code>model_compile_info</code> method on the specified stream.
14+
*
15+
* @param[in,out] o stream for generating
16+
*/
17+
void generate_model_compile_info_method(std::ostream& o) {
18+
o << INDENT << "std::vector<std::string> model_compile_info() const {" << EOL
19+
<< INDENT2 << "std::vector<std::string> stanc_info;" << EOL << INDENT2
20+
<< "stanc_info.push_back(\"stanc_version = stanc2\");" << EOL << INDENT2
21+
<< "return stanc_info;" << EOL << INDENT << "}" << EOL2;
22+
}
23+
24+
} // namespace lang
25+
} // namespace stan
26+
#endif

src/stan/model/model_base.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ class model_base : public prob_grad {
5353
*/
5454
virtual std::string model_name() const = 0;
5555

56+
/**
57+
* Returns the compile information of the model:
58+
* stanc version and stanc flags used to compile the model.
59+
*
60+
* @return model name
61+
*/
62+
virtual std::vector<std::string> model_compile_info() const = 0;
63+
5664
/**
5765
* Set the specified argument to sequence of parameters, transformed
5866
* parameters, and generated quantities in the order in which they

src/test/unit/model/model_base_crtp_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ struct mock_model : public stan::model::model_base_crtp<mock_model> {
1515

1616
std::string model_name() const override { return "mock_model"; }
1717

18+
std::vector<std::string> model_compile_info() const {
19+
std::vector<std::string> stanc_info;
20+
stanc_info.push_back("stanc_version = stanc2");
21+
return stanc_info;
22+
}
23+
1824
void get_param_names(std::vector<std::string>& names) const override {}
1925
void get_dims(std::vector<std::vector<size_t> >& dimss) const override {}
2026

src/test/unit/model/model_base_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ struct mock_model : public stan::model::model_base {
1313

1414
std::string model_name() const override { return "mock_model"; }
1515

16+
std::vector<std::string> model_compile_info() const {
17+
std::vector<std::string> stanc_info;
18+
stanc_info.push_back("stanc_version = stanc2");
19+
return stanc_info;
20+
}
21+
1622
void get_param_names(std::vector<std::string>& names) const override {}
1723
void get_dims(std::vector<std::vector<size_t> >& dimss) const override {}
1824

0 commit comments

Comments
 (0)