Slower .hpp file (stanc3):
// Code generated by stanc 159a90f0
#include <stan/model/model_header.hpp>
namespace slowdown_model_namespace {
template <typename T, typename S>
std::vector<T> resize_to_match__(std::vector<T>& dst, const std::vector<S>& src) {
dst.resize(src.size());
return dst;
}
template <typename T>
Eigen::Matrix<T, -1, -1>
resize_to_match__(Eigen::Matrix<T, -1, -1>& dst, const Eigen::Matrix<T, -1, -1>& src) {
dst.resize(src.rows(), src.cols());
return dst;
}
template <typename T>
Eigen::Matrix<T, 1, -1>
resize_to_match__(Eigen::Matrix<T, 1, -1>& dst, const Eigen::Matrix<T, 1, -1>& src) {
dst.resize(src.size());
return dst;
}
template <typename T>
Eigen::Matrix<T, -1, 1>
resize_to_match__(Eigen::Matrix<T, -1, 1>& dst, const Eigen::Matrix<T, -1, 1>& src) {
dst.resize(src.size());
return dst;
}
std::vector<double> to_doubles__(std::initializer_list<double> x) {
return x;
}
std::vector<stan::math::var> to_vars__(std::initializer_list<stan::math::var> x) {
return x;
}
inline void validate_positive_index(const char* var_name, const char* expr,
int val) {
if (val < 1) {
std::stringstream msg;
msg << "Found dimension size less than one in simplex declaration"
<< "; variable=" << var_name << "; dimension size expression=" << expr
<< "; expression value=" << val;
std::string msg_str(msg.str());
throw std::invalid_argument(msg_str.c_str());
}
}
inline void validate_unit_vector_index(const char* var_name, const char* expr,
int val) {
if (val <= 1) {
std::stringstream msg;
if (val == 1) {
msg << "Found dimension size one in unit vector declaration."
<< " One-dimensional unit vector is discrete"
<< " but the target distribution must be continuous."
<< " variable=" << var_name << "; dimension size expression=" << expr;
} else {
msg << "Found dimension size less than one in unit vector declaration"
<< "; variable=" << var_name << "; dimension size expression=" << expr
<< "; expression value=" << val;
}
std::string msg_str(msg.str());
throw std::invalid_argument(msg_str.c_str());
}
}
using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::model_base_crtp;
using stan::model::rvalue;
using stan::model::cons_list;
using stan::model::index_uni;
using stan::model::index_max;
using stan::model::index_min;
using stan::model::index_min_max;
using stan::model::index_multi;
using stan::model::index_omni;
using stan::model::nil_index_list;
using namespace stan::math;
static int current_statement__ = 0;
static const std::vector<string> locations_array__ = {" (found before start of program)",
" (in '/cmdstanr-git/slowdown.stan', line 7, column 2 to column 13)",
" (in '/cmdstanr-git/slowdown.stan', line 8, column 2 to column 17)",
" (in '/cmdstanr-git/slowdown.stan', line 9, column 2 to column 22)",
" (in '/cmdstanr-git/slowdown.stan', line 13, column 2 to column 24)",
" (in '/cmdstanr-git/slowdown.stan', line 14, column 2 to column 23)",
" (in '/cmdstanr-git/slowdown.stan', line 15, column 2 to column 23)",
" (in '/cmdstanr-git/slowdown.stan', line 18, column 2 to column 43)",
" (in '/cmdstanr-git/slowdown.stan', line 2, column 2 to column 17)",
" (in '/cmdstanr-git/slowdown.stan', line 3, column 2 to column 14)",
" (in '/cmdstanr-git/slowdown.stan', line 4, column 2 to column 17)"};
class slowdown_model : public model_base_crtp<slowdown_model> {
private:
int pos__;
int N;
Eigen::Matrix<double, -1, 1> y;
Eigen::Matrix<double, -1, -1> x;
public:
~slowdown_model() { }
std::string model_name() const { return "slowdown_model"; }
slowdown_model(stan::io::var_context& context__,
unsigned int random_seed__ = 0,
std::ostream* pstream__ = nullptr) : model_base_crtp(0) {
typedef double local_scalar_t__;
boost::ecuyer1988 base_rng__ =
stan::services::util::create_rng(random_seed__, 0);
(void) base_rng__; // suppress unused var warning
static const char* function__ = "slowdown_model_namespace::slowdown_model";
(void) function__; // suppress unused var warning
try {
pos__ = 1;
context__.validate_dims("data initialization","N","int",
context__.to_vec());
current_statement__ = 8;
pos__ = 1;
current_statement__ = 8;
N = context__.vals_i("N")[(pos__ - 1)];
current_statement__ = 9;
validate_non_negative_index("y", "N", N);
context__.validate_dims("data initialization","y","double",
context__.to_vec(N));
y = Eigen::Matrix<double, -1, 1>(N);
current_statement__ = 9;
pos__ = 1;
current_statement__ = 9;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 9;
assign(y, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("y")[(pos__ - 1)], "assigning variable y");
current_statement__ = 9;
pos__ = (pos__ + 1);}
current_statement__ = 10;
validate_non_negative_index("x", "N", N);
current_statement__ = 10;
validate_non_negative_index("x", "1", 1);
context__.validate_dims("data initialization","x","double",
context__.to_vec(N, 1));
x = Eigen::Matrix<double, -1, -1>(N, 1);
current_statement__ = 10;
pos__ = 1;
current_statement__ = 10;
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
current_statement__ = 10;
for (size_t sym2__ = 1; sym2__ <= N; ++sym2__) {
current_statement__ = 10;
assign(x,
cons_list(index_uni(sym2__),
cons_list(index_uni(sym1__), nil_index_list())),
context__.vals_r("x")[(pos__ - 1)], "assigning variable x");
current_statement__ = 10;
pos__ = (pos__ + 1);}}
current_statement__ = 8;
current_statement__ = 8;
check_greater_or_equal(function__, "N", N, 1);
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
num_params_r__ = 0U;
try {
num_params_r__ += 1;
current_statement__ = 2;
validate_non_negative_index("beta", "1", 1);
num_params_r__ += 1;
num_params_r__ += 1;
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
}
template <bool propto__, bool jacobian__, typename T__>
T__ log_prob(std::vector<T__>& params_r__, std::vector<int>& params_i__,
std::ostream* pstream__ = 0) const {
typedef T__ local_scalar_t__;
T__ lp__(0.0);
stan::math::accumulator<T__> lp_accum__;
static const char* function__ = "slowdown_model_namespace::log_prob";
(void) function__; // suppress unused var warning
stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
try {
local_scalar_t__ alpha;
current_statement__ = 1;
alpha = in__.scalar();
current_statement__ = 2;
validate_non_negative_index("beta", "1", 1);
Eigen::Matrix<local_scalar_t__, -1, 1> beta;
beta = Eigen::Matrix<local_scalar_t__, -1, 1>(1);
current_statement__ = 2;
beta = in__.vector(1);
local_scalar_t__ sigma;
current_statement__ = 3;
sigma = in__.scalar();
current_statement__ = 3;
if (jacobian__) {
current_statement__ = 3;
sigma = stan::math::lb_constrain(sigma, 0, lp__);
} else {
current_statement__ = 3;
sigma = stan::math::lb_constrain(sigma, 0);
}
{
current_statement__ = 4;
lp_accum__.add(normal_log<propto__>(alpha, 0, 10));
current_statement__ = 5;
lp_accum__.add(normal_log<propto__>(beta, 0, 10));
current_statement__ = 6;
lp_accum__.add(normal_log<propto__>(sigma, 0, 5));
current_statement__ = 7;
lp_accum__.add(normal_id_glm_lpdf<propto__>(y, x, alpha, beta, sigma));
}
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
lp_accum__.add(lp__);
return lp_accum__.sum();
} // log_prob()
template <typename RNG>
void write_array(RNG& base_rng__, std::vector<double>& params_r__,
std::vector<int>& params_i__, std::vector<double>& vars__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true,
std::ostream* pstream__ = 0) const {
typedef double local_scalar_t__;
vars__.resize(0);
stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
static const char* function__ = "slowdown_model_namespace::write_array";
(void) function__; // suppress unused var warning
(void) function__; // suppress unused var warning
double lp__ = 0.0;
(void) lp__; // dummy to suppress unused var warning
stan::math::accumulator<double> lp_accum__;
try {
double alpha;
current_statement__ = 1;
alpha = in__.scalar();
current_statement__ = 2;
validate_non_negative_index("beta", "1", 1);
Eigen::Matrix<double, -1, 1> beta;
beta = Eigen::Matrix<double, -1, 1>(1);
current_statement__ = 2;
beta = in__.vector(1);
double sigma;
current_statement__ = 3;
sigma = in__.scalar();
current_statement__ = 3;
sigma = stan::math::lb_constrain(sigma, 0);
vars__.push_back(alpha);
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
vars__.push_back(beta[(sym1__ - 1)]);}
vars__.push_back(sigma);
if (logical_negation((primitive_value(emit_transformed_parameters__) ||
primitive_value(emit_generated_quantities__)))) {
return ;
}
if (logical_negation(emit_generated_quantities__)) {
return ;
}
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
} // write_array()
void transform_inits(const stan::io::var_context& context__,
std::vector<int>& params_i__,
std::vector<double>& vars__, std::ostream* pstream__) const {
typedef double local_scalar_t__;
vars__.resize(0);
vars__.reserve(num_params_r__);
try {
int pos__;
pos__ = 1;
double alpha;
current_statement__ = 1;
pos__ = 1;
current_statement__ = 1;
alpha = context__.vals_r("alpha")[(pos__ - 1)];
current_statement__ = 2;
validate_non_negative_index("beta", "1", 1);
Eigen::Matrix<double, -1, 1> beta;
beta = Eigen::Matrix<double, -1, 1>(1);
current_statement__ = 2;
pos__ = 1;
current_statement__ = 2;
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
current_statement__ = 2;
assign(beta, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("beta")[(pos__ - 1)], "assigning variable beta");
current_statement__ = 2;
pos__ = (pos__ + 1);}
double sigma;
current_statement__ = 3;
pos__ = 1;
current_statement__ = 3;
sigma = context__.vals_r("sigma")[(pos__ - 1)];
current_statement__ = 3;
sigma = stan::math::lb_free(sigma, 0);
vars__.push_back(alpha);
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
vars__.push_back(beta[(sym1__ - 1)]);}
vars__.push_back(sigma);
} catch (const std::exception& e) {
stan::lang::rethrow_located(e, locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
} // transform_inits()
void get_param_names(std::vector<std::string>& names__) const {
names__.resize(0);
names__.push_back("alpha");
names__.push_back("beta");
names__.push_back("sigma");
} // get_param_names()
void get_dims(std::vector<std::vector<size_t>>& dimss__) const {
dimss__.resize(0);
std::vector<size_t> dims__;
dimss__.push_back(dims__);
dims__.resize(0);
dims__.push_back(1);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
} // get_dims()
void constrained_param_names(std::vector<std::string>& param_names__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true) const {
param_names__.push_back(std::string() + "alpha");
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
{
param_names__.push_back(std::string() + "beta" + '.' + std::to_string(sym1__));
}}
param_names__.push_back(std::string() + "sigma");
if (emit_transformed_parameters__) {
}
if (emit_generated_quantities__) {
}
} // constrained_param_names()
void unconstrained_param_names(std::vector<std::string>& param_names__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true) const {
param_names__.push_back(std::string() + "alpha");
for (size_t sym1__ = 1; sym1__ <= 1; ++sym1__) {
{
param_names__.push_back(std::string() + "beta" + '.' + std::to_string(sym1__));
}}
param_names__.push_back(std::string() + "sigma");
if (emit_transformed_parameters__) {
}
if (emit_generated_quantities__) {
}
} // unconstrained_param_names()
std::string get_constrained_sizedtypes() const {
stringstream s__;
s__ << "[{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" << 1 << "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]";
return s__.str();
} // get_constrained_sizedtypes()
std::string get_unconstrained_sizedtypes() const {
stringstream s__;
s__ << "[{\"name\":\"alpha\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" << 1 << "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]";
return s__.str();
} // get_unconstrained_sizedtypes()
// Begin method overload boilerplate
template <typename RNG>
void write_array(RNG& base_rng__,
Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true,
std::ostream* pstream = 0) const {
std::vector<double> params_r_vec(params_r.size());
for (int i = 0; i < params_r.size(); ++i)
params_r_vec[i] = params_r(i);
std::vector<double> vars_vec;
std::vector<int> params_i_vec;
write_array(base_rng__, params_r_vec, params_i_vec, vars_vec,
emit_transformed_parameters__, emit_generated_quantities__, pstream);
vars.resize(vars_vec.size());
for (int i = 0; i < vars.size(); ++i)
vars(i) = vars_vec[i];
}
template <bool propto__, bool jacobian__, typename T_>
T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
std::ostream* pstream = 0) const {
std::vector<T_> vec_params_r;
vec_params_r.reserve(params_r.size());
for (int i = 0; i < params_r.size(); ++i)
vec_params_r.push_back(params_r(i));
std::vector<int> vec_params_i;
return log_prob<propto__,jacobian__,T_>(vec_params_r, vec_params_i, pstream);
}
void transform_inits(const stan::io::var_context& context,
Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
std::ostream* pstream__) const {
std::vector<double> params_r_vec;
std::vector<int> params_i_vec;
transform_inits(context, params_i_vec, params_r_vec, pstream__);
params_r.resize(params_r_vec.size());
for (int i = 0; i < params_r.size(); ++i)
params_r(i) = params_r_vec[i];
}
};
}
typedef slowdown_model_namespace::slowdown_model stan_model;
#ifndef USING_R
// Boilerplate
stan::model::model_base& new_model(
stan::io::var_context& data_context,
unsigned int seed,
std::ostream* msg_stream) {
stan_model* m = new stan_model(data_context, seed, msg_stream);
return *m;
}
#endif