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

/*
    boundIRT 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.

    boundIRT 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 boundIRT.  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_NormalIRT_inf_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 88> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 17, column 2 to column 18)",
  " (in 'string', line 18, column 2 to column 19)",
  " (in 'string', line 19, column 2 to column 21)",
  " (in 'string', line 20, column 2 to column 23)",
  " (in 'string', line 21, column 2 to column 24)",
  " (in 'string', line 22, column 2 to column 23)",
  " (in 'string', line 25, column 2 to column 45)",
  " (in 'string', line 26, column 2 to column 41)",
  " (in 'string', line 27, column 2 to column 26)",
  " (in 'string', line 28, column 2 to column 26)",
  " (in 'string', line 30, column 23 to column 42)",
  " (in 'string', line 30, column 4 to column 42)",
  " (in 'string', line 31, column 23 to column 58)",
  " (in 'string', line 31, column 4 to column 58)",
  " (in 'string', line 32, column 22 to column 40)",
  " (in 'string', line 32, column 4 to column 40)",
  " (in 'string', line 33, column 22 to column 56)",
  " (in 'string', line 33, column 4 to column 56)",
  " (in 'string', line 29, column 17 to line 34, column 3)",
  " (in 'string', line 29, column 2 to line 34, column 3)",
  " (in 'string', line 38, column 23 to column 56)",
  " (in 'string', line 38, column 4 to column 56)",
  " (in 'string', line 39, column 22 to column 72)",
  " (in 'string', line 39, column 55 to column 69)",
  " (in 'string', line 39, column 4 to column 72)",
  " (in 'string', line 37, column 17 to line 40, column 3)",
  " (in 'string', line 37, column 2 to line 40, column 3)",
  " (in 'string', line 41, column 2 to column 21)",
  " (in 'string', line 42, column 2 to column 22)",
  " (in 'string', line 43, column 2 to column 24)",
  " (in 'string', line 44, column 2 to column 21)",
  " (in 'string', line 47, column 9 to column 35)",
  " (in 'string', line 66, column 14 to column 51)",
  " (in 'string', line 67, column 14 to column 30)",
  " (in 'string', line 65, column 24 to line 68, column 12)",
  " (in 'string', line 65, column 11 to line 68, column 12)",
  " (in 'string', line 70, column 14 to column 51)",
  " (in 'string', line 71, column 14 to column 32)",
  " (in 'string', line 69, column 24 to line 72, column 12)",
  " (in 'string', line 69, column 11 to line 72, column 12)",
  " (in 'string', line 64, column 13 to line 73, column 10)",
  " (in 'string', line 50, column 13 to column 50)",
  " (in 'string', line 51, column 13 to column 50)",
  " (in 'string', line 52, column 13 to column 32)",
  " (in 'string', line 49, column 46 to line 53, column 12)",
  " (in 'string', line 49, column 11 to line 53, column 12)",
  " (in 'string', line 55, column 12 to column 49)",
  " (in 'string', line 56, column 12 to column 30)",
  " (in 'string', line 54, column 45 to line 57, column 11)",
  " (in 'string', line 54, column 10 to line 57, column 11)",
  " (in 'string', line 59, column 13 to column 50)",
  " (in 'string', line 60, column 13 to column 29)",
  " (in 'string', line 58, column 46 to line 61, column 12)",
  " (in 'string', line 58, column 11 to line 61, column 12)",
  " (in 'string', line 62, column 11 to column 65)",
  " (in 'string', line 48, column 51 to line 63, column 10)",
  " (in 'string', line 48, column 9 to line 73, column 10)",
  " (in 'string', line 46, column 21 to line 74, column 6)",
  " (in 'string', line 46, column 6 to line 74, column 6)",
  " (in 'string', line 45, column 18 to line 75, column 6)",
  " (in 'string', line 45, column 5 to line 75, column 6)",
  " (in 'string', line 2, column 2 to column 17)",
  " (in 'string', line 3, column 2 to column 19)",
  " (in 'string', line 4, column 9 to column 10)",
  " (in 'string', line 4, column 11 to column 14)",
  " (in 'string', line 4, column 2 to column 18)",
  " (in 'string', line 5, column 24 to column 27)",
  " (in 'string', line 5, column 2 to column 29)",
  " (in 'string', line 6, column 23 to column 26)",
  " (in 'string', line 6, column 2 to column 28)",
  " (in 'string', line 7, column 2 to column 22)",
  " (in 'string', line 8, column 2 to column 21)",
  " (in 'string', line 10, column 2 to column 19)",
  " (in 'string', line 11, column 2 to column 19)",
  " (in 'string', line 12, column 2 to column 19)",
  " (in 'string', line 13, column 2 to column 19)",
  " (in 'string', line 14, column 2 to column 19)",
  " (in 'string', line 17, column 9 to column 10)",
  " (in 'string', line 18, column 9 to column 12)",
  " (in 'string', line 19, column 9 to column 12)",
  " (in 'string', line 20, column 9 to column 12)",
  " (in 'string', line 21, column 9 to column 15)",
  " (in 'string', line 22, column 9 to column 14)",
  " (in 'string', line 25, column 18 to column 21)",
  " (in 'string', line 26, column 18 to column 21)",
  " (in 'string', line 27, column 9 to column 12)",
  " (in 'string', line 28, column 9 to column 12)"};
#include <stan_meta_header.hpp>
class model_NormalIRT_inf final : public model_base_crtp<model_NormalIRT_inf> {
private:
  int N;
  int nit;
  Eigen::Matrix<double,-1,-1> z_data__;
  std::vector<int> zero_inf;
  std::vector<int> one_inf;
  int n_zero;
  int n_one;
  double sT;
  double sA;
  double sB;
  double sP;
  double sG;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> z{nullptr, 0, 0};
public:
  ~model_NormalIRT_inf() {}
  model_NormalIRT_inf(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_NormalIRT_inf_namespace::model_NormalIRT_inf";
    // 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__ = 62;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 62;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 62;
      stan::math::check_greater_or_equal(function__, "N", N, 0);
      current_statement__ = 63;
      context__.validate_dims("data initialization", "nit", "int",
        std::vector<size_t>{});
      nit = std::numeric_limits<int>::min();
      current_statement__ = 63;
      nit = context__.vals_i("nit")[(1 - 1)];
      current_statement__ = 63;
      stan::math::check_greater_or_equal(function__, "nit", nit, 0);
      current_statement__ = 64;
      stan::math::validate_non_negative_index("z", "N", N);
      current_statement__ = 65;
      stan::math::validate_non_negative_index("z", "nit", nit);
      current_statement__ = 66;
      context__.validate_dims("data initialization", "z", "double",
        std::vector<size_t>{static_cast<size_t>(N), static_cast<size_t>(nit)});
      z_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, nit,
                   std::numeric_limits<double>::quiet_NaN());
      new (&z) Eigen::Map<Eigen::Matrix<double,-1,-1>>(z_data__.data(), N,
        nit);
      {
        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__ <= nit; ++sym1__) {
          current_statement__ = 66;
          for (int sym2__ = 1; sym2__ <= N; ++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("zero_inf", "nit", nit);
      current_statement__ = 68;
      context__.validate_dims("data initialization", "zero_inf", "int",
        std::vector<size_t>{static_cast<size_t>(nit)});
      zero_inf = std::vector<int>(nit, std::numeric_limits<int>::min());
      current_statement__ = 68;
      zero_inf = context__.vals_i("zero_inf");
      current_statement__ = 68;
      stan::math::check_greater_or_equal(function__, "zero_inf", zero_inf, 0);
      current_statement__ = 69;
      stan::math::validate_non_negative_index("one_inf", "nit", nit);
      current_statement__ = 70;
      context__.validate_dims("data initialization", "one_inf", "int",
        std::vector<size_t>{static_cast<size_t>(nit)});
      one_inf = std::vector<int>(nit, std::numeric_limits<int>::min());
      current_statement__ = 70;
      one_inf = context__.vals_i("one_inf");
      current_statement__ = 70;
      stan::math::check_greater_or_equal(function__, "one_inf", one_inf, 0);
      current_statement__ = 71;
      context__.validate_dims("data initialization", "n_zero", "int",
        std::vector<size_t>{});
      n_zero = std::numeric_limits<int>::min();
      current_statement__ = 71;
      n_zero = context__.vals_i("n_zero")[(1 - 1)];
      current_statement__ = 71;
      stan::math::check_greater_or_equal(function__, "n_zero", n_zero, 0);
      current_statement__ = 72;
      context__.validate_dims("data initialization", "n_one", "int",
        std::vector<size_t>{});
      n_one = std::numeric_limits<int>::min();
      current_statement__ = 72;
      n_one = context__.vals_i("n_one")[(1 - 1)];
      current_statement__ = 72;
      stan::math::check_greater_or_equal(function__, "n_one", n_one, 0);
      current_statement__ = 73;
      context__.validate_dims("data initialization", "sT", "double",
        std::vector<size_t>{});
      sT = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 73;
      sT = context__.vals_r("sT")[(1 - 1)];
      current_statement__ = 73;
      stan::math::check_greater_or_equal(function__, "sT", sT, 0);
      current_statement__ = 74;
      context__.validate_dims("data initialization", "sA", "double",
        std::vector<size_t>{});
      sA = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 74;
      sA = context__.vals_r("sA")[(1 - 1)];
      current_statement__ = 74;
      stan::math::check_greater_or_equal(function__, "sA", sA, 0);
      current_statement__ = 75;
      context__.validate_dims("data initialization", "sB", "double",
        std::vector<size_t>{});
      sB = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 75;
      sB = context__.vals_r("sB")[(1 - 1)];
      current_statement__ = 75;
      stan::math::check_greater_or_equal(function__, "sB", sB, 0);
      current_statement__ = 76;
      context__.validate_dims("data initialization", "sP", "double",
        std::vector<size_t>{});
      sP = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 76;
      sP = context__.vals_r("sP")[(1 - 1)];
      current_statement__ = 76;
      stan::math::check_greater_or_equal(function__, "sP", sP, 0);
      current_statement__ = 77;
      context__.validate_dims("data initialization", "sG", "double",
        std::vector<size_t>{});
      sG = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 77;
      sG = context__.vals_r("sG")[(1 - 1)];
      current_statement__ = 77;
      stan::math::check_greater_or_equal(function__, "sG", sG, 0);
      current_statement__ = 78;
      stan::math::validate_non_negative_index("theta", "N", N);
      current_statement__ = 79;
      stan::math::validate_non_negative_index("beta", "nit", nit);
      current_statement__ = 80;
      stan::math::validate_non_negative_index("ln_phi", "nit", nit);
      current_statement__ = 81;
      stan::math::validate_non_negative_index("ln_alpha", "nit", nit);
      current_statement__ = 82;
      stan::math::validate_non_negative_index("gamma0", "n_zero", n_zero);
      current_statement__ = 83;
      stan::math::validate_non_negative_index("gamma1", "n_one", n_one);
      current_statement__ = 84;
      stan::math::validate_non_negative_index("alpha", "nit", nit);
      current_statement__ = 85;
      stan::math::validate_non_negative_index("phi", "nit", nit);
      current_statement__ = 86;
      stan::math::validate_non_negative_index("gamma0_star", "nit", nit);
      current_statement__ = 87;
      stan::math::validate_non_negative_index("gamma1_star", "nit", nit);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = N + nit + nit + nit + n_zero + n_one;
  }
  inline std::string model_name() const final {
    return "model_NormalIRT_inf";
  }
  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_NormalIRT_inf_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> theta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
      current_statement__ = 1;
      theta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(N);
      Eigen::Matrix<local_scalar_t__,-1,1> beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 2;
      beta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_phi =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 3;
      ln_phi = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 4;
      ln_alpha = in__.template read<
                   Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma0 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_zero, DUMMY_VAR__);
      current_statement__ = 5;
      gamma0 = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_zero);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_one, DUMMY_VAR__);
      current_statement__ = 6;
      gamma1 = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_one);
      Eigen::Matrix<local_scalar_t__,-1,1> alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 7;
      stan::model::assign(alpha, stan::math::exp(ln_alpha),
        "assigning variable alpha");
      Eigen::Matrix<local_scalar_t__,-1,1> phi =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 8;
      stan::model::assign(phi, stan::math::exp(ln_phi),
        "assigning variable phi");
      Eigen::Matrix<local_scalar_t__,-1,1> gamma0_star =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma1_star =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 20;
      for (int i = 1; i <= nit; ++i) {
        current_statement__ = 12;
        if (stan::math::logical_eq(
              stan::model::rvalue(zero_inf, "zero_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 11;
          stan::model::assign(gamma0_star, -10,
            "assigning variable gamma0_star", stan::model::index_uni(i));
        }
        current_statement__ = 14;
        if (stan::math::logical_neq(
              stan::model::rvalue(zero_inf, "zero_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 13;
          stan::model::assign(gamma0_star,
            stan::model::rvalue(gamma0, "gamma0",
              stan::model::index_uni(
                stan::model::rvalue(zero_inf, "zero_inf",
                  stan::model::index_uni(i)))),
            "assigning variable gamma0_star", stan::model::index_uni(i));
        }
        current_statement__ = 16;
        if (stan::math::logical_eq(
              stan::model::rvalue(one_inf, "one_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 15;
          stan::model::assign(gamma1_star, 10,
            "assigning variable gamma1_star", stan::model::index_uni(i));
        }
        current_statement__ = 18;
        if (stan::math::logical_neq(
              stan::model::rvalue(one_inf, "one_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 17;
          stan::model::assign(gamma1_star,
            stan::model::rvalue(gamma1, "gamma1",
              stan::model::index_uni(
                stan::model::rvalue(one_inf, "one_inf",
                  stan::model::index_uni(i)))),
            "assigning variable gamma1_star", stan::model::index_uni(i));
        }
      }
      current_statement__ = 7;
      stan::math::check_greater_or_equal(function__, "alpha", alpha, 0);
      current_statement__ = 8;
      stan::math::check_greater_or_equal(function__, "phi", phi, 0);
      {
        current_statement__ = 27;
        for (int i = 1; i <= nit; ++i) {
          current_statement__ = 22;
          if (stan::math::logical_neq(
                stan::model::rvalue(zero_inf, "zero_inf",
                  stan::model::index_uni(i)), 0)) {
            current_statement__ = 21;
            lp_accum__.add(stan::math::normal_lpdf<propto__>(
                             stan::model::rvalue(gamma0, "gamma0",
                               stan::model::index_uni(
                                 stan::model::rvalue(zero_inf, "zero_inf",
                                   stan::model::index_uni(i)))), 0, sG));
          }
          current_statement__ = 25;
          if (stan::math::logical_neq(
                stan::model::rvalue(one_inf, "one_inf",
                  stan::model::index_uni(i)), 0)) {
            current_statement__ = 23;
            lp_accum__.add(stan::math::normal_lpdf<propto__>(
                             stan::model::rvalue(gamma1, "gamma1",
                               stan::model::index_uni(
                                 stan::model::rvalue(one_inf, "one_inf",
                                   stan::model::index_uni(i)))), 0, sG));
            current_statement__ = 24;
            if (stan::math::logical_lt(
                  stan::model::rvalue(gamma1, "gamma1",
                    stan::model::index_uni(
                      stan::model::rvalue(one_inf, "one_inf",
                        stan::model::index_uni(i)))),
                  stan::model::rvalue(gamma0_star, "gamma0_star",
                    stan::model::index_uni(i)))) {
              current_statement__ = 24;
              lp_accum__.add(stan::math::negative_infinity());
            } else {
              current_statement__ = 24;
              lp_accum__.add(-stan::math::normal_lccdf(
                                stan::model::rvalue(gamma0_star,
                                  "gamma0_star", stan::model::index_uni(i)),
                                0, sG));
            }
          }
        }
        current_statement__ = 28;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(beta, 0, sB));
        current_statement__ = 29;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(ln_phi, 0, sP));
        current_statement__ = 30;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(ln_alpha, 0, sA));
        current_statement__ = 31;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(theta, 0, sT));
        current_statement__ = 61;
        for (int p = 1; p <= N; ++p) {
          current_statement__ = 59;
          for (int i = 1; i <= nit; ++i) {
            local_scalar_t__ at = DUMMY_VAR__;
            current_statement__ = 32;
            at = (stan::model::rvalue(alpha, "alpha",
                    stan::model::index_uni(i))
              *
              stan::model::rvalue(theta, "theta", stan::model::index_uni(p)));
            current_statement__ = 57;
            if ((stan::math::primitive_value(
                   (stan::math::primitive_value(
                      stan::math::logical_neq(
                        stan::model::rvalue(z, "z",
                          stan::model::index_uni(p),
                          stan::model::index_uni(i)), 0)) &&
                   stan::math::primitive_value(
                     stan::math::logical_neq(
                       stan::model::rvalue(z, "z", stan::model::index_uni(p),
                         stan::model::index_uni(i)), 1))))
                &&
                stan::math::primitive_value(
                  stan::math::logical_neq(
                    stan::model::rvalue(z, "z", stan::model::index_uni(p),
                      stan::model::index_uni(i)), -999)))) {
              current_statement__ = 46;
              if ((stan::math::primitive_value(
                     stan::math::logical_neq(
                       stan::model::rvalue(zero_inf, "zero_inf",
                         stan::model::index_uni(i)), 0))
                  &&
                  stan::math::primitive_value(
                    stan::math::logical_neq(
                      stan::model::rvalue(one_inf, "one_inf",
                        stan::model::index_uni(i)), 0)))) {
                local_scalar_t__ p1 = DUMMY_VAR__;
                current_statement__ = 42;
                p1 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma1_star, "gamma1_star",
                          stan::model::index_uni(i)) - at));
                local_scalar_t__ p0 = DUMMY_VAR__;
                current_statement__ = 43;
                p0 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma0_star, "gamma0_star",
                          stan::model::index_uni(i)) - at));
                current_statement__ = 44;
                lp_accum__.add(stan::math::log((p1 - p0)));
              }
              current_statement__ = 50;
              if ((stan::math::primitive_value(
                     stan::math::logical_neq(
                       stan::model::rvalue(zero_inf, "zero_inf",
                         stan::model::index_uni(i)), 0))
                  &&
                  stan::math::primitive_value(
                    stan::math::logical_eq(
                      stan::model::rvalue(one_inf, "one_inf",
                        stan::model::index_uni(i)), 0)))) {
                local_scalar_t__ p0 = DUMMY_VAR__;
                current_statement__ = 47;
                p0 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma0_star, "gamma0_star",
                          stan::model::index_uni(i)) - at));
                current_statement__ = 48;
                lp_accum__.add(stan::math::log1m(p0));
              }
              current_statement__ = 54;
              if ((stan::math::primitive_value(
                     stan::math::logical_eq(
                       stan::model::rvalue(zero_inf, "zero_inf",
                         stan::model::index_uni(i)), 0))
                  &&
                  stan::math::primitive_value(
                    stan::math::logical_neq(
                      stan::model::rvalue(one_inf, "one_inf",
                        stan::model::index_uni(i)), 0)))) {
                local_scalar_t__ p1 = DUMMY_VAR__;
                current_statement__ = 51;
                p1 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma1_star, "gamma1_star",
                          stan::model::index_uni(i)) - at));
                current_statement__ = 52;
                lp_accum__.add(stan::math::log(p1));
              }
              current_statement__ = 55;
              lp_accum__.add(stan::math::normal_lpdf<false>(
                               stan::model::rvalue(z, "z",
                                 stan::model::index_uni(p),
                                 stan::model::index_uni(i)),
                               (stan::model::rvalue(beta, "beta",
                                  stan::model::index_uni(i)) + at),
                               stan::math::sqrt(
                                 stan::model::rvalue(phi, "phi",
                                   stan::model::index_uni(i)))));
            } else {
              current_statement__ = 36;
              if (stan::math::logical_eq(
                    stan::model::rvalue(z, "z", stan::model::index_uni(p),
                      stan::model::index_uni(i)), 0)) {
                local_scalar_t__ p0 = DUMMY_VAR__;
                current_statement__ = 33;
                p0 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma0_star, "gamma0_star",
                          stan::model::index_uni(i)) - at));
                current_statement__ = 34;
                lp_accum__.add(stan::math::log(p0));
              }
              current_statement__ = 40;
              if (stan::math::logical_eq(
                    stan::model::rvalue(z, "z", stan::model::index_uni(p),
                      stan::model::index_uni(i)), 1)) {
                local_scalar_t__ p1 = DUMMY_VAR__;
                current_statement__ = 37;
                p1 = stan::math::inv_logit(
                       (stan::model::rvalue(gamma1_star, "gamma1_star",
                          stan::model::index_uni(i)) - at));
                current_statement__ = 38;
                lp_accum__.add(stan::math::log1m(p1));
              }
            }
          }
        }
      }
    } 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_NormalIRT_inf_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,1> theta =
        Eigen::Matrix<double,-1,1>::Constant(N,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      theta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(N);
      Eigen::Matrix<double,-1,1> beta =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      beta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<double,-1,1> ln_phi =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      ln_phi = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<double,-1,1> ln_alpha =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 4;
      ln_alpha = in__.template read<
                   Eigen::Matrix<local_scalar_t__,-1,1>>(nit);
      Eigen::Matrix<double,-1,1> gamma0 =
        Eigen::Matrix<double,-1,1>::Constant(n_zero,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 5;
      gamma0 = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_zero);
      Eigen::Matrix<double,-1,1> gamma1 =
        Eigen::Matrix<double,-1,1>::Constant(n_one,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 6;
      gamma1 = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_one);
      Eigen::Matrix<double,-1,1> alpha =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> phi =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> gamma0_star =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> gamma1_star =
        Eigen::Matrix<double,-1,1>::Constant(nit,
          std::numeric_limits<double>::quiet_NaN());
      out__.write(theta);
      out__.write(beta);
      out__.write(ln_phi);
      out__.write(ln_alpha);
      out__.write(gamma0);
      out__.write(gamma1);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 7;
      stan::model::assign(alpha, stan::math::exp(ln_alpha),
        "assigning variable alpha");
      current_statement__ = 8;
      stan::model::assign(phi, stan::math::exp(ln_phi),
        "assigning variable phi");
      current_statement__ = 20;
      for (int i = 1; i <= nit; ++i) {
        current_statement__ = 12;
        if (stan::math::logical_eq(
              stan::model::rvalue(zero_inf, "zero_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 11;
          stan::model::assign(gamma0_star, -10,
            "assigning variable gamma0_star", stan::model::index_uni(i));
        }
        current_statement__ = 14;
        if (stan::math::logical_neq(
              stan::model::rvalue(zero_inf, "zero_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 13;
          stan::model::assign(gamma0_star,
            stan::model::rvalue(gamma0, "gamma0",
              stan::model::index_uni(
                stan::model::rvalue(zero_inf, "zero_inf",
                  stan::model::index_uni(i)))),
            "assigning variable gamma0_star", stan::model::index_uni(i));
        }
        current_statement__ = 16;
        if (stan::math::logical_eq(
              stan::model::rvalue(one_inf, "one_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 15;
          stan::model::assign(gamma1_star, 10,
            "assigning variable gamma1_star", stan::model::index_uni(i));
        }
        current_statement__ = 18;
        if (stan::math::logical_neq(
              stan::model::rvalue(one_inf, "one_inf",
                stan::model::index_uni(i)), 0)) {
          current_statement__ = 17;
          stan::model::assign(gamma1_star,
            stan::model::rvalue(gamma1, "gamma1",
              stan::model::index_uni(
                stan::model::rvalue(one_inf, "one_inf",
                  stan::model::index_uni(i)))),
            "assigning variable gamma1_star", stan::model::index_uni(i));
        }
      }
      current_statement__ = 7;
      stan::math::check_greater_or_equal(function__, "alpha", alpha, 0);
      current_statement__ = 8;
      stan::math::check_greater_or_equal(function__, "phi", phi, 0);
      if (emit_transformed_parameters__) {
        out__.write(alpha);
        out__.write(phi);
        out__.write(gamma0_star);
        out__.write(gamma1_star);
      }
      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> theta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(theta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(N),
        "assigning variable theta");
      out__.write(theta);
      Eigen::Matrix<local_scalar_t__,-1,1> beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(beta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit),
        "assigning variable beta");
      out__.write(beta);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_phi =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(ln_phi,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit),
        "assigning variable ln_phi");
      out__.write(ln_phi);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(ln_alpha,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(nit),
        "assigning variable ln_alpha");
      out__.write(ln_alpha);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma0 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_zero, DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(gamma0,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(n_zero),
        "assigning variable gamma0");
      out__.write(gamma0);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_one, DUMMY_VAR__);
      current_statement__ = 6;
      stan::model::assign(gamma1,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(n_one),
        "assigning variable gamma1");
      out__.write(gamma1);
    } 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", "theta", "double",
        std::vector<size_t>{static_cast<size_t>(N)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "beta", "double",
        std::vector<size_t>{static_cast<size_t>(nit)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "ln_phi", "double",
        std::vector<size_t>{static_cast<size_t>(nit)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "ln_alpha",
        "double", std::vector<size_t>{static_cast<size_t>(nit)});
      current_statement__ = 5;
      context__.validate_dims("parameter initialization", "gamma0", "double",
        std::vector<size_t>{static_cast<size_t>(n_zero)});
      current_statement__ = 6;
      context__.validate_dims("parameter initialization", "gamma1", "double",
        std::vector<size_t>{static_cast<size_t>(n_one)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> theta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> theta_flat__;
        current_statement__ = 1;
        theta_flat__ = context__.vals_r("theta");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 1;
          stan::model::assign(theta, theta_flat__[(pos__ - 1)],
            "assigning variable theta", stan::model::index_uni(sym1__));
          current_statement__ = 1;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(theta);
      Eigen::Matrix<local_scalar_t__,-1,1> beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> beta_flat__;
        current_statement__ = 2;
        beta_flat__ = context__.vals_r("beta");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
          current_statement__ = 2;
          stan::model::assign(beta, beta_flat__[(pos__ - 1)],
            "assigning variable beta", stan::model::index_uni(sym1__));
          current_statement__ = 2;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(beta);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_phi =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> ln_phi_flat__;
        current_statement__ = 3;
        ln_phi_flat__ = context__.vals_r("ln_phi");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
          current_statement__ = 3;
          stan::model::assign(ln_phi, ln_phi_flat__[(pos__ - 1)],
            "assigning variable ln_phi", stan::model::index_uni(sym1__));
          current_statement__ = 3;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(ln_phi);
      Eigen::Matrix<local_scalar_t__,-1,1> ln_alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nit, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> ln_alpha_flat__;
        current_statement__ = 4;
        ln_alpha_flat__ = context__.vals_r("ln_alpha");
        current_statement__ = 4;
        pos__ = 1;
        current_statement__ = 4;
        for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
          current_statement__ = 4;
          stan::model::assign(ln_alpha, ln_alpha_flat__[(pos__ - 1)],
            "assigning variable ln_alpha", stan::model::index_uni(sym1__));
          current_statement__ = 4;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(ln_alpha);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma0 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_zero, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> gamma0_flat__;
        current_statement__ = 5;
        gamma0_flat__ = context__.vals_r("gamma0");
        current_statement__ = 5;
        pos__ = 1;
        current_statement__ = 5;
        for (int sym1__ = 1; sym1__ <= n_zero; ++sym1__) {
          current_statement__ = 5;
          stan::model::assign(gamma0, gamma0_flat__[(pos__ - 1)],
            "assigning variable gamma0", stan::model::index_uni(sym1__));
          current_statement__ = 5;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(gamma0);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_one, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> gamma1_flat__;
        current_statement__ = 6;
        gamma1_flat__ = context__.vals_r("gamma1");
        current_statement__ = 6;
        pos__ = 1;
        current_statement__ = 6;
        for (int sym1__ = 1; sym1__ <= n_one; ++sym1__) {
          current_statement__ = 6;
          stan::model::assign(gamma1, gamma1_flat__[(pos__ - 1)],
            "assigning variable gamma1", stan::model::index_uni(sym1__));
          current_statement__ = 6;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(gamma1);
    } 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>{"theta", "beta", "ln_phi", "ln_alpha",
                "gamma0", "gamma1"};
    if (emit_transformed_parameters__) {
      std::vector<std::string>
        temp{"alpha", "phi", "gamma0_star", "gamma1_star"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    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>(N)},
                std::vector<size_t>{static_cast<size_t>(nit)},
                std::vector<size_t>{static_cast<size_t>(nit)},
                std::vector<size_t>{static_cast<size_t>(nit)},
                std::vector<size_t>{static_cast<size_t>(n_zero)},
                std::vector<size_t>{static_cast<size_t>(n_one)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(nit)},
             std::vector<size_t>{static_cast<size_t>(nit)},
             std::vector<size_t>{static_cast<size_t>(nit)},
             std::vector<size_t>{static_cast<size_t>(nit)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
    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__ <= N; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "beta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "ln_phi" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "ln_alpha" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_zero; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma0" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_one; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma1" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "phi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma0_star" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma1_star" + '.' +
          std::to_string(sym1__));
      }
    }
    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__ <= N; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "beta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "ln_phi" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
      param_names__.emplace_back(std::string() + "ln_alpha" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_zero; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma0" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_one; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma1" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "phi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma0_star" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nit; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma1_star" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {}
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"theta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"ln_phi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"ln_alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"gamma0\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_zero) + "},\"block\":\"parameters\"},{\"name\":\"gamma1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_one) + "},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma0_star\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma1_star\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"theta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"ln_phi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"ln_alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"parameters\"},{\"name\":\"gamma0\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_zero) + "},\"block\":\"parameters\"},{\"name\":\"gamma1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_one) + "},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma0_star\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma1_star\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nit) + "},\"block\":\"transformed_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__ = (((((N + nit) + nit) + nit) + n_zero) +
      n_one);
    const size_t num_transformed = emit_transformed_parameters * ((((nit +
      nit) + nit) + nit));
    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__ = (((((N + nit) + nit) + nit) + n_zero) +
      n_one);
    const size_t num_transformed = emit_transformed_parameters * ((((nit +
      nit) + nit) + nit));
    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_NormalIRT_inf_namespace::model_NormalIRT_inf;
#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_NormalIRT_inf_namespace::profiles__;
}
#endif
#endif
