#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#include <rstan/rstaninc.hpp>
#ifndef USE_STANC3
#define USE_STANC3
#endif
// Code generated by stanc v2.26.1-1-g67504470
#include <stan/model/model_header.hpp>
namespace model5db02a5e1a95__namespace {
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 std::pow;
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;
using stan::math::pow; 
stan::math::profile_map profiles__;
static int current_statement__= 0;
static const std::vector<string> locations_array__ = {" (found before start of program)",
                                                      " (in 'string', line 12, column 2 to column 10)",
                                                      " (in 'string', line 13, column 2 to column 10)",
                                                      " (in 'string', line 14, column 2 to column 18)",
                                                      " (in 'string', line 15, column 2 to column 20)",
                                                      " (in 'string', line 19, column 4 to column 41)",
                                                      " (in 'string', line 18, column 17 to line 20, column 3)",
                                                      " (in 'string', line 18, column 2 to line 20, column 3)",
                                                      " (in 'string', line 22, column 4 to column 61)",
                                                      " (in 'string', line 21, column 21 to line 23, column 3)",
                                                      " (in 'string', line 21, column 2 to line 23, column 3)",
                                                      " (in 'string', line 24, column 2 to column 46)",
                                                      " (in 'string', line 3, column 2 to column 17)",
                                                      " (in 'string', line 4, column 9 to column 10)",
                                                      " (in 'string', line 4, column 2 to column 12)",
                                                      " (in 'string', line 5, column 9 to column 10)",
                                                      " (in 'string', line 5, column 2 to column 12)",
                                                      " (in 'string', line 6, column 2 to column 21)",
                                                      " (in 'string', line 7, column 2 to column 13)",
                                                      " (in 'string', line 8, column 13 to column 18)",
                                                      " (in 'string', line 8, column 2 to column 20)"};
class model5db02a5e1a95_ final : public model_base_crtp<model5db02a5e1a95_> {
private:
  int n;
  std::vector<double> y;
  std::vector<double> x;
  int ncens;
  double ycens;
  std::vector<double> xcens;
 
public:
  ~model5db02a5e1a95_() { }
  
  inline std::string model_name() const final { return "model5db02a5e1a95_"; }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.26.1-1-g67504470", "stancflags = "};
  }
  
  
  model5db02a5e1a95_(stan::io::var_context& context__,
                     unsigned int random_seed__ = 0,
                     std::ostream* pstream__ = nullptr) : model_base_crtp(0) {
    using local_scalar_t__ = double ;
    boost::ecuyer1988 base_rng__ = 
        stan::services::util::create_rng(random_seed__, 0);
    (void) base_rng__;  // suppress unused var warning
    static const char* function__ = "model5db02a5e1a95__namespace::model5db02a5e1a95_";
    (void) function__;  // suppress unused var warning
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    (void) DUMMY_VAR__;  // suppress unused var warning
    
    try {
      int pos__;
      pos__ = std::numeric_limits<int>::min();
      
      pos__ = 1;
      current_statement__ = 12;
      context__.validate_dims("data initialization","n","int",
          context__.to_vec());
      n = std::numeric_limits<int>::min();
      
      current_statement__ = 12;
      n = context__.vals_i("n")[(1 - 1)];
      current_statement__ = 12;
      current_statement__ = 12;
      check_greater_or_equal(function__, "n", n, 1);
      current_statement__ = 13;
      validate_non_negative_index("y", "n", n);
      current_statement__ = 14;
      context__.validate_dims("data initialization","y","double",
          context__.to_vec(n));
      y = std::vector<double>(n, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 14;
      assign(y, nil_index_list(), context__.vals_r("y"),
        "assigning variable y");
      current_statement__ = 15;
      validate_non_negative_index("x", "n", n);
      current_statement__ = 16;
      context__.validate_dims("data initialization","x","double",
          context__.to_vec(n));
      x = std::vector<double>(n, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 16;
      assign(x, nil_index_list(), context__.vals_r("x"),
        "assigning variable x");
      current_statement__ = 17;
      context__.validate_dims("data initialization","ncens","int",
          context__.to_vec());
      ncens = std::numeric_limits<int>::min();
      
      current_statement__ = 17;
      ncens = context__.vals_i("ncens")[(1 - 1)];
      current_statement__ = 17;
      current_statement__ = 17;
      check_greater_or_equal(function__, "ncens", ncens, 1);
      current_statement__ = 18;
      context__.validate_dims("data initialization","ycens","double",
          context__.to_vec());
      ycens = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 18;
      ycens = context__.vals_r("ycens")[(1 - 1)];
      current_statement__ = 19;
      validate_non_negative_index("xcens", "ncens", ncens);
      current_statement__ = 20;
      context__.validate_dims("data initialization","xcens","double",
          context__.to_vec(ncens));
      xcens = std::vector<double>(ncens, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 20;
      assign(xcens, nil_index_list(), context__.vals_r("xcens"),
        "assigning variable xcens");
    } 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;
      num_params_r__ += 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 VecR, typename VecI, stan::require_vector_like_t<VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline stan::scalar_type_t<VecR> log_prob_impl(VecR& params_r__,
                                                 VecI& params_i__,
                                                 std::ostream* pstream__ = nullptr) const {
    using T__ = stan::scalar_type_t<VecR>;
    using local_scalar_t__ = T__;
    T__ lp__(0.0);
    stan::math::accumulator<T__> lp_accum__;
    static const char* function__ = "model5db02a5e1a95__namespace::log_prob";
(void) function__;  // suppress unused var warning
    stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    (void) DUMMY_VAR__;  // suppress unused var warning
    
    try {
      local_scalar_t__ b0;
      b0 = DUMMY_VAR__;
      
      current_statement__ = 1;
      b0 = in__.scalar();
      local_scalar_t__ b1;
      b1 = DUMMY_VAR__;
      
      current_statement__ = 2;
      b1 = in__.scalar();
      local_scalar_t__ s;
      s = DUMMY_VAR__;
      
      current_statement__ = 3;
      s = in__.scalar();
      current_statement__ = 3;
      if (jacobian__) {
        current_statement__ = 3;
        s = stan::math::lb_constrain(s, 0, lp__);
      } else {
        current_statement__ = 3;
        s = stan::math::lb_constrain(s, 0);
      }
      local_scalar_t__ v;
      v = DUMMY_VAR__;
      
      current_statement__ = 4;
      v = in__.scalar();
      current_statement__ = 4;
      if (jacobian__) {
        current_statement__ = 4;
        v = stan::math::lb_constrain(v, 0.5, lp__);
      } else {
        current_statement__ = 4;
        v = stan::math::lb_constrain(v, 0.5);
      }
      {
        current_statement__ = 7;
        for (int i = 1; i <= n; ++i) {
          current_statement__ = 5;
          lp_accum__.add(
            student_t_lpdf<propto__>(y[(i - 1)], v, (b0 + (b1 * x[(i - 1)])),
              s));}
        current_statement__ = 10;
        for (int i = 1; i <= ncens; ++i) {
          current_statement__ = 8;
          lp_accum__.add(
            student_t_lcdf(ycens, v, (b0 + (b1 * xcens[(i - 1)])), s));}
        current_statement__ = 11;
        lp_accum__.add(
          ((stan::math::log(v) - (3 * stan::math::log((v + 0.75)))) -
            (2 * stan::math::log(s))));
      }
    } 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_impl() 
    
  template <typename RNG, typename VecR, typename VecI, typename VecVar, stan::require_vector_like_vt<std::is_floating_point, VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr, stan::require_std_vector_vt<std::is_floating_point, VecVar>* = nullptr>
  inline void write_array_impl(RNG& base_rng__, VecR& params_r__,
                               VecI& params_i__, VecVar& vars__,
                               const bool emit_transformed_parameters__ = true,
                               const bool emit_generated_quantities__ = true,
                               std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    vars__.resize(0);
    stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
    static const char* function__ = "model5db02a5e1a95__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__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    (void) DUMMY_VAR__;  // suppress unused var warning
    
    try {
      double b0;
      b0 = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 1;
      b0 = in__.scalar();
      double b1;
      b1 = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 2;
      b1 = in__.scalar();
      double s;
      s = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      s = in__.scalar();
      current_statement__ = 3;
      s = stan::math::lb_constrain(s, 0);
      double v;
      v = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 4;
      v = in__.scalar();
      current_statement__ = 4;
      v = stan::math::lb_constrain(v, 0.5);
      vars__.emplace_back(b0);
      vars__.emplace_back(b1);
      vars__.emplace_back(s);
      vars__.emplace_back(v);
      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_impl() 
    
  template <typename VecVar, typename VecI, stan::require_std_vector_t<VecVar>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void transform_inits_impl(const stan::io::var_context& context__,
                                   VecI& params_i__, VecVar& vars__,
                                   std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    vars__.clear();
    vars__.reserve(num_params_r__);
    
    try {
      int pos__;
      pos__ = std::numeric_limits<int>::min();
      
      pos__ = 1;
      double b0;
      b0 = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 1;
      b0 = context__.vals_r("b0")[(1 - 1)];
      double b1;
      b1 = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 2;
      b1 = context__.vals_r("b1")[(1 - 1)];
      double s;
      s = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      s = context__.vals_r("s")[(1 - 1)];
      double s_free__;
      s_free__ = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      s_free__ = stan::math::lb_free(s, 0);
      double v;
      v = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 4;
      v = context__.vals_r("v")[(1 - 1)];
      double v_free__;
      v_free__ = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 4;
      v_free__ = stan::math::lb_free(v, 0.5);
      vars__.emplace_back(b0);
      vars__.emplace_back(b1);
      vars__.emplace_back(s_free__);
      vars__.emplace_back(v_free__);
    } 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_impl() 
    
  inline void get_param_names(std::vector<std::string>& names__) const {
    
    names__.clear();
    names__.emplace_back("b0");
    names__.emplace_back("b1");
    names__.emplace_back("s");
    names__.emplace_back("v");
    } // get_param_names() 
    
  inline void get_dims(std::vector<std::vector<size_t>>& dimss__) const {
    dimss__.clear();
    dimss__.emplace_back(std::vector<size_t>{});
    
    dimss__.emplace_back(std::vector<size_t>{});
    
    dimss__.emplace_back(std::vector<size_t>{});
    
    dimss__.emplace_back(std::vector<size_t>{});
    
    } // get_dims() 
    
  inline void constrained_param_names(
                                      std::vector<std::string>& param_names__,
                                      bool emit_transformed_parameters__ = true,
                                      bool emit_generated_quantities__ = true) const
    final {
    
    param_names__.emplace_back(std::string() + "b0");
    param_names__.emplace_back(std::string() + "b1");
    param_names__.emplace_back(std::string() + "s");
    param_names__.emplace_back(std::string() + "v");
    if (emit_transformed_parameters__) {
      
    }
    
    if (emit_generated_quantities__) {
      
    }
    
    } // constrained_param_names() 
    
  inline void unconstrained_param_names(
                                        std::vector<std::string>& param_names__,
                                        bool emit_transformed_parameters__ = true,
                                        bool emit_generated_quantities__ = true) const
    final {
    
    param_names__.emplace_back(std::string() + "b0");
    param_names__.emplace_back(std::string() + "b1");
    param_names__.emplace_back(std::string() + "s");
    param_names__.emplace_back(std::string() + "v");
    if (emit_transformed_parameters__) {
      
    }
    
    if (emit_generated_quantities__) {
      
    }
    
    } // unconstrained_param_names() 
    
  inline std::string get_constrained_sizedtypes() const {
    stringstream s__;
    s__ << "[{\"name\":\"b0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"b1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"s\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"v\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]";
    return s__.str();
    } // get_constrained_sizedtypes() 
    
  inline std::string get_unconstrained_sizedtypes() const {
    stringstream s__;
    s__ << "[{\"name\":\"b0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"b1\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"s\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"v\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]";
    return s__.str();
    } // get_unconstrained_sizedtypes() 
    
  
    // Begin method overload boilerplate
    template <typename RNG>
    inline void write_array(RNG& base_rng,
                            Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
                            Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
                            const bool emit_transformed_parameters = true,
                            const bool emit_generated_quantities = true,
                            std::ostream* pstream = nullptr) const {
      std::vector<double> vars_vec(vars.size());
      std::vector<int> params_i;
      write_array_impl(base_rng, params_r, params_i, vars_vec,
          emit_transformed_parameters, emit_generated_quantities, pstream);
      vars.resize(vars_vec.size());
      for (int i = 0; i < vars.size(); ++i) {
        vars.coeffRef(i) = vars_vec[i];
      }
    }
    template <typename RNG>
    inline 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 = nullptr) const {
      write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream);
    }
    template <bool propto__, bool jacobian__, typename T_>
    inline T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
                       std::ostream* pstream = nullptr) const {
      Eigen::Matrix<int, -1, 1> params_i;
      return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
    }
    template <bool propto__, bool jacobian__, typename T__>
    inline T__ log_prob(std::vector<T__>& params_r,
                        std::vector<int>& params_i,
                        std::ostream* pstream = nullptr) const {
      return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
    }
  
    inline void transform_inits(const stan::io::var_context& context,
                         Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
                         std::ostream* pstream = nullptr) const final {
      std::vector<double> params_r_vec(params_r.size());
      std::vector<int> params_i;
      transform_inits_impl(context, params_i, params_r_vec, pstream);
      params_r.resize(params_r_vec.size());
      for (int i = 0; i < params_r.size(); ++i) {
        params_r.coeffRef(i) = params_r_vec[i];
      }
    }
    inline void transform_inits(const stan::io::var_context& context,
                                std::vector<int>& params_i,
                                std::vector<double>& vars,
                                std::ostream* pstream = nullptr) const final {
      transform_inits_impl(context, params_i, vars, pstream);
    }        
};
}
using stan_model = model5db02a5e1a95__namespace::model5db02a5e1a95_;
#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;
}
stan::math::profile_map& get_stan_profile_data() {
  return model5db02a5e1a95__namespace::profiles__;
}
#endif
#endif