Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/stan/model/model_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class model_base : public prob_grad {
bool include_tparams = true,
bool include_gqs = true) const = 0;

/**
* Return a string containing the transformed data computed by the model at
* construction as JSON string.
* The format of the string is the same as the expected input format for the
* `stan::json` input methods, i.e. complex numbers are rendered as a 2-list,
* tuples as objects with integer keys counting from 1
*/
virtual std::string get_transformed_data_json() const = 0;

/**
* Return the log density for the specified unconstrained
* parameters, without Jacobian and with normalizing constants for
Expand Down
3 changes: 3 additions & 0 deletions src/test/unit/io/random_var_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class mock_throwing_model_in_write_array : public stan::model::prob_grad {
param_names__.push_back(param_name.str());
}
}

std::string get_transformed_data_json() const { return std::string("{}"); }

template <typename RNG>
void write_array(RNG& base_rng__, std::vector<double>& params_r__,
std::vector<int>& params_i__, std::vector<double>& vars__,
Expand Down
4 changes: 4 additions & 0 deletions src/test/unit/model/model_base_crtp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct mock_model : public stan::model::model_base_crtp<mock_model> {
bool include_tparams,
bool include_gqs) const override {}

std::string get_transformed_data_json() const override {
return std::string("{}");
}

template <bool propto, bool jacobian, typename T>
T log_prob(Eigen::Matrix<T, -1, 1>& params_r, std::ostream* msgs) const {
if constexpr (std::is_same<T, double>::value) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/unit/model/model_base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ struct mock_model : public stan::model::model_base {
bool include_gqs) const override {}
void get_dims(std::vector<std::vector<size_t> >& dimss, bool include_tparams,
bool include_gqs) const override {}

std::string get_transformed_data_json() const override {
return std::string("{}");
}
void constrained_param_names(std::vector<std::string>& param_names,
bool include_tparams,
bool include_gqs) const override {}
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/services/util/initialize_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class mock_throwing_model : public stan::model::prob_grad {
param_names__.push_back(param_name.str());
}
}
std::string get_transformed_data_json() const { return std::string("{}"); }

template <typename RNG>
void write_array(RNG& base_rng__, std::vector<double>& params_r__,
std::vector<int>& params_i__, std::vector<double>& vars__,
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/services/util/mcmc_writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class throwing_model : public stan::model::model_base_crtp<throwing_model> {

} // unconstrained_param_names()

std::string get_transformed_data_json() const { return std::string("{}"); }

// Begin method overload boilerplate
template <typename RNG>
void write_array(RNG& base_rng,
Expand Down
Loading