// Generated by rstantools.  Do not edit by hand.

/*
    glmmr is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    glmmr is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with glmmr.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#ifndef USE_STANC3
#define USE_STANC3
#endif
#include <rstan/rstaninc.hpp>
// Code generated by stanc v2.32.2
#include <stan/model/model_header.hpp>
namespace model_mcml_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 79> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 17, column 2 to column 18)",
  " (in 'string', line 20, column 2 to column 23)",
  " (in 'string', line 59, column 4 to column 53)",
  " (in 'string', line 58, column 21 to line 60, column 3)",
  " (in 'string', line 58, column 9 to line 60, column 3)",
  " (in 'string', line 57, column 4 to column 48)",
  " (in 'string', line 56, column 21 to line 58, column 3)",
  " (in 'string', line 56, column 9 to line 60, column 3)",
  " (in 'string', line 55, column 4 to column 36)",
  " (in 'string', line 54, column 21 to line 56, column 3)",
  " (in 'string', line 54, column 9 to line 60, column 3)",
  " (in 'string', line 53, column 4 to column 41)",
  " (in 'string', line 52, column 21 to line 54, column 3)",
  " (in 'string', line 52, column 9 to line 60, column 3)",
  " (in 'string', line 51, column 4 to column 43)",
  " (in 'string', line 50, column 21 to line 52, column 3)",
  " (in 'string', line 50, column 9 to line 60, column 3)",
  " (in 'string', line 49, column 4 to column 47)",
  " (in 'string', line 48, column 21 to line 50, column 3)",
  " (in 'string', line 48, column 9 to line 60, column 3)",
  " (in 'string', line 47, column 4 to column 35)",
  " (in 'string', line 46, column 20 to line 48, column 3)",
  " (in 'string', line 46, column 9 to line 60, column 3)",
  " (in 'string', line 45, column 4 to column 40)",
  " (in 'string', line 44, column 21 to line 46, column 3)",
  " (in 'string', line 44, column 9 to line 60, column 3)",
  " (in 'string', line 43, column 4 to column 57)",
  " (in 'string', line 42, column 21 to line 44, column 3)",
  " (in 'string', line 42, column 9 to line 60, column 3)",
  " (in 'string', line 41, column 4 to column 73)",
  " (in 'string', line 40, column 20 to line 42, column 3)",
  " (in 'string', line 40, column 9 to line 60, column 3)",
  " (in 'string', line 39, column 4 to column 66)",
  " (in 'string', line 38, column 21 to line 40, column 3)",
  " (in 'string', line 38, column 9 to line 60, column 3)",
  " (in 'string', line 37, column 4 to column 70)",
  " (in 'string', line 36, column 20 to line 38, column 3)",
  " (in 'string', line 36, column 9 to line 60, column 3)",
  " (in 'string', line 28, column 11 to column 42)",
  " (in 'string', line 28, column 4 to column 62)",
  " (in 'string', line 29, column 11 to column 17)",
  " (in 'string', line 29, column 4 to column 27)",
  " (in 'string', line 30, column 11 to column 17)",
  " (in 'string', line 30, column 4 to column 28)",
  " (in 'string', line 32, column 6 to column 45)",
  " (in 'string', line 33, column 6 to column 35)",
  " (in 'string', line 31, column 22 to line 34, column 5)",
  " (in 'string', line 31, column 4 to line 34, column 5)",
  " (in 'string', line 35, column 4 to column 65)",
  " (in 'string', line 27, column 22 to line 36, column 3)",
  " (in 'string', line 27, column 9 to line 60, column 3)",
  " (in 'string', line 26, column 4 to column 56)",
  " (in 'string', line 25, column 22 to line 27, column 3)",
  " (in 'string', line 25, column 9 to line 60, column 3)",
  " (in 'string', line 24, column 4 to column 69)",
  " (in 'string', line 23, column 15 to line 25, column 3)",
  " (in 'string', line 23, column 2 to line 60, column 3)",
  " (in 'string', line 2, column 2 to column 13)",
  " (in 'string', line 3, column 2 to column 12)",
  " (in 'string', line 4, column 2 to column 14)",
  " (in 'string', line 5, column 2 to column 8)",
  " (in 'string', line 6, column 9 to column 40)",
  " (in 'string', line 6, column 2 to column 45)",
  " (in 'string', line 7, column 9 to column 40)",
  " (in 'string', line 7, column 41 to column 42)",
  " (in 'string', line 7, column 2 to column 46)",
  " (in 'string', line 8, column 8 to column 14)",
  " (in 'string', line 8, column 2 to column 27)",
  " (in 'string', line 9, column 8 to column 13)",
  " (in 'string', line 9, column 2 to column 24)",
  " (in 'string', line 10, column 9 to column 15)",
  " (in 'string', line 10, column 2 to column 23)",
  " (in 'string', line 11, column 8 to column 15)",
  " (in 'string', line 11, column 2 to column 23)",
  " (in 'string', line 12, column 2 to column 31)",
  " (in 'string', line 13, column 2 to column 11)",
  " (in 'string', line 14, column 2 to column 19)",
  " (in 'string', line 17, column 9 to column 10)"};
#include <stan_meta_header.hpp>
class model_mcml final : public model_base_crtp<model_mcml> {
private:
  int N_cont;
  int N_int;
  int N_binom;
  int Q;
  Eigen::Matrix<double,-1,1> Xb_data__;
  Eigen::Matrix<double,-1,-1> Z_data__;
  std::vector<double> ycont;
  std::vector<int> yint;
  Eigen::Matrix<double,-1,1> sigma_data__;
  std::vector<int> n;
  double q;
  int type;
  double constr_zero;
  Eigen::Map<Eigen::Matrix<double,-1,1>> Xb{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Z{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> sigma{nullptr, 0};
public:
  ~model_mcml() {}
  model_mcml(stan::io::var_context& context__, unsigned int
             random_seed__ = 0, std::ostream* pstream__ = nullptr)
      : model_base_crtp(0) {
    int current_statement__ = 0;
    using local_scalar_t__ = double;
    boost::ecuyer1988 base_rng__ =
      stan::services::util::create_rng(random_seed__, 0);
    // suppress unused var warning
    (void) base_rng__;
    static constexpr const char* function__ =
      "model_mcml_namespace::model_mcml";
    // suppress unused var warning
    (void) function__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      current_statement__ = 58;
      context__.validate_dims("data initialization", "N_cont", "int",
        std::vector<size_t>{});
      N_cont = std::numeric_limits<int>::min();
      current_statement__ = 58;
      N_cont = context__.vals_i("N_cont")[(1 - 1)];
      current_statement__ = 59;
      context__.validate_dims("data initialization", "N_int", "int",
        std::vector<size_t>{});
      N_int = std::numeric_limits<int>::min();
      current_statement__ = 59;
      N_int = context__.vals_i("N_int")[(1 - 1)];
      current_statement__ = 60;
      context__.validate_dims("data initialization", "N_binom", "int",
        std::vector<size_t>{});
      N_binom = std::numeric_limits<int>::min();
      current_statement__ = 60;
      N_binom = context__.vals_i("N_binom")[(1 - 1)];
      current_statement__ = 61;
      context__.validate_dims("data initialization", "Q", "int",
        std::vector<size_t>{});
      Q = std::numeric_limits<int>::min();
      current_statement__ = 61;
      Q = context__.vals_i("Q")[(1 - 1)];
      current_statement__ = 62;
      stan::math::validate_non_negative_index("Xb",
        "N_cont > N_int ? N_cont : N_int",
        (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int));
      current_statement__ = 63;
      context__.validate_dims("data initialization", "Xb", "double",
        std::vector<size_t>{static_cast<size_t>(
                              (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int))});
      Xb_data__ = Eigen::Matrix<double,-1,1>::Constant((stan::math::logical_gt(
                                                          N_cont, N_int) ? N_cont : N_int),
                    std::numeric_limits<double>::quiet_NaN());
      new (&Xb) Eigen::Map<Eigen::Matrix<double,-1,1>>(Xb_data__.data(),
        (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int));
      {
        std::vector<local_scalar_t__> Xb_flat__;
        current_statement__ = 63;
        Xb_flat__ = context__.vals_r("Xb");
        current_statement__ = 63;
        pos__ = 1;
        current_statement__ = 63;
        for (int sym1__ = 1; sym1__ <=
             (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int); ++sym1__) {
          current_statement__ = 63;
          stan::model::assign(Xb, Xb_flat__[(pos__ - 1)],
            "assigning variable Xb", stan::model::index_uni(sym1__));
          current_statement__ = 63;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 64;
      stan::math::validate_non_negative_index("Z",
        "N_cont > N_int ? N_cont : N_int",
        (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int));
      current_statement__ = 65;
      stan::math::validate_non_negative_index("Z", "Q", Q);
      current_statement__ = 66;
      context__.validate_dims("data initialization", "Z", "double",
        std::vector<size_t>{static_cast<size_t>(
                              (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int)),
          static_cast<size_t>(Q)});
      Z_data__ = Eigen::Matrix<double,-1,-1>::Constant((stan::math::logical_gt(
                                                          N_cont, N_int) ? N_cont : N_int),
                   Q, std::numeric_limits<double>::quiet_NaN());
      new (&Z) Eigen::Map<Eigen::Matrix<double,-1,-1>>(Z_data__.data(),
        (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int), Q);
      {
        std::vector<local_scalar_t__> Z_flat__;
        current_statement__ = 66;
        Z_flat__ = context__.vals_r("Z");
        current_statement__ = 66;
        pos__ = 1;
        current_statement__ = 66;
        for (int sym1__ = 1; sym1__ <= Q; ++sym1__) {
          current_statement__ = 66;
          for (int sym2__ = 1; sym2__ <=
               (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int); ++sym2__) {
            current_statement__ = 66;
            stan::model::assign(Z, Z_flat__[(pos__ - 1)],
              "assigning variable Z", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 66;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 67;
      stan::math::validate_non_negative_index("ycont", "N_cont", N_cont);
      current_statement__ = 68;
      context__.validate_dims("data initialization", "ycont", "double",
        std::vector<size_t>{static_cast<size_t>(N_cont)});
      ycont = std::vector<double>(N_cont,
                std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 68;
      ycont = context__.vals_r("ycont");
      current_statement__ = 69;
      stan::math::validate_non_negative_index("yint", "N_int", N_int);
      current_statement__ = 70;
      context__.validate_dims("data initialization", "yint", "int",
        std::vector<size_t>{static_cast<size_t>(N_int)});
      yint = std::vector<int>(N_int, std::numeric_limits<int>::min());
      current_statement__ = 70;
      yint = context__.vals_i("yint");
      current_statement__ = 71;
      stan::math::validate_non_negative_index("sigma", "N_cont", N_cont);
      current_statement__ = 72;
      context__.validate_dims("data initialization", "sigma", "double",
        std::vector<size_t>{static_cast<size_t>(N_cont)});
      sigma_data__ = Eigen::Matrix<double,-1,1>::Constant(N_cont,
                       std::numeric_limits<double>::quiet_NaN());
      new (&sigma)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(sigma_data__.data(), N_cont);
      {
        std::vector<local_scalar_t__> sigma_flat__;
        current_statement__ = 72;
        sigma_flat__ = context__.vals_r("sigma");
        current_statement__ = 72;
        pos__ = 1;
        current_statement__ = 72;
        for (int sym1__ = 1; sym1__ <= N_cont; ++sym1__) {
          current_statement__ = 72;
          stan::model::assign(sigma, sigma_flat__[(pos__ - 1)],
            "assigning variable sigma", stan::model::index_uni(sym1__));
          current_statement__ = 72;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 73;
      stan::math::validate_non_negative_index("n", "N_binom", N_binom);
      current_statement__ = 74;
      context__.validate_dims("data initialization", "n", "int",
        std::vector<size_t>{static_cast<size_t>(N_binom)});
      n = std::vector<int>(N_binom, std::numeric_limits<int>::min());
      current_statement__ = 74;
      n = context__.vals_i("n");
      current_statement__ = 75;
      context__.validate_dims("data initialization", "q", "double",
        std::vector<size_t>{});
      q = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 75;
      q = context__.vals_r("q")[(1 - 1)];
      current_statement__ = 75;
      stan::math::check_greater_or_equal(function__, "q", q, 0);
      current_statement__ = 75;
      stan::math::check_less_or_equal(function__, "q", q, 1);
      current_statement__ = 76;
      context__.validate_dims("data initialization", "type", "int",
        std::vector<size_t>{});
      type = std::numeric_limits<int>::min();
      current_statement__ = 76;
      type = context__.vals_i("type")[(1 - 1)];
      current_statement__ = 77;
      context__.validate_dims("data initialization", "constr_zero", "double",
        std::vector<size_t>{});
      constr_zero = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 77;
      constr_zero = context__.vals_r("constr_zero")[(1 - 1)];
      current_statement__ = 78;
      stan::math::validate_non_negative_index("gamma", "Q", Q);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = Q;
  }
  inline std::string model_name() const final {
    return "model_mcml";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
             "stancflags = --allow-undefined"};
  }
  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__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model_mcml_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> gamma =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Q, DUMMY_VAR__);
      current_statement__ = 1;
      gamma = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Q);
      {
        current_statement__ = 2;
        lp_accum__.add(stan::math::std_normal_lpdf<propto__>(gamma));
        current_statement__ = 57;
        if (stan::math::logical_eq(type, 1)) {
          current_statement__ = 55;
          lp_accum__.add(stan::math::normal_id_glm_lpdf<propto__>(
                           stan::math::to_vector(ycont), Z, Xb, gamma, sigma));
        } else {
          current_statement__ = 54;
          if (stan::math::logical_eq(type, 2)) {
            current_statement__ = 52;
            lp_accum__.add(stan::math::normal_lpdf<propto__>(
                             stan::math::to_vector(stan::math::log(ycont)),
                             stan::math::add(Xb,
                               stan::math::multiply(Z, gamma)), sigma));
          } else {
            current_statement__ = 51;
            if (stan::math::logical_eq(type, 3)) {
              current_statement__ = 39;
              stan::math::validate_non_negative_index("mu",
                "N_cont > N_int ? N_cont : N_int",
                (stan::math::logical_gt(N_cont, N_int) ? N_cont : N_int));
              Eigen::Matrix<local_scalar_t__,-1,1> mu =
                Eigen::Matrix<local_scalar_t__,-1,1>::Constant((stan::math::logical_gt(
                                                                  N_cont,
                                                                  N_int) ? N_cont : N_int),
                  DUMMY_VAR__);
              current_statement__ = 40;
              stan::model::assign(mu,
                stan::math::add(Xb, stan::math::multiply(Z, gamma)),
                "assigning variable mu");
              current_statement__ = 41;
              stan::math::validate_non_negative_index("logitmu", "N_cont",
                N_cont);
              Eigen::Matrix<local_scalar_t__,-1,1> logitmu =
                Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_cont,
                  DUMMY_VAR__);
              current_statement__ = 43;
              stan::math::validate_non_negative_index("logitmu1", "N_cont",
                N_cont);
              Eigen::Matrix<local_scalar_t__,-1,1> logitmu1 =
                Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_cont,
                  DUMMY_VAR__);
              current_statement__ = 48;
              for (int i = 1; i <= N_cont; ++i) {
                current_statement__ = 45;
                stan::model::assign(logitmu,
                  (stan::math::exp(
                     stan::model::rvalue(mu, "mu", stan::model::index_uni(i)))
                  / (1 +
                  stan::math::exp(
                    stan::model::rvalue(mu, "mu", stan::model::index_uni(i))))),
                  "assigning variable logitmu", stan::model::index_uni(i));
                current_statement__ = 46;
                stan::model::assign(logitmu1, (1 -
                  stan::model::rvalue(logitmu, "logitmu",
                    stan::model::index_uni(i))),
                  "assigning variable logitmu1", stan::model::index_uni(i));
              }
              current_statement__ = 49;
              lp_accum__.add(stan::math::beta_lpdf<propto__>(
                               stan::math::to_vector(ycont),
                               stan::math::multiply(logitmu,
                                 stan::model::rvalue(sigma, "sigma",
                                   stan::model::index_uni(1))),
                               stan::math::multiply(logitmu1,
                                 stan::model::rvalue(sigma, "sigma",
                                   stan::model::index_uni(1)))));
            } else {
              current_statement__ = 38;
              if (stan::math::logical_eq(type, 4)) {
                current_statement__ = 36;
                lp_accum__.add(stan::math::gamma_lpdf<propto__>(
                                 stan::math::to_vector(ycont), (1 /
                                 stan::model::rvalue(sigma, "sigma",
                                   stan::model::index_uni(1))),
                                 stan::math::divide(1,
                                   stan::math::multiply(
                                     stan::model::rvalue(sigma, "sigma",
                                       stan::model::index_uni(1)),
                                     stan::math::add(Xb,
                                       stan::math::multiply(Z, gamma))))));
              } else {
                current_statement__ = 35;
                if (stan::math::logical_eq(type, 5)) {
                  current_statement__ = 33;
                  lp_accum__.add(stan::math::gamma_lpdf<propto__>(
                                   stan::math::to_vector(ycont), (1 /
                                   stan::model::rvalue(sigma, "sigma",
                                     stan::model::index_uni(1))),
                                   stan::math::divide(
                                     stan::math::add(Xb,
                                       stan::math::multiply(Z, gamma)),
                                     stan::model::rvalue(sigma, "sigma",
                                       stan::model::index_uni(1)))));
                } else {
                  current_statement__ = 32;
                  if (stan::math::logical_eq(type, 6)) {
                    current_statement__ = 30;
                    lp_accum__.add(stan::math::gamma_lpdf<propto__>(
                                     stan::math::to_vector(ycont), (1 /
                                     stan::model::rvalue(sigma, "sigma",
                                       stan::model::index_uni(1))),
                                     stan::math::divide(1,
                                       stan::math::multiply(
                                         stan::model::rvalue(sigma, "sigma",
                                           stan::model::index_uni(1)),
                                         stan::math::log(
                                           stan::math::add(Xb,
                                             stan::math::multiply(Z, gamma)))))));
                  } else {
                    current_statement__ = 29;
                    if (stan::math::logical_eq(type, 7)) {
                      current_statement__ = 27;
                      lp_accum__.add(stan::math::bernoulli_logit_glm_lpmf<
                                       propto__>(yint, Z, Xb, gamma));
                    } else {
                      current_statement__ = 26;
                      if (stan::math::logical_eq(type, 8)) {
                        current_statement__ = 24;
                        lp_accum__.add(stan::math::bernoulli_lpmf<propto__>(
                                         yint,
                                         stan::math::exp(
                                           stan::math::add(Xb,
                                             stan::math::multiply(Z, gamma)))));
                      } else {
                        current_statement__ = 23;
                        if (stan::math::logical_eq(type, 9)) {
                          current_statement__ = 21;
                          lp_accum__.add(stan::math::bernoulli_lpmf<
                                           propto__>(yint,
                                           stan::math::add(Xb,
                                             stan::math::multiply(Z, gamma))));
                        } else {
                          current_statement__ = 20;
                          if (stan::math::logical_eq(type, 10)) {
                            current_statement__ = 18;
                            lp_accum__.add(stan::math::bernoulli_lpmf<
                                             propto__>(yint,
                                             stan::math::Phi_approx(
                                               stan::math::add(Xb,
                                                 stan::math::multiply(Z,
                                                   gamma)))));
                          } else {
                            current_statement__ = 17;
                            if (stan::math::logical_eq(type, 11)) {
                              current_statement__ = 15;
                              lp_accum__.add(stan::math::binomial_logit_lpmf<
                                               propto__>(yint, n,
                                               stan::math::add(Xb,
                                                 stan::math::multiply(Z,
                                                   gamma))));
                            } else {
                              current_statement__ = 14;
                              if (stan::math::logical_eq(type, 12)) {
                                current_statement__ = 12;
                                lp_accum__.add(stan::math::binomial_lpmf<
                                                 propto__>(yint, n,
                                                 stan::math::exp(
                                                   stan::math::add(Xb,
                                                     stan::math::multiply(Z,
                                                       gamma)))));
                              } else {
                                current_statement__ = 11;
                                if (stan::math::logical_eq(type, 13)) {
                                  current_statement__ = 9;
                                  lp_accum__.add(stan::math::binomial_lpmf<
                                                   propto__>(yint, n,
                                                   stan::math::add(Xb,
                                                     stan::math::multiply(Z,
                                                       gamma))));
                                } else {
                                  current_statement__ = 8;
                                  if (stan::math::logical_eq(type, 14)) {
                                    current_statement__ = 6;
                                    lp_accum__.add(stan::math::binomial_lpmf<
                                                     propto__>(yint, n,
                                                     stan::math::Phi_approx(
                                                       stan::math::add(Xb,
                                                         stan::math::multiply(
                                                           Z, gamma)))));
                                  } else {
                                    current_statement__ = 5;
                                    if (stan::math::logical_eq(type, 15)) {
                                      current_statement__ = 3;
                                      lp_accum__.add(stan::math::poisson_log_glm_lpmf<
                                                       propto__>(yint, Z, Xb,
                                                       gamma));
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    lp_accum__.add(lp__);
    return lp_accum__.sum();
  }
  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_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;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    static constexpr bool propto__ = true;
    // suppress unused var warning
    (void) propto__;
    double lp__ = 0.0;
    // suppress unused var warning
    (void) lp__;
    int current_statement__ = 0;
    stan::math::accumulator<double> lp_accum__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    constexpr bool jacobian__ = false;
    static constexpr const char* function__ =
      "model_mcml_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,1> gamma =
        Eigen::Matrix<double,-1,1>::Constant(Q,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      gamma = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Q);
      out__.write(gamma);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, typename VecI,
            stan::require_vector_t<VecVar>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void
  unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
                         VecVar& vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> gamma =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Q, DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(gamma,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(Q),
        "assigning variable gamma");
      out__.write(gamma);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
  inline void
  transform_inits_impl(const stan::io::var_context& context__, VecVar&
                       vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      current_statement__ = 1;
      context__.validate_dims("parameter initialization", "gamma", "double",
        std::vector<size_t>{static_cast<size_t>(Q)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> gamma =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Q, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> gamma_flat__;
        current_statement__ = 1;
        gamma_flat__ = context__.vals_r("gamma");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= Q; ++sym1__) {
          current_statement__ = 1;
          stan::model::assign(gamma, gamma_flat__[(pos__ - 1)],
            "assigning variable gamma", stan::model::index_uni(sym1__));
          current_statement__ = 1;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(gamma);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  inline void
  get_param_names(std::vector<std::string>& names__, const bool
                  emit_transformed_parameters__ = true, const bool
                  emit_generated_quantities__ = true) const {
    names__ = std::vector<std::string>{"gamma"};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
           emit_transformed_parameters__ = true, const bool
           emit_generated_quantities__ = true) const {
    dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{static_cast<
                                                                    size_t>(Q)}};
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  constrained_param_names(std::vector<std::string>& param_names__, bool
                          emit_transformed_parameters__ = true, bool
                          emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= Q; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline void
  unconstrained_param_names(std::vector<std::string>& param_names__, bool
                            emit_transformed_parameters__ = true, bool
                            emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= Q; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {}
    if (emit_generated_quantities__) {}
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"gamma\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Q) + "},\"block\":\"parameters\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"gamma\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Q) + "},\"block\":\"parameters\"}]");
  }
  // Begin method overload boilerplate
  template <typename RNG> inline void
  write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
              Eigen::Matrix<double,-1,1>& vars, const bool
              emit_transformed_parameters = true, const bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = Q;
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * (0);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    std::vector<int> params_i;
    vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  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 {
    const size_t num_params__ = Q;
    const size_t num_transformed = emit_transformed_parameters * (0);
    const size_t num_gen_quantities = emit_generated_quantities * (0);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    vars = std::vector<double>(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    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_,-1,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,-1,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(context, params_i, params_r_vec, pstream);
    params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
                 params_r_vec.size());
  }
  inline void
  transform_inits(const stan::io::var_context& context, std::vector<int>&
                  params_i, std::vector<double>& vars, std::ostream*
                  pstream__ = nullptr) const {
    vars.resize(num_params_r__);
    transform_inits_impl(context, vars, pstream__);
  }
  inline void
  unconstrain_array(const std::vector<double>& params_constrained,
                    std::vector<double>& params_unconstrained, std::ostream*
                    pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = std::vector<double>(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
  inline void
  unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
                    Eigen::Matrix<double,-1,1>& params_unconstrained,
                    std::ostream* pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
};
}
using stan_model = model_mcml_namespace::model_mcml;
#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 model_mcml_namespace::profiles__;
}
#endif
#endif
